17#include <QDoubleValidator>
18#include <QGraphicsScene>
37 "DlgSettingsGridRemoval",
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)
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;
78void DlgSettingsGridRemoval::createPreview (QGridLayout *layout,
int &row)
82 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
83 layout->addWidget (labelPreview, row++, 0, 1, 5);
85 m_scenePreview =
new QGraphicsScene (
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);
93 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
96void DlgSettingsGridRemoval::createRemoveGridLines (QGridLayout *layout,
int &row)
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);
106 QLabel *labelCloseDistance =
new QLabel (QString (
"%1:").arg (tr (
"Close distance (pixels)")));
107 layout->addWidget (labelCloseDistance, row, 2);
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"));
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);
119 createRemoveGridLinesX (layout, row);
120 createRemoveGridLinesY (layout, row);
123void DlgSettingsGridRemoval::createRemoveGridLinesX (QGridLayout *layout,
int &row)
127 QString titleX = tr (
"X Grid Lines");
129 titleX = QString (QChar (0x98, 0x03)) + QString (
" %1").arg (tr (
"Grid Lines"));
131 QGroupBox *groupX =
new QGroupBox (titleX);
132 layout->addWidget (groupX, row, 2);
134 QGridLayout *layoutGroup =
new QGridLayout;
135 groupX->setLayout (layoutGroup);
137 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
138 layoutGroup->addWidget (labelDisable, 0, 0);
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"));
153 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
154 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
156 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
157 layoutGroup->addWidget (labelCount, 1, 0);
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"));
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);
167 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
168 layoutGroup->addWidget (labelStart, 2, 0);
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);
178 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
179 layoutGroup->addWidget (labelStep, 3, 0);
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);
189 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
190 layoutGroup->addWidget (labelStop, 4, 0);
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);
201void DlgSettingsGridRemoval::createRemoveGridLinesY (QGridLayout *layout,
int &row)
205 QString titleY = tr (
"Y Grid Lines");
207 titleY = QString (tr (
"R Grid Lines"));
209 QGroupBox *groupY =
new QGroupBox (titleY);
210 layout->addWidget (groupY, row++, 3);
212 QGridLayout *layoutGroup =
new QGridLayout;
213 groupY->setLayout (layoutGroup);
215 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
216 layoutGroup->addWidget (labelDisable, 0, 0);
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"));
231 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
232 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
234 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
235 layoutGroup->addWidget (labelCount, 1, 0);
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"));
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);
245 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
246 layoutGroup->addWidget (labelStart, 2, 0);
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);
256 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
257 layoutGroup->addWidget (labelStep, 3, 0);
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);
267 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
268 layoutGroup->addWidget (labelStop, 4, 0);
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);
283 QWidget *subPanel =
new QWidget ();
284 QGridLayout *layout =
new QGridLayout (subPanel);
285 subPanel->setLayout (layout);
287 layout->setColumnStretch(0, 1);
288 layout->setColumnStretch(1, 0);
289 layout->setColumnStretch(2, 0);
290 layout->setColumnStretch(3, 0);
291 layout->setColumnStretch(4, 1);
294 createRemoveGridLines (layout, row);
295 createPreview (layout, row);
305 m_modelGridRemovalAfter->setStable ();
309 *m_modelGridRemovalBefore,
310 *m_modelGridRemovalAfter);
323 delete m_modelGridRemovalBefore;
324 delete m_modelGridRemovalAfter;
335 m_chkRemoveGridLines->setChecked (m_modelGridRemovalAfter->removeDefinedGridLines());
337 m_editCloseDistance->setText (QString::number (m_modelGridRemovalAfter->closeDistance()));
339 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->gridCoordDisableX()));
340 m_cmbDisableX->setCurrentIndex (indexDisableX);
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()));
347 int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridRemovalAfter->gridCoordDisableY()));
348 m_cmbDisableY->setCurrentIndex (indexDisableY);
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()));
367void DlgSettingsGridRemoval::slotCloseDistance(
const QString &)
371 m_modelGridRemovalAfter->
setCloseDistance(m_editCloseDistance->text().toDouble());
376void DlgSettingsGridRemoval::slotCountX(
const QString &count)
380 m_modelGridRemovalAfter->setCountX(count.toInt());
381 updateDisplayedVariableX ();
386void DlgSettingsGridRemoval::slotCountY(
const QString &count)
390 m_modelGridRemovalAfter->setCountY(count.toInt());
391 updateDisplayedVariableY ();
396void DlgSettingsGridRemoval::slotDisableX(
const QString &)
401 m_modelGridRemovalAfter->setGridCoordDisableX(gridCoordDisable);
402 updateDisplayedVariableX ();
407void DlgSettingsGridRemoval::slotDisableY(
const QString &)
412 m_modelGridRemovalAfter->setGridCoordDisableY(gridCoordDisable);
413 updateDisplayedVariableY ();
418void DlgSettingsGridRemoval::slotRemoveGridLines (
int state)
422 m_modelGridRemovalAfter->setRemoveDefinedGridLines(state == Qt::Checked);
427void DlgSettingsGridRemoval::slotStartX(
const QString &startX)
431 m_modelGridRemovalAfter->setStartX(startX.toDouble());
432 updateDisplayedVariableX ();
437void DlgSettingsGridRemoval::slotStartY(
const QString &startY)
441 m_modelGridRemovalAfter->setStartY(startY.toDouble());
442 updateDisplayedVariableY ();
447void DlgSettingsGridRemoval::slotStepX(
const QString &stepX)
451 m_modelGridRemovalAfter->setStepX(stepX.toDouble());
452 updateDisplayedVariableX ();
457void DlgSettingsGridRemoval::slotStepY(
const QString &stepY)
461 m_modelGridRemovalAfter->setStepY(stepY.toDouble());
462 updateDisplayedVariableY ();
467void DlgSettingsGridRemoval::slotStopX(
const QString &stopX)
471 m_modelGridRemovalAfter->setStopX(stopX.toDouble());
472 updateDisplayedVariableX ();
477void DlgSettingsGridRemoval::slotStopY(
const QString &stopY)
481 m_modelGridRemovalAfter->setStopY(stopY.toDouble());
482 updateDisplayedVariableY ();
487void DlgSettingsGridRemoval::updateControls ()
489 m_editCloseDistance->setEnabled (m_chkRemoveGridLines->isChecked ());
491 m_cmbDisableX->setEnabled (m_chkRemoveGridLines->isChecked ());
499 m_cmbDisableY->setEnabled (m_chkRemoveGridLines->isChecked ());
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();
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);
530void DlgSettingsGridRemoval::updateDisplayedVariableX ()
532 GridInitializer initializer;
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 ())));
545 m_editStartX->setText (QString::number (initializer.
computeStart (linearAxis,
546 m_modelGridRemovalAfter->stopX (),
547 m_modelGridRemovalAfter->stepX (),
548 m_modelGridRemovalAfter->countX ())));
552 m_editStepX->setText (QString::number (initializer.
computeStep (linearAxis,
553 m_modelGridRemovalAfter->startX (),
554 m_modelGridRemovalAfter->stopX (),
555 m_modelGridRemovalAfter->countX ())));
559 m_editStopX->setText (QString::number (initializer.
computeStop (linearAxis,
560 m_modelGridRemovalAfter->startX (),
561 m_modelGridRemovalAfter->stepX (),
562 m_modelGridRemovalAfter->countX ())));
567void DlgSettingsGridRemoval::updateDisplayedVariableY ()
569 GridInitializer initializer;
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 ())));
582 m_editStartY->setText (QString::number (initializer.
computeStart (linearAxis,
583 m_modelGridRemovalAfter->stopY (),
584 m_modelGridRemovalAfter->stepY (),
585 m_modelGridRemovalAfter->countY ())));
589 m_editStepY->setText (QString::number (initializer.
computeStep (linearAxis,
590 m_modelGridRemovalAfter->startY (),
591 m_modelGridRemovalAfter->stopY (),
592 m_modelGridRemovalAfter->countY ())));
596 m_editStopY->setText (QString::number (initializer.
computeStop (linearAxis,
597 m_modelGridRemovalAfter->startY (),
598 m_modelGridRemovalAfter->stepY (),
599 m_modelGridRemovalAfter->countY ())));
604void DlgSettingsGridRemoval::updatePreview ()
606 GridRemoval gridRemoval (
mainWindow().isGnuplot());
608 QPixmap pixmap = gridRemoval.remove (
mainWindow ().transformation(),
609 *m_modelGridRemovalAfter,
612 m_scenePreview->clear();
613 m_scenePreview->addPixmap (pixmap);
const double CLOSE_DISTANCE_MIN
const double CLOSE_DISTANCE_MAX
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
QString gridCoordDisableToString(GridCoordDisable gridCoordDisable)
@ GRID_COORD_DISABLE_STOP
@ GRID_COORD_DISABLE_START
@ GRID_COORD_DISABLE_STEP
@ GRID_COORD_DISABLE_COUNT
log4cpp::Category * mainCat
Command for DlgSettingsGridRemoval.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
virtual void handleOk()
Process slotOk.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual ~DlgSettingsGridRemoval()
DlgSettingsGridRemoval(MainWindow &mainWindow)
Single constructor.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
void setCloseDistance(double closeDistance)
Set method for close distance.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
double computeStep(bool linearAxis, double start, double stop, int count) const
Compute axis scale step from the other axis parameters.
double computeStart(bool linearAxis, double stop, double step, int count) const
Compute axis scale start from the other axis parameters.
int computeCount(bool linearAxis, double start, double stop, double step) const
Compute axis scale count from the other axis parameters.
double computeStop(bool linearAxis, double start, double step, int count) const
Compute axis scale stop from the other axis parameters.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
@ VIEW_ASPECT_RATIO_VARIABLE
#define LOG4CPP_INFO_S(logger)