-
Notifications
You must be signed in to change notification settings - Fork 4
/
dialogservice.cpp
62 lines (51 loc) · 1.88 KB
/
dialogservice.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
52
53
54
55
56
57
58
59
60
61
62
#include "dialogservice.h"
#include <QDialog>
#include <QFormLayout>
#include <QMap>
#include <QLineEdit>
#include <QLabel>
#include <QDialogButtonBox>
#include <QObject>
DialogService::DialogService()
{
}
/**
* @brief Displays the Edit attributes dialog for a {@link DomElement}.
* @param inputMap Contains a key-value pair for each available attribute on a given {@link DomElement}.
* @return The updated map with attributes and values.
*/
QMap<QString, QString> DialogService::showDialog(QMap<QString, QString> &inputMap)
{
QDialog dialog(Q_NULLPTR);
dialog.setWindowTitle("Edit attributes");
// Use a layout allowing to have a label next to each field
QFormLayout form(&dialog);
// Add some text above the fields
form.addRow(new QLabel("Fill in the attribute values "
"for your HTML element in the input boxes below"));
// Add the lineEdits with their respective labels
QMap<QString, QLineEdit *> fields;
for (QString key : inputMap.keys())
{
QLineEdit *lineEdit = new QLineEdit(&dialog);
lineEdit->setText(inputMap.value(key));
QString label = QString(key + ": ");
form.addRow(label, lineEdit);
fields.insert(key, lineEdit);
}
// Add some standard buttons (Cancel/Ok) at the bottom of the dialog
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
// Show the dialog as modal
QMap<QString, QString> resultMap;
if (dialog.exec() == QDialog::Accepted)
{
for (QString key : fields.keys()) {
resultMap.insert(key, fields.value(key)->text());
}
}
return resultMap;
}