18#include <QDoubleValidator>
19#include <QGraphicsScene>
35 "DlgSettingsGridDisplay",
37 m_validatorCountX (nullptr),
38 m_validatorStartX (nullptr),
39 m_validatorStepX (nullptr),
40 m_validatorStopX (nullptr),
41 m_validatorCountY (nullptr),
42 m_validatorStartY (nullptr),
43 m_validatorStepY (nullptr),
44 m_validatorStopY (nullptr),
45 m_scenePreview (nullptr),
46 m_viewPreview (nullptr),
47 m_modelGridDisplayBefore (nullptr),
48 m_modelGridDisplayAfter (nullptr)
60 delete m_validatorCountX;
61 delete m_validatorStartX;
62 delete m_validatorStepX;
63 delete m_validatorStopX;
64 delete m_validatorCountY;
65 delete m_validatorStartY;
66 delete m_validatorStepY;
67 delete m_validatorStopY;
70void DlgSettingsGridDisplay::createDisplayCommon (QGridLayout *layout,
int &row)
74 QWidget *widgetCommon =
new QWidget;
75 layout->addWidget (widgetCommon, row++, 2, 1, 2);
77 QGridLayout *layoutCommon =
new QGridLayout;
78 widgetCommon->setLayout (layoutCommon);
81 m_labelLimitWarning =
new QLabel;
82 m_labelLimitWarning->setStyleSheet (
"QLabel { color: red; }");
83 layoutCommon->addWidget (m_labelLimitWarning, rowCommon++, 0, 1, 4, Qt::AlignCenter);
85 QLabel *labelColor =
new QLabel (QString (
"%1:").arg (tr (
"Color")));
86 layoutCommon->addWidget (labelColor, rowCommon, 1);
88 m_cmbColor =
new QComboBox;
89 m_cmbColor->setWhatsThis (tr (
"Select a color for the lines"));
91 connect (m_cmbColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotColor (
const QString &)));
92 layoutCommon->addWidget (m_cmbColor, rowCommon++, 2);
94 QLabel *labelLineWidth =
new QLabel (QString (
"%1:").arg (tr (
"Line width")));
95 layoutCommon->addWidget (labelLineWidth, rowCommon, 1);
97 m_spinLineWidth =
new QSpinBox (widgetCommon);
98 m_spinLineWidth->setWhatsThis (tr (
"Select a width for the grid display lines."));
99 m_spinLineWidth->setMinimum (0);
100 connect (m_spinLineWidth, SIGNAL (valueChanged (
int)),
this, SLOT (slotLineWidth (
int)));
101 layoutCommon->addWidget (m_spinLineWidth, rowCommon++, 2);
104 layoutCommon->setColumnStretch (0, 1);
105 layoutCommon->setColumnStretch (1, 0);
106 layoutCommon->setColumnStretch (2, 0);
107 layoutCommon->setColumnStretch (3, 1);
110void DlgSettingsGridDisplay::createDisplayGridLinesX (QGridLayout *layout,
int &row)
114 m_groupX =
new QGroupBox;
115 layout->addWidget (m_groupX, row, 2);
117 QGridLayout *layoutGroup =
new QGridLayout;
118 m_groupX->setLayout (layoutGroup);
120 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
121 layoutGroup->addWidget (labelDisable, 0, 0);
123 m_cmbDisableX =
new QComboBox;
124 m_cmbDisableX->setWhatsThis (tr (
"Disabled value.\n\n"
125 "The X grid lines are specified using only three values at a time. For flexibility, four values "
126 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
127 "updated as the other values change"));
136 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
137 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
139 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
140 layoutGroup->addWidget (labelCount, 1, 0);
142 m_editCountX =
new QLineEdit;
143 m_editCountX->setWhatsThis (tr (
"Number of X grid lines.\n\n"
144 "The number of X grid lines must be entered as an integer greater than zero"));
145 m_validatorCountX =
new QDoubleValidator;
146 m_validatorCountX->setBottom (
COUNT_MIN);
148 m_editCountX->setValidator (m_validatorCountX);
149 connect (m_editCountX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotCountX (
const QString &)));
150 layoutGroup->addWidget (m_editCountX, 1, 1);
152 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
153 layoutGroup->addWidget (labelStart, 2, 0);
155 m_editStartX =
new QLineEdit;
156 m_editStartX->setWhatsThis (tr (
"Value of the first X grid line.\n\n"
157 "The start value cannot be greater than the stop value"));
158 m_validatorStartX =
new QDoubleValidator;
159 m_editStartX->setValidator (m_validatorStartX);
160 connect (m_editStartX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStartX (
const QString &)));
161 layoutGroup->addWidget (m_editStartX, 2, 1);
163 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
164 layoutGroup->addWidget (labelStep, 3, 0);
166 m_editStepX =
new QLineEdit;
167 m_editStepX->setWhatsThis (tr (
"Difference in value between two successive X grid lines.\n\n"
168 "The step value must be greater than zero (linear) or one (log)"));
169 m_validatorStepX =
new QDoubleValidator;
170 m_editStepX->setValidator (m_validatorStepX);
171 connect (m_editStepX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStepX (
const QString &)));
172 layoutGroup->addWidget (m_editStepX, 3, 1);
174 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
175 layoutGroup->addWidget (labelStop, 4, 0);
177 m_editStopX =
new QLineEdit;
178 m_editStopX->setWhatsThis (tr (
"Value of the last X grid line.\n\n"
179 "The stop value cannot be less than the start value"));
180 m_validatorStopX =
new QDoubleValidator;
181 m_editStopX->setValidator (m_validatorStopX);
182 connect (m_editStopX, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStopX (
const QString &)));
183 layoutGroup->addWidget (m_editStopX, 4, 1);
186void DlgSettingsGridDisplay::createDisplayGridLinesY (QGridLayout *layout,
int &row)
190 m_groupY =
new QGroupBox;
191 layout->addWidget (m_groupY, row++, 3);
193 QGridLayout *layoutGroup =
new QGridLayout;
194 m_groupY->setLayout (layoutGroup);
196 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
197 layoutGroup->addWidget (labelDisable, 0, 0);
199 m_cmbDisableY =
new QComboBox;
200 m_cmbDisableY->setWhatsThis (tr (
"Disabled value.\n\n"
201 "The Y grid lines are specified using only three values at a time. For flexibility, four values "
202 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
203 "updated as the other values change"));
212 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
213 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
215 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
216 layoutGroup->addWidget (labelCount, 1, 0);
218 m_editCountY =
new QLineEdit;
219 m_editCountY->setWhatsThis (tr (
"Number of Y grid lines.\n\n"
220 "The number of Y grid lines must be entered as an integer greater than zero"));
221 m_validatorCountY =
new QDoubleValidator;
222 m_validatorCountY->setBottom (
COUNT_MIN);
224 m_editCountY->setValidator (m_validatorCountY);
225 connect (m_editCountY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotCountY (
const QString &)));
226 layoutGroup->addWidget (m_editCountY, 1, 1);
228 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
229 layoutGroup->addWidget (labelStart, 2, 0);
231 m_editStartY =
new QLineEdit;
232 m_editStartY->setWhatsThis (tr (
"Value of the first Y grid line.\n\n"
233 "The start value cannot be greater than the stop value"));
234 m_validatorStartY =
new QDoubleValidator;
235 m_editStartY->setValidator (m_validatorStartY);
236 connect (m_editStartY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStartY (
const QString &)));
237 layoutGroup->addWidget (m_editStartY, 2, 1);
239 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
240 layoutGroup->addWidget (labelStep, 3, 0);
242 m_editStepY =
new QLineEdit;
243 m_editStepY->setWhatsThis (tr (
"Difference in value between two successive Y grid lines.\n\n"
244 "The step value must be greater than zero (linear) or one (log)"));
245 m_validatorStepY =
new QDoubleValidator;
246 m_editStepY->setValidator (m_validatorStepY);
247 connect (m_editStepY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStepY (
const QString &)));
248 layoutGroup->addWidget (m_editStepY, 3, 1);
250 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
251 layoutGroup->addWidget (labelStop, 4, 0);
253 m_editStopY =
new QLineEdit;
254 m_editStopY->setWhatsThis (tr (
"Value of the last Y grid line.\n\n"
255 "The stop value cannot be less than the start value"));
256 m_validatorStopY =
new QDoubleValidator;
257 m_editStopY->setValidator (m_validatorStopY);
258 connect (m_editStopY, SIGNAL (textEdited (
const QString &)),
this, SLOT (slotStopY (
const QString &)));
259 layoutGroup->addWidget (m_editStopY, 4, 1);
266void DlgSettingsGridDisplay::createPreview (QGridLayout *layout,
int &row)
270 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
271 layout->addWidget (labelPreview, row++, 0, 1, 5);
273 m_scenePreview =
new QGraphicsScene (
this);
277 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect grid display"));
278 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
279 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
281 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
288 QWidget *subPanel =
new QWidget ();
289 QGridLayout *layout =
new QGridLayout (subPanel);
290 subPanel->setLayout (layout);
292 layout->setColumnStretch(0, 1);
293 layout->setColumnStretch(1, 0);
294 layout->setColumnStretch(2, 0);
295 layout->setColumnStretch(3, 0);
296 layout->setColumnStretch(4, 1);
305 createDisplayGridLinesX (layout, row);
306 createDisplayGridLinesY (layout, row);
307 createDisplayCommon (layout, row);
308 createPreview (layout, row);
318 m_modelGridDisplayAfter->setStable (
true);
322 *m_modelGridDisplayBefore,
323 *m_modelGridDisplayAfter);
336 delete m_modelGridDisplayBefore;
337 delete m_modelGridDisplayAfter;
340 QString titleX = tr (
"X Grid Lines");
342 titleX = QString (QChar (0x98, 0x03)) + QString (
" %1").arg (tr (
"Grid Lines"));
344 m_groupX->setTitle (titleX);
346 QString titleY = tr (
"Y Grid Lines");
348 titleY = QString (tr (
"Radius Grid Lines"));
350 m_groupY->setTitle (titleY);
357 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridDisplayAfter->disableX()));
358 m_cmbDisableX->setCurrentIndex (indexDisableX);
360 m_editCountX->setText(QString::number(m_modelGridDisplayAfter->countX()));
361 m_editStartX->setText(QString::number(m_modelGridDisplayAfter->startX()));
362 m_editStepX->setText(QString::number(m_modelGridDisplayAfter->stepX()));
363 m_editStopX->setText(QString::number(m_modelGridDisplayAfter->stopX()));
365 int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridDisplayAfter->disableY()));
366 m_cmbDisableY->setCurrentIndex (indexDisableY);
368 m_editCountY->setText(QString::number(m_modelGridDisplayAfter->countY()));
369 m_editStartY->setText(QString::number(m_modelGridDisplayAfter->startY()));
370 m_editStepY->setText(QString::number(m_modelGridDisplayAfter->stepY()));
371 m_editStopY->setText(QString::number(m_modelGridDisplayAfter->stopY()));
373 int indexColor = m_cmbColor->findData(QVariant(m_modelGridDisplayAfter->paletteColor()));
375 m_cmbColor->setCurrentIndex(indexColor);
377 m_spinLineWidth->setValue (m_modelGridDisplayAfter->lineWidth ());
394void DlgSettingsGridDisplay::slotColor (QString
const &)
403void DlgSettingsGridDisplay::slotCountX(
const QString &count)
407 m_modelGridDisplayAfter->setCountX(
unsigned (count.toInt()));
408 updateDisplayedVariableX ();
413void DlgSettingsGridDisplay::slotCountY(
const QString &count)
417 m_modelGridDisplayAfter->setCountY(
unsigned (count.toInt()));
418 updateDisplayedVariableY ();
423void DlgSettingsGridDisplay::slotDisableX(
const QString &)
428 m_modelGridDisplayAfter->setDisableX(gridCoordDisable);
429 updateDisplayedVariableX ();
434void DlgSettingsGridDisplay::slotDisableY(
const QString &)
439 m_modelGridDisplayAfter->setDisableY(gridCoordDisable);
440 updateDisplayedVariableY ();
445void DlgSettingsGridDisplay::slotLineWidth (
int lineWidth)
449 m_modelGridDisplayAfter->setLineWidth (lineWidth);
454void DlgSettingsGridDisplay::slotStartX(
const QString &startX)
458 m_modelGridDisplayAfter->setStartX(startX.toDouble());
459 updateDisplayedVariableX ();
464void DlgSettingsGridDisplay::slotStartY(
const QString &startY)
468 m_modelGridDisplayAfter->setStartY(startY.toDouble());
469 updateDisplayedVariableY ();
474void DlgSettingsGridDisplay::slotStepX(
const QString &stepX)
478 m_modelGridDisplayAfter->setStepX(stepX.toDouble());
479 updateDisplayedVariableX ();
484void DlgSettingsGridDisplay::slotStepY(
const QString &stepY)
488 m_modelGridDisplayAfter->setStepY(stepY.toDouble());
489 updateDisplayedVariableY ();
494void DlgSettingsGridDisplay::slotStopX(
const QString &stopX)
498 m_modelGridDisplayAfter->setStopX(stopX.toDouble());
499 updateDisplayedVariableX ();
504void DlgSettingsGridDisplay::slotStopY(
const QString &stopY)
508 m_modelGridDisplayAfter->setStopY(stopY.toDouble());
509 updateDisplayedVariableY ();
514void DlgSettingsGridDisplay::slotWhatsThis ()
516 QWhatsThis::enterWhatsThisMode();
519bool DlgSettingsGridDisplay::textItemsAreValid ()
const
521 QString textCountX = m_editCountX->text();
522 QString textCountY = m_editCountY->text();
523 QString textStartX = m_editStartX->text();
524 QString textStartY = m_editStartY->text();
525 QString textStepX = m_editStepX->text();
526 QString textStepY = m_editStepY->text();
527 QString textStopX = m_editStopX->text();
528 QString textStopY = m_editStopY->text();
536 !textCountX.isEmpty() &&
537 !textCountY.isEmpty() &&
538 !textStartX.isEmpty() &&
539 !textStartY.isEmpty() &&
540 !textStepX.isEmpty() &&
541 !textStepY.isEmpty() &&
542 !textStopX.isEmpty() &&
543 !textStopY.isEmpty() &&
544 m_validatorCountX->validate(textCountX, pos) == QValidator::Acceptable &&
545 m_validatorCountY->validate(textCountY, pos) == QValidator::Acceptable &&
546 m_validatorStartX->validate(textStartX, pos) == QValidator::Acceptable &&
547 m_validatorStartY->validate(textStartY, pos) == QValidator::Acceptable &&
548 m_validatorStepX->validate(textStepX, pos) == QValidator::Acceptable &&
549 m_validatorStepY->validate(textStepY, pos) == QValidator::Acceptable &&
550 m_validatorStopX->validate(textStopX, pos) == QValidator::Acceptable &&
551 m_validatorStopY->validate(textStopY, pos) == QValidator::Acceptable) {
554 double stepX = textCountX.toDouble ();
555 double stepY = textCountY.toDouble ();
557 if (qAbs (stepX) > 0 && qAbs (stepY) > 0) {
566bool DlgSettingsGridDisplay::textItemsDoNotBreakLineCountLimit ()
568 if (textItemsAreValid ()) {
569 QString textCountX = m_editCountX->text();
570 QString textCountY = m_editCountY->text();
571 QString textStartX = m_editStartX->text();
572 QString textStartY = m_editStartY->text();
573 QString textStepX = m_editStepX->text();
574 QString textStepY = m_editStepY->text();
575 QString textStopX = m_editStopX->text();
576 QString textStopY = m_editStopY->text();
579 GridInitializer initializer;
584 int countX = textCountX.toInt ();
587 textStartX.toDouble (),
588 textStopX.toDouble (),
589 textStepX.toDouble ());
591 int countY = textCountY.toInt ();
594 textStartY.toDouble (),
595 textStopY.toDouble (),
596 textStepY.toDouble ());
599 return (countX <=
mainWindow ().modelMainWindow ().maximumGridLines() &&
600 countY <=
mainWindow ().modelMainWindow ().maximumGridLines());
606void DlgSettingsGridDisplay::updateControls ()
620 if (textItemsDoNotBreakLineCountLimit ()) {
621 m_labelLimitWarning->setText (
"");
623 m_labelLimitWarning->setText (tr (
"Grid line count exceeds limit set by Settings / Main Window."));
626 enableOk (textItemsAreValid () && textItemsDoNotBreakLineCountLimit ());
629void DlgSettingsGridDisplay::updateDisplayedVariableX ()
631 GridInitializer initializer;
635 switch (m_modelGridDisplayAfter->disableX()) {
637 m_editCountX->setText (QString::number (initializer.
computeCount (linearAxis,
638 m_modelGridDisplayAfter->startX (),
639 m_modelGridDisplayAfter->stopX (),
640 m_modelGridDisplayAfter->stepX ())));
644 m_editStartX->setText (QString::number (initializer.
computeStart (linearAxis,
645 m_modelGridDisplayAfter->stopX (),
646 m_modelGridDisplayAfter->stepX (),
647 signed (m_modelGridDisplayAfter->countX ()))));
651 m_editStepX->setText (QString::number (initializer.
computeStep (linearAxis,
652 m_modelGridDisplayAfter->startX (),
653 m_modelGridDisplayAfter->stopX (),
654 signed (m_modelGridDisplayAfter->countX ()))));
658 m_editStopX->setText (QString::number (initializer.
computeStop (linearAxis,
659 m_modelGridDisplayAfter->startX (),
660 m_modelGridDisplayAfter->stepX (),
661 signed (m_modelGridDisplayAfter->countX ()))));
666void DlgSettingsGridDisplay::updateDisplayedVariableY ()
668 GridInitializer initializer;
672 switch (m_modelGridDisplayAfter->disableY()) {
674 m_editCountY->setText (QString::number (initializer.
computeCount (linearAxis,
675 m_modelGridDisplayAfter->startY (),
676 m_modelGridDisplayAfter->stopY (),
677 m_modelGridDisplayAfter->stepY ())));
681 m_editStartY->setText (QString::number (initializer.
computeStart (linearAxis,
682 m_modelGridDisplayAfter->stopY (),
683 m_modelGridDisplayAfter->stepY (),
684 signed (m_modelGridDisplayAfter->countY ()))));
688 m_editStepY->setText (QString::number (initializer.
computeStep (linearAxis,
689 m_modelGridDisplayAfter->startY (),
690 m_modelGridDisplayAfter->stopY (),
691 signed (m_modelGridDisplayAfter->countY ()))));
695 m_editStopY->setText (QString::number (initializer.
computeStop (linearAxis,
696 m_modelGridDisplayAfter->startY (),
697 m_modelGridDisplayAfter->stepY (),
698 signed (m_modelGridDisplayAfter->countY ()))));
703void DlgSettingsGridDisplay::updatePreview ()
705 m_gridLines.clear ();
707 if (textItemsAreValid ()) {
709 GridLineFactory factory (*m_scenePreview,
712 factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
QString gridCoordDisableToString(GridCoordDisable gridCoordDisable)
@ GRID_COORD_DISABLE_STOP
@ GRID_COORD_DISABLE_START
@ GRID_COORD_DISABLE_STEP
@ GRID_COORD_DISABLE_COUNT
log4cpp::Category * mainCat
Command for DlgSettingsGridDisplay.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
void addPixmap(QGraphicsScene &scene, const QPixmap &pixmap)
Adds pixmap to the scene.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual ~DlgSettingsGridDisplay()
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
DlgSettingsGridDisplay(MainWindow &mainWindow)
Single constructor.
virtual void handleOk()
Process slotOk.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void setPaletteColor(ColorPalette paletteColor)
Set method for color.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
double computeStep(bool linearAxis, double start, double stop, int count) const
Compute axis scale step from the other axis parameters.
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
@ VIEW_ASPECT_RATIO_VARIABLE
#define LOG4CPP_INFO_S(logger)