-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewbehaviourldlg.cpp
More file actions
126 lines (110 loc) · 3.46 KB
/
newbehaviourldlg.cpp
File metadata and controls
126 lines (110 loc) · 3.46 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "newbehaviourldlg.h"
#include "ui_newbehaviourdlg.h"
#include <QIntValidator>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QMessageBox>
#include <QSettings>
#include <QDebug>
NewBehaviourlDlg::NewBehaviourlDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewBehaviourDlg)
{
//existingBehaviourNames = behaviourNames;
ui->setupUi(this);
}
NewBehaviourlDlg::~NewBehaviourlDlg()
{
delete ui;
}
QString NewBehaviourlDlg::getName()
{
return behaviourName;
}
QString NewBehaviourlDlg::getNotes()
{
return notes;
}
QString NewBehaviourlDlg::importFrom()
{
if (ui->comboBox->currentIndex() == 0)
{
return "";
}
else
{
return ui->comboBox->currentText();
}
}
void NewBehaviourlDlg::setExistingBehaviourNames(QStringList *existing)
{
existingBehaviourNames = existing;
ui->comboBox->addItems(*existing); // "import from" combobox
ui->comboBox->setCurrentIndex(0);
}
void NewBehaviourlDlg::setPreexisting()
{
preexisting = true;
ui->leName->setReadOnly(true);
// Load values from settings
QSettings settings;
current_name = settings.value("current_model").toString();
ui->leName->setText(current_name);
ui->teNotes->setText(settings.value(current_name + "/notes").toString());
ui->comboBox->setEnabled(false);
setWindowTitle("Edit Behaviour Description");
}
void NewBehaviourlDlg::accept()
{
behaviourName = ui->leName->text().simplified();
notes = ui->teNotes->toPlainText().simplified();
QSettings settings;
if (preexisting)
{
// Can only change notes -- name is fixed
// Write the notes to settings
settings.setValue(behaviourName + "/notes", notes);
// Close the dialog
QDialog::accept();
return;
}
else
{
// TODO: use a textChanged signal to monitor behaviour name as it is
// typed and only enable the OK button when valid...
QString upper = behaviourName.toUpper();
if (behaviourName.size() > 0 && upper != "GENERAL" && upper != "STATE")
{
// Check that the behaviour name isn't a duplicate
if (existingBehaviourNames->contains(behaviourName))
{
// duplicate name entered
QMessageBox msgBox;
msgBox.setText(tr("Please enter a new behaviour name"));
msgBox.setInformativeText(tr("The name you entered has already been used!"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(tr("Error"));
msgBox.exec();
return;
}
// Close the dialog
QDialog::accept();
return;
}
else
{
QMessageBox msgBox(this);
msgBox.setWindowModality(Qt::WindowModal);
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(tr("Error"));
msgBox.setText(tr("You have not entered a valid behaviour name!"));
// TODO: remove the reserved words (general and state) from model
// names by prefixing them with 'u-' or something
msgBox.setDetailedText(tr("Behaviour names must be unique and must contain "
"at least one non-space character. 'General' "
"and 'state' are not allowed as model names."));
msgBox.exec();
return;
}
}
}