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