Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
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_MAX = 100;
28 const int COUNT_DECIMALS = 0;
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  QLabel *labelColor = new QLabel (tr ("Color:"));
62  layoutCommon->addWidget (labelColor, rowCommon, 1);
63 
64  m_cmbColor = new QComboBox;
65  m_cmbColor->setWhatsThis (tr ("Select a color for the lines"));
67  connect (m_cmbColor, SIGNAL (activated (const QString &)), this, SLOT (slotColor (const QString &))); // activated() ignores code changes
68  layoutCommon->addWidget (m_cmbColor, rowCommon++, 2);
69 
70  // Make sure there is an empty column, for padding, on the left and right sides
71  layoutCommon->setColumnStretch (0, 1);
72  layoutCommon->setColumnStretch (1, 0);
73  layoutCommon->setColumnStretch (2, 0);
74  layoutCommon->setColumnStretch (3, 1);
75 }
76 
77 void DlgSettingsGridDisplay::createDisplayGridLinesX (QGridLayout *layout, int &row)
78 {
79  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesX";
80 
81  m_groupX = new QGroupBox; // Text is added at load time at which point current context is known
82  layout->addWidget (m_groupX, row, 2);
83 
84  QGridLayout *layoutGroup = new QGridLayout;
85  m_groupX->setLayout (layoutGroup);
86 
87  QLabel *labelDisable = new QLabel (tr ("Disable:"));
88  layoutGroup->addWidget (labelDisable, 0, 0);
89 
90  m_cmbDisableX = new QComboBox;
91  m_cmbDisableX->setWhatsThis (tr ("Disabled value.\n\n"
92  "The X grid lines are specified using only three values at a time. For flexibility, four values "
93  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
94  "updated as the other values change"));
95  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
96  QVariant (GRID_COORD_DISABLE_COUNT));
97  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
98  QVariant (GRID_COORD_DISABLE_START));
99  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
100  QVariant (GRID_COORD_DISABLE_STEP));
101  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
102  QVariant (GRID_COORD_DISABLE_STOP));
103  connect (m_cmbDisableX, SIGNAL (activated (const QString &)), this, SLOT (slotDisableX (const QString &))); // activated() ignores code changes
104  layoutGroup->addWidget (m_cmbDisableX, 0, 1);
105 
106  QLabel *labelCount = new QLabel (tr ("Count:"));
107  layoutGroup->addWidget (labelCount, 1, 0);
108 
109  m_editCountX = new QLineEdit;
110  m_editCountX->setWhatsThis (tr ("Number of X grid lines.\n\n"
111  "The number of X grid lines must be entered as an integer greater than zero"));
112  m_validatorCountX = new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
113  m_editCountX->setValidator (m_validatorCountX);
114  connect (m_editCountX, SIGNAL (textEdited (const QString &)), this, SLOT (slotCountX (const QString &)));
115  layoutGroup->addWidget (m_editCountX, 1, 1);
116 
117  QLabel *labelStart = new QLabel (tr ("Start:"));
118  layoutGroup->addWidget (labelStart, 2, 0);
119 
120  m_editStartX = new QLineEdit;
121  m_editStartX->setWhatsThis (tr ("Value of the first X grid line.\n\n"
122  "The start value cannot be greater than the stop value"));
123  m_validatorStartX = new QDoubleValidator;
124  m_editStartX->setValidator (m_validatorStartX);
125  connect (m_editStartX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStartX (const QString &)));
126  layoutGroup->addWidget (m_editStartX, 2, 1);
127 
128  QLabel *labelStep = new QLabel (tr ("Step:"));
129  layoutGroup->addWidget (labelStep, 3, 0);
130 
131  m_editStepX = new QLineEdit;
132  m_editStepX->setWhatsThis (tr ("Difference in value between two successive X grid lines.\n\n"
133  "The step value must be greater than zero"));
134  m_validatorStepX = new QDoubleValidator;
135  m_editStepX->setValidator (m_validatorStepX);
136  connect (m_editStepX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStepX (const QString &)));
137  layoutGroup->addWidget (m_editStepX, 3, 1);
138 
139  QLabel *labelStop = new QLabel (tr ("Stop:"));
140  layoutGroup->addWidget (labelStop, 4, 0);
141 
142  m_editStopX = new QLineEdit;
143  m_editStopX->setWhatsThis (tr ("Value of the last X grid line.\n\n"
144  "The stop value cannot be less than the start value"));
145  m_validatorStopX = new QDoubleValidator;
146  m_editStopX->setValidator (m_validatorStopX);
147  connect (m_editStopX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStopX (const QString &)));
148  layoutGroup->addWidget (m_editStopX, 4, 1);
149 }
150 
151 void DlgSettingsGridDisplay::createDisplayGridLinesY (QGridLayout *layout, int &row)
152 {
153  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesY";
154 
155  m_groupY = new QGroupBox; // Text is added at load time at which point current context is known
156  layout->addWidget (m_groupY, row++, 3);
157 
158  QGridLayout *layoutGroup = new QGridLayout;
159  m_groupY->setLayout (layoutGroup);
160 
161  QLabel *labelDisable = new QLabel (tr ("Disable:"));
162  layoutGroup->addWidget (labelDisable, 0, 0);
163 
164  m_cmbDisableY = new QComboBox;
165  m_cmbDisableY->setWhatsThis (tr ("Disabled value.\n\n"
166  "The Y grid lines are specified using only three values at a time. For flexibility, four values "
167  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
168  "updated as the other values change"));
169  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
170  QVariant (GRID_COORD_DISABLE_COUNT));
171  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
172  QVariant (GRID_COORD_DISABLE_START));
173  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
174  QVariant (GRID_COORD_DISABLE_STEP));
175  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
176  QVariant (GRID_COORD_DISABLE_STOP));
177  connect (m_cmbDisableY, SIGNAL (activated (const QString &)), this, SLOT (slotDisableY (const QString &))); // activated() ignores code changes
178  layoutGroup->addWidget (m_cmbDisableY, 0, 1);
179 
180  QLabel *labelCount = new QLabel (tr ("Count:"));
181  layoutGroup->addWidget (labelCount, 1, 0);
182 
183  m_editCountY = new QLineEdit;
184  m_editCountY->setWhatsThis (tr ("Number of Y grid lines.\n\n"
185  "The number of Y grid lines must be entered as an integer greater than zero"));
186  m_validatorCountY = new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
187  m_editCountY->setValidator (m_validatorCountY);
188  connect (m_editCountY, SIGNAL (textEdited (const QString &)), this, SLOT (slotCountY (const QString &)));
189  layoutGroup->addWidget (m_editCountY, 1, 1);
190 
191  QLabel *labelStart = new QLabel (tr ("Start:"));
192  layoutGroup->addWidget (labelStart, 2, 0);
193 
194  m_editStartY = new QLineEdit;
195  m_editStartY->setWhatsThis (tr ("Value of the first Y grid line.\n\n"
196  "The start value cannot be greater than the stop value"));
197  m_validatorStartY = new QDoubleValidator;
198  m_editStartY->setValidator (m_validatorStartY);
199  connect (m_editStartY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStartY (const QString &)));
200  layoutGroup->addWidget (m_editStartY, 2, 1);
201 
202  QLabel *labelStep = new QLabel (tr ("Step:"));
203  layoutGroup->addWidget (labelStep, 3, 0);
204 
205  m_editStepY = new QLineEdit;
206  m_editStepY->setWhatsThis (tr ("Difference in value between two successive Y grid lines.\n\n"
207  "The step value must be greater than zero"));
208  m_validatorStepY = new QDoubleValidator;
209  m_editStepY->setValidator (m_validatorStepY);
210  connect (m_editStepY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStepY (const QString &)));
211  layoutGroup->addWidget (m_editStepY, 3, 1);
212 
213  QLabel *labelStop = new QLabel (tr ("Stop:"));
214  layoutGroup->addWidget (labelStop, 4, 0);
215 
216  m_editStopY = new QLineEdit;
217  m_editStopY->setWhatsThis (tr ("Value of the last Y grid line.\n\n"
218  "The stop value cannot be less than the start value"));
219  m_validatorStopY = new QDoubleValidator;
220  m_editStopY->setValidator (m_validatorStopY);
221  connect (m_editStopY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStopY (const QString &)));
222  layoutGroup->addWidget (m_editStopY, 4, 1);
223 }
224 
225 void DlgSettingsGridDisplay::createOptionalSaveDefault (QHBoxLayout * /* layout */)
226 {
227 }
228 
229 void DlgSettingsGridDisplay::createPreview (QGridLayout *layout, int &row)
230 {
231  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createPreview";
232 
233  QLabel *labelPreview = new QLabel (tr ("Preview"));
234  layout->addWidget (labelPreview, row++, 0, 1, 5);
235 
236  m_scenePreview = new QGraphicsScene (this);
237  m_viewPreview = new ViewPreview (m_scenePreview,
238  ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
239  this);
240  m_viewPreview->setWhatsThis (tr ("Preview window that shows how current settings affect grid display"));
241  m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
242  m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
243  m_viewPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
244  layout->addWidget (m_viewPreview, row++, 0, 1, 5);
245 }
246 
248 {
249  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createSubPanel";
250 
251  const int COLUMN_CHECKBOX_WIDTH = 60;
252 
253  QWidget *subPanel = new QWidget ();
254  QGridLayout *layout = new QGridLayout (subPanel);
255  subPanel->setLayout (layout);
256 
257  layout->setColumnStretch(0, 1); // Empty first column
258  layout->setColumnStretch(1, 0); // Checkbox part of "section" checkboxes. In other rows this has empty space as indentation
259  layout->setColumnMinimumWidth(1, COLUMN_CHECKBOX_WIDTH);
260  layout->setColumnStretch(2, 0); // X
261  layout->setColumnStretch(3, 0); // Y
262  layout->setColumnStretch(4, 1); // Empty last column
263 
264  int row = 0;
265  createDisplayGridLinesX (layout, row);
266  createDisplayGridLinesY (layout, row);
267  createDisplayCommon (layout, row);
268  createPreview (layout, row);
269 
270  return subPanel;
271 }
272 
274 {
275  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::handleOk";
276 
277  // Set the stable flag
278  m_modelGridDisplayAfter->setStable (true);
279 
281  cmdMediator ().document(),
282  *m_modelGridDisplayBefore,
283  *m_modelGridDisplayAfter);
284  cmdMediator ().push (cmd);
285 
286  hide ();
287 }
288 
290 {
291  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::load";
292 
293  setCmdMediator (cmdMediator);
294 
295  // Flush old data
296  if (m_modelGridDisplayBefore != 0) {
297  delete m_modelGridDisplayBefore;
298  }
299  if (m_modelGridDisplayAfter != 0) {
300  delete m_modelGridDisplayAfter;
301  }
302 
303  // Display cartesian or polar headers as appropriate
304  QString titleX = tr ("X Grid Lines");
305  if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
306  titleX = QString (QChar (0x98, 0x03)) + QString (" %1").arg (tr ("Grid Lines"));
307  }
308  m_groupX->setTitle (titleX);
309 
310  QString titleY = tr ("Y Grid Lines");
311  if (cmdMediator.document ().modelCoords().coordsType() == COORDS_TYPE_POLAR) {
312  titleY = QString (tr ("Radius Grid Lines"));
313  }
314  m_groupY->setTitle (titleY);
315 
316  // Save new data
317  m_modelGridDisplayBefore = new DocumentModelGridDisplay (cmdMediator.document());
318  m_modelGridDisplayAfter = new DocumentModelGridDisplay (cmdMediator.document());
319 
320  // Populate controls
321  int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridDisplayAfter->disableX()));
322  m_cmbDisableX->setCurrentIndex (indexDisableX);
323 
324  m_editCountX->setText(QString::number(m_modelGridDisplayAfter->countX()));
325  m_editStartX->setText(QString::number(m_modelGridDisplayAfter->startX()));
326  m_editStepX->setText(QString::number(m_modelGridDisplayAfter->stepX()));
327  m_editStopX->setText(QString::number(m_modelGridDisplayAfter->stopX()));
328 
329  int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridDisplayAfter->disableY()));
330  m_cmbDisableY->setCurrentIndex (indexDisableY);
331 
332  m_editCountY->setText(QString::number(m_modelGridDisplayAfter->countY()));
333  m_editStartY->setText(QString::number(m_modelGridDisplayAfter->startY()));
334  m_editStepY->setText(QString::number(m_modelGridDisplayAfter->stepY()));
335  m_editStopY->setText(QString::number(m_modelGridDisplayAfter->stopY()));
336 
337  int indexColor = m_cmbColor->findData(QVariant(m_modelGridDisplayAfter->paletteColor()));
338  ENGAUGE_ASSERT (indexColor >= 0);
339  m_cmbColor->setCurrentIndex(indexColor);
340 
341  m_scenePreview->addPixmap (cmdMediator.document().pixmap());
342 
343  updateControls ();
344  enableOk (false); // Disable Ok button since there not yet any changes
345  updatePreview();
346 }
347 
348 void DlgSettingsGridDisplay::slotColor (QString const &)
349 {
350  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotColor";
351 
352  m_modelGridDisplayAfter->setPaletteColor((ColorPalette) m_cmbColor->currentData().toInt());
353  updateControls();
354  updatePreview();
355 }
356 
357 void DlgSettingsGridDisplay::slotCountX(const QString &count)
358 {
359  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountX";
360 
361  m_modelGridDisplayAfter->setCountX(count.toInt());
362  updateDisplayedVariableX ();
363  updateControls ();
364  updatePreview();
365 }
366 
367 void DlgSettingsGridDisplay::slotCountY(const QString &count)
368 {
369  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotCountY";
370 
371  m_modelGridDisplayAfter->setCountY(count.toInt());
372  updateDisplayedVariableY ();
373  updateControls ();
374  updatePreview();
375 }
376 
377 void DlgSettingsGridDisplay::slotDisableX(const QString &)
378 {
379  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableX";
380 
381  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
382  m_modelGridDisplayAfter->setDisableX(gridCoordDisable);
383  updateDisplayedVariableX ();
384  updateControls();
385  updatePreview();
386 }
387 
388 void DlgSettingsGridDisplay::slotDisableY(const QString &)
389 {
390  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotDisableY";
391 
392  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
393  m_modelGridDisplayAfter->setDisableY(gridCoordDisable);
394  updateDisplayedVariableY ();
395  updateControls();
396  updatePreview();
397 }
398 
399 void DlgSettingsGridDisplay::slotStartX(const QString &startX)
400 {
401  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartX";
402 
403  m_modelGridDisplayAfter->setStartX(startX.toDouble());
404  updateDisplayedVariableX ();
405  updateControls();
406  updatePreview();
407 }
408 
409 void DlgSettingsGridDisplay::slotStartY(const QString &startY)
410 {
411  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStartY";
412 
413  m_modelGridDisplayAfter->setStartY(startY.toDouble());
414  updateDisplayedVariableY ();
415  updateControls();
416  updatePreview();
417 }
418 
419 void DlgSettingsGridDisplay::slotStepX(const QString &stepX)
420 {
421  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepX";
422 
423  m_modelGridDisplayAfter->setStepX(stepX.toDouble());
424  updateDisplayedVariableX ();
425  updateControls();
426  updatePreview();
427 }
428 
429 void DlgSettingsGridDisplay::slotStepY(const QString &stepY)
430 {
431  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStepY";
432 
433  m_modelGridDisplayAfter->setStepY(stepY.toDouble());
434  updateDisplayedVariableY ();
435  updateControls();
436  updatePreview();
437 }
438 
439 void DlgSettingsGridDisplay::slotStopX(const QString &stopX)
440 {
441  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopX";
442 
443  m_modelGridDisplayAfter->setStopX(stopX.toDouble());
444  updateDisplayedVariableX ();
445  updateControls();
446  updatePreview();
447 }
448 
449 void DlgSettingsGridDisplay::slotStopY(const QString &stopY)
450 {
451  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::slotStopY";
452 
453  m_modelGridDisplayAfter->setStopY(stopY.toDouble());
454  updateDisplayedVariableY ();
455  updateControls();
456  updatePreview();
457 }
458 
459 bool DlgSettingsGridDisplay::textItemsAreValid () const
460 {
461  QString textCountX = m_editCountX->text();
462  QString textCountY = m_editCountY->text();
463  QString textStartX = m_editStartX->text();
464  QString textStartY = m_editStartY->text();
465  QString textStepX = m_editStepX->text();
466  QString textStepY = m_editStepY->text();
467  QString textStopX = m_editStopX->text();
468  QString textStopY = m_editStopY->text();
469 
470  // To prevent an infinite loop, skip if either:
471  // 1) a field is empty
472  // 2) value in a field is malformed
473  int pos;
474  return (!textCountX.isEmpty() &&
475  !textCountY.isEmpty() &&
476  !textStartX.isEmpty() &&
477  !textStartY.isEmpty() &&
478  !textStepX.isEmpty() &&
479  !textStepY.isEmpty() &&
480  !textStopX.isEmpty() &&
481  !textStopY.isEmpty() &&
482  m_validatorCountX->validate(textCountX, pos) == QValidator::Acceptable &&
483  m_validatorCountY->validate(textCountY, pos) == QValidator::Acceptable &&
484  m_validatorStartX->validate(textStartX, pos) == QValidator::Acceptable &&
485  m_validatorStartY->validate(textStartY, pos) == QValidator::Acceptable &&
486  m_validatorStepX->validate(textStepX, pos) == QValidator::Acceptable &&
487  m_validatorStepY->validate(textStepY, pos) == QValidator::Acceptable &&
488  m_validatorStopX->validate(textStopX, pos) == QValidator::Acceptable &&
489  m_validatorStopY->validate(textStopY, pos) == QValidator::Acceptable);
490 }
491 
492 void DlgSettingsGridDisplay::updateControls ()
493 {
494  GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
495  m_editCountX->setEnabled (disableX != GRID_COORD_DISABLE_COUNT);
496  m_editStartX->setEnabled (disableX != GRID_COORD_DISABLE_START);
497  m_editStepX->setEnabled (disableX != GRID_COORD_DISABLE_STEP);
498  m_editStopX->setEnabled (disableX != GRID_COORD_DISABLE_STOP);
499 
500  GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
501  m_editCountY->setEnabled (disableY != GRID_COORD_DISABLE_COUNT);
502  m_editStartY->setEnabled (disableY != GRID_COORD_DISABLE_START);
503  m_editStepY->setEnabled (disableY != GRID_COORD_DISABLE_STEP);
504  m_editStopY->setEnabled (disableY != GRID_COORD_DISABLE_STOP);
505 
506  enableOk (textItemsAreValid ());
507 }
508 
509 void DlgSettingsGridDisplay::updateDisplayedVariableX ()
510 {
511  GridInitializer initializer;
512 
513  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
514 
515  switch (m_modelGridDisplayAfter->disableX()) {
516  case GRID_COORD_DISABLE_COUNT:
517  m_editCountX->setText (QString::number (initializer.computeCount (linearAxis,
518  m_modelGridDisplayAfter->startX (),
519  m_modelGridDisplayAfter->stopX (),
520  m_modelGridDisplayAfter->stepX ())));
521  break;
522 
523  case GRID_COORD_DISABLE_START:
524  m_editStartX->setText (QString::number (initializer.computeStart (linearAxis,
525  m_modelGridDisplayAfter->stopX (),
526  m_modelGridDisplayAfter->stepX (),
527  m_modelGridDisplayAfter->countX ())));
528  break;
529 
530  case GRID_COORD_DISABLE_STEP:
531  m_editStepX->setText (QString::number (initializer.computeStep (linearAxis,
532  m_modelGridDisplayAfter->startX (),
533  m_modelGridDisplayAfter->stopX (),
534  m_modelGridDisplayAfter->countX ())));
535  break;
536 
537  case GRID_COORD_DISABLE_STOP:
538  m_editStopX->setText (QString::number (initializer.computeStop (linearAxis,
539  m_modelGridDisplayAfter->startX (),
540  m_modelGridDisplayAfter->stepX (),
541  m_modelGridDisplayAfter->countX ())));
542  break;
543 
544  default:
545  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableX";
546  break;
547  }
548 }
549 
550 void DlgSettingsGridDisplay::updateDisplayedVariableY ()
551 {
552  GridInitializer initializer;
553 
554  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleYRadius () == COORD_SCALE_LINEAR);
555 
556  switch (m_modelGridDisplayAfter->disableY()) {
557  case GRID_COORD_DISABLE_COUNT:
558  m_editCountY->setText (QString::number (initializer.computeCount (linearAxis,
559  m_modelGridDisplayAfter->startY (),
560  m_modelGridDisplayAfter->stopY (),
561  m_modelGridDisplayAfter->stepY ())));
562  break;
563 
564  case GRID_COORD_DISABLE_START:
565  m_editStartY->setText (QString::number (initializer.computeStart (linearAxis,
566  m_modelGridDisplayAfter->stopY (),
567  m_modelGridDisplayAfter->stepY (),
568  m_modelGridDisplayAfter->countY ())));
569  break;
570 
571  case GRID_COORD_DISABLE_STEP:
572  m_editStepY->setText (QString::number (initializer.computeStep (linearAxis,
573  m_modelGridDisplayAfter->startY (),
574  m_modelGridDisplayAfter->stopY (),
575  m_modelGridDisplayAfter->countY ())));
576  break;
577 
578  case GRID_COORD_DISABLE_STOP:
579  m_editStopY->setText (QString::number (initializer.computeStop (linearAxis,
580  m_modelGridDisplayAfter->startY (),
581  m_modelGridDisplayAfter->stepY (),
582  m_modelGridDisplayAfter->countY ())));
583  break;
584 
585  default:
586  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableY";
587  break;
588  }
589 }
590 
591 void DlgSettingsGridDisplay::updatePreview ()
592 {
593  m_gridLines.clear ();
594 
595  if (textItemsAreValid ()) {
596 
597  GridLineFactory factory (*m_scenePreview,
598  cmdMediator ().document ().modelCoords());
599 
600  factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,
601  mainWindow ().modelMainWindow(),
602  mainWindow ().transformation(),
603  m_gridLines);
604  }
605 }
double stopX() const
Get method for x grid line upper bound (inclusive).
Factory class for generating the points, composed of QGraphicsItem objects, along a GridLine...
GridCoordDisable disableX() const
Get method for x grid line disabled variable.
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
double stepX() const
Get method for x grid line increment.
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
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.
Command for DlgSettingsGridDisplay.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:665
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
QPixmap pixmap() const
Return the image that is being digitized.
Definition: Document.cpp:742
double startX() const
Get method for x grid line lower bound (inclusive).
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
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
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
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.
This class initializes the count, start, step and stop parameters for one coordinate (either x/theta ...
virtual void handleOk()
Process slotOk.
CoordsType coordsType() const
Get method for coordinates type.
void setDisableX(GridCoordDisable disableX)
Set method for x grid line disabled variable.
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
ColorPalette paletteColor() const
Get method for color.
void setDisableY(GridCoordDisable disableY)
Set method for y grid line disabled variable.
double stopY() const
Get method for y grid line upper bound (inclusive).
double startY() const
Get method for y grid line lower bound (inclusive).
void setCountX(unsigned int countX)
Set method for x grid line count.
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.
double stepY() const
Get method for y grid line increment.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
Command queue stack.
Definition: CmdMediator.h:23
Abstract base class for all Settings dialogs.
double computeStep(bool linearAxis, double start, double stop, int count) const
Compute axis scale step from the other axis parameters.
GridCoordDisable disableY() const
Get method for y grid line disabled variable.
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:83
void setPaletteColor(ColorPalette paletteColor)
Set method for color.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
unsigned int countX() const
Get method for x grid line count.
unsigned int countY() const
Get method for y grid line count.