Engauge Digitizer  2
 All Classes Functions Variables Typedefs Enumerations Friends Pages
DlgSettingsGridRemoval.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 "CmdSettingsGridRemoval.h"
9 #include "DlgSettingsGridRemoval.h"
10 #include "EngaugeAssert.h"
11 #include "GridInitializer.h"
12 #include "GridRemoval.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 <QPixmap>
25 #include "ViewPreview.h"
26 
27 const double CLOSE_DISTANCE_MAX = 64;
28 const double CLOSE_DISTANCE_MIN = 0;
29 const int CLOSE_DECIMALS = 1;
30 const int COUNT_MIN = 1;
31 const int COUNT_MAX = 100;
32 const int COUNT_DECIMALS = 0;
33 const int MINIMUM_HEIGHT = 480;
34 
36  DlgSettingsAbstractBase (tr ("Grid Removal"),
37  "DlgSettingsGridRemoval",
38  mainWindow),
39  m_scenePreview (0),
40  m_viewPreview (0),
41  m_modelGridRemovalBefore (0),
42  m_modelGridRemovalAfter (0)
43 {
44  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::DlgSettingsGridRemoval";
45 
46  QWidget *subPanel = createSubPanel ();
47  finishPanel (subPanel);
48 }
49 
50 DlgSettingsGridRemoval::~DlgSettingsGridRemoval()
51 {
52  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::~DlgSettingsGridRemoval";
53 }
54 
55 void DlgSettingsGridRemoval::createOptionalSaveDefault (QHBoxLayout * /* layout */)
56 {
57 }
58 
59 void DlgSettingsGridRemoval::createPreview (QGridLayout *layout, int &row)
60 {
61  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::createPreview";
62 
63  QLabel *labelPreview = new QLabel (tr ("Preview"));
64  layout->addWidget (labelPreview, row++, 0, 1, 5);
65 
66  m_scenePreview = new QGraphicsScene (this);
67  m_viewPreview = new ViewPreview (m_scenePreview,
68  ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
69  this);
70  m_viewPreview->setWhatsThis (tr ("Preview window that shows how current settings affect grid removal"));
71  m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
72  m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
73  m_viewPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
74  layout->addWidget (m_viewPreview, row++, 0, 1, 5);
75 }
76 
77 void DlgSettingsGridRemoval::createRemoveGridLines (QGridLayout *layout, int &row)
78 {
79  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::createRemoveGridLines";
80 
81  m_chkRemoveGridLines = new QCheckBox (tr ("Remove pixels close to defined grid lines"));
82  m_chkRemoveGridLines->setWhatsThis (tr ("Check this box to have pixels close to regularly spaced gridlines removed.\n\n"
83  "This option is only available when the axis points have all been defined."));
84  connect (m_chkRemoveGridLines, SIGNAL (stateChanged (int)), this, SLOT (slotRemoveGridLines (int)));
85  layout->addWidget (m_chkRemoveGridLines, row++, 1, 1, 3);
86 
87  QLabel *labelCloseDistance = new QLabel (QString ("%1:").arg (tr ("Close distance (pixels)")));
88  layout->addWidget (labelCloseDistance, row, 2);
89 
90  m_editCloseDistance = new QLineEdit;
91  m_editCloseDistance->setWhatsThis (tr ("Set closeness distance in pixels.\n\n"
92  "Pixels that are closer to the regularly spaced gridlines, than this distance, "
93  "will be removed.\n\n"
94  "This value cannot be negative. A zero value disables this feature. Decimal values are allowed"));
95  m_validatorCloseDistance = new QDoubleValidator (CLOSE_DISTANCE_MIN, CLOSE_DISTANCE_MAX, CLOSE_DECIMALS);
96  m_editCloseDistance->setValidator (m_validatorCloseDistance);
97  connect (m_editCloseDistance, SIGNAL (textChanged (const QString &)), this, SLOT (slotCloseDistance (const QString &)));
98  layout->addWidget (m_editCloseDistance, row++, 3);
99 
100  createRemoveGridLinesX (layout, row);
101  createRemoveGridLinesY (layout, row);
102 }
103 
104 void DlgSettingsGridRemoval::createRemoveGridLinesX (QGridLayout *layout, int &row)
105 {
106  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::createRemoveGridLinesX";
107 
108  QString titleX = tr ("X Grid Lines");
109  if (false) {
110  titleX = QString (QChar (0x98, 0x03)) + QString (" %1").arg (tr ("Grid Lines"));
111  }
112  QGroupBox *groupX = new QGroupBox (titleX);
113  layout->addWidget (groupX, row, 2);
114 
115  QGridLayout *layoutGroup = new QGridLayout;
116  groupX->setLayout (layoutGroup);
117 
118  QLabel *labelDisable = new QLabel (QString ("%1:").arg (tr ("Disable")));
119  layoutGroup->addWidget (labelDisable, 0, 0);
120 
121  m_cmbDisableX = new QComboBox;
122  m_cmbDisableX->setWhatsThis (tr ("Disabled value.\n\n"
123  "The X grid lines are specified using only three values at a time. For flexibility, four values "
124  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
125  "updated as the other values change"));
126  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
127  QVariant (GRID_COORD_DISABLE_COUNT));
128  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
129  QVariant (GRID_COORD_DISABLE_START));
130  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
131  QVariant (GRID_COORD_DISABLE_STEP));
132  m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
133  QVariant (GRID_COORD_DISABLE_STOP));
134  connect (m_cmbDisableX, SIGNAL (activated (const QString &)), this, SLOT (slotDisableX (const QString &))); // activated() ignores code changes
135  layoutGroup->addWidget (m_cmbDisableX, 0, 1);
136 
137  QLabel *labelCount = new QLabel (QString ("%1:").arg (tr ("Count")));
138  layoutGroup->addWidget (labelCount, 1, 0);
139 
140  m_editCountX = new QLineEdit;
141  m_editCountX->setWhatsThis (tr ("Number of X grid lines.\n\n"
142  "The number of X grid lines must be entered as an integer greater than zero"));
143  m_validatorCountX = new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
144  m_editCountX->setValidator (m_validatorCountX);
145  connect (m_editCountX, SIGNAL (textChanged (const QString &)), this, SLOT (slotCountX (const QString &)));
146  layoutGroup->addWidget (m_editCountX, 1, 1);
147 
148  QLabel *labelStart = new QLabel (QString ("%1:").arg (tr ("Start")));
149  layoutGroup->addWidget (labelStart, 2, 0);
150 
151  m_editStartX = new QLineEdit;
152  m_editStartX->setWhatsThis (tr ("Value of the first X grid line.\n\n"
153  "The start value cannot be greater than the stop value"));
154  m_validatorStartX = new QDoubleValidator;
155  m_editStartX->setValidator (m_validatorStartX);
156  connect (m_editStartX, SIGNAL (textChanged (const QString &)), this, SLOT (slotStartX (const QString &)));
157  layoutGroup->addWidget (m_editStartX, 2, 1);
158 
159  QLabel *labelStep = new QLabel (QString ("%1:").arg (tr ("Step")));
160  layoutGroup->addWidget (labelStep, 3, 0);
161 
162  m_editStepX = new QLineEdit;
163  m_editStepX->setWhatsThis (tr ("Difference in value between two successive X grid lines.\n\n"
164  "The step value must be greater than zero"));
165  m_validatorStepX = new QDoubleValidator;
166  m_editStepX->setValidator (m_validatorStepX);
167  connect (m_editStepX, SIGNAL (textChanged (const QString &)), this, SLOT (slotStepX (const QString &)));
168  layoutGroup->addWidget (m_editStepX, 3, 1);
169 
170  QLabel *labelStop = new QLabel (QString ("%1:").arg (tr ("Stop")));
171  layoutGroup->addWidget (labelStop, 4, 0);
172 
173  m_editStopX = new QLineEdit;
174  m_editStopX->setWhatsThis (tr ("Value of the last X grid line.\n\n"
175  "The stop value cannot be less than the start value"));
176  m_validatorStopX = new QDoubleValidator;
177  m_editStopX->setValidator (m_validatorStopX);
178  connect (m_editStopX, SIGNAL (textChanged (const QString &)), this, SLOT (slotStopX (const QString &)));
179  layoutGroup->addWidget (m_editStopX, 4, 1);
180 }
181 
182 void DlgSettingsGridRemoval::createRemoveGridLinesY (QGridLayout *layout, int &row)
183 {
184  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::createRemoveGridLinesY";
185 
186  QString titleY = tr ("Y Grid Lines");
187  if (false) {
188  titleY = QString (tr ("R Grid Lines"));
189  }
190  QGroupBox *groupY = new QGroupBox (titleY);
191  layout->addWidget (groupY, row++, 3);
192 
193  QGridLayout *layoutGroup = new QGridLayout;
194  groupY->setLayout (layoutGroup);
195 
196  QLabel *labelDisable = new QLabel (QString ("%1:").arg (tr ("Disable")));
197  layoutGroup->addWidget (labelDisable, 0, 0);
198 
199  m_cmbDisableY = new QComboBox;
200  m_cmbDisableY->setWhatsThis (tr ("Disabled value.\n\n"
201  "The Y grid lines are specified using only three values at a time. For flexibility, four values "
202  "are offered so you must chose which value is disabled. Once disabled, that value is simply "
203  "updated as the other values change"));
204  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
205  QVariant (GRID_COORD_DISABLE_COUNT));
206  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
207  QVariant (GRID_COORD_DISABLE_START));
208  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
209  QVariant (GRID_COORD_DISABLE_STEP));
210  m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
211  QVariant (GRID_COORD_DISABLE_STOP));
212  connect (m_cmbDisableY, SIGNAL (activated (const QString &)), this, SLOT (slotDisableY (const QString &))); // activated() ignores code changes
213  layoutGroup->addWidget (m_cmbDisableY, 0, 1);
214 
215  QLabel *labelCount = new QLabel (QString ("%1:").arg (tr ("Count")));
216  layoutGroup->addWidget (labelCount, 1, 0);
217 
218  m_editCountY = new QLineEdit;
219  m_editCountY->setWhatsThis (tr ("Number of Y grid lines.\n\n"
220  "The number of Y grid lines must be entered as an integer greater than zero"));
221  m_validatorCountY = new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
222  m_editCountY->setValidator (m_validatorCountY);
223  connect (m_editCountY, SIGNAL (textChanged (const QString &)), this, SLOT (slotCountY (const QString &)));
224  layoutGroup->addWidget (m_editCountY, 1, 1);
225 
226  QLabel *labelStart = new QLabel (QString ("%1:").arg (tr ("Start")));
227  layoutGroup->addWidget (labelStart, 2, 0);
228 
229  m_editStartY = new QLineEdit;
230  m_editStartY->setWhatsThis (tr ("Value of the first Y grid line.\n\n"
231  "The start value cannot be greater than the stop value"));
232  m_validatorStartY = new QDoubleValidator;
233  m_editStartY->setValidator (m_validatorStartY);
234  connect (m_editStartY, SIGNAL (textChanged (const QString &)), this, SLOT (slotStartY (const QString &)));
235  layoutGroup->addWidget (m_editStartY, 2, 1);
236 
237  QLabel *labelStep = new QLabel (QString ("%1:").arg (tr ("Step")));
238  layoutGroup->addWidget (labelStep, 3, 0);
239 
240  m_editStepY = new QLineEdit;
241  m_editStepY->setWhatsThis (tr ("Difference in value between two successive Y grid lines.\n\n"
242  "The step value must be greater than zero"));
243  m_validatorStepY = new QDoubleValidator;
244  m_editStepY->setValidator (m_validatorStepY);
245  connect (m_editStepY, SIGNAL (textChanged (const QString &)), this, SLOT (slotStepY (const QString &)));
246  layoutGroup->addWidget (m_editStepY, 3, 1);
247 
248  QLabel *labelStop = new QLabel (QString ("%1:").arg (tr ("Stop")));
249  layoutGroup->addWidget (labelStop, 4, 0);
250 
251  m_editStopY = new QLineEdit;
252  m_editStopY->setWhatsThis (tr ("Value of the last Y grid line.\n\n"
253  "The stop value cannot be less than the start value"));
254  m_validatorStopY = new QDoubleValidator;
255  m_editStopY->setValidator (m_validatorStopY);
256  connect (m_editStopY, SIGNAL (textChanged (const QString &)), this, SLOT (slotStopY (const QString &)));
257  layoutGroup->addWidget (m_editStopY, 4, 1);
258 }
259 
261 {
262  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::createSubPanel";
263 
264  QWidget *subPanel = new QWidget ();
265  QGridLayout *layout = new QGridLayout (subPanel);
266  subPanel->setLayout (layout);
267 
268  layout->setColumnStretch(0, 1); // Empty first column
269  layout->setColumnStretch(1, 0); // Checkbox part of "section" checkboxes. In other rows this has empty space as indentation
270  layout->setColumnStretch(2, 0); // X
271  layout->setColumnStretch(3, 0); // Y
272  layout->setColumnStretch(4, 1); // Empty last column
273 
274  int row = 0;
275  createRemoveGridLines (layout, row);
276  createPreview (layout, row);
277 
278  return subPanel;
279 }
280 
282 {
283  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::handleOk";
284 
285  // Set the stable flag
286  m_modelGridRemovalAfter->setStable ();
287 
289  cmdMediator ().document(),
290  *m_modelGridRemovalBefore,
291  *m_modelGridRemovalAfter);
292  cmdMediator ().push (cmd);
293 
294  hide ();
295 }
296 
298 {
299  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::load";
300 
301  setCmdMediator (cmdMediator);
302 
303  // Flush old data
304  delete m_modelGridRemovalBefore;
305  delete m_modelGridRemovalAfter;
306 
307  // Save new data
308  m_modelGridRemovalBefore = new DocumentModelGridRemoval (cmdMediator.document());
309  m_modelGridRemovalAfter = new DocumentModelGridRemoval (cmdMediator.document());
310 
311  // Sanity checks. Incoming defaults must be acceptable to the local limits
312  ENGAUGE_ASSERT (CLOSE_DISTANCE_MIN <= m_modelGridRemovalAfter->closeDistance());
313  ENGAUGE_ASSERT (CLOSE_DISTANCE_MAX >= m_modelGridRemovalAfter->closeDistance());
314 
315  // Populate controls
316  m_chkRemoveGridLines->setChecked (m_modelGridRemovalAfter->removeDefinedGridLines());
317 
318  m_editCloseDistance->setText (QString::number (m_modelGridRemovalAfter->closeDistance()));
319 
320  int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->gridCoordDisableX()));
321  m_cmbDisableX->setCurrentIndex (indexDisableX);
322 
323  m_editCountX->setText(QString::number(m_modelGridRemovalAfter->countX()));
324  m_editStartX->setText(QString::number(m_modelGridRemovalAfter->startX()));
325  m_editStepX->setText(QString::number(m_modelGridRemovalAfter->stepX()));
326  m_editStopX->setText(QString::number(m_modelGridRemovalAfter->stopX()));
327 
328  int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridRemovalAfter->gridCoordDisableY()));
329  m_cmbDisableY->setCurrentIndex (indexDisableY);
330 
331  m_editCountY->setText(QString::number(m_modelGridRemovalAfter->countY()));
332  m_editStartY->setText(QString::number(m_modelGridRemovalAfter->startY()));
333  m_editStepY->setText(QString::number(m_modelGridRemovalAfter->stepY()));
334  m_editStopY->setText(QString::number(m_modelGridRemovalAfter->stopY()));
335 
336  updateControls ();
337  enableOk (false); // Disable Ok button since there not yet any changes
338  updatePreview();
339 }
340 
342 {
343  if (!smallDialogs) {
344  setMinimumHeight (MINIMUM_HEIGHT);
345  }
346 }
347 
348 void DlgSettingsGridRemoval::slotCloseDistance(const QString &)
349 {
350  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotCloseDistance";
351 
352  m_modelGridRemovalAfter->setCloseDistance(m_editCloseDistance->text().toDouble());
353  updateControls ();
354  updatePreview();
355 }
356 
357 void DlgSettingsGridRemoval::slotCountX(const QString &count)
358 {
359  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotCountX";
360 
361  m_modelGridRemovalAfter->setCountX(count.toInt());
362  updateDisplayedVariableX ();
363  updateControls ();
364  updatePreview();
365 }
366 
367 void DlgSettingsGridRemoval::slotCountY(const QString &count)
368 {
369  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotCountY";
370 
371  m_modelGridRemovalAfter->setCountY(count.toInt());
372  updateDisplayedVariableY ();
373  updateControls ();
374  updatePreview();
375 }
376 
377 void DlgSettingsGridRemoval::slotDisableX(const QString &)
378 {
379  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotDisableX";
380 
381  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
382  m_modelGridRemovalAfter->setGridCoordDisableX(gridCoordDisable);
383  updateDisplayedVariableX ();
384  updateControls();
385  updatePreview();
386 }
387 
388 void DlgSettingsGridRemoval::slotDisableY(const QString &)
389 {
390  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotDisableY";
391 
392  GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
393  m_modelGridRemovalAfter->setGridCoordDisableY(gridCoordDisable);
394  updateDisplayedVariableY ();
395  updateControls();
396  updatePreview();
397 }
398 
399 void DlgSettingsGridRemoval::slotRemoveGridLines (int state)
400 {
401  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotRemoveGridLines";
402 
403  m_modelGridRemovalAfter->setRemoveDefinedGridLines(state == Qt::Checked);
404  updateControls();
405  updatePreview();
406 }
407 
408 void DlgSettingsGridRemoval::slotStartX(const QString &startX)
409 {
410  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotStartX";
411 
412  m_modelGridRemovalAfter->setStartX(startX.toDouble());
413  updateDisplayedVariableX ();
414  updateControls();
415  updatePreview();
416 }
417 
418 void DlgSettingsGridRemoval::slotStartY(const QString &startY)
419 {
420  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotStartY";
421 
422  m_modelGridRemovalAfter->setStartY(startY.toDouble());
423  updateDisplayedVariableY ();
424  updateControls();
425  updatePreview();
426 }
427 
428 void DlgSettingsGridRemoval::slotStepX(const QString &stepX)
429 {
430  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotStepX";
431 
432  m_modelGridRemovalAfter->setStepX(stepX.toDouble());
433  updateDisplayedVariableX ();
434  updateControls();
435  updatePreview();
436 }
437 
438 void DlgSettingsGridRemoval::slotStepY(const QString &stepY)
439 {
440  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotStepY";
441 
442  m_modelGridRemovalAfter->setStepY(stepY.toDouble());
443  updateDisplayedVariableY ();
444  updateControls();
445  updatePreview();
446 }
447 
448 void DlgSettingsGridRemoval::slotStopX(const QString &stopX)
449 {
450  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotStopX";
451 
452  m_modelGridRemovalAfter->setStopX(stopX.toDouble());
453  updateDisplayedVariableX ();
454  updateControls();
455  updatePreview();
456 }
457 
458 void DlgSettingsGridRemoval::slotStopY(const QString &stopY)
459 {
460  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::slotStopY";
461 
462  m_modelGridRemovalAfter->setStopY(stopY.toDouble());
463  updateDisplayedVariableY ();
464  updateControls();
465  updatePreview();
466 }
467 
468 void DlgSettingsGridRemoval::updateControls ()
469 {
470  m_editCloseDistance->setEnabled (m_chkRemoveGridLines->isChecked ());
471 
472  m_cmbDisableX->setEnabled (m_chkRemoveGridLines->isChecked ());
473 
474  GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
475  m_editCountX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_COUNT));
476  m_editStartX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_START));
477  m_editStepX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STEP));
478  m_editStopX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STOP));
479 
480  m_cmbDisableY->setEnabled (m_chkRemoveGridLines->isChecked ());
481 
482  GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
483  m_editCountY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_COUNT));
484  m_editStartY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_START));
485  m_editStepY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STEP));
486  m_editStopY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STOP));
487 
488  QString textCloseDistance = m_editCloseDistance->text();
489  QString textCountX = m_editCountX->text();
490  QString textStartX = m_editStartX->text();
491  QString textStepX = m_editStepX->text();
492  QString textStopX = m_editStopX->text();
493  QString textCountY = m_editCountY->text();
494  QString textStartY = m_editStartY->text();
495  QString textStepY = m_editStepY->text();
496  QString textStopY = m_editStopY->text();
497 
498  int pos;
499  bool isOk = (m_validatorCloseDistance->validate (textCloseDistance, pos) == QValidator::Acceptable) &&
500  (m_validatorCountX->validate (textCountX, pos) == QValidator::Acceptable) &&
501  (m_validatorStartX->validate (textStartX, pos) == QValidator::Acceptable) &&
502  (m_validatorStepX->validate (textStepX, pos) == QValidator::Acceptable) &&
503  (m_validatorStopX->validate (textStopX, pos) == QValidator::Acceptable) &&
504  (m_validatorCountY->validate (textCountY, pos) == QValidator::Acceptable) &&
505  (m_validatorStartY->validate (textStartY, pos) == QValidator::Acceptable) &&
506  (m_validatorStepY->validate (textStepY, pos) == QValidator::Acceptable) &&
507  (m_validatorStopY->validate (textStopY, pos) == QValidator::Acceptable);
508  enableOk (isOk);
509 }
510 
511 void DlgSettingsGridRemoval::updateDisplayedVariableX ()
512 {
513  GridInitializer initializer;
514 
515  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleXTheta() == COORD_SCALE_LINEAR);
516 
517  switch (m_modelGridRemovalAfter->gridCoordDisableX()) {
518  case GRID_COORD_DISABLE_COUNT:
519  m_editCountX->setText (QString::number (initializer.computeCount (linearAxis,
520  m_modelGridRemovalAfter->startX (),
521  m_modelGridRemovalAfter->stopX (),
522  m_modelGridRemovalAfter->stepX ())));
523  break;
524 
525  case GRID_COORD_DISABLE_START:
526  m_editStartX->setText (QString::number (initializer.computeStart (linearAxis,
527  m_modelGridRemovalAfter->stopX (),
528  m_modelGridRemovalAfter->stepX (),
529  m_modelGridRemovalAfter->countX ())));
530  break;
531 
532  case GRID_COORD_DISABLE_STEP:
533  m_editStepX->setText (QString::number (initializer.computeStep (linearAxis,
534  m_modelGridRemovalAfter->startX (),
535  m_modelGridRemovalAfter->stopX (),
536  m_modelGridRemovalAfter->countX ())));
537  break;
538 
539  case GRID_COORD_DISABLE_STOP:
540  m_editStopX->setText (QString::number (initializer.computeStop (linearAxis,
541  m_modelGridRemovalAfter->startX (),
542  m_modelGridRemovalAfter->stepX (),
543  m_modelGridRemovalAfter->countX ())));
544  break;
545 
546  default:
547  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridRemoval::updateDisplayedVariableX";
548  break;
549  }
550 }
551 
552 void DlgSettingsGridRemoval::updateDisplayedVariableY ()
553 {
554  GridInitializer initializer;
555 
556  bool linearAxis = (cmdMediator ().document ().modelCoords ().coordScaleYRadius () == COORD_SCALE_LINEAR);
557 
558  switch (m_modelGridRemovalAfter->gridCoordDisableY()) {
559  case GRID_COORD_DISABLE_COUNT:
560  m_editCountY->setText (QString::number (initializer.computeCount (linearAxis,
561  m_modelGridRemovalAfter->startY (),
562  m_modelGridRemovalAfter->stopY (),
563  m_modelGridRemovalAfter->stepY ())));
564  break;
565 
566  case GRID_COORD_DISABLE_START:
567  m_editStartY->setText (QString::number (initializer.computeStart (linearAxis,
568  m_modelGridRemovalAfter->stopY (),
569  m_modelGridRemovalAfter->stepY (),
570  m_modelGridRemovalAfter->countY ())));
571  break;
572 
573  case GRID_COORD_DISABLE_STEP:
574  m_editStepY->setText (QString::number (initializer.computeStep (linearAxis,
575  m_modelGridRemovalAfter->startY (),
576  m_modelGridRemovalAfter->stopY (),
577  m_modelGridRemovalAfter->countY ())));
578  break;
579 
580  case GRID_COORD_DISABLE_STOP:
581  m_editStopY->setText (QString::number (initializer.computeStop (linearAxis,
582  m_modelGridRemovalAfter->startY (),
583  m_modelGridRemovalAfter->stepY (),
584  m_modelGridRemovalAfter->countY ())));
585  break;
586 
587  default:
588  LOG4CPP_ERROR_S ((*mainCat)) << "DlgSettingsGridRemoval::updateDisplayedVariableY";
589  break;
590  }
591 }
592 
593 void DlgSettingsGridRemoval::updatePreview ()
594 {
595  GridRemoval gridRemoval (mainWindow().isGnuplot());
596 
597  QPixmap pixmap = gridRemoval.remove (mainWindow ().transformation(),
598  *m_modelGridRemovalAfter,
599  cmdMediator ().document().pixmap().toImage());
600 
601  m_scenePreview->clear();
602  m_scenePreview->addPixmap (pixmap);
603 }
double closeDistance() const
Get method for close distance.
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
bool removeDefinedGridLines() const
Get method for removing defined grid lines.
void setCloseDistance(double closeDistance)
Set method for close distance.
double startY() const
Get method for y start.
void setCountX(int countX)
Set method for x count.
void setStopY(double stopY)
Set method for y stop.
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:691
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
void setStartY(double startY)
Set method for y start.
GridCoordDisable gridCoordDisableX() const
Get method for x coord parameter to disable.
void setStepY(double stepY)
Set method for y step.
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
double stepY() const
Get method for y step.
GridCoordDisable gridCoordDisableY() const
Get method for y coord parameter to disable.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
void setStartX(double startX)
Set method for x start.
virtual void handleOk()
Process slotOk.
void setCountY(int countY)
Set method for y count.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
DlgSettingsGridRemoval(MainWindow &mainWindow)
Single constructor.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
Definition: ViewPreview.h:14
void setStepX(double stepX)
Set method for x step.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
double stopX() const
Get method for x stop.
This class initializes the count, start, step and stop parameters for one coordinate (either x/theta ...
void setRemoveDefinedGridLines(bool removeDefinedGridLines)
Set method for removing defined grid lines.
double startX() const
Get method for x start.
double stopY() const
Get method for y stop.
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
void setGridCoordDisableY(GridCoordDisable gridCoordDisable)
Set method for y coord parameter to disable.
Command for DlgSettingsGridRemoval.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
void setGridCoordDisableX(GridCoordDisable gridCoordDisable)
Set method for x coord parameter to disable.
int countX() const
Get method for x count.
int countY() const
Get method for y count.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
double stepX() const
Get method for x step.
void setStable()
Set the stable flag to true. This public version has no argument since it cannot be undone...
void enableOk(bool enable)
Let leaf subclass control the Ok button.
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.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
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:91
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void setStopX(double stopX)
Set method for x stop.
Strategy class for grid removal.
Definition: GridRemoval.h:24