-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputdialog.cpp
51 lines (42 loc) · 1.41 KB
/
inputdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "inputdialog.h"
InputDialog::InputDialog(QWidget* parent, QString hint) : QDialog(parent)
{
gridlayout = new QGridLayout(this);
lytMain = new QFormLayout();
topLaybel = new QLabel("添加自定义方案");
gridlayout->addWidget(topLaybel);
gridlayout->addLayout(lytMain, 1, 0, 2, 2);
tLabel = new QLabel("方案名", this);
tLine = new QLineEdit(this);
lytMain->addRow(tLabel, tLine);
tHint = new QLabel(hint, this);
tCommand = new QLineEdit(this);
lytMain->addRow(tHint, tCommand);
buttonBox = new QDialogButtonBox
( QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, this );
lytMain->addWidget(buttonBox);
bool conn = connect(buttonBox, &QDialogButtonBox::accepted,
this, &InputDialog::accept);
Q_ASSERT(conn);
conn = connect(buttonBox, &QDialogButtonBox::rejected,
this, &InputDialog::reject);
Q_ASSERT(conn);
setLayout(lytMain);
}
std::pair<QString, QString> InputDialog::getStrings(QString hint, QWidget *parent, bool *ok)
{
InputDialog *dialog = new InputDialog(parent, hint);
const int ret = dialog->exec();
if (ok)
*ok = !!ret;
std::pair<QString, QString> pa;
if(ret){
pa = std::make_pair(dialog->tLine->text(), dialog->tCommand->text());
}
else{
pa = std::make_pair("", "");
}
delete dialog;
return pa;
}