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_MAX = 100;
28 const int COUNT_DECIMALS = 0;
29 const int MINIMUM_HEIGHT = 480;
30 
32  DlgSettingsAbstractBase (tr ("Grid Display"),
33  "DlgSettingsGridDisplay",
34  mainWindow),
35  m_scenePreview (0),
36  m_viewPreview (0),
37  m_modelGridDisplayBefore (0),
38  m_modelGridDisplayAfter (0)
39 {
40  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::DlgSettingsGridDisplay";
41 
42  QWidget *subPanel = createSubPanel ();
43  finishPanel (subPanel);
44 }
45 
46 DlgSettingsGridDisplay::~DlgSettingsGridDisplay()
47 {
48  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::~DlgSettingsGridDisplay";
49 }
50 
51 void DlgSettingsGridDisplay::createDisplayCommon (QGridLayout *layout, int &row)
52 {
53  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayCommon";
54 
55  QWidget *widgetCommon = new QWidget;
56  layout->addWidget (widgetCommon, row++, 2, 1, 2);
57 
58  QGridLayout *layoutCommon = new QGridLayout;
59  widgetCommon->setLayout (layoutCommon);
60  int rowCommon = 0;
61 
62  QLabel *labelColor = new QLabel (tr ("Color:"));
63  layoutCommon->addWidget (labelColor, rowCommon, 1);
64 
65  m_cmbColor = new QComboBox;
66  m_cmbColor->setWhatsThis (tr ("Select a color for the lines"));
68  connect (m_cmbColor, SIGNAL (activated (const QString &)), this, SLOT (slotColor (const QString &))); // activated() ignores code changes
69  layoutCommon->addWidget (m_cmbColor, rowCommon++, 2);
70 
71  // Make sure there is an empty column, for padding, on the left and right sides
72  layoutCommon->setColumnStretch (0, 1);
73  layoutCommon->setColumnStretch (1, 0);
74  layoutCommon->setColumnStretch (2, 0);
75  layoutCommon->setColumnStretch (3, 1);
76 }
77 
78 void DlgSettingsGridDisplay::createDisplayGridLinesX (QGridLayout *layout, int &row)
79 {
80  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesX";
81 
82  m_groupX = new QGroupBox; // Text is added at load time at which point current context is known
83  layout->addWidget (m_groupX, row, 2);
84 
85  QGridLayout *layoutGroup = new QGridLayout;
86  m_groupX->setLayout (layoutGroup);
87 
88  QLabel *labelDisable = new QLabel (tr ("Disable:"));
89  layoutGroup->addWidget (labelDisable, 0, 0);
90 
91  m_cmbDisableX = new QComboBox;
92  m_cmbDisableX->setWhatsThis (tr ("Disabled value.\n\n"
93  "The X grid lines are specified using only three values at a time. For flexibility, four values "
94  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
95  "updated as the other values change"));
96  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
97  QVariant (GRID_COORD_DISABLE_COUNT));
98  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
99  QVariant (GRID_COORD_DISABLE_START));
100  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
101  QVariant (GRID_COORD_DISABLE_STEP));
102  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
103  QVariant (GRID_COORD_DISABLE_STOP));
104  connect (m_cmbDisableX, SIGNAL (activated (const QString &)), this, SLOT (slotDisableX (const QString &))); // activated() ignores code changes
105  layoutGroup->addWidget (m_cmbDisableX, 0, 1);
106 
107  QLabel *labelCount = new QLabel (tr ("Count:"));
108  layoutGroup->addWidget (labelCount, 1, 0);
109 
110  m_editCountX = new QLineEdit;
111  m_editCountX->setWhatsThis (tr ("Number of X grid lines.\n\n"
112  "The number of X grid lines must be entered as an integer greater than zero"));
113  m_validatorCountX = new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
114  m_editCountX->setValidator (m_validatorCountX);
115  connect (m_editCountX, SIGNAL (textEdited (const QString &)), this, SLOT (slotCountX (const QString &)));
116  layoutGroup->addWidget (m_editCountX, 1, 1);
117 
118  QLabel *labelStart = new QLabel (tr ("Start:"));
119  layoutGroup->addWidget (labelStart, 2, 0);
120 
121  m_editStartX = new QLineEdit;
122  m_editStartX->setWhatsThis (tr ("Value of the first X grid line.\n\n"
123  "The start value cannot be greater than the stop value"));
124  m_validatorStartX = new QDoubleValidator;
125  m_editStartX->setValidator (m_validatorStartX);
126  connect (m_editStartX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStartX (const QString &)));
127  layoutGroup->addWidget (m_editStartX, 2, 1);
128 
129  QLabel *labelStep = new QLabel (tr ("Step:"));
130  layoutGroup->addWidget (labelStep, 3, 0);
131 
132  m_editStepX = new QLineEdit;
133  m_editStepX->setWhatsThis (tr ("Difference in value between two successive X grid lines.\n\n"
134  "The step value must be greater than zero"));
135  m_validatorStepX = new QDoubleValidator;
136  m_editStepX->setValidator (m_validatorStepX);
137  connect (m_editStepX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStepX (const QString &)));
138  layoutGroup->addWidget (m_editStepX, 3, 1);
139 
140  QLabel *labelStop = new QLabel (tr ("Stop:"));
141  layoutGroup->addWidget (labelStop, 4, 0);
142 
143  m_editStopX = new QLineEdit;
144  m_editStopX->setWhatsThis (tr ("Value of the last X grid line.\n\n"
145  "The stop value cannot be less than the start value"));
146  m_validatorStopX = new QDoubleValidator;
147  m_editStopX->setValidator (m_validatorStopX);
148  connect (m_editStopX, SIGNAL (textEdited (const QString &)), this, SLOT (slotStopX (const QString &)));
149  layoutGroup->addWidget (m_editStopX, 4, 1);
150 }
151 
152 void DlgSettingsGridDisplay::createDisplayGridLinesY (QGridLayout *layout, int &row)
153 {
154  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createDisplayGridLinesY";
155 
156  m_groupY = new QGroupBox; // Text is added at load time at which point current context is known
157  layout->addWidget (m_groupY, row++, 3);
158 
159  QGridLayout *layoutGroup = new QGridLayout;
160  m_groupY->setLayout (layoutGroup);
161 
162  QLabel *labelDisable = new QLabel (tr ("Disable:"));
163  layoutGroup->addWidget (labelDisable, 0, 0);
164 
165  m_cmbDisableY = new QComboBox;
166  m_cmbDisableY->setWhatsThis (tr ("Disabled value.\n\n"
167  "The Y grid lines are specified using only three values at a time. For flexibility, four values "
168  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
169  "updated as the other values change"));
170  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
171  QVariant (GRID_COORD_DISABLE_COUNT));
172  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
173  QVariant (GRID_COORD_DISABLE_START));
174  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
175  QVariant (GRID_COORD_DISABLE_STEP));
176  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
177  QVariant (GRID_COORD_DISABLE_STOP));
178  connect (m_cmbDisableY, SIGNAL (activated (const QString &)), this, SLOT (slotDisableY (const QString &))); // activated() ignores code changes
179  layoutGroup->addWidget (m_cmbDisableY, 0, 1);
180 
181  QLabel *labelCount = new QLabel (tr ("Count:"));
182  layoutGroup->addWidget (labelCount, 1, 0);
183 
184  m_editCountY = new QLineEdit;
185  m_editCountY->setWhatsThis (tr ("Number of Y grid lines.\n\n"
186  "The number of Y grid lines must be entered as an integer greater than zero"));
187  m_validatorCountY = new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
188  m_editCountY->setValidator (m_validatorCountY);
189  connect (m_editCountY, SIGNAL (textEdited (const QString &)), this, SLOT (slotCountY (const QString &)));
190  layoutGroup->addWidget (m_editCountY, 1, 1);
191 
192  QLabel *labelStart = new QLabel (tr ("Start:"));
193  layoutGroup->addWidget (labelStart, 2, 0);
194 
195  m_editStartY = new QLineEdit;
196  m_editStartY->setWhatsThis (tr ("Value of the first Y grid line.\n\n"
197  "The start value cannot be greater than the stop value"));
198  m_validatorStartY = new QDoubleValidator;
199  m_editStartY->setValidator (m_validatorStartY);
200  connect (m_editStartY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStartY (const QString &)));
201  layoutGroup->addWidget (m_editStartY, 2, 1);
202 
203  QLabel *labelStep = new QLabel (tr ("Step:"));
204  layoutGroup->addWidget (labelStep, 3, 0);
205 
206  m_editStepY = new QLineEdit;
207  m_editStepY->setWhatsThis (tr ("Difference in value between two successive Y grid lines.\n\n"
208  "The step value must be greater than zero"));
209  m_validatorStepY = new QDoubleValidator;
210  m_editStepY->setValidator (m_validatorStepY);
211  connect (m_editStepY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStepY (const QString &)));
212  layoutGroup->addWidget (m_editStepY, 3, 1);
213 
214  QLabel *labelStop = new QLabel (tr ("Stop:"));
215  layoutGroup->addWidget (labelStop, 4, 0);
216 
217  m_editStopY = new QLineEdit;
218  m_editStopY->setWhatsThis (tr ("Value of the last Y grid line.\n\n"
219  "The stop value cannot be less than the start value"));
220  m_validatorStopY = new QDoubleValidator;
221  m_editStopY->setValidator (m_validatorStopY);
222  connect (m_editStopY, SIGNAL (textEdited (const QString &)), this, SLOT (slotStopY (const QString &)));
223  layoutGroup->addWidget (m_editStopY, 4, 1);
224 }
225 
226 void DlgSettingsGridDisplay::createOptionalSaveDefault (QHBoxLayout * /* layout */)
227 {
228 }
229 
230 void DlgSettingsGridDisplay::createPreview (QGridLayout *layout, int &row)
231 {
232  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createPreview";
233 
234  QLabel *labelPreview = new QLabel (tr ("Preview"));
235  layout->addWidget (labelPreview, row++, 0, 1, 5);
236 
237  m_scenePreview = new QGraphicsScene (this);
238  m_viewPreview = new ViewPreview (m_scenePreview,
239  ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
240  this);
241  m_viewPreview->setWhatsThis (tr ("Preview window that shows how current settings affect grid display"));
242  m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
243  m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
244  m_viewPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
245  layout->addWidget (m_viewPreview, row++, 0, 1, 5);
246 }
247 
249 {
250  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::createSubPanel";
251 
252  const int COLUMN_CHECKBOX_WIDTH = 60;
253 
254  QWidget *subPanel = new QWidget ();
255  QGridLayout *layout = new QGridLayout (subPanel);
256  subPanel->setLayout (layout);
257 
258  layout->setColumnStretch(0, 1); // Empty first column
259  layout->setColumnStretch(1, 0); // Checkbox part of "section" checkboxes. In other rows this has empty space as indentation
260  layout->setColumnMinimumWidth(1, COLUMN_CHECKBOX_WIDTH);
261  layout->setColumnStretch(2, 0); // X
262  layout->setColumnStretch(3, 0); // Y
263  layout->setColumnStretch(4, 1); // Empty last column
264 
265  int row = 0;
266  createDisplayGridLinesX (layout, row);
267  createDisplayGridLinesY (layout, row);
268  createDisplayCommon (layout, row);
269  createPreview (layout, row);
270 
271  return subPanel;
272 }
273 
275 {
276  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::handleOk";
277 
278  // Set the stable flag
279  m_modelGridDisplayAfter->setStable (true);
280 
282  cmdMediator ().document(),
283  *m_modelGridDisplayBefore,
284  *m_modelGridDisplayAfter);
285  cmdMediator ().push (cmd);
286 
287  hide ();
288 }
289 
291 {
292  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridDisplay::load";
293 
294  setCmdMediator (cmdMediator);
295 
296  // Flush old data
297  if (m_modelGridDisplayBefore != 0) {
298  delete m_modelGridDisplayBefore;
299  }
300  if (m_modelGridDisplayAfter != 0) {
301  delete m_modelGridDisplayAfter;
302  }
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  int pos;
482  return (!textCountX.isEmpty() &&
483  !textCountY.isEmpty() &&
484  !textStartX.isEmpty() &&
485  !textStartY.isEmpty() &&
486  !textStepX.isEmpty() &&
487  !textStepY.isEmpty() &&
488  !textStopX.isEmpty() &&
489  !textStopY.isEmpty() &&
490  m_validatorCountX->validate(textCountX, pos) == QValidator::Acceptable &&
491  m_validatorCountY->validate(textCountY, pos) == QValidator::Acceptable &&
492  m_validatorStartX->validate(textStartX, pos) == QValidator::Acceptable &&
493  m_validatorStartY->validate(textStartY, pos) == QValidator::Acceptable &&
494  m_validatorStepX->validate(textStepX, pos) == QValidator::Acceptable &&
495  m_validatorStepY->validate(textStepY, pos) == QValidator::Acceptable &&
496  m_validatorStopX->validate(textStopX, pos) == QValidator::Acceptable &&
497  m_validatorStopY->validate(textStopY, pos) == QValidator::Acceptable);
498 }
499 
500 void DlgSettingsGridDisplay::updateControls ()
501 {
502  GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
503  m_editCountX->setEnabled (disableX != GRID_COORD_DISABLE_COUNT);
504  m_editStartX->setEnabled (disableX != GRID_COORD_DISABLE_START);
505  m_editStepX->setEnabled (disableX != GRID_COORD_DISABLE_STEP);
506  m_editStopX->setEnabled (disableX != GRID_COORD_DISABLE_STOP);
507 
508  GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
509  m_editCountY->setEnabled (disableY != GRID_COORD_DISABLE_COUNT);
510  m_editStartY->setEnabled (disableY != GRID_COORD_DISABLE_START);
511  m_editStepY->setEnabled (disableY != GRID_COORD_DISABLE_STEP);
512  m_editStopY->setEnabled (disableY != GRID_COORD_DISABLE_STOP);
513 
514  enableOk (textItemsAreValid ());
515 }
516 
517 void DlgSettingsGridDisplay::updateDisplayedVariableX ()
518 {
519  GridInitializer initializer;
520 
521  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
522 
523  switch (m_modelGridDisplayAfter->disableX()) {
524  case GRID_COORD_DISABLE_COUNT:
525  m_editCountX->setText (QString::number (initializer.computeCount (linearAxis,
526  m_modelGridDisplayAfter->startX (),
527  m_modelGridDisplayAfter->stopX (),
528  m_modelGridDisplayAfter->stepX ())));
529  break;
530 
531  case GRID_COORD_DISABLE_START:
532  m_editStartX->setText (QString::number (initializer.computeStart (linearAxis,
533  m_modelGridDisplayAfter->stopX (),
534  m_modelGridDisplayAfter->stepX (),
535  m_modelGridDisplayAfter->countX ())));
536  break;
537 
538  case GRID_COORD_DISABLE_STEP:
539  m_editStepX->setText (QString::number (initializer.computeStep (linearAxis,
540  m_modelGridDisplayAfter->startX (),
541  m_modelGridDisplayAfter->stopX (),
542  m_modelGridDisplayAfter->countX ())));
543  break;
544 
545  case GRID_COORD_DISABLE_STOP:
546  m_editStopX->setText (QString::number (initializer.computeStop (linearAxis,
547  m_modelGridDisplayAfter->startX (),
548  m_modelGridDisplayAfter->stepX (),
549  m_modelGridDisplayAfter->countX ())));
550  break;
551 
552  default:
553  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableX";
554  break;
555  }
556 }
557 
558 void DlgSettingsGridDisplay::updateDisplayedVariableY ()
559 {
560  GridInitializer initializer;
561 
562  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleYRadius () == COORD_SCALE_LINEAR);
563 
564  switch (m_modelGridDisplayAfter->disableY()) {
565  case GRID_COORD_DISABLE_COUNT:
566  m_editCountY->setText (QString::number (initializer.computeCount (linearAxis,
567  m_modelGridDisplayAfter->startY (),
568  m_modelGridDisplayAfter->stopY (),
569  m_modelGridDisplayAfter->stepY ())));
570  break;
571 
572  case GRID_COORD_DISABLE_START:
573  m_editStartY->setText (QString::number (initializer.computeStart (linearAxis,
574  m_modelGridDisplayAfter->stopY (),
575  m_modelGridDisplayAfter->stepY (),
576  m_modelGridDisplayAfter->countY ())));
577  break;
578 
579  case GRID_COORD_DISABLE_STEP:
580  m_editStepY->setText (QString::number (initializer.computeStep (linearAxis,
581  m_modelGridDisplayAfter->startY (),
582  m_modelGridDisplayAfter->stopY (),
583  m_modelGridDisplayAfter->countY ())));
584  break;
585 
586  case GRID_COORD_DISABLE_STOP:
587  m_editStopY->setText (QString::number (initializer.computeStop (linearAxis,
588  m_modelGridDisplayAfter->startY (),
589  m_modelGridDisplayAfter->stepY (),
590  m_modelGridDisplayAfter->countY ())));
591  break;
592 
593  default:
594  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridDisplay::updateDisplayedVariableY";
595  break;
596  }
597 }
598 
599 void DlgSettingsGridDisplay::updatePreview ()
600 {
601  m_gridLines.clear ();
602 
603  if (textItemsAreValid ()) {
604 
605  GridLineFactory factory (*m_scenePreview,
606  cmdMediator ().document ().modelCoords());
607 
608  factory.createGridLinesForEvenlySpacedGrid (*m_modelGridDisplayAfter,
609  cmdMediator ().document (),
610  mainWindow ().modelMainWindow(),
611  mainWindow ().transformation(),
612  m_gridLines);
613  }
614 }
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.
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.
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:693
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:815
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
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
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.
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 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:86
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.