17 #include <QDoubleValidator>
18 #include <QGraphicsScene>
19 #include <QGridLayout>
21 #include <QHBoxLayout>
32 "DlgSettingsGridDisplay",
34 m_validatorCountX (nullptr),
35 m_validatorStartX (nullptr),
36 m_validatorStepX (nullptr),
37 m_validatorStopX (nullptr),
38 m_validatorCountY (nullptr),
39 m_validatorStartY (nullptr),
40 m_validatorStepY (nullptr),
41 m_validatorStopY (nullptr),
42 m_scenePreview (nullptr),
43 m_viewPreview (nullptr),
44 m_modelGridDisplayBefore (nullptr),
45 m_modelGridDisplayAfter (nullptr)
57 delete m_validatorCountX;
58 delete m_validatorStartX;
59 delete m_validatorStepX;
60 delete m_validatorStopX;
61 delete m_validatorCountY;
62 delete m_validatorStartY;
63 delete m_validatorStepY;
64 delete m_validatorStopY;
67 void DlgSettingsGridDisplay::createDisplayCommon (QGridLayout *layout,
int &row)
71 QWidget *widgetCommon =
new QWidget;
72 layout->addWidget (widgetCommon, row++, 2, 1, 2);
74 QGridLayout *layoutCommon =
new QGridLayout;
75 widgetCommon->setLayout (layoutCommon);
78 m_labelLimitWarning =
new QLabel;
79 m_labelLimitWarning->setStyleSheet (
"QLabel { color: red; }");
80 layoutCommon->addWidget (m_labelLimitWarning, rowCommon++, 0, 1, 4, Qt::AlignCenter);
82 QLabel *labelColor =
new QLabel (QString (
"%1:").arg (tr (
"Color")));
83 layoutCommon->addWidget (labelColor, rowCommon, 1);
85 m_cmbColor =
new QComboBox;
86 m_cmbColor->setWhatsThis (tr (
"Select a color for the lines"));
88 connect (m_cmbColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotColor (
const QString &)));
89 layoutCommon->addWidget (m_cmbColor, rowCommon++, 2);
92 layoutCommon->setColumnStretch (0, 1);
93 layoutCommon->setColumnStretch (1, 0);
94 layoutCommon->setColumnStretch (2, 0);
95 layoutCommon->setColumnStretch (3, 1);
98 void DlgSettingsGridDisplay::createDisplayGridLinesX (QGridLayout *layout,
int &row)
102 m_groupX =
new QGroupBox;
103 layout->addWidget (m_groupX, row, 2);
105 QGridLayout *layoutGroup =
new QGridLayout;
106 m_groupX->setLayout (layoutGroup);
108 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
109 layoutGroup->addWidget (labelDisable, 0, 0);
111 m_cmbDisableX =
new QComboBox;
112 m_cmbDisableX->setWhatsThis (tr (
"Disabled value.\n\n"
113 "The X grid lines are specified using only three values at a time. For flexibility, four values "
114 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
115 "updated as the other values change"));
124 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
125 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
127 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
128 layoutGroup->addWidget (labelCount, 1, 0);
130 m_editCountX =
new QLineEdit;
131 m_editCountX->setWhatsThis (tr (
"Number of X grid lines.\n\n"
132 "The number of X grid lines must be entered as an integer greater than zero"));
133 m_validatorCountX =
new QDoubleValidator;
134 m_validatorCountX->setBottom (
COUNT_MIN);
136 m_editCountX->setValidator (m_validatorCountX);
137 connect (m_editCountX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotCountX (
const QString &)));
138 layoutGroup->addWidget (m_editCountX, 1, 1);
140 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
141 layoutGroup->addWidget (labelStart, 2, 0);
143 m_editStartX =
new QLineEdit;
144 m_editStartX->setWhatsThis (tr (
"Value of the first X grid line.\n\n"
145 "The start value cannot be greater than the stop value"));
146 m_validatorStartX =
new QDoubleValidator;
147 m_editStartX->setValidator (m_validatorStartX);
148 connect (m_editStartX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStartX (
const QString &)));
149 layoutGroup->addWidget (m_editStartX, 2, 1);
151 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
152 layoutGroup->addWidget (labelStep, 3, 0);
154 m_editStepX =
new QLineEdit;
155 m_editStepX->setWhatsThis (tr (
"Difference in value between two successive X grid lines.\n\n"
156 "The step value must be greater than zero (linear) or one (log)"));
157 m_validatorStepX =
new QDoubleValidator;
158 m_editStepX->setValidator (m_validatorStepX);
159 connect (m_editStepX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStepX (
const QString &)));
160 layoutGroup->addWidget (m_editStepX, 3, 1);
162 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
163 layoutGroup->addWidget (labelStop, 4, 0);
165 m_editStopX =
new QLineEdit;
166 m_editStopX->setWhatsThis (tr (
"Value of the last X grid line.\n\n"
167 "The stop value cannot be less than the start value"));
168 m_validatorStopX =
new QDoubleValidator;
169 m_editStopX->setValidator (m_validatorStopX);
170 connect (m_editStopX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStopX (
const QString &)));
171 layoutGroup->addWidget (m_editStopX, 4, 1);
174 void DlgSettingsGridDisplay::createDisplayGridLinesY (QGridLayout *layout,
int &row)
178 m_groupY =
new QGroupBox;
179 layout->addWidget (m_groupY, row++, 3);
181 QGridLayout *layoutGroup =
new QGridLayout;
182 m_groupY->setLayout (layoutGroup);
184 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
185 layoutGroup->addWidget (labelDisable, 0, 0);
187 m_cmbDisableY =
new QComboBox;
188 m_cmbDisableY->setWhatsThis (tr (
"Disabled value.\n\n"
189 "The Y grid lines are specified using only three values at a time. For flexibility, four values "
190 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
191 "updated as the other values change"));
200 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
201 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
203 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
204 layoutGroup->addWidget (labelCount, 1, 0);
206 m_editCountY =
new QLineEdit;
207 m_editCountY->setWhatsThis (tr (
"Number of Y grid lines.\n\n"
208 "The number of Y grid lines must be entered as an integer greater than zero"));
209 m_validatorCountY =
new QDoubleValidator;
210 m_validatorCountY->setBottom (
COUNT_MIN);
212 m_editCountY->setValidator (m_validatorCountY);
213 connect (m_editCountY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotCountY (
const QString &)));
214 layoutGroup->addWidget (m_editCountY, 1, 1);
216 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
217 layoutGroup->addWidget (labelStart, 2, 0);
219 m_editStartY =
new QLineEdit;
220 m_editStartY->setWhatsThis (tr (
"Value of the first Y grid line.\n\n"
221 "The start value cannot be greater than the stop value"));
222 m_validatorStartY =
new QDoubleValidator;
223 m_editStartY->setValidator (m_validatorStartY);
224 connect (m_editStartY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStartY (
const QString &)));
225 layoutGroup->addWidget (m_editStartY, 2, 1);
227 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
228 layoutGroup->addWidget (labelStep, 3, 0);
230 m_editStepY =
new QLineEdit;
231 m_editStepY->setWhatsThis (tr (
"Difference in value between two successive Y grid lines.\n\n"
232 "The step value must be greater than zero (linear) or one (log)"));
233 m_validatorStepY =
new QDoubleValidator;
234 m_editStepY->setValidator (m_validatorStepY);
235 connect (m_editStepY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStepY (
const QString &)));
236 layoutGroup->addWidget (m_editStepY, 3, 1);
238 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
239 layoutGroup->addWidget (labelStop, 4, 0);
241 m_editStopY =
new QLineEdit;
242 m_editStopY->setWhatsThis (tr (
"Value of the last Y grid line.\n\n"
243 "The stop value cannot be less than the start value"));
244 m_validatorStopY =
new QDoubleValidator;
245 m_editStopY->setValidator (m_validatorStopY);
246 connect (m_editStopY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStopY (
const QString &)));
247 layoutGroup->addWidget (m_editStopY, 4, 1);
254 void DlgSettingsGridDisplay::createPreview (QGridLayout *layout,
int &row)
258 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
259 layout->addWidget (labelPreview, row++, 0, 1, 5);
261 m_scenePreview =
new QGraphicsScene (
this);
265 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect grid display"));
266 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
267 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
269 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
276 QWidget *subPanel =
new QWidget ();
277 QGridLayout *layout =
new QGridLayout (subPanel);
278 subPanel->setLayout (layout);
280 layout->setColumnStretch(0, 1);
281 layout->setColumnStretch(1, 0);
282 layout->setColumnStretch(2, 0);
283 layout->setColumnStretch(3, 0);
284 layout->setColumnStretch(4, 1);
287 createDisplayGridLinesX (layout, row);
288 createDisplayGridLinesY (layout, row);
289 createDisplayCommon (layout, row);
290 createPreview (layout, row);
300 m_modelGridDisplayAfter->
setStable (
true);
304 *m_modelGridDisplayBefore,
305 *m_modelGridDisplayAfter);
318 delete m_modelGridDisplayBefore;
319 delete m_modelGridDisplayAfter;
322 QString titleX = tr (
"X Grid Lines");
324 titleX = QString (QChar (0x98, 0x03)) + QString (
" %1").arg (tr (
"Grid Lines"));
326 m_groupX->setTitle (titleX);
328 QString titleY = tr (
"Y Grid Lines");
330 titleY = QString (tr (
"Radius Grid Lines"));
332 m_groupY->setTitle (titleY);
339 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridDisplayAfter->
disableX()));
340 m_cmbDisableX->setCurrentIndex (indexDisableX);
342 m_editCountX->setText(QString::number(m_modelGridDisplayAfter->
countX()));
343 m_editStartX->setText(QString::number(m_modelGridDisplayAfter->
startX()));
344 m_editStepX->setText(QString::number(m_modelGridDisplayAfter->
stepX()));
345 m_editStopX->setText(QString::number(m_modelGridDisplayAfter->
stopX()));
347 int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridDisplayAfter->
disableY()));
348 m_cmbDisableY->setCurrentIndex (indexDisableY);
350 m_editCountY->setText(QString::number(m_modelGridDisplayAfter->
countY()));
351 m_editStartY->setText(QString::number(m_modelGridDisplayAfter->
startY()));
352 m_editStepY->setText(QString::number(m_modelGridDisplayAfter->
stepY()));
353 m_editStopY->setText(QString::number(m_modelGridDisplayAfter->
stopY()));
355 int indexColor = m_cmbColor->findData(QVariant(m_modelGridDisplayAfter->
paletteColor()));
357 m_cmbColor->setCurrentIndex(indexColor);
373 void DlgSettingsGridDisplay::slotColor (QString
const &)
377 m_modelGridDisplayAfter->
setPaletteColor(static_cast<ColorPalette> (m_cmbColor->currentData().toInt()));
382 void DlgSettingsGridDisplay::slotCountX(
const QString &count)
386 m_modelGridDisplayAfter->
setCountX(
unsigned (count.toInt()));
387 updateDisplayedVariableX ();
392 void DlgSettingsGridDisplay::slotCountY(
const QString &count)
396 m_modelGridDisplayAfter->
setCountY(
unsigned (count.toInt()));
397 updateDisplayedVariableY ();
402 void DlgSettingsGridDisplay::slotDisableX(
const QString &)
406 GridCoordDisable gridCoordDisable = static_cast<GridCoordDisable> (m_cmbDisableX->currentData().toInt());
407 m_modelGridDisplayAfter->
setDisableX(gridCoordDisable);
408 updateDisplayedVariableX ();
413 void DlgSettingsGridDisplay::slotDisableY(
const QString &)
417 GridCoordDisable gridCoordDisable = static_cast<GridCoordDisable> (m_cmbDisableY->currentData().toInt());
418 m_modelGridDisplayAfter->
setDisableY(gridCoordDisable);
419 updateDisplayedVariableY ();
424 void DlgSettingsGridDisplay::slotStartX(
const QString &startX)
428 m_modelGridDisplayAfter->
setStartX(startX.toDouble());
429 updateDisplayedVariableX ();
434 void DlgSettingsGridDisplay::slotStartY(
const QString &startY)
438 m_modelGridDisplayAfter->
setStartY(startY.toDouble());
439 updateDisplayedVariableY ();
444 void DlgSettingsGridDisplay::slotStepX(
const QString &stepX)
448 m_modelGridDisplayAfter->
setStepX(stepX.toDouble());
449 updateDisplayedVariableX ();
454 void DlgSettingsGridDisplay::slotStepY(
const QString &stepY)
458 m_modelGridDisplayAfter->
setStepY(stepY.toDouble());
459 updateDisplayedVariableY ();
464 void DlgSettingsGridDisplay::slotStopX(
const QString &stopX)
468 m_modelGridDisplayAfter->
setStopX(stopX.toDouble());
469 updateDisplayedVariableX ();
474 void DlgSettingsGridDisplay::slotStopY(
const QString &stopY)
478 m_modelGridDisplayAfter->
setStopY(stopY.toDouble());
479 updateDisplayedVariableY ();
484 bool DlgSettingsGridDisplay::textItemsAreValid ()
const
486 QString textCountX = m_editCountX->text();
487 QString textCountY = m_editCountY->text();
488 QString textStartX = m_editStartX->text();
489 QString textStartY = m_editStartY->text();
490 QString textStepX = m_editStepX->text();
491 QString textStepY = m_editStepY->text();
492 QString textStopX = m_editStopX->text();
493 QString textStopY = m_editStopY->text();
501 !textCountX.isEmpty() &&
502 !textCountY.isEmpty() &&
503 !textStartX.isEmpty() &&
504 !textStartY.isEmpty() &&
505 !textStepX.isEmpty() &&
506 !textStepY.isEmpty() &&
507 !textStopX.isEmpty() &&
508 !textStopY.isEmpty() &&
509 m_validatorCountX->validate(textCountX, pos) == QValidator::Acceptable &&
510 m_validatorCountY->validate(textCountY, pos) == QValidator::Acceptable &&
511 m_validatorStartX->validate(textStartX, pos) == QValidator::Acceptable &&
512 m_validatorStartY->validate(textStartY, pos) == QValidator::Acceptable &&
513 m_validatorStepX->validate(textStepX, pos) == QValidator::Acceptable &&
514 m_validatorStepY->validate(textStepY, pos) == QValidator::Acceptable &&
515 m_validatorStopX->validate(textStopX, pos) == QValidator::Acceptable &&
516 m_validatorStopY->validate(textStopY, pos) == QValidator::Acceptable) {
519 double stepX = textCountX.toDouble ();
520 double stepY = textCountY.toDouble ();
522 if (qAbs (stepX) > 0 && qAbs (stepY) > 0) {
531 bool DlgSettingsGridDisplay::textItemsDoNotBreakLineCountLimit ()
533 if (textItemsAreValid ()) {
534 QString textCountX = m_editCountX->text();
535 QString textCountY = m_editCountY->text();
536 QString textStartX = m_editStartX->text();
537 QString textStartY = m_editStartY->text();
538 QString textStepX = m_editStepX->text();
539 QString textStepY = m_editStepY->text();
540 QString textStopX = m_editStopX->text();
541 QString textStopY = m_editStopY->text();
549 int countX = textCountX.toInt ();
552 textStartX.toDouble (),
553 textStopX.toDouble (),
554 textStepX.toDouble ());
556 int countY = textCountY.toInt ();
559 textStartY.toDouble (),
560 textStopY.toDouble (),
561 textStepY.toDouble ());
571 void DlgSettingsGridDisplay::updateControls ()
573 GridCoordDisable disableX = static_cast<GridCoordDisable> (m_cmbDisableX->currentData().toInt());
579 GridCoordDisable disableY = static_cast<GridCoordDisable> (m_cmbDisableY->currentData().toInt());
585 if (textItemsDoNotBreakLineCountLimit ()) {
586 m_labelLimitWarning->setText (
"");
588 m_labelLimitWarning->setText (tr (
"Grid line count exceeds limit set by Settings / Main Window."));
591 enableOk (textItemsAreValid () && textItemsDoNotBreakLineCountLimit ());
594 void DlgSettingsGridDisplay::updateDisplayedVariableX ()
600 switch (m_modelGridDisplayAfter->
disableX()) {
602 m_editCountX->setText (QString::number (initializer.
computeCount (linearAxis,
603 m_modelGridDisplayAfter->
startX (),
604 m_modelGridDisplayAfter->
stopX (),
605 m_modelGridDisplayAfter->
stepX ())));
609 m_editStartX->setText (QString::number (initializer.
computeStart (linearAxis,
610 m_modelGridDisplayAfter->
stopX (),
611 m_modelGridDisplayAfter->
stepX (),
612 signed (m_modelGridDisplayAfter->
countX ()))));
616 m_editStepX->setText (QString::number (initializer.
computeStep (linearAxis,
617 m_modelGridDisplayAfter->
startX (),
618 m_modelGridDisplayAfter->
stopX (),
619 signed (m_modelGridDisplayAfter->
countX ()))));
623 m_editStopX->setText (QString::number (initializer.
computeStop (linearAxis,
624 m_modelGridDisplayAfter->
startX (),
625 m_modelGridDisplayAfter->
stepX (),
626 signed (m_modelGridDisplayAfter->
countX ()))));
631 void DlgSettingsGridDisplay::updateDisplayedVariableY ()
637 switch (m_modelGridDisplayAfter->
disableY()) {
639 m_editCountY->setText (QString::number (initializer.
computeCount (linearAxis,
640 m_modelGridDisplayAfter->
startY (),
641 m_modelGridDisplayAfter->
stopY (),
642 m_modelGridDisplayAfter->
stepY ())));
646 m_editStartY->setText (QString::number (initializer.
computeStart (linearAxis,
647 m_modelGridDisplayAfter->
stopY (),
648 m_modelGridDisplayAfter->
stepY (),
649 signed (m_modelGridDisplayAfter->
countY ()))));
653 m_editStepY->setText (QString::number (initializer.
computeStep (linearAxis,
654 m_modelGridDisplayAfter->
startY (),
655 m_modelGridDisplayAfter->
stopY (),
656 signed (m_modelGridDisplayAfter->
countY ()))));
660 m_editStopY->setText (QString::number (initializer.
computeStop (linearAxis,
661 m_modelGridDisplayAfter->
startY (),
662 m_modelGridDisplayAfter->
stepY (),
663 signed (m_modelGridDisplayAfter->
countY ()))));
668 void DlgSettingsGridDisplay::updatePreview ()
670 m_gridLines.
clear ();
672 if (textItemsAreValid ()) {
677 factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,