/
graphpanelwidgetcustomaxesdialog.cpp
226 lines (156 loc) · 6.9 KB
/
graphpanelwidgetcustomaxesdialog.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
//==============================================================================
// Graph Panel widget custom axes dialog
//==============================================================================
#include "coreguiutils.h"
#include "graphpanelwidgetcustomaxesdialog.h"
#include "plugin.h"
//==============================================================================
#include "ui_graphpanelwidgetcustomaxesdialog.h"
//==============================================================================
#include <QPushButton>
#include <QRegularExpressionValidator>
#include <QSettings>
//==============================================================================
namespace OpenCOR {
namespace GraphPanelWidget {
//==============================================================================
GraphPanelWidgetCustomAxesDialog::GraphPanelWidgetCustomAxesDialog(const double &pMinX,
const double &pMaxX,
const double &pMinY,
const double &pMaxY,
QWidget *pParent) :
Core::Dialog(pParent),
mGui(new Ui::GraphPanelWidgetCustomAxesDialog)
{
// Set up the GUI
mGui->setupUi(this);
connect(mGui->buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
// Create our 'special' settings
// Note: special in the sense that we don't retrieve them from the plugin
// itself since this is not a view, a window or anything like that...
mSettings = new QSettings();
mSettings->beginGroup(SettingsPlugins);
mSettings->beginGroup("GraphPanelWidget");
mSettings->beginGroup("GraphPanelWidgetCustomAxesDialog");
// Only allow double numbers
QRegularExpressionValidator *doubleRegExValidator = new QRegularExpressionValidator(QRegularExpression("^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$"), this);
mGui->xMinValue->setValidator(doubleRegExValidator);
mGui->xMaxValue->setValidator(doubleRegExValidator);
mGui->yMinValue->setValidator(doubleRegExValidator);
mGui->yMaxValue->setValidator(doubleRegExValidator);
// Populate ourselves
mGui->xMinValue->setText(QString::number(pMinX));
mGui->xMaxValue->setText(QString::number(pMaxX));
mGui->yMinValue->setText(QString::number(pMinY));
mGui->yMaxValue->setText(QString::number(pMaxY));
// Select all of the minimum X value
mGui->xMinValue->selectAll();
}
//==============================================================================
GraphPanelWidgetCustomAxesDialog::~GraphPanelWidgetCustomAxesDialog()
{
// Delete the GUI
delete mGui;
}
//==============================================================================
double GraphPanelWidgetCustomAxesDialog::minX() const
{
// Return our minimum X value
return mGui->xMinValue->text().toDouble();
}
//==============================================================================
double GraphPanelWidgetCustomAxesDialog::maxX() const
{
// Return our maximum X value
return mGui->xMaxValue->text().toDouble();
}
//==============================================================================
double GraphPanelWidgetCustomAxesDialog::minY() const
{
// Return our minimum Y value
return mGui->yMinValue->text().toDouble();
}
//==============================================================================
double GraphPanelWidgetCustomAxesDialog::maxY() const
{
// Return our maximum Y value
return mGui->yMaxValue->text().toDouble();
}
//==============================================================================
void GraphPanelWidgetCustomAxesDialog::checkValue(QLineEdit *pValue)
{
// Check that we don't have an empty value and if we do then set the value
// to zero and select it
if (pValue->text().isEmpty()) {
pValue->setText("0");
pValue->selectAll();
}
}
//==============================================================================
void GraphPanelWidgetCustomAxesDialog::on_xMinValue_textEdited(const QString &pValue)
{
Q_UNUSED(pValue);
// Check our X-min value
checkValue(mGui->xMinValue);
}
//==============================================================================
void GraphPanelWidgetCustomAxesDialog::on_xMaxValue_textEdited(const QString &pValue)
{
Q_UNUSED(pValue);
// Check our X-max value
checkValue(mGui->xMaxValue);
}
//==============================================================================
void GraphPanelWidgetCustomAxesDialog::on_yMinValue_textEdited(const QString &pValue)
{
Q_UNUSED(pValue);
// Check our Y-min value
checkValue(mGui->yMinValue);
}
//==============================================================================
void GraphPanelWidgetCustomAxesDialog::on_yMaxValue_textEdited(const QString &pValue)
{
Q_UNUSED(pValue);
// Check our Y-max value
checkValue(mGui->yMaxValue);
}
//==============================================================================
void GraphPanelWidgetCustomAxesDialog::on_buttonBox_accepted()
{
// Check that the values make sense
bool xProblem = minX() >= maxX();
bool yProblem = minY() >= maxY();
if (xProblem && yProblem) {
Core::warningMessageBox(tr("Custom Axes"),
tr("X-min and Y-min must be lower than X-max and Y-max, respectively."));
} else if (xProblem) {
Core::warningMessageBox(tr("Custom Axes"),
tr("X-min must be lower than X-max."));
} else if (yProblem) {
Core::warningMessageBox(tr("Custom Axes"),
tr("Y-min must be lower than Y-max."));
} else {
// Confirm that we accepted the changes
accept();
}
}
//==============================================================================
} // namespace GraphPanelWidget
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================