Qt input: pass QString by reference (#20467)
* simple arry for keyboard layout * revert some changespull/20271/head^2
parent
3d48bd934d
commit
f7957f681d
|
@ -3,7 +3,7 @@
|
|||
#include "input.hpp"
|
||||
#include "qt_window.hpp"
|
||||
|
||||
InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
||||
InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog(parent) {
|
||||
layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(50, 50, 50, 50);
|
||||
layout->setSpacing(20);
|
||||
|
@ -43,7 +43,7 @@ InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
|||
layout->addWidget(line, 1, Qt::AlignTop);
|
||||
|
||||
k = new Keyboard(this);
|
||||
QObject::connect(k, SIGNAL(emitButton(QString)), this, SLOT(handleInput(QString)));
|
||||
QObject::connect(k, SIGNAL(emitButton(const QString&)), this, SLOT(handleInput(const QString&)));
|
||||
layout->addWidget(k, 2, Qt::AlignBottom);
|
||||
|
||||
setStyleSheet(R"(
|
||||
|
@ -56,7 +56,7 @@ InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) {
|
|||
setLayout(layout);
|
||||
}
|
||||
|
||||
QString InputDialog::getText(const QString prompt, int minLength) {
|
||||
QString InputDialog::getText(const QString &prompt, int minLength) {
|
||||
InputDialog d = InputDialog(prompt);
|
||||
d.setMinLength(minLength);
|
||||
const int ret = d.exec();
|
||||
|
@ -76,7 +76,7 @@ void InputDialog::show(){
|
|||
setMainWindow(this);
|
||||
}
|
||||
|
||||
void InputDialog::handleInput(QString s) {
|
||||
void InputDialog::handleInput(const QString &s) {
|
||||
if (!QString::compare(s,"⌫")) {
|
||||
line->backspace();
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void InputDialog::handleInput(QString s) {
|
|||
line->insert(s.left(1));
|
||||
}
|
||||
|
||||
void InputDialog::setMessage(QString message, bool clearInputField){
|
||||
void InputDialog::setMessage(const QString &message, bool clearInputField){
|
||||
label->setText(message);
|
||||
if (clearInputField){
|
||||
line->setText("");
|
||||
|
@ -112,7 +112,7 @@ void InputDialog::setMinLength(int length){
|
|||
}
|
||||
|
||||
|
||||
ConfirmationDialog::ConfirmationDialog(QString prompt_text, QString confirm_text, QString cancel_text,
|
||||
ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString &confirm_text, const QString &cancel_text,
|
||||
QWidget *parent):QDialog(parent) {
|
||||
setWindowFlags(Qt::Popup);
|
||||
layout = new QVBoxLayout();
|
||||
|
@ -161,12 +161,12 @@ ConfirmationDialog::ConfirmationDialog(QString prompt_text, QString confirm_text
|
|||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool ConfirmationDialog::alert(const QString prompt_text) {
|
||||
bool ConfirmationDialog::alert(const QString &prompt_text) {
|
||||
ConfirmationDialog d = ConfirmationDialog(prompt_text, "Ok", "");
|
||||
return d.exec();
|
||||
}
|
||||
|
||||
bool ConfirmationDialog::confirm(const QString prompt_text) {
|
||||
bool ConfirmationDialog::confirm(const QString &prompt_text) {
|
||||
ConfirmationDialog d = ConfirmationDialog(prompt_text);
|
||||
return d.exec();
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ class InputDialog : public QDialog {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InputDialog(QString prompt_text, QWidget* parent = 0);
|
||||
static QString getText(QString prompt, int minLength = -1);
|
||||
explicit InputDialog(const QString &prompt_text, QWidget* parent = 0);
|
||||
static QString getText(const QString &prompt, int minLength = -1);
|
||||
QString text();
|
||||
void setMessage(QString message, bool clearInputField=true);
|
||||
void setMessage(const QString &message, bool clearInputField = true);
|
||||
void setMinLength(int length);
|
||||
void show();
|
||||
|
||||
|
@ -31,21 +31,21 @@ public slots:
|
|||
int exec() override;
|
||||
|
||||
private slots:
|
||||
void handleInput(QString s);
|
||||
void handleInput(const QString &s);
|
||||
|
||||
signals:
|
||||
void cancel();
|
||||
void emitText(QString text);
|
||||
void emitText(const QString &text);
|
||||
};
|
||||
|
||||
class ConfirmationDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfirmationDialog(QString prompt_text, QString confirm_text = "Ok",
|
||||
QString cancel_text = "Cancel", QWidget* parent = 0);
|
||||
static bool alert(QString prompt_text);
|
||||
static bool confirm(QString prompt_text);
|
||||
explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text = "Ok",
|
||||
const QString &cancel_text = "Cancel", QWidget* parent = 0);
|
||||
static bool alert(const QString &prompt_text);
|
||||
static bool confirm(const QString &prompt_text);
|
||||
|
||||
private:
|
||||
QLabel *prompt;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
const int DEFAULT_STRETCH = 1;
|
||||
const int SPACEBAR_STRETCH = 3;
|
||||
|
||||
KeyboardLayout::KeyboardLayout(QWidget *parent, std::vector<QVector<QString>> layout) : QWidget(parent) {
|
||||
KeyboardLayout::KeyboardLayout(QWidget* parent, const std::vector<QVector<QString>>& layout) : QWidget(parent) {
|
||||
QVBoxLayout* vlayout = new QVBoxLayout;
|
||||
vlayout->setMargin(0);
|
||||
vlayout->setSpacing(35);
|
||||
|
|
|
@ -12,7 +12,7 @@ class KeyboardLayout : public QWidget {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KeyboardLayout(QWidget *parent, std::vector<QVector<QString>> layout);
|
||||
explicit KeyboardLayout(QWidget* parent, const std::vector<QVector<QString>>& layout);
|
||||
};
|
||||
|
||||
class Keyboard : public QFrame {
|
||||
|
@ -28,5 +28,5 @@ private slots:
|
|||
void handleButton(QAbstractButton* m_button);
|
||||
|
||||
signals:
|
||||
void emitButton(QString s);
|
||||
void emitButton(const QString &s);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue