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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 (QString ("%1:").arg (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 
299 
300  // Flush old data
301  delete m_modelGridDisplayBefore;
302  delete m_modelGridDisplayAfter;
303 
304  // Display cartesian or polar headers as appropriate
305  QString titleX = tr ("X Grid Lines");
306  if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
307  titleX = QString (QChar (0x98, 0x03)) + QString (" %1").arg (tr ("Grid Lines"));
308  }
309  m_groupX->setTitle (titleX);
310 
311  QString titleY = tr ("Y Grid Lines");
312  if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
313  titleY = QString (tr ("Radius Grid Lines"));
314  }
315  m_groupY->setTitle (titleY);
316 
317  // Save new data
318  m_modelGridDisplayBefore = new DocumentModelGridDisplay (cmdMediator.document());
319  m_modelGridDisplayAfter = new DocumentModelGridDisplay (cmdMediator.document());
320 
321  // Populate controls
322  int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridDisplayAfter->disableX()));
323  m_cmbDisableX->setCurrentIndex (indexDisableX);
324 
325  m_editCountX->setText(QString::number(m_modelGridDisplayAfter->countX()));
326  m_editStartX->setText(QString::number(m_modelGridDisplayAfter->startX()));
327  m_editStepX->setText(QString::number(m_modelGridDisplayAfter->stepX()));
328  m_editStopX->setText(QString::number(m_modelGridDisplayAfter->stopX()));
329 
330  int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridDisplayAfter->disableY()));
331  m_cmbDisableY->setCurrentIndex (indexDisableY);
332 
333  m_editCountY->setText(QString::number(m_modelGridDisplayAfter->countY()));
334  m_editStartY->setText(QString::number(m_modelGridDisplayAfter->startY()));
335  m_editStepY->setText(QString::number(m_modelGridDisplayAfter->stepY()));
336  m_editStopY->setText(QString::number(m_modelGridDisplayAfter->stopY()));
337 
338  int indexColor = m_cmbColor->findData(QVariant(m_modelGridDisplayAfter->paletteColor()));
339  ENGAUGE_ASSERT (indexColor >= 0);
340  m_cmbColor->setCurrentIndex(indexColor);
341 
342  m_scenePreview->addPixmap (cmdMediator.document().pixmap());
343 
344  updateControls ();
345  enableOk (false); // Disable Ok button since there not yet any changes
346  updatePreview();
347 }
348 
350 {
351  if (!smallDialogs) {
352  setMinimumHeight (MINIMUM_HEIGHT);
353  }
354 }
355 
356 void DlgSettingsGridDisplay::slotColor (QString const &)
357 {
358  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotColor";
359 
360  m_modelGridDisplayAfter->setPaletteColor((ColorPalette) m_cmbColor->currentData().toInt());
361  updateControls();
362  updatePreview();
363 }
364 
365 void DlgSettingsGridDisplay::slotCountX(const QString &count)
366 {
367  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountX";
368 
369  m_modelGridDisplayAfter->setCountX(count.toInt());
370  updateDisplayedVariableX ();
371  updateControls ();
372  updatePreview();
373 }
374 
375 void DlgSettingsGridDisplay::slotCountY(const QString &count)
376 {
377  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountY";
378 
379  m_modelGridDisplayAfter->setCountY(count.toInt());
380  updateDisplayedVariableY ();
381  updateControls ();
382  updatePreview();
383 }
384 
385 void DlgSettingsGridDisplay::slotDisableX(const QString &)
386 {
387  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableX";
388 
389  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
390  m_modelGridDisplayAfter->setDisableX(gridCoordDisable);
391  updateDisplayedVariableX ();
392  updateControls();
393  updatePreview();
394 }
395 
396 void DlgSettingsGridDisplay::slotDisableY(const QString &)
397 {
398  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableY";
399 
400  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
401  m_modelGridDisplayAfter->setDisableY(gridCoordDisable);
402  updateDisplayedVariableY ();
403  updateControls();
404  updatePreview();
405 }
406 
407 void DlgSettingsGridDisplay::slotStartX(const QString &startX)
408 {
409  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartX";
410 
411  m_modelGridDisplayAfter->setStartX(startX.toDouble());
412  updateDisplayedVariableX ();
413  updateControls();
414  updatePreview();
415 }
416 
417 void DlgSettingsGridDisplay::slotStartY(const QString &startY)
418 {
419  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartY";
420 
421  m_modelGridDisplayAfter->setStartY(startY.toDouble());
422  updateDisplayedVariableY ();
423  updateControls();
424  updatePreview();
425 }
426 
427 void DlgSettingsGridDisplay::slotStepX(const QString &stepX)
428 {
429  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepX";
430 
431  m_modelGridDisplayAfter->setStepX(stepX.toDouble());
432  updateDisplayedVariableX ();
433  updateControls();
434  updatePreview();
435 }
436 
437 void DlgSettingsGridDisplay::slotStepY(const QString &stepY)
438 {
439  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepY";
440 
441  m_modelGridDisplayAfter->setStepY(stepY.toDouble());
442  updateDisplayedVariableY ();
443  updateControls();
444  updatePreview();
445 }
446 
447 void DlgSettingsGridDisplay::slotStopX(const QString &stopX)
448 {
449  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopX";
450 
451  m_modelGridDisplayAfter->setStopX(stopX.toDouble());
452  updateDisplayedVariableX ();
453  updateControls();
454  updatePreview();
455 }
456 
457 void DlgSettingsGridDisplay::slotStopY(const QString &stopY)
458 {
459  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopY";
460 
461  m_modelGridDisplayAfter->setStopY(stopY.toDouble());
462  updateDisplayedVariableY ();
463  updateControls();
464  updatePreview();
465 }
466 
467 bool DlgSettingsGridDisplay::textItemsAreValid () const
468 {
469  QString textCountX = m_editCountX->text();
470  QString textCountY = m_editCountY->text();
471  QString textStartX = m_editStartX->text();
472  QString textStartY = m_editStartY->text();
473  QString textStepX = m_editStepX->text();
474  QString textStepY = m_editStepY->text();
475  QString textStopX = m_editStopX->text();
476  QString textStopY = m_editStopY->text();
477 
478  // To prevent an infinite loop, skip if either:
479  // 1) a field is empty
480  // 2) value in a field is malformed
481  bool ok = false;
482  int pos;
483  if (
484  !textCountX.isEmpty() &&
485  !textCountY.isEmpty() &&
486  !textStartX.isEmpty() &&
487  !textStartY.isEmpty() &&
488  !textStepX.isEmpty() &&
489  !textStepY.isEmpty() &&
490  !textStopX.isEmpty() &&
491  !textStopY.isEmpty() &&
492  m_validatorCountX->validate(textCountX, pos) == QValidator::Acceptable &&
493  m_validatorCountY->validate(textCountY, pos) == QValidator::Acceptable &&
494  m_validatorStartX->validate(textStartX, pos) == QValidator::Acceptable &&
495  m_validatorStartY->validate(textStartY, pos) == QValidator::Acceptable &&
496  m_validatorStepX->validate(textStepX, pos) == QValidator::Acceptable &&
497  m_validatorStepY->validate(textStepY, pos) == QValidator::Acceptable &&
498  m_validatorStopX->validate(textStopX, pos) == QValidator::Acceptable &&
499  m_validatorStopY->validate(textStopY, pos) == QValidator::Acceptable) {
500 
501  // Reject zero steps
502  double stepX = textCountX.toDouble ();
503  double stepY = textCountY.toDouble ();
504 
505  if (stepX != 0 && stepY != 0) {
506 
507  ok = true;
508  }
509  }
510 
511  return ok;
512 }
513 
514 bool DlgSettingsGridDisplay::textItemsDoNotBreakLineCountLimit ()
515 {
516  if (textItemsAreValid ()) {
517  QString textCountX = m_editCountX->text();
518  QString textCountY = m_editCountY->text();
519  QString textStartX = m_editStartX->text();
520  QString textStartY = m_editStartY->text();
521  QString textStepX = m_editStepX->text();
522  QString textStepY = m_editStepY->text();
523  QString textStopX = m_editStopX->text();
524  QString textStopY = m_editStopY->text();
525 
526  // Given that text fields have good values, now compare grid line counts to limit
527  GridInitializer initializer;
528 
529  bool linearAxisXTheta = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
530  bool linearAxisYRadius = (cmdMediator ().document ().modelCoords ().coordScaleYRadius() == COORD_SCALE_LINEAR);
531 
532  int countX = textCountX.toInt ();
533  if (m_modelGridDisplayAfter->disableX() == GRID_COORD_DISABLE_COUNT) {
534  countX = initializer.computeCount (linearAxisXTheta,
535  textStartX.toDouble (),
536  textStopX.toDouble (),
537  textStepX.toDouble ());
538  }
539  int countY = textCountY.toInt ();
540  if (m_modelGridDisplayAfter->disableY() == GRID_COORD_DISABLE_COUNT) {
541  countY = initializer.computeCount (linearAxisYRadius,
542  textStartY.toDouble (),
543  textStopY.toDouble (),
544  textStepY.toDouble ());
545  }
546 
547  return (countX <= mainWindow ().modelMainWindow ().maximumGridLines() &&
548  countY <= mainWindow ().modelMainWindow ().maximumGridLines());
549  }
550 
551  return true;
552 }
553 
554 void DlgSettingsGridDisplay::updateControls ()
555 {
556  GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
557  m_editCountX->setEnabled (disableX != GRID_COORD_DISABLE_COUNT);
558  m_editStartX->setEnabled (disableX != GRID_COORD_DISABLE_START);
559  m_editStepX->setEnabled (disableX != GRID_COORD_DISABLE_STEP);
560  m_editStopX->setEnabled (disableX != GRID_COORD_DISABLE_STOP);
561 
562  GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
563  m_editCountY->setEnabled (disableY != GRID_COORD_DISABLE_COUNT);
564  m_editStartY->setEnabled (disableY != GRID_COORD_DISABLE_START);
565  m_editStepY->setEnabled (disableY != GRID_COORD_DISABLE_STEP);
566  m_editStopY->setEnabled (disableY != GRID_COORD_DISABLE_STOP);
567 
568  if (textItemsDoNotBreakLineCountLimit ()) {
569  m_labelLimitWarning->setText ("");
570  } else {
571  m_labelLimitWarning->setText (tr ("Grid line count exceeds limit set by Settings / Main Window."));
572  }
573 
574  enableOk (textItemsAreValid () && textItemsDoNotBreakLineCountLimit ());
575 }
576 
577 void DlgSettingsGridDisplay::updateDisplayedVariableX ()
578 {
579  GridInitializer initializer;
580 
581  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
582 
583  switch (m_modelGridDisplayAfter->disableX()) {
584  case GRID_COORD_DISABLE_COUNT:
585  m_editCountX->setText (QString::number (initializer.computeCount (linearAxis,
586  m_modelGridDisplayAfter->startX (),
587  m_modelGridDisplayAfter->stopX (),
588  m_modelGridDisplayAfter->stepX ())));
589  break;
590 
591  case GRID_COORD_DISABLE_START:
592  m_editStartX->setText (QString::number (initializer.computeStart (linearAxis,
593  m_modelGridDisplayAfter->stopX (),
594  m_modelGridDisplayAfter->stepX (),
595  m_modelGridDisplayAfter->countX ())));
596  break;
597 
598  case GRID_COORD_DISABLE_STEP:
599  m_editStepX->setText (QString::number (initializer.computeStep (linearAxis,
600  m_modelGridDisplayAfter->startX (),
601  m_modelGridDisplayAfter->stopX (),
602  m_modelGridDisplayAfter->countX ())));
603  break;
604 
605  case GRID_COORD_DISABLE_STOP:
606  m_editStopX->setText (QString::number (initializer.computeStop (linearAxis,
607  m_modelGridDisplayAfter->startX (),
608  m_modelGridDisplayAfter->stepX (),
609  m_modelGridDisplayAfter->countX ())));
610  break;
611 
612  default:
613  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableX";
614  break;
615  }
616 }
617 
618 void DlgSettingsGridDisplay::updateDisplayedVariableY ()
619 {
620  GridInitializer initializer;
621 
622  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleYRadius () == COORD_SCALE_LINEAR);
623 
624  switch (m_modelGridDisplayAfter->disableY()) {
625  case GRID_COORD_DISABLE_COUNT:
626  m_editCountY->setText (QString::number (initializer.computeCount (linearAxis,
627  m_modelGridDisplayAfter->startY (),
628  m_modelGridDisplayAfter->stopY (),
629  m_modelGridDisplayAfter->stepY ())));
630  break;
631 
632  case GRID_COORD_DISABLE_START:
633  m_editStartY->setText (QString::number (initializer.computeStart (linearAxis,
634  m_modelGridDisplayAfter->stopY (),
635  m_modelGridDisplayAfter->stepY (),
636  m_modelGridDisplayAfter->countY ())));
637  break;
638 
639  case GRID_COORD_DISABLE_STEP:
640  m_editStepY->setText (QString::number (initializer.computeStep (linearAxis,
641  m_modelGridDisplayAfter->startY (),
642  m_modelGridDisplayAfter->stopY (),
643  m_modelGridDisplayAfter->countY ())));
644  break;
645 
646  case GRID_COORD_DISABLE_STOP:
647  m_editStopY->setText (QString::number (initializer.computeStop (linearAxis,
648  m_modelGridDisplayAfter->startY (),
649  m_modelGridDisplayAfter->stepY (),
650  m_modelGridDisplayAfter->countY ())));
651  break;
652 
653  default:
654  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableY";
655  break;
656  }
657 }
658 
659 void DlgSettingsGridDisplay::updatePreview ()
660 {
661  m_gridLines.clear ();
662 
663  if (textItemsAreValid ()) {
664 
665  GridLineFactory factory (*m_scenePreview,
666  cmdMediator ().document ().modelCoords());
667 
668  factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,
669  cmdMediator ().document (),
670  mainWindow ().modelMainWindow(),
671  mainWindow ().transformation(),
672  m_gridLines);
673  }
674 }
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.
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:813
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:691
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:91
void setPaletteColor(ColorPalette paletteColor)
Set method for color.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.