-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddeditpropertydialog.cpp
72 lines (60 loc) · 2.43 KB
/
addeditpropertydialog.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
63
64
65
66
67
68
69
70
71
72
#include "addeditpropertydialog.h"
#include "ui_addeditpropertydialog.h"
#include <QMessageBox>
AddEditPropertyDialog::AddEditPropertyDialog(bool add, PropertiesDock *propertiesDock, QWidget *parent, QString propertyName, QString propertyText) :
QDialog(parent),
ui(new Ui::AddEditPropertyDialog)
{
ui->setupUi(this);
this->propertiesDock = propertiesDock;
/* change the ui depending on whether this should be an add or edit property window */
if (add) {
windowTitle = "Add Property";
ui->addEditButton->setText("Add");
} else {
windowTitle = "Edit Property";
ui->addEditButton->setText("Edit");
ui->propertyNameField->setText(propertyName);
ui->propertyTextField->setPlainText(propertyText);
}
setWindowTitle(windowTitle);
setWindowFlags(Qt::Window);
connect(ui->addEditButton, SIGNAL(clicked()), this, SLOT(parseAndAccept()));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
QString AddEditPropertyDialog::getPropertyName()
{
return ui->propertyNameField->text().trimmed();
}
QString AddEditPropertyDialog::getPropertyText()
{
return ui->propertyTextField->toPlainText();
}
void AddEditPropertyDialog::parseAndAccept()
{
QString propertyName = ui->propertyNameField->text().trimmed();
/* show a message box if the property name field is empty */
if (propertyName.count() == 0) {
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, windowTitle, "The property name may not be empty", QMessageBox::Ok, this, Qt::WindowCloseButtonHint);
msgBox->exec();
return;
}
/* show a message box if this property name already exists */
if (propertiesDock->propertyNameExists(propertyName)) {
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, windowTitle, "A property with this name already exists", QMessageBox::Ok, this, Qt::WindowCloseButtonHint);
msgBox->exec();
return;
}
/* show a message box if the property text field is empty */
if (ui->propertyTextField->toPlainText().trimmed().count() == 0) {
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, windowTitle, "The property text may not be empty", QMessageBox::Ok, this, Qt::WindowCloseButtonHint);
msgBox->exec();
return;
}
/* if everything is ok, accept the input */
accept();
}
AddEditPropertyDialog::~AddEditPropertyDialog()
{
delete ui;
}