Engauge Digitizer  2
DlgSettingsGridDisplay.cpp
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 "CmdMediator.h"
8 #include "CmdSettingsGridDisplay.h"
9 #include "DlgSettingsGridDisplay.h"
10 #include "EngaugeAssert.h"
11 #include "GridInitializer.h"
12 #include "GridLineFactory.h"
13 #include "Logger.h"
14 #include "MainWindow.h"
15 #include <QCheckBox>
16 #include <QComboBox>
17 #include <QDoubleValidator>
18 #include <QGraphicsScene>
19 #include <QGridLayout>
20 #include <QGroupBox>
21 #include <QHBoxLayout>
22 #include <QLabel>
23 #include <QLineEdit>
24 #include "ViewPreview.h"
25 
26 const int COUNT_MIN = 1;
27 const int COUNT_DECIMALS = 0;
28 const int MINIMUM_HEIGHT = 480;
29 
31  DlgSettingsAbstractBase (tr ("Grid Display"),
32  "DlgSettingsGridDisplay",
33  mainWindow),
34  m_scenePreview (0),
35  m_viewPreview (0),
36  m_modelGridDisplayBefore (0),
37  m_modelGridDisplayAfter (0)
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::DlgSettingsGridDisplay";
40 
41  QWidget *subPanel = createSubPanel ();
42  finishPanel (subPanel);
43 }
44 
45 DlgSettingsGridDisplay::~DlgSettingsGridDisplay()
46 {
47  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::~DlgSettingsGridDisplay";
48 }
49 
50 void DlgSettingsGridDisplay::createDisplayCommon (QGridLayout *layout, int &row)
51 {
52  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayCommon";
53 
54  QWidget *widgetCommon = new QWidget;
55  layout->addWidget (widgetCommon, row++, 2, 1, 2);
56 
57  QGridLayout *layoutCommon = new QGridLayout;
58  widgetCommon->setLayout (layoutCommon);
59  int rowCommon = 0;
60 
61  m_labelLimitWarning = new QLabel;
62  m_labelLimitWarning->setStyleSheet ("QLabel { color: red; }");
63  layoutCommon->addWidget (m_labelLimitWarning, rowCommon++, 0, 1, 4, Qt::AlignCenter);
64 
65  QLabel *labelColor = new QLabel (tr ("Color:"));
66  layoutCommon->addWidget (labelColor, rowCommon, 1);
67 
68  m_cmbColor = new QComboBox;
69  m_cmbColor->setWhatsThis (tr ("Select a color for the lines"));
71  connect (m_cmbColor, SIGNAL (activated (const QString &)), this, SLOT (slotColor (const QString &))); // activated() ignores code changes
72  layoutCommon->addWidget (m_cmbColor, rowCommon++, 2);
73 
74  // Make sure there is an empty column, for padding, on the left and right sides
75  layoutCommon->setColumnStretch (0, 1);
76  layoutCommon->setColumnStretch (1, 0);
77  layoutCommon->setColumnStretch (2, 0);
78  layoutCommon->setColumnStretch (3, 1);
79 }
80 
81 void DlgSettingsGridDisplay::createDisplayGridLinesX (QGridLayout *layout, int &row)
82 {
83  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesX";
84 
85  m_groupX = new QGroupBox; // Text is added at load time at which point current context is known
86  layout->addWidget (m_groupX, row, 2);
87 
88  QGridLayout *layoutGroup = new QGridLayout;
89  m_groupX->setLayout (layoutGroup);
90 
91  QLabel *labelDisable = new QLabel (tr ("Disable:"));
92  layoutGroup->addWidget (labelDisable, 0, 0);
93 
94  m_cmbDisableX = new QComboBox;
95  m_cmbDisableX->setWhatsThis (tr ("Disabled value.\n\n"
96  "The X grid lines are specified using only three values at a time. For flexibility, four values "
97  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
98  "updated as the other values change"));
99  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
100  QVariant (GRID_COORD_DISABLE_COUNT));
101  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
102  QVariant (GRID_COORD_DISABLE_START));
103  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
104  QVariant (GRID_COORD_DISABLE_STEP));
105  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
106  QVariant (GRID_COORD_DISABLE_STOP));
107  connect (m_cmbDisableX, SIGNAL (activated (const QString &)), this, SLOT (slotDisableX (const QString &))); // activated() ignores code changes
108  layoutGroup->addWidget (m_cmbDisableX, 0, 1);
109 
110  QLabel *labelCount = new QLabel (tr ("Count:"));
111  layoutGroup->addWidget (labelCount, 1, 0);
112 
113  m_editCountX = new QLineEdit;
114  m_editCountX->setWhatsThis (tr ("Number of X grid lines.\n\n"
115  "The number of X grid lines must be entered as an integer greater than zero"));
116  m_validatorCountX = new QDoubleValidator;
117  m_validatorCountX->setBottom (COUNT_MIN);
118  m_validatorCountX->setDecimals (COUNT_DECIMALS);
119  m_editCountX->setValidator (m_validatorCountX);
120  connect (m_editCountX, SIGNAL (textEdited (const QString &)), this, SLOT (slotCountX (const QString &)));
121  layoutGroup->addWidget (m_editCountX, 1, 1);
122 
123  QLabel *labelStart = new QLabel (tr ("Start:"));
124  layoutGroup->addWidget (labelStart, 2, 0);
125 
126  m_editStartX = new QLineEdit;
127  m_editStartX->setWhatsThis (tr ("Value of the first X grid line.\n\n"
128  "The start value cannot be greater than the stop value"));
129  m_validatorStartX = new QDoubleValidator;
130  m_editStartX->setValidator (m_validatorStartX);
131  connect (m_editStartX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStartX (const QString &)));
132  layoutGroup->addWidget (m_editStartX, 2, 1);
133 
134  QLabel *labelStep = new QLabel (tr ("Step:"));
135  layoutGroup->addWidget (labelStep, 3, 0);
136 
137  m_editStepX = new QLineEdit;
138  m_editStepX->setWhatsThis (tr ("Difference in value between two successive X grid lines.\n\n"
139  "The step value must be greater than zero"));
140  m_validatorStepX = new QDoubleValidator;
141  m_editStepX->setValidator (m_validatorStepX);
142  connect (m_editStepX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStepX (const QString &)));
143  layoutGroup->addWidget (m_editStepX, 3, 1);
144 
145  QLabel *labelStop = new QLabel (tr ("Stop:"));
146  layoutGroup->addWidget (labelStop, 4, 0);
147 
148  m_editStopX = new QLineEdit;
149  m_editStopX->setWhatsThis (tr ("Value of the last X grid line.\n\n"
150  "The stop value cannot be less than the start value"));
151  m_validatorStopX = new QDoubleValidator;
152  m_editStopX->setValidator (m_validatorStopX);
153  connect (m_editStopX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStopX (const QString &)));
154  layoutGroup->addWidget (m_editStopX, 4, 1);
155 }
156 
157 void DlgSettingsGridDisplay::createDisplayGridLinesY (QGridLayout *layout, int &row)
158 {
159  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesY";
160 
161  m_groupY = new QGroupBox; // Text is added at load time at which point current context is known
162  layout->addWidget (m_groupY, row++, 3);
163 
164  QGridLayout *layoutGroup = new QGridLayout;
165  m_groupY->setLayout (layoutGroup);
166 
167  QLabel *labelDisable = new QLabel (tr ("Disable:"));
168  layoutGroup->addWidget (labelDisable, 0, 0);
169 
170  m_cmbDisableY = new QComboBox;
171  m_cmbDisableY->setWhatsThis (tr ("Disabled value.\n\n"
172  "The Y grid lines are specified using only three values at a time. For flexibility, four values "
173  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
174  "updated as the other values change"));
175  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
176  QVariant (GRID_COORD_DISABLE_COUNT));
177  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
178  QVariant (GRID_COORD_DISABLE_START));
179  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
180  QVariant (GRID_COORD_DISABLE_STEP));
181  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
182  QVariant (GRID_COORD_DISABLE_STOP));
183  connect (m_cmbDisableY, SIGNAL (activated (const QString &)), this, SLOT (slotDisableY (const QString &))); // activated() ignores code changes
184  layoutGroup->addWidget (m_cmbDisableY, 0, 1);
185 
186  QLabel *labelCount = new QLabel (tr ("Count:"));
187  layoutGroup->addWidget (labelCount, 1, 0);
188 
189  m_editCountY = new QLineEdit;
190  m_editCountY->setWhatsThis (tr ("Number of Y grid lines.\n\n"
191  "The number of Y grid lines must be entered as an integer greater than zero"));
192  m_validatorCountY = new QDoubleValidator;
193  m_validatorCountY->setBottom (COUNT_MIN);
194  m_validatorCountY->setDecimals (COUNT_DECIMALS);
195  m_editCountY->setValidator (m_validatorCountY);
196  connect (m_editCountY, SIGNAL (textEdited (const QString &)), this, SLOT (slotCountY (const QString &)));
197  layoutGroup->addWidget (m_editCountY, 1, 1);
198 
199  QLabel *labelStart = new QLabel (tr ("Start:"));
200  layoutGroup->addWidget (labelStart, 2, 0);
201 
202  m_editStartY = new QLineEdit;
203  m_editStartY->setWhatsThis (tr ("Value of the first Y grid line.\n\n"
204  "The start value cannot be greater than the stop value"));
205  m_validatorStartY = new QDoubleValidator;
206  m_editStartY->setValidator (m_validatorStartY);
207  connect (m_editStartY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStartY (const QString &)));
208  layoutGroup->addWidget (m_editStartY, 2, 1);
209 
210  QLabel *labelStep = new QLabel (tr ("Step:"));
211  layoutGroup->addWidget (labelStep, 3, 0);
212 
213  m_editStepY = new QLineEdit;
214  m_editStepY->setWhatsThis (tr ("Difference in value between two successive Y grid lines.\n\n"
215  "The step value must be greater than zero"));
216  m_validatorStepY = new QDoubleValidator;
217  m_editStepY->setValidator (m_validatorStepY);
218  connect (m_editStepY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStepY (const QString &)));
219  layoutGroup->addWidget (m_editStepY, 3, 1);
220 
221  QLabel *labelStop = new QLabel (tr ("Stop:"));
222  layoutGroup->addWidget (labelStop, 4, 0);
223 
224  m_editStopY = new QLineEdit;
225  m_editStopY->setWhatsThis (tr ("Value of the last Y grid line.\n\n"
226  "The stop value cannot be less than the start value"));
227  m_validatorStopY = new QDoubleValidator;
228  m_editStopY->setValidator (m_validatorStopY);
229  connect (m_editStopY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStopY (const QString &)));
230  layoutGroup->addWidget (m_editStopY, 4, 1);
231 }
232 
233 void DlgSettingsGridDisplay::createOptionalSaveDefault (QHBoxLayout * /* layout */)
234 {
235 }
236 
237 void DlgSettingsGridDisplay::createPreview (QGridLayout *layout, int &row)
238 {
239  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createPreview";
240 
241  QLabel *labelPreview = new QLabel (tr ("Preview"));
242  layout->addWidget (labelPreview, row++, 0, 1, 5);
243 
244  m_scenePreview = new QGraphicsScene (this);
245  m_viewPreview = new ViewPreview (m_scenePreview,
246  ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
247  this);
248  m_viewPreview->setWhatsThis (tr ("Preview window that shows how current settings affect grid display"));
249  m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
250  m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
251  m_viewPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
252  layout->addWidget (m_viewPreview, row++, 0, 1, 5);
253 }
254 
256 {
257  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createSubPanel";
258 
259  QWidget *subPanel = new QWidget ();
260  QGridLayout *layout = new QGridLayout (subPanel);
261  subPanel->setLayout (layout);
262 
263  layout->setColumnStretch(0, 1); // Empty first column
264  layout->setColumnStretch(1, 0); // Checkbox part of "section" checkboxes. In other rows this has empty space as indentation
265  layout->setColumnStretch(2, 0); // X
266  layout->setColumnStretch(3, 0); // Y
267  layout->setColumnStretch(4, 1); // Empty last column
268 
269  int row = 0;
270  createDisplayGridLinesX (layout, row);
271  createDisplayGridLinesY (layout, row);
272  createDisplayCommon (layout, row);
273  createPreview (layout, row);
274 
275  return subPanel;
276 }
277 
279 {
280  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::handleOk";
281 
282  // Set the stable flag
283  m_modelGridDisplayAfter->setStable (true);
284 
286  cmdMediator ().document(),
287  *m_modelGridDisplayBefore,
288  *m_modelGridDisplayAfter);
289  cmdMediator ().push (cmd);
290 
291  hide ();
292 }
293 
295 {
296  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::load";
297 
298  setCmdMediator (cmdMediator);
299 
300  // Flush old data
301  if (m_modelGridDisplayBefore != 0) {
302  delete m_modelGridDisplayBefore;
303  }
304  if (m_modelGridDisplayAfter != 0) {
305  delete m_modelGridDisplayAfter;
306  }
307 
308  // Display cartesian or polar headers as appropriate
309  QString titleX = tr ("X Grid Lines");
310  if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
311  titleX = QString (QChar (0x98, 0x03)) + QString (" %1").arg (tr ("Grid Lines"));
312  }
313  m_groupX->setTitle (titleX);
314 
315  QString titleY = tr ("Y Grid Lines");
316  if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
317  titleY = QString (tr ("Radius Grid Lines"));
318  }
319  m_groupY->setTitle (titleY);
320 
321  // Save new data
322  m_modelGridDisplayBefore = new DocumentModelGridDisplay (cmdMediator.document());
323  m_modelGridDisplayAfter = new DocumentModelGridDisplay (cmdMediator.document());
324 
325  // Populate controls
326  int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridDisplayAfter->disableX()));
327  m_cmbDisableX->setCurrentIndex (indexDisableX);
328 
329  m_editCountX->setText(QString::number(m_modelGridDisplayAfter->countX()));
330  m_editStartX->setText(QString::number(m_modelGridDisplayAfter->startX()));
331  m_editStepX->setText(QString::number(m_modelGridDisplayAfter->stepX()));
332  m_editStopX->setText(QString::number(m_modelGridDisplayAfter->stopX()));
333 
334  int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridDisplayAfter->disableY()));
335  m_cmbDisableY->setCurrentIndex (indexDisableY);
336 
337  m_editCountY->setText(QString::number(m_modelGridDisplayAfter->countY()));
338  m_editStartY->setText(QString::number(m_modelGridDisplayAfter->startY()));
339  m_editStepY->setText(QString::number(m_modelGridDisplayAfter->stepY()));
340  m_editStopY->setText(QString::number(m_modelGridDisplayAfter->stopY()));
341 
342  int indexColor = m_cmbColor->findData(QVariant(m_modelGridDisplayAfter->paletteColor()));
343  ENGAUGE_ASSERT (indexColor >= 0);
344  m_cmbColor->setCurrentIndex(indexColor);
345 
346  m_scenePreview->addPixmap (cmdMediator.document().pixmap());
347 
348  updateControls ();
349  enableOk (false); // Disable Ok button since there not yet any changes
350  updatePreview();
351 }
352 
354 {
355  if (!smallDialogs) {
356  setMinimumHeight (MINIMUM_HEIGHT);
357  }
358 }
359 
360 void DlgSettingsGridDisplay::slotColor (QString const &)
361 {
362  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotColor";
363 
364  m_modelGridDisplayAfter->setPaletteColor((ColorPalette) m_cmbColor->currentData().toInt());
365  updateControls();
366  updatePreview();
367 }
368 
369 void DlgSettingsGridDisplay::slotCountX(const QString &count)
370 {
371  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountX";
372 
373  m_modelGridDisplayAfter->setCountX(count.toInt());
374  updateDisplayedVariableX ();
375  updateControls ();
376  updatePreview();
377 }
378 
379 void DlgSettingsGridDisplay::slotCountY(const QString &count)
380 {
381  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountY";
382 
383  m_modelGridDisplayAfter->setCountY(count.toInt());
384  updateDisplayedVariableY ();
385  updateControls ();
386  updatePreview();
387 }
388 
389 void DlgSettingsGridDisplay::slotDisableX(const QString &)
390 {
391  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableX";
392 
393  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
394  m_modelGridDisplayAfter->setDisableX(gridCoordDisable);
395  updateDisplayedVariableX ();
396  updateControls();
397  updatePreview();
398 }
399 
400 void DlgSettingsGridDisplay::slotDisableY(const QString &)
401 {
402  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableY";
403 
404  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
405  m_modelGridDisplayAfter->setDisableY(gridCoordDisable);
406  updateDisplayedVariableY ();
407  updateControls();
408  updatePreview();
409 }
410 
411 void DlgSettingsGridDisplay::slotStartX(const QString &startX)
412 {
413  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartX";
414 
415  m_modelGridDisplayAfter->setStartX(startX.toDouble());
416  updateDisplayedVariableX ();
417  updateControls();
418  updatePreview();
419 }
420 
421 void DlgSettingsGridDisplay::slotStartY(const QString &startY)
422 {
423  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartY";
424 
425  m_modelGridDisplayAfter->setStartY(startY.toDouble());
426  updateDisplayedVariableY ();
427  updateControls();
428  updatePreview();
429 }
430 
431 void DlgSettingsGridDisplay::slotStepX(const QString &stepX)
432 {
433  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepX";
434 
435  m_modelGridDisplayAfter->setStepX(stepX.toDouble());
436  updateDisplayedVariableX ();
437  updateControls();
438  updatePreview();
439 }
440 
441 void DlgSettingsGridDisplay::slotStepY(const QString &stepY)
442 {
443  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepY";
444 
445  m_modelGridDisplayAfter->setStepY(stepY.toDouble());
446  updateDisplayedVariableY ();
447  updateControls();
448  updatePreview();
449 }
450 
451 void DlgSettingsGridDisplay::slotStopX(const QString &stopX)
452 {
453  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopX";
454 
455  m_modelGridDisplayAfter->setStopX(stopX.toDouble());
456  updateDisplayedVariableX ();
457  updateControls();
458  updatePreview();
459 }
460 
461 void DlgSettingsGridDisplay::slotStopY(const QString &stopY)
462 {
463  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopY";
464 
465  m_modelGridDisplayAfter->setStopY(stopY.toDouble());
466  updateDisplayedVariableY ();
467  updateControls();
468  updatePreview();
469 }
470 
471 bool DlgSettingsGridDisplay::textItemsAreValid () const
472 {
473  QString textCountX = m_editCountX->text();
474  QString textCountY = m_editCountY->text();
475  QString textStartX = m_editStartX->text();
476  QString textStartY = m_editStartY->text();
477  QString textStepX = m_editStepX->text();
478  QString textStepY = m_editStepY->text();
479  QString textStopX = m_editStopX->text();
480  QString textStopY = m_editStopY->text();
481 
482  // To prevent an infinite loop, skip if either:
483  // 1) a field is empty
484  // 2) value in a field is malformed
485  bool ok = false;
486  int pos;
487  if (
488  !textCountX.isEmpty() &&
489  !textCountY.isEmpty() &&
490  !textStartX.isEmpty() &&
491  !textStartY.isEmpty() &&
492  !textStepX.isEmpty() &&
493  !textStepY.isEmpty() &&
494  !textStopX.isEmpty() &&
495  !textStopY.isEmpty() &&
496  m_validatorCountX->validate(textCountX, pos) == QValidator::Acceptable &&
497  m_validatorCountY->validate(textCountY, pos) == QValidator::Acceptable &&
498  m_validatorStartX->validate(textStartX, pos) == QValidator::Acceptable &&
499  m_validatorStartY->validate(textStartY, pos) == QValidator::Acceptable &&
500  m_validatorStepX->validate(textStepX, pos) == QValidator::Acceptable &&
501  m_validatorStepY->validate(textStepY, pos) == QValidator::Acceptable &&
502  m_validatorStopX->validate(textStopX, pos) == QValidator::Acceptable &&
503  m_validatorStopY->validate(textStopY, pos) == QValidator::Acceptable) {
504 
505  // Reject zero steps
506  double stepX = textCountX.toDouble ();
507  double stepY = textCountY.toDouble ();
508 
509  if (stepX != 0 && stepY != 0) {
510 
511  ok = true;
512  }
513  }
514 
515  return ok;
516 }
517 
518 bool DlgSettingsGridDisplay::textItemsDoNotBreakLineCountLimit ()
519 {
520  if (textItemsAreValid ()) {
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  // Given that text fields have good values, now compare grid line counts to limit
531  GridInitializer initializer;
532 
533  bool linearAxisXTheta = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
534  bool linearAxisYRadius = (cmdMediator ().document ().modelCoords ().coordScaleYRadius() == COORD_SCALE_LINEAR);
535 
536  int countX = textCountX.toInt ();
537  if (m_modelGridDisplayAfter->disableX() == GRID_COORD_DISABLE_COUNT) {
538  countX = initializer.computeCount (linearAxisXTheta,
539  textStartX.toDouble (),
540  textStopX.toDouble (),
541  textStepX.toDouble ());
542  }
543  int countY = textCountY.toInt ();
544  if (m_modelGridDisplayAfter->disableY() == GRID_COORD_DISABLE_COUNT) {
545  countY = initializer.computeCount (linearAxisYRadius,
546  textStartY.toDouble (),
547  textStopY.toDouble (),
548  textStepY.toDouble ());
549  }
550 
551  return (countX <= mainWindow ().modelMainWindow ().maximumGridLines() &&
552  countY <= mainWindow ().modelMainWindow ().maximumGridLines());
553  }
554 
555  return true;
556 }
557 
558 void DlgSettingsGridDisplay::updateControls ()
559 {
560  GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
561  m_editCountX->setEnabled (disableX != GRID_COORD_DISABLE_COUNT);
562  m_editStartX->setEnabled (disableX != GRID_COORD_DISABLE_START);
563  m_editStepX->setEnabled (disableX != GRID_COORD_DISABLE_STEP);
564  m_editStopX->setEnabled (disableX != GRID_COORD_DISABLE_STOP);
565 
566  GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
567  m_editCountY->setEnabled (disableY != GRID_COORD_DISABLE_COUNT);
568  m_editStartY->setEnabled (disableY != GRID_COORD_DISABLE_START);
569  m_editStepY->setEnabled (disableY != GRID_COORD_DISABLE_STEP);
570  m_editStopY->setEnabled (disableY != GRID_COORD_DISABLE_STOP);
571 
572  if (textItemsDoNotBreakLineCountLimit ()) {
573  m_labelLimitWarning->setText ("");
574  } else {
575  m_labelLimitWarning->setText (tr ("Grid line count exceeds limit set by Settings / Main Window."));
576  }
577 
578  enableOk (textItemsAreValid () && textItemsDoNotBreakLineCountLimit ());
579 }
580 
581 void DlgSettingsGridDisplay::updateDisplayedVariableX ()
582 {
583  GridInitializer initializer;
584 
585  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
586 
587  switch (m_modelGridDisplayAfter->disableX()) {
588  case GRID_COORD_DISABLE_COUNT:
589  m_editCountX->setText (QString::number (initializer.computeCount (linearAxis,
590  m_modelGridDisplayAfter->startX (),
591  m_modelGridDisplayAfter->stopX (),
592  m_modelGridDisplayAfter->stepX ())));
593  break;
594 
595  case GRID_COORD_DISABLE_START:
596  m_editStartX->setText (QString::number (initializer.computeStart (linearAxis,
597  m_modelGridDisplayAfter->stopX (),
598  m_modelGridDisplayAfter->stepX (),
599  m_modelGridDisplayAfter->countX ())));
600  break;
601 
602  case GRID_COORD_DISABLE_STEP:
603  m_editStepX->setText (QString::number (initializer.computeStep (linearAxis,
604  m_modelGridDisplayAfter->startX (),
605  m_modelGridDisplayAfter->stopX (),
606  m_modelGridDisplayAfter->countX ())));
607  break;
608 
609  case GRID_COORD_DISABLE_STOP:
610  m_editStopX->setText (QString::number (initializer.computeStop (linearAxis,
611  m_modelGridDisplayAfter->startX (),
612  m_modelGridDisplayAfter->stepX (),
613  m_modelGridDisplayAfter->countX ())));
614  break;
615 
616  default:
617  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableX";
618  break;
619  }
620 }
621 
622 void DlgSettingsGridDisplay::updateDisplayedVariableY ()
623 {
624  GridInitializer initializer;
625 
626  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleYRadius () == COORD_SCALE_LINEAR);
627 
628  switch (m_modelGridDisplayAfter->disableY()) {
629  case GRID_COORD_DISABLE_COUNT:
630  m_editCountY->setText (QString::number (initializer.computeCount (linearAxis,
631  m_modelGridDisplayAfter->startY (),
632  m_modelGridDisplayAfter->stopY (),
633  m_modelGridDisplayAfter->stepY ())));
634  break;
635 
636  case GRID_COORD_DISABLE_START:
637  m_editStartY->setText (QString::number (initializer.computeStart (linearAxis,
638  m_modelGridDisplayAfter->stopY (),
639  m_modelGridDisplayAfter->stepY (),
640  m_modelGridDisplayAfter->countY ())));
641  break;
642 
643  case GRID_COORD_DISABLE_STEP:
644  m_editStepY->setText (QString::number (initializer.computeStep (linearAxis,
645  m_modelGridDisplayAfter->startY (),
646  m_modelGridDisplayAfter->stopY (),
647  m_modelGridDisplayAfter->countY ())));
648  break;
649 
650  case GRID_COORD_DISABLE_STOP:
651  m_editStopY->setText (QString::number (initializer.computeStop (linearAxis,
652  m_modelGridDisplayAfter->startY (),
653  m_modelGridDisplayAfter->stepY (),
654  m_modelGridDisplayAfter->countY ())));
655  break;
656 
657  default:
658  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableY";
659  break;
660  }
661 }
662 
663 void DlgSettingsGridDisplay::updatePreview ()
664 {
665  m_gridLines.clear ();
666 
667  if (textItemsAreValid ()) {
668 
669  GridLineFactory factory (*m_scenePreview,
670  cmdMediator ().document ().modelCoords());
671 
672  factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,
673  cmdMediator ().document (),
674  mainWindow ().modelMainWindow(),
675  mainWindow ().transformation(),
676  m_gridLines);
677  }
678 }
Factory class for generating the points, composed of QGraphicsItem objects, along a GridLine...
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
GridCoordDisable disableY() const
Get method for y grid line disabled variable.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void clear()
Deallocate and remove all grid lines.
Definition: GridLines.cpp:19
void setCountY(unsigned int countY)
Set method for y grid line count.
void setStepX(double stepX)
Set method for x grid line increment.
void createGridLinesForEvenlySpacedGrid(const DocumentModelGridDisplay &modelGridDisplay, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, GridLines &gridLines)
Create a rectangular (cartesian) or annular (polar) grid of evenly spaced grid lines.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
unsigned int countX() const
Get method for x grid line count.
Command for DlgSettingsGridDisplay.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
void setStepY(double yStep)
Set method for y grid line increment.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
unsigned int countY() const
Get method for y grid line count.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
DlgSettingsGridDisplay(MainWindow &mainWindow)
Single constructor.
void setStable(bool stable)
Set method for stable flag.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
Definition: ViewPreview.h:14
GridCoordDisable disableX() const
Get method for x grid line disabled variable.
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
This class initializes the count, start, step and stop parameters for one coordinate (either x/theta ...
virtual void handleOk()
Process slotOk.
int maximumGridLines() const
Maximum number of grid lines.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
double stopY() const
Get method for y grid line upper bound (inclusive).
void setDisableX(GridCoordDisable disableX)
Set method for x grid line disabled variable.
double stopX() const
Get method for x grid line upper bound (inclusive).
ColorPalette paletteColor() const
Get method for color.
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
void setDisableY(GridCoordDisable disableY)
Set method for y grid line disabled variable.
double startY() const
Get method for y grid line lower bound (inclusive).
void setCountX(unsigned int countX)
Set method for x grid line count.
MainWindowModel modelMainWindow() const
Get method for main window model.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
CoordsType coordsType() const
Get method for coordinates type.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
Command queue stack.
Definition: CmdMediator.h:23
Abstract base class for all Settings dialogs.
double stepY() const
Get method for y grid line increment.
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
double startX() const
Get method for x grid line lower bound (inclusive).
QPixmap pixmap() const
Return the image that is being digitized.
Definition: Document.cpp:811
double computeStep(bool linearAxis, double start, double stop, int count) const
Compute axis scale step from the other axis parameters.
double stepX() const
Get method for x grid line increment.
MainWindow & mainWindow()
Get method for MainWindow.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:689
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89
void setPaletteColor(ColorPalette paletteColor)
Set method for color.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.