18#include <QDoubleValidator>
19#include <QGraphicsScene>
39 "DlgSettingsGridRemoval",
41 m_validatorCloseDistance (nullptr),
42 m_validatorCountX (nullptr),
43 m_validatorStartX (nullptr),
44 m_validatorStepX (nullptr),
45 m_validatorStopX (nullptr),
46 m_validatorCountY (nullptr),
47 m_validatorStartY (nullptr),
48 m_validatorStepY (nullptr),
49 m_validatorStopY (nullptr),
50 m_scenePreview (nullptr),
51 m_viewPreview (nullptr),
52 m_modelGridRemovalBefore (nullptr),
53 m_modelGridRemovalAfter (nullptr)
65 delete m_validatorCloseDistance;
66 delete m_validatorCountX;
67 delete m_validatorStartX;
68 delete m_validatorStepX;
69 delete m_validatorStopX;
70 delete m_validatorCountY;
71 delete m_validatorStartY;
72 delete m_validatorStepY;
73 delete m_validatorStopY;
80void DlgSettingsGridRemoval::createPreview (QGridLayout *layout,
int &row)
84 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
85 layout->addWidget (labelPreview, row++, 0, 1, 5);
87 m_scenePreview =
new QGraphicsScene (
this);
91 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect grid removal"));
92 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
93 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
95 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
98void DlgSettingsGridRemoval::createRemoveGridLines (QGridLayout *layout,
int &row)
102 m_chkRemoveGridLines =
new QCheckBox (tr (
"Remove pixels close to defined grid lines"));
103 m_chkRemoveGridLines->setWhatsThis (tr (
"Check this box to have pixels close to regularly spaced gridlines removed.\n\n"
104 "This option is only available when the axis points have all been defined."));
105 connect (m_chkRemoveGridLines, SIGNAL (stateChanged (
int)),
this, SLOT (slotRemoveGridLines (
int)));
106 layout->addWidget (m_chkRemoveGridLines, row++, 1, 1, 3);
108 QLabel *labelCloseDistance =
new QLabel (QString (
"%1:").arg (tr (
"Close distance (pixels)")));
109 layout->addWidget (labelCloseDistance, row, 2);
111 m_editCloseDistance =
new QLineEdit;
112 m_editCloseDistance->setWhatsThis (tr (
"Set closeness distance in pixels.\n\n"
113 "Pixels that are closer to the regularly spaced gridlines, than this distance, "
114 "will be removed.\n\n"
115 "This value cannot be negative. A zero value disables this feature. Decimal values are allowed"));
117 m_editCloseDistance->setValidator (m_validatorCloseDistance);
118 connect (m_editCloseDistance, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCloseDistance (
const QString &)));
119 layout->addWidget (m_editCloseDistance, row++, 3);
121 createRemoveGridLinesX (layout, row);
122 createRemoveGridLinesY (layout, row);
125void DlgSettingsGridRemoval::createRemoveGridLinesX (QGridLayout *layout,
int &row)
129 QString titleX = tr (
"X Grid Lines");
131 titleX = QString (QChar (0x98, 0x03)) + QString (
" %1").arg (tr (
"Grid Lines"));
133 QGroupBox *groupX =
new QGroupBox (titleX);
134 layout->addWidget (groupX, row, 2);
136 QGridLayout *layoutGroup =
new QGridLayout;
137 groupX->setLayout (layoutGroup);
139 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
140 layoutGroup->addWidget (labelDisable, 0, 0);
142 m_cmbDisableX =
new QComboBox;
143 m_cmbDisableX->setWhatsThis (tr (
"Disabled value.\n\n"
144 "The X grid lines are specified using only three values at a time. For flexibility, four values "
145 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
146 "updated as the other values change"));
155 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
156 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
158 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
159 layoutGroup->addWidget (labelCount, 1, 0);
161 m_editCountX =
new QLineEdit;
162 m_editCountX->setWhatsThis (tr (
"Number of X grid lines.\n\n"
163 "The number of X grid lines must be entered as an integer greater than zero"));
165 m_editCountX->setValidator (m_validatorCountX);
166 connect (m_editCountX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountX (
const QString &)));
167 layoutGroup->addWidget (m_editCountX, 1, 1);
169 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
170 layoutGroup->addWidget (labelStart, 2, 0);
172 m_editStartX =
new QLineEdit;
173 m_editStartX->setWhatsThis (tr (
"Value of the first X grid line.\n\n"
174 "The start value cannot be greater than the stop value"));
175 m_validatorStartX =
new QDoubleValidator;
176 m_editStartX->setValidator (m_validatorStartX);
177 connect (m_editStartX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartX (
const QString &)));
178 layoutGroup->addWidget (m_editStartX, 2, 1);
180 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
181 layoutGroup->addWidget (labelStep, 3, 0);
183 m_editStepX =
new QLineEdit;
184 m_editStepX->setWhatsThis (tr (
"Difference in value between two successive X grid lines.\n\n"
185 "The step value must be greater than zero (linear) or one (log)"));
186 m_validatorStepX =
new QDoubleValidator;
187 m_editStepX->setValidator (m_validatorStepX);
188 connect (m_editStepX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepX (
const QString &)));
189 layoutGroup->addWidget (m_editStepX, 3, 1);
191 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
192 layoutGroup->addWidget (labelStop, 4, 0);
194 m_editStopX =
new QLineEdit;
195 m_editStopX->setWhatsThis (tr (
"Value of the last X grid line.\n\n"
196 "The stop value cannot be less than the start value"));
197 m_validatorStopX =
new QDoubleValidator;
198 m_editStopX->setValidator (m_validatorStopX);
199 connect (m_editStopX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopX (
const QString &)));
200 layoutGroup->addWidget (m_editStopX, 4, 1);
203void DlgSettingsGridRemoval::createRemoveGridLinesY (QGridLayout *layout,
int &row)
207 QString titleY = tr (
"Y Grid Lines");
209 titleY = QString (tr (
"R Grid Lines"));
211 QGroupBox *groupY =
new QGroupBox (titleY);
212 layout->addWidget (groupY, row++, 3);
214 QGridLayout *layoutGroup =
new QGridLayout;
215 groupY->setLayout (layoutGroup);
217 QLabel *labelDisable =
new QLabel (QString (
"%1:").arg (tr (
"Disable")));
218 layoutGroup->addWidget (labelDisable, 0, 0);
220 m_cmbDisableY =
new QComboBox;
221 m_cmbDisableY->setWhatsThis (tr (
"Disabled value.\n\n"
222 "The Y grid lines are specified using only three values at a time. For flexibility, four values "
223 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
224 "updated as the other values change"));
233 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
234 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
236 QLabel *labelCount =
new QLabel (QString (
"%1:").arg (tr (
"Count")));
237 layoutGroup->addWidget (labelCount, 1, 0);
239 m_editCountY =
new QLineEdit;
240 m_editCountY->setWhatsThis (tr (
"Number of Y grid lines.\n\n"
241 "The number of Y grid lines must be entered as an integer greater than zero"));
243 m_editCountY->setValidator (m_validatorCountY);
244 connect (m_editCountY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountY (
const QString &)));
245 layoutGroup->addWidget (m_editCountY, 1, 1);
247 QLabel *labelStart =
new QLabel (QString (
"%1:").arg (tr (
"Start")));
248 layoutGroup->addWidget (labelStart, 2, 0);
250 m_editStartY =
new QLineEdit;
251 m_editStartY->setWhatsThis (tr (
"Value of the first Y grid line.\n\n"
252 "The start value cannot be greater than the stop value"));
253 m_validatorStartY =
new QDoubleValidator;
254 m_editStartY->setValidator (m_validatorStartY);
255 connect (m_editStartY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartY (
const QString &)));
256 layoutGroup->addWidget (m_editStartY, 2, 1);
258 QLabel *labelStep =
new QLabel (QString (
"%1:").arg (tr (
"Step")));
259 layoutGroup->addWidget (labelStep, 3, 0);
261 m_editStepY =
new QLineEdit;
262 m_editStepY->setWhatsThis (tr (
"Difference in value between two successive Y grid lines.\n\n"
263 "The step value must be greater than zero (linear) or one (log)"));
264 m_validatorStepY =
new QDoubleValidator;
265 m_editStepY->setValidator (m_validatorStepY);
266 connect (m_editStepY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepY (
const QString &)));
267 layoutGroup->addWidget (m_editStepY, 3, 1);
269 QLabel *labelStop =
new QLabel (QString (
"%1:").arg (tr (
"Stop")));
270 layoutGroup->addWidget (labelStop, 4, 0);
272 m_editStopY =
new QLineEdit;
273 m_editStopY->setWhatsThis (tr (
"Value of the last Y grid line.\n\n"
274 "The stop value cannot be less than the start value"));
275 m_validatorStopY =
new QDoubleValidator;
276 m_editStopY->setValidator (m_validatorStopY);
277 connect (m_editStopY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopY (
const QString &)));
278 layoutGroup->addWidget (m_editStopY, 4, 1);
285 QWidget *subPanel =
new QWidget ();
286 QGridLayout *layout =
new QGridLayout (subPanel);
287 subPanel->setLayout (layout);
289 layout->setColumnStretch(0, 1);
290 layout->setColumnStretch(1, 0);
291 layout->setColumnStretch(2, 0);
292 layout->setColumnStretch(3, 0);
293 layout->setColumnStretch(4, 1);
302 createRemoveGridLines (layout, row);
303 createPreview (layout, row);
313 m_modelGridRemovalAfter->setStable ();
317 *m_modelGridRemovalBefore,
318 *m_modelGridRemovalAfter);
331 delete m_modelGridRemovalBefore;
332 delete m_modelGridRemovalAfter;
343 m_chkRemoveGridLines->setChecked (m_modelGridRemovalAfter->removeDefinedGridLines());
345 m_editCloseDistance->setText (QString::number (m_modelGridRemovalAfter->closeDistance()));
347 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->gridCoordDisableX()));
348 m_cmbDisableX->setCurrentIndex (indexDisableX);
350 m_editCountX->setText(QString::number(m_modelGridRemovalAfter->countX()));
351 m_editStartX->setText(QString::number(m_modelGridRemovalAfter->startX()));
352 m_editStepX->setText(QString::number(m_modelGridRemovalAfter->stepX()));
353 m_editStopX->setText(QString::number(m_modelGridRemovalAfter->stopX()));
355 int indexDisableY = m_cmbDisableY->findData (QVariant (m_modelGridRemovalAfter->gridCoordDisableY()));
356 m_cmbDisableY->setCurrentIndex (indexDisableY);
358 m_editCountY->setText(QString::number(m_modelGridRemovalAfter->countY()));
359 m_editStartY->setText(QString::number(m_modelGridRemovalAfter->startY()));
360 m_editStepY->setText(QString::number(m_modelGridRemovalAfter->stepY()));
361 m_editStopY->setText(QString::number(m_modelGridRemovalAfter->stopY()));
375void DlgSettingsGridRemoval::slotCloseDistance(
const QString &)
379 m_modelGridRemovalAfter->
setCloseDistance(m_editCloseDistance->text().toDouble());
384void DlgSettingsGridRemoval::slotCountX(
const QString &count)
388 m_modelGridRemovalAfter->setCountX(count.toInt());
389 updateDisplayedVariableX ();
394void DlgSettingsGridRemoval::slotCountY(
const QString &count)
398 m_modelGridRemovalAfter->setCountY(count.toInt());
399 updateDisplayedVariableY ();
404void DlgSettingsGridRemoval::slotDisableX(
const QString &)
409 m_modelGridRemovalAfter->setGridCoordDisableX(gridCoordDisable);
410 updateDisplayedVariableX ();
415void DlgSettingsGridRemoval::slotDisableY(
const QString &)
420 m_modelGridRemovalAfter->setGridCoordDisableY(gridCoordDisable);
421 updateDisplayedVariableY ();
426void DlgSettingsGridRemoval::slotRemoveGridLines (
int state)
430 m_modelGridRemovalAfter->setRemoveDefinedGridLines(state == Qt::Checked);
435void DlgSettingsGridRemoval::slotStartX(
const QString &startX)
439 m_modelGridRemovalAfter->setStartX(startX.toDouble());
440 updateDisplayedVariableX ();
445void DlgSettingsGridRemoval::slotStartY(
const QString &startY)
449 m_modelGridRemovalAfter->setStartY(startY.toDouble());
450 updateDisplayedVariableY ();
455void DlgSettingsGridRemoval::slotStepX(
const QString &stepX)
459 m_modelGridRemovalAfter->setStepX(stepX.toDouble());
460 updateDisplayedVariableX ();
465void DlgSettingsGridRemoval::slotStepY(
const QString &stepY)
469 m_modelGridRemovalAfter->setStepY(stepY.toDouble());
470 updateDisplayedVariableY ();
475void DlgSettingsGridRemoval::slotStopX(
const QString &stopX)
479 m_modelGridRemovalAfter->setStopX(stopX.toDouble());
480 updateDisplayedVariableX ();
485void DlgSettingsGridRemoval::slotStopY(
const QString &stopY)
489 m_modelGridRemovalAfter->setStopY(stopY.toDouble());
490 updateDisplayedVariableY ();
495void DlgSettingsGridRemoval::slotWhatsThis ()
497 QWhatsThis::enterWhatsThisMode();
500void DlgSettingsGridRemoval::updateControls ()
502 m_editCloseDistance->setEnabled (m_chkRemoveGridLines->isChecked ());
504 m_cmbDisableX->setEnabled (m_chkRemoveGridLines->isChecked ());
512 m_cmbDisableY->setEnabled (m_chkRemoveGridLines->isChecked ());
520 QString textCloseDistance = m_editCloseDistance->text();
521 QString textCountX = m_editCountX->text();
522 QString textStartX = m_editStartX->text();
523 QString textStepX = m_editStepX->text();
524 QString textStopX = m_editStopX->text();
525 QString textCountY = m_editCountY->text();
526 QString textStartY = m_editStartY->text();
527 QString textStepY = m_editStepY->text();
528 QString textStopY = m_editStopY->text();
531 bool isOk = (m_validatorCloseDistance->validate (textCloseDistance, pos) == QValidator::Acceptable) &&
532 (m_validatorCountX->validate (textCountX, pos) == QValidator::Acceptable) &&
533 (m_validatorStartX->validate (textStartX, pos) == QValidator::Acceptable) &&
534 (m_validatorStepX->validate (textStepX, pos) == QValidator::Acceptable) &&
535 (m_validatorStopX->validate (textStopX, pos) == QValidator::Acceptable) &&
536 (m_validatorCountY->validate (textCountY, pos) == QValidator::Acceptable) &&
537 (m_validatorStartY->validate (textStartY, pos) == QValidator::Acceptable) &&
538 (m_validatorStepY->validate (textStepY, pos) == QValidator::Acceptable) &&
539 (m_validatorStopY->validate (textStopY, pos) == QValidator::Acceptable);
543void DlgSettingsGridRemoval::updateDisplayedVariableX ()
545 GridInitializer initializer;
549 switch (m_modelGridRemovalAfter->gridCoordDisableX()) {
551 m_editCountX->setText (QString::number (initializer.
computeCount (linearAxis,
552 m_modelGridRemovalAfter->startX (),
553 m_modelGridRemovalAfter->stopX (),
554 m_modelGridRemovalAfter->stepX ())));
558 m_editStartX->setText (QString::number (initializer.
computeStart (linearAxis,
559 m_modelGridRemovalAfter->stopX (),
560 m_modelGridRemovalAfter->stepX (),
561 m_modelGridRemovalAfter->countX ())));
565 m_editStepX->setText (QString::number (initializer.
computeStep (linearAxis,
566 m_modelGridRemovalAfter->startX (),
567 m_modelGridRemovalAfter->stopX (),
568 m_modelGridRemovalAfter->countX ())));
572 m_editStopX->setText (QString::number (initializer.
computeStop (linearAxis,
573 m_modelGridRemovalAfter->startX (),
574 m_modelGridRemovalAfter->stepX (),
575 m_modelGridRemovalAfter->countX ())));
580void DlgSettingsGridRemoval::updateDisplayedVariableY ()
582 GridInitializer initializer;
586 switch (m_modelGridRemovalAfter->gridCoordDisableY()) {
588 m_editCountY->setText (QString::number (initializer.
computeCount (linearAxis,
589 m_modelGridRemovalAfter->startY (),
590 m_modelGridRemovalAfter->stopY (),
591 m_modelGridRemovalAfter->stepY ())));
595 m_editStartY->setText (QString::number (initializer.
computeStart (linearAxis,
596 m_modelGridRemovalAfter->stopY (),
597 m_modelGridRemovalAfter->stepY (),
598 m_modelGridRemovalAfter->countY ())));
602 m_editStepY->setText (QString::number (initializer.
computeStep (linearAxis,
603 m_modelGridRemovalAfter->startY (),
604 m_modelGridRemovalAfter->stopY (),
605 m_modelGridRemovalAfter->countY ())));
609 m_editStopY->setText (QString::number (initializer.
computeStop (linearAxis,
610 m_modelGridRemovalAfter->startY (),
611 m_modelGridRemovalAfter->stepY (),
612 m_modelGridRemovalAfter->countY ())));
617void DlgSettingsGridRemoval::updatePreview ()
619 GridRemoval gridRemoval (
mainWindow().isGnuplot());
621 QPixmap pixmap = gridRemoval.remove (
mainWindow ().transformation(),
622 *m_modelGridRemovalAfter,
625 m_scenePreview->clear();
const double CLOSE_DISTANCE_MIN
const double CLOSE_DISTANCE_MAX
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
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 createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void addPixmap(QGraphicsScene &scene, const QPixmap &pixmap)
Adds pixmap to the scene.
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.
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)