Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgSettingsGridDisplay.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "ButtonWhatsThis.h"
8#include "CmdMediator.h"
11#include "EngaugeAssert.h"
12#include "GridInitializer.h"
13#include "GridLineFactory.h"
14#include "Logger.h"
15#include "MainWindow.h"
16#include <QCheckBox>
17#include <QComboBox>
18#include <QDoubleValidator>
19#include <QGraphicsScene>
20#include <QGridLayout>
21#include <QGroupBox>
22#include <QHBoxLayout>
23#include <QLabel>
24#include <QLineEdit>
25#include <QSpinBox>
26#include <QWhatsThis>
27#include "ViewPreview.h"
28
29const int COUNT_MIN = 1;
30const int COUNT_DECIMALS = 0;
31const int MINIMUM_HEIGHT = 540;
32
34 DlgSettingsAbstractBase (tr ("Grid Display"),
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)
49{
50 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::DlgSettingsGridDisplay";
51
52 QWidget *subPanel = createSubPanel ();
53 finishPanel (subPanel);
54}
55
57{
58 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::~DlgSettingsGridDisplay";
59
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;
68}
69
70void DlgSettingsGridDisplay::createDisplayCommon (QGridLayout *layout, int &row)
71{
72 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayCommon";
73
74 QWidget *widgetCommon = new QWidget;
75 layout->addWidget (widgetCommon, row++, 2, 1, 2);
76
77 QGridLayout *layoutCommon = new QGridLayout;
78 widgetCommon->setLayout (layoutCommon);
79 int rowCommon = 0;
80
81 m_labelLimitWarning = new QLabel;
82 m_labelLimitWarning->setStyleSheet ("QLabel { color: red; }");
83 layoutCommon->addWidget (m_labelLimitWarning, rowCommon++, 0, 1, 4, Qt::AlignCenter);
84
85 QLabel *labelColor = new QLabel (QString ("%1:").arg (tr ("Color")));
86 layoutCommon->addWidget (labelColor, rowCommon, 1);
87
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 &))); // activated() ignores code changes
92 layoutCommon->addWidget (m_cmbColor, rowCommon++, 2);
93
94 QLabel *labelLineWidth = new QLabel (QString ("%1:").arg (tr ("Line width")));
95 layoutCommon->addWidget (labelLineWidth, rowCommon, 1);
96
97 m_spinLineWidth = new QSpinBox (widgetCommon);
98 m_spinLineWidth->setWhatsThis (tr ("Select a width for the grid display lines."));
99 m_spinLineWidth->setMinimum (0); // 0 line width is always scaled to be one pixel in width, and always visible
100 connect (m_spinLineWidth, SIGNAL (valueChanged (int)), this, SLOT (slotLineWidth (int)));
101 layoutCommon->addWidget (m_spinLineWidth, rowCommon++, 2);
102
103 // Make sure there is an empty column, for padding, on the left and right sides
104 layoutCommon->setColumnStretch (0, 1);
105 layoutCommon->setColumnStretch (1, 0);
106 layoutCommon->setColumnStretch (2, 0);
107 layoutCommon->setColumnStretch (3, 1);
108}
109
110void DlgSettingsGridDisplay::createDisplayGridLinesX (QGridLayout *layout, int &row)
111{
112 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesX";
113
114 m_groupX = new QGroupBox; // Text is added at load time at which point current context is known
115 layout->addWidget (m_groupX, row, 2);
116
117 QGridLayout *layoutGroup = new QGridLayout;
118 m_groupX->setLayout (layoutGroup);
119
120 QLabel *labelDisable = new QLabel (QString ("%1:").arg (tr ("Disable")));
121 layoutGroup->addWidget (labelDisable, 0, 0);
122
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"));
128 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
129 QVariant (GRID_COORD_DISABLE_COUNT));
130 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
131 QVariant (GRID_COORD_DISABLE_START));
132 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
133 QVariant (GRID_COORD_DISABLE_STEP));
134 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
135 QVariant (GRID_COORD_DISABLE_STOP));
136 connect (m_cmbDisableX, SIGNAL (activated (const QString &)), this, SLOT (slotDisableX (const QString &))); // activated() ignores code changes
137 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
138
139 QLabel *labelCount = new QLabel (QString ("%1:").arg (tr ("Count")));
140 layoutGroup->addWidget (labelCount, 1, 0);
141
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);
147 m_validatorCountX->setDecimals (COUNT_DECIMALS);
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);
151
152 QLabel *labelStart = new QLabel (QString ("%1:").arg (tr ("Start")));
153 layoutGroup->addWidget (labelStart, 2, 0);
154
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);
162
163 QLabel *labelStep = new QLabel (QString ("%1:").arg (tr ("Step")));
164 layoutGroup->addWidget (labelStep, 3, 0);
165
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);
173
174 QLabel *labelStop = new QLabel (QString ("%1:").arg (tr ("Stop")));
175 layoutGroup->addWidget (labelStop, 4, 0);
176
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);
184}
185
186void DlgSettingsGridDisplay::createDisplayGridLinesY (QGridLayout *layout, int &row)
187{
188 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesY";
189
190 m_groupY = new QGroupBox; // Text is added at load time at which point current context is known
191 layout->addWidget (m_groupY, row++, 3);
192
193 QGridLayout *layoutGroup = new QGridLayout;
194 m_groupY->setLayout (layoutGroup);
195
196 QLabel *labelDisable = new QLabel (QString ("%1:").arg (tr ("Disable")));
197 layoutGroup->addWidget (labelDisable, 0, 0);
198
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"));
204 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
205 QVariant (GRID_COORD_DISABLE_COUNT));
206 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
207 QVariant (GRID_COORD_DISABLE_START));
208 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
209 QVariant (GRID_COORD_DISABLE_STEP));
210 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
211 QVariant (GRID_COORD_DISABLE_STOP));
212 connect (m_cmbDisableY, SIGNAL (activated (const QString &)), this, SLOT (slotDisableY (const QString &))); // activated() ignores code changes
213 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
214
215 QLabel *labelCount = new QLabel (QString ("%1:").arg (tr ("Count")));
216 layoutGroup->addWidget (labelCount, 1, 0);
217
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);
223 m_validatorCountY->setDecimals (COUNT_DECIMALS);
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);
227
228 QLabel *labelStart = new QLabel (QString ("%1:").arg (tr ("Start")));
229 layoutGroup->addWidget (labelStart, 2, 0);
230
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);
238
239 QLabel *labelStep = new QLabel (QString ("%1:").arg (tr ("Step")));
240 layoutGroup->addWidget (labelStep, 3, 0);
241
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);
249
250 QLabel *labelStop = new QLabel (QString ("%1:").arg (tr ("Stop")));
251 layoutGroup->addWidget (labelStop, 4, 0);
252
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);
260}
261
263{
264}
265
266void DlgSettingsGridDisplay::createPreview (QGridLayout *layout, int &row)
267{
268 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createPreview";
269
270 QLabel *labelPreview = new QLabel (tr ("Preview"));
271 layout->addWidget (labelPreview, row++, 0, 1, 5);
272
273 m_scenePreview = new QGraphicsScene (this);
274 m_viewPreview = new ViewPreview (m_scenePreview,
276 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);
280 m_viewPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
281 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
282}
283
285{
286 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createSubPanel";
287
288 QWidget *subPanel = new QWidget ();
289 QGridLayout *layout = new QGridLayout (subPanel);
290 subPanel->setLayout (layout);
291
292 layout->setColumnStretch(0, 1); // Empty first column
293 layout->setColumnStretch(1, 0); // Checkbox part of "section" checkboxes. In other rows this has empty space as indentation
294 layout->setColumnStretch(2, 0); // X
295 layout->setColumnStretch(3, 0); // Y
296 layout->setColumnStretch(4, 1); // Empty last column
297
298 int row = 0;
299
300 createWhatsThis (layout,
301 m_btnWhatsThis,
302 row++,
303 4);
304
305 createDisplayGridLinesX (layout, row);
306 createDisplayGridLinesY (layout, row);
307 createDisplayCommon (layout, row);
308 createPreview (layout, row);
309
310 return subPanel;
311}
312
314{
315 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::handleOk";
316
317 // Set the stable flag
318 m_modelGridDisplayAfter->setStable (true);
319
321 cmdMediator ().document(),
322 *m_modelGridDisplayBefore,
323 *m_modelGridDisplayAfter);
324 cmdMediator ().push (cmd);
325
326 hide ();
327}
328
330{
331 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::load";
332
334
335 // Flush old data
336 delete m_modelGridDisplayBefore;
337 delete m_modelGridDisplayAfter;
338
339 // Display cartesian or polar headers as appropriate
340 QString titleX = tr ("X Grid Lines");
341 if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
342 titleX = QString (QChar (0x98, 0x03)) + QString (" %1").arg (tr ("Grid Lines"));
343 }
344 m_groupX->setTitle (titleX);
345
346 QString titleY = tr ("Y Grid Lines");
347 if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
348 titleY = QString (tr ("Radius Grid Lines"));
349 }
350 m_groupY->setTitle (titleY);
351
352 // Save new data
353 m_modelGridDisplayBefore = new DocumentModelGridDisplay (cmdMediator.document());
354 m_modelGridDisplayAfter = new DocumentModelGridDisplay (cmdMediator.document());
355
356 // Populate controls
357 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridDisplayAfter->disableX()));
358 m_cmbDisableX->setCurrentIndex (indexDisableX);
359
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()));
364
365 int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridDisplayAfter->disableY()));
366 m_cmbDisableY->setCurrentIndex (indexDisableY);
367
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()));
372
373 int indexColor = m_cmbColor->findData(QVariant(m_modelGridDisplayAfter->paletteColor()));
374 ENGAUGE_ASSERT (indexColor >= 0);
375 m_cmbColor->setCurrentIndex(indexColor);
376
377 m_spinLineWidth->setValue (m_modelGridDisplayAfter->lineWidth ());
378
379 addPixmap (*m_scenePreview,
380 cmdMediator.document().pixmap());
381
382 updateControls ();
383 enableOk (false); // Disable Ok button since there not yet any changes
384 updatePreview();
385}
386
388{
389 if (!smallDialogs) {
390 setMinimumHeight (MINIMUM_HEIGHT);
391 }
392}
393
394void DlgSettingsGridDisplay::slotColor (QString const &)
395{
396 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotColor";
397
398 m_modelGridDisplayAfter->setPaletteColor(static_cast<ColorPalette> (m_cmbColor->currentData().toInt()));
399 updateControls();
400 updatePreview();
401}
402
403void DlgSettingsGridDisplay::slotCountX(const QString &count)
404{
405 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountX";
406
407 m_modelGridDisplayAfter->setCountX(unsigned (count.toInt()));
408 updateDisplayedVariableX ();
409 updateControls ();
410 updatePreview();
411}
412
413void DlgSettingsGridDisplay::slotCountY(const QString &count)
414{
415 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountY";
416
417 m_modelGridDisplayAfter->setCountY(unsigned (count.toInt()));
418 updateDisplayedVariableY ();
419 updateControls ();
420 updatePreview();
421}
422
423void DlgSettingsGridDisplay::slotDisableX(const QString &)
424{
425 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableX";
426
427 GridCoordDisable gridCoordDisable = static_cast<GridCoordDisable> (m_cmbDisableX->currentData().toInt());
428 m_modelGridDisplayAfter->setDisableX(gridCoordDisable);
429 updateDisplayedVariableX ();
430 updateControls();
431 updatePreview();
432}
433
434void DlgSettingsGridDisplay::slotDisableY(const QString &)
435{
436 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableY";
437
438 GridCoordDisable gridCoordDisable = static_cast<GridCoordDisable> (m_cmbDisableY->currentData().toInt());
439 m_modelGridDisplayAfter->setDisableY(gridCoordDisable);
440 updateDisplayedVariableY ();
441 updateControls();
442 updatePreview();
443}
444
445void DlgSettingsGridDisplay::slotLineWidth (int lineWidth)
446{
447 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotLineWidth width=" << lineWidth;
448
449 m_modelGridDisplayAfter->setLineWidth (lineWidth);
450 updateControls();
451 updatePreview();
452}
453
454void DlgSettingsGridDisplay::slotStartX(const QString &startX)
455{
456 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartX";
457
458 m_modelGridDisplayAfter->setStartX(startX.toDouble());
459 updateDisplayedVariableX ();
460 updateControls();
461 updatePreview();
462}
463
464void DlgSettingsGridDisplay::slotStartY(const QString &startY)
465{
466 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartY";
467
468 m_modelGridDisplayAfter->setStartY(startY.toDouble());
469 updateDisplayedVariableY ();
470 updateControls();
471 updatePreview();
472}
473
474void DlgSettingsGridDisplay::slotStepX(const QString &stepX)
475{
476 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepX";
477
478 m_modelGridDisplayAfter->setStepX(stepX.toDouble());
479 updateDisplayedVariableX ();
480 updateControls();
481 updatePreview();
482}
483
484void DlgSettingsGridDisplay::slotStepY(const QString &stepY)
485{
486 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepY";
487
488 m_modelGridDisplayAfter->setStepY(stepY.toDouble());
489 updateDisplayedVariableY ();
490 updateControls();
491 updatePreview();
492}
493
494void DlgSettingsGridDisplay::slotStopX(const QString &stopX)
495{
496 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopX";
497
498 m_modelGridDisplayAfter->setStopX(stopX.toDouble());
499 updateDisplayedVariableX ();
500 updateControls();
501 updatePreview();
502}
503
504void DlgSettingsGridDisplay::slotStopY(const QString &stopY)
505{
506 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopY";
507
508 m_modelGridDisplayAfter->setStopY(stopY.toDouble());
509 updateDisplayedVariableY ();
510 updateControls();
511 updatePreview();
512}
513
514void DlgSettingsGridDisplay::slotWhatsThis ()
515{
516 QWhatsThis::enterWhatsThisMode();
517}
518
519bool DlgSettingsGridDisplay::textItemsAreValid () const
520{
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();
529
530 // To prevent an infinite loop, skip if either:
531 // 1) a field is empty
532 // 2) value in a field is malformed
533 bool ok = false;
534 int pos;
535 if (
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) {
552
553 // Reject zero steps
554 double stepX = textCountX.toDouble ();
555 double stepY = textCountY.toDouble ();
556
557 if (qAbs (stepX) > 0 && qAbs (stepY) > 0) {
558
559 ok = true;
560 }
561 }
562
563 return ok;
564}
565
566bool DlgSettingsGridDisplay::textItemsDoNotBreakLineCountLimit ()
567{
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();
577
578 // Given that text fields have good values, now compare grid line counts to limit
579 GridInitializer initializer;
580
581 bool linearAxisXTheta = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
582 bool linearAxisYRadius = (cmdMediator ().document ().modelCoords ().coordScaleYRadius() == COORD_SCALE_LINEAR);
583
584 int countX = textCountX.toInt ();
585 if (m_modelGridDisplayAfter->disableX() == GRID_COORD_DISABLE_COUNT) {
586 countX = initializer.computeCount (linearAxisXTheta,
587 textStartX.toDouble (),
588 textStopX.toDouble (),
589 textStepX.toDouble ());
590 }
591 int countY = textCountY.toInt ();
592 if (m_modelGridDisplayAfter->disableY() == GRID_COORD_DISABLE_COUNT) {
593 countY = initializer.computeCount (linearAxisYRadius,
594 textStartY.toDouble (),
595 textStopY.toDouble (),
596 textStepY.toDouble ());
597 }
598
599 return (countX <= mainWindow ().modelMainWindow ().maximumGridLines() &&
600 countY <= mainWindow ().modelMainWindow ().maximumGridLines());
601 }
602
603 return true;
604}
605
606void DlgSettingsGridDisplay::updateControls ()
607{
608 GridCoordDisable disableX = static_cast<GridCoordDisable> (m_cmbDisableX->currentData().toInt());
609 m_editCountX->setEnabled (disableX != GRID_COORD_DISABLE_COUNT);
610 m_editStartX->setEnabled (disableX != GRID_COORD_DISABLE_START);
611 m_editStepX->setEnabled (disableX != GRID_COORD_DISABLE_STEP);
612 m_editStopX->setEnabled (disableX != GRID_COORD_DISABLE_STOP);
613
614 GridCoordDisable disableY = static_cast<GridCoordDisable> (m_cmbDisableY->currentData().toInt());
615 m_editCountY->setEnabled (disableY != GRID_COORD_DISABLE_COUNT);
616 m_editStartY->setEnabled (disableY != GRID_COORD_DISABLE_START);
617 m_editStepY->setEnabled (disableY != GRID_COORD_DISABLE_STEP);
618 m_editStopY->setEnabled (disableY != GRID_COORD_DISABLE_STOP);
619
620 if (textItemsDoNotBreakLineCountLimit ()) {
621 m_labelLimitWarning->setText ("");
622 } else {
623 m_labelLimitWarning->setText (tr ("Grid line count exceeds limit set by Settings / Main Window."));
624 }
625
626 enableOk (textItemsAreValid () && textItemsDoNotBreakLineCountLimit ());
627}
628
629void DlgSettingsGridDisplay::updateDisplayedVariableX ()
630{
631 GridInitializer initializer;
632
633 bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
634
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 ())));
641 break;
642
644 m_editStartX->setText (QString::number (initializer.computeStart (linearAxis,
645 m_modelGridDisplayAfter->stopX (),
646 m_modelGridDisplayAfter->stepX (),
647 signed (m_modelGridDisplayAfter->countX ()))));
648 break;
649
651 m_editStepX->setText (QString::number (initializer.computeStep (linearAxis,
652 m_modelGridDisplayAfter->startX (),
653 m_modelGridDisplayAfter->stopX (),
654 signed (m_modelGridDisplayAfter->countX ()))));
655 break;
656
658 m_editStopX->setText (QString::number (initializer.computeStop (linearAxis,
659 m_modelGridDisplayAfter->startX (),
660 m_modelGridDisplayAfter->stepX (),
661 signed (m_modelGridDisplayAfter->countX ()))));
662 break;
663 }
664}
665
666void DlgSettingsGridDisplay::updateDisplayedVariableY ()
667{
668 GridInitializer initializer;
669
670 bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleYRadius () == COORD_SCALE_LINEAR);
671
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 ())));
678 break;
679
681 m_editStartY->setText (QString::number (initializer.computeStart (linearAxis,
682 m_modelGridDisplayAfter->stopY (),
683 m_modelGridDisplayAfter->stepY (),
684 signed (m_modelGridDisplayAfter->countY ()))));
685 break;
686
688 m_editStepY->setText (QString::number (initializer.computeStep (linearAxis,
689 m_modelGridDisplayAfter->startY (),
690 m_modelGridDisplayAfter->stopY (),
691 signed (m_modelGridDisplayAfter->countY ()))));
692 break;
693
695 m_editStopY->setText (QString::number (initializer.computeStop (linearAxis,
696 m_modelGridDisplayAfter->startY (),
697 m_modelGridDisplayAfter->stepY (),
698 signed (m_modelGridDisplayAfter->countY ()))));
699 break;
700 }
701}
702
703void DlgSettingsGridDisplay::updatePreview ()
704{
705 m_gridLines.clear ();
706
707 if (textItemsAreValid ()) {
708
709 GridLineFactory factory (*m_scenePreview,
710 cmdMediator ().document ().modelCoords());
711
712 factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,
713 cmdMediator ().document (),
714 mainWindow ().modelMainWindow(),
715 mainWindow ().transformation(),
716 m_gridLines);
717 }
718}
ColorPalette
@ COORD_SCALE_LINEAR
Definition CoordScale.h:13
@ COORDS_TYPE_POLAR
Definition CoordsType.h:14
const int MINIMUM_HEIGHT
const int COUNT_DECIMALS
const int COUNT_MIN
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
QString gridCoordDisableToString(GridCoordDisable gridCoordDisable)
GridCoordDisable
@ GRID_COORD_DISABLE_STOP
@ GRID_COORD_DISABLE_START
@ GRID_COORD_DISABLE_STEP
@ GRID_COORD_DISABLE_COUNT
log4cpp::Category * mainCat
Definition Logger.cpp:14
Command queue stack.
Definition CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
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 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.
Definition Document.cpp:707
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...
Definition MainWindow.h:95
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
Definition ViewPreview.h:15
@ VIEW_ASPECT_RATIO_VARIABLE
Definition ViewPreview.h:22
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18