1 #include "CmdMediator.h"
2 #include "CmdSettingsGridRemoval.h"
3 #include "DlgSettingsGridRemoval.h"
4 #include "EngaugeAssert.h"
6 #include "MainWindow.h"
9 #include <QDoubleValidator>
10 #include <QGraphicsScene>
11 #include <QGridLayout>
13 #include <QHBoxLayout>
16 #include "ViewPreview.h"
18 const double CLOSE_DISTANCE_MAX = 64;
19 const double CLOSE_DISTANCE_MIN = 0;
20 const int CLOSE_DECIMALS = 1;
21 const int COUNT_MIN = 1;
22 const int COUNT_MAX = 100;
23 const int COUNT_DECIMALS = 0;
27 "DlgSettingsGridRemoval",
31 m_modelGridRemovalBefore (0),
32 m_modelGridRemovalAfter (0)
34 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::DlgSettingsGridRemoval";
40 DlgSettingsGridRemoval::~DlgSettingsGridRemoval()
42 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::~DlgSettingsGridRemoval";
45 void DlgSettingsGridRemoval::createPreview (QGridLayout *layout,
int &row)
47 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createPreview";
49 QLabel *labelPreview =
new QLabel (
"Preview");
50 layout->addWidget (labelPreview, row++, 0, 1, 5);
52 m_scenePreview =
new QGraphicsScene (
this);
54 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
56 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect grid removal"));
57 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
60 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
63 void DlgSettingsGridRemoval::createRemoveGridLines (QGridLayout *layout,
int &row)
65 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLines";
67 m_chkRemoveGridLines =
new QCheckBox (
"Remove pixels close to defined grid lines");
68 m_chkRemoveGridLines->setWhatsThis (
"Check this box to have pixels close to regularly spaced gridlines removed.\n\n"
69 "This option is only available when the axis points have all been defined.");
70 connect (m_chkRemoveGridLines, SIGNAL (stateChanged (
int)),
this, SLOT (slotRemoveGridLines (
int)));
71 layout->addWidget (m_chkRemoveGridLines, row++, 1, 1, 3);
73 QLabel *labelCloseDistance =
new QLabel (
"Close distance (pixels):");
74 layout->addWidget (labelCloseDistance, row, 2);
76 m_editCloseDistance =
new QLineEdit;
77 m_editCloseDistance->setWhatsThis (
"Set closeness distance in pixels.\n\n"
78 "Pixels that are closer to the regularly spaced gridlines, than this distance, "
79 "will be removed.\n\n"
80 "This value cannot be negative. A zero value disables this feature. Decimal values are allowed");
81 m_validatorCloseDistance =
new QDoubleValidator (CLOSE_DISTANCE_MIN, CLOSE_DISTANCE_MAX, CLOSE_DECIMALS);
82 m_editCloseDistance->setValidator (m_validatorCloseDistance);
83 connect (m_editCloseDistance, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCloseDistance (
const QString &)));
84 layout->addWidget (m_editCloseDistance, row++, 3);
86 createRemoveGridLinesX (layout, row);
87 createRemoveGridLinesY (layout, row);
90 void DlgSettingsGridRemoval::createRemoveGridLinesX (QGridLayout *layout,
int &row)
92 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLinesX";
94 QString titleX =
"X Grid Lines";
96 titleX = QString (QChar (0x98, 0x03)) + QString (
" Grid Lines");
98 QGroupBox *groupX =
new QGroupBox (titleX);
99 layout->addWidget (groupX, row, 2);
101 QGridLayout *layoutGroup =
new QGridLayout;
102 groupX->setLayout (layoutGroup);
104 QLabel *labelDisable =
new QLabel (
"Disable:");
105 layoutGroup->addWidget (labelDisable, 0, 0);
107 m_cmbDisableX =
new QComboBox;
108 m_cmbDisableX->setWhatsThis (
"Disabled value.\n\n"
109 "The X grid lines are specified using only three values at a time. For flexibility, four values "
110 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
111 "updated as the other values change");
112 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
113 QVariant (GRID_COORD_DISABLE_COUNT));
114 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
115 QVariant (GRID_COORD_DISABLE_START));
116 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
117 QVariant (GRID_COORD_DISABLE_STEP));
118 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
119 QVariant (GRID_COORD_DISABLE_STOP));
120 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
121 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
123 QLabel *labelCount =
new QLabel (
"Count:");
124 layoutGroup->addWidget (labelCount, 1, 0);
126 m_editCountX =
new QLineEdit;
127 m_editCountX->setWhatsThis (
"Number of X grid lines.\n\n"
128 "The number of X grid lines must be entered as an integer greater than zero");
129 m_validatorCountX =
new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
130 m_editCountX->setValidator (m_validatorCountX);
131 connect (m_editCountX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountX (
const QString &)));
132 layoutGroup->addWidget (m_editCountX, 1, 1);
134 QLabel *labelStart =
new QLabel (
"Start:");
135 layoutGroup->addWidget (labelStart, 2, 0);
137 m_editStartX =
new QLineEdit;
138 m_editStartX->setWhatsThis (
"Value of the first X grid line.\n\n"
139 "The start value cannot be greater than the stop value");
140 m_validatorStartX =
new QDoubleValidator;
141 m_editStartX->setValidator (m_validatorStartX);
142 connect (m_editStartX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartX (
const QString &)));
143 layoutGroup->addWidget (m_editStartX, 2, 1);
145 QLabel *labelStep =
new QLabel (
"Step:");
146 layoutGroup->addWidget (labelStep, 3, 0);
148 m_editStepX =
new QLineEdit;
149 m_editStepX->setWhatsThis (
"Difference in value between two successive X grid lines.\n\n"
150 "The step value must be greater than zero");
151 m_validatorStepX =
new QDoubleValidator;
152 m_editStepX->setValidator (m_validatorStepX);
153 connect (m_editStepX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepX (
const QString &)));
154 layoutGroup->addWidget (m_editStepX, 3, 1);
156 QLabel *labelStop =
new QLabel (
"Stop:");
157 layoutGroup->addWidget (labelStop, 4, 0);
159 m_editStopX =
new QLineEdit;
160 m_editStopX->setWhatsThis (
"Value of the last X grid line.\n\n"
161 "The stop value cannot be less than the start value");
162 m_validatorStopX =
new QDoubleValidator;
163 m_editStopX->setValidator (m_validatorStopX);
164 connect (m_editStopX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopX (
const QString &)));
165 layoutGroup->addWidget (m_editStopX, 4, 1);
168 void DlgSettingsGridRemoval::createRemoveGridLinesY (QGridLayout *layout,
int &row)
170 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLinesY";
172 QString titleY =
"Y Grid Lines";
174 titleY = QString (
"R Grid Lines");
176 QGroupBox *groupY =
new QGroupBox (titleY);
177 layout->addWidget (groupY, row++, 3);
179 QGridLayout *layoutGroup =
new QGridLayout;
180 groupY->setLayout (layoutGroup);
182 QLabel *labelDisable =
new QLabel (
"Disable:");
183 layoutGroup->addWidget (labelDisable, 0, 0);
185 m_cmbDisableY =
new QComboBox;
186 m_cmbDisableY->setWhatsThis (
"Disabled value.\n\n"
187 "The Y grid lines are specified using only three values at a time. For flexibility, four values "
188 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
189 "updated as the other values change");
190 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
191 QVariant (GRID_COORD_DISABLE_COUNT));
192 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
193 QVariant (GRID_COORD_DISABLE_START));
194 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
195 QVariant (GRID_COORD_DISABLE_STEP));
196 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
197 QVariant (GRID_COORD_DISABLE_STOP));
198 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
199 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
201 QLabel *labelCount =
new QLabel (
"Count:");
202 layoutGroup->addWidget (labelCount, 1, 0);
204 m_editCountY =
new QLineEdit;
205 m_editCountY->setWhatsThis (
"Number of Y grid lines.\n\n"
206 "The number of Y grid lines must be entered as an integer greater than zero");
207 m_validatorCountY =
new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
208 m_editCountY->setValidator (m_validatorCountY);
209 connect (m_editCountY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountY (
const QString &)));
210 layoutGroup->addWidget (m_editCountY, 1, 1);
212 QLabel *labelStart =
new QLabel (
"Start:");
213 layoutGroup->addWidget (labelStart, 2, 0);
215 m_editStartY =
new QLineEdit;
216 m_editStartY->setWhatsThis (
"Value of the first Y grid line.\n\n"
217 "The start value cannot be greater than the stop value");
218 m_validatorStartY =
new QDoubleValidator;
219 m_editStartY->setValidator (m_validatorStartY);
220 connect (m_editStartY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartY (
const QString &)));
221 layoutGroup->addWidget (m_editStartY, 2, 1);
223 QLabel *labelStep =
new QLabel (
"Step:");
224 layoutGroup->addWidget (labelStep, 3, 0);
226 m_editStepY =
new QLineEdit;
227 m_editStepY->setWhatsThis (
"Difference in value between two successive Y grid lines.\n\n"
228 "The step value must be greater than zero");
229 m_validatorStepY =
new QDoubleValidator;
230 m_editStepY->setValidator (m_validatorStepY);
231 connect (m_editStepY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepY (
const QString &)));
232 layoutGroup->addWidget (m_editStepY, 3, 1);
234 QLabel *labelStop =
new QLabel (
"Stop:");
235 layoutGroup->addWidget (labelStop, 4, 0);
237 m_editStopY =
new QLineEdit;
238 m_editStopY->setWhatsThis (
"Value of the last Y grid line.\n\n"
239 "The stop value cannot be less than the start value");
240 m_validatorStopY =
new QDoubleValidator;
241 m_editStopY->setValidator (m_validatorStopY);
242 connect (m_editStopY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopY (
const QString &)));
243 layoutGroup->addWidget (m_editStopY, 4, 1);
248 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createSubPanel";
250 const int COLUMN_CHECKBOX_WIDTH = 60;
252 QWidget *subPanel =
new QWidget ();
253 QGridLayout *layout =
new QGridLayout (subPanel);
254 subPanel->setLayout (layout);
256 layout->setColumnStretch(0, 1);
257 layout->setColumnStretch(1, 0);
258 layout->setColumnMinimumWidth(1, COLUMN_CHECKBOX_WIDTH);
259 layout->setColumnStretch(2, 0);
260 layout->setColumnStretch(3, 0);
261 layout->setColumnStretch(4, 1);
264 createRemoveGridLines (layout, row);
265 createPreview (layout, row);
272 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::handleOk";
279 *m_modelGridRemovalBefore,
280 *m_modelGridRemovalAfter);
288 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::load";
293 if (m_modelGridRemovalBefore != 0) {
294 delete m_modelGridRemovalBefore;
296 if (m_modelGridRemovalAfter != 0) {
297 delete m_modelGridRemovalAfter;
305 ENGAUGE_ASSERT (CLOSE_DISTANCE_MIN <= m_modelGridRemovalAfter->closeDistance());
306 ENGAUGE_ASSERT (CLOSE_DISTANCE_MAX >= m_modelGridRemovalAfter->
closeDistance());
311 m_editCloseDistance->setText (QString::number (m_modelGridRemovalAfter->
closeDistance()));
313 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->
gridCoordDisableX()));
314 m_cmbDisableX->setCurrentIndex (indexDisableX);
316 m_editCountX->setText(QString::number(m_modelGridRemovalAfter->
countX()));
317 m_editStartX->setText(QString::number(m_modelGridRemovalAfter->
startX()));
318 m_editStepX->setText(QString::number(m_modelGridRemovalAfter->
stepX()));
319 m_editStopX->setText(QString::number(m_modelGridRemovalAfter->
stopX()));
321 int indexDisableY = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->
gridCoordDisableY()));
322 m_cmbDisableY->setCurrentIndex (indexDisableY);
324 m_editCountY->setText(QString::number(m_modelGridRemovalAfter->
countY()));
325 m_editStartY->setText(QString::number(m_modelGridRemovalAfter->
startY()));
326 m_editStepY->setText(QString::number(m_modelGridRemovalAfter->
stepY()));
327 m_editStopY->setText(QString::number(m_modelGridRemovalAfter->
stopY()));
329 m_scenePreview->clear();
337 void DlgSettingsGridRemoval::slotCloseDistance(
const QString &)
339 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCloseDistance";
341 m_modelGridRemovalAfter->
setCloseDistance(m_editCloseDistance->text().toDouble());
346 void DlgSettingsGridRemoval::slotCountX(
const QString &count)
348 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCountX";
350 m_modelGridRemovalAfter->
setCountX(count.toInt());
355 void DlgSettingsGridRemoval::slotCountY(
const QString &count)
357 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCountY";
359 m_modelGridRemovalAfter->
setCountY(count.toInt());
364 void DlgSettingsGridRemoval::slotDisableX(
const QString &)
366 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotDisableX";
368 GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
374 void DlgSettingsGridRemoval::slotDisableY(
const QString &)
376 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotDisableY";
378 GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
384 void DlgSettingsGridRemoval::slotRemoveGridLines (
int state)
386 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotRemoveGridLines";
393 void DlgSettingsGridRemoval::slotStartX(
const QString &startX)
395 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStartX";
397 m_modelGridRemovalAfter->
setStartX(startX.toDouble());
402 void DlgSettingsGridRemoval::slotStartY(
const QString &startY)
404 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStartY";
406 m_modelGridRemovalAfter->
setStartY(startY.toDouble());
411 void DlgSettingsGridRemoval::slotStepX(
const QString &stepX)
413 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStepX";
415 m_modelGridRemovalAfter->
setStepX(stepX.toDouble());
420 void DlgSettingsGridRemoval::slotStepY(
const QString &stepY)
422 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStepY";
424 m_modelGridRemovalAfter->
setStepY(stepY.toDouble());
429 void DlgSettingsGridRemoval::slotStopX(
const QString &stopX)
431 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStopX";
433 m_modelGridRemovalAfter->
setStopX(stopX.toDouble());
438 void DlgSettingsGridRemoval::slotStopY(
const QString &stopY)
440 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStopY";
442 m_modelGridRemovalAfter->
setStopY(stopY.toDouble());
447 void DlgSettingsGridRemoval::updateControls ()
449 m_editCloseDistance->setEnabled (m_chkRemoveGridLines->isChecked ());
451 m_cmbDisableX->setEnabled (m_chkRemoveGridLines->isChecked ());
453 GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
454 m_editCountX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_COUNT));
455 m_editStartX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_START));
456 m_editStepX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STEP));
457 m_editStopX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STOP));
459 m_cmbDisableY->setEnabled (m_chkRemoveGridLines->isChecked ());
461 GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
462 m_editCountY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_COUNT));
463 m_editStartY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_START));
464 m_editStepY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STEP));
465 m_editStopY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STOP));
467 QString textCloseDistance = m_editCloseDistance->text();
468 QString textCountX = m_editCountX->text();
469 QString textStartX = m_editStartX->text();
470 QString textStepX = m_editStepX->text();
471 QString textStopX = m_editStopX->text();
472 QString textCountY = m_editCountY->text();
473 QString textStartY = m_editStartY->text();
474 QString textStepY = m_editStepY->text();
475 QString textStopY = m_editStopY->text();
478 bool isOk = (m_validatorCloseDistance->validate (textCloseDistance, pos) == QValidator::Acceptable) &&
479 (m_validatorCountX->validate (textCountX, pos) == QValidator::Acceptable) &&
480 (m_validatorStartX->validate (textStartX, pos) == QValidator::Acceptable) &&
481 (m_validatorStepX->validate (textStepX, pos) == QValidator::Acceptable) &&
482 (m_validatorStopX->validate (textStopX, pos) == QValidator::Acceptable) &&
483 (m_validatorCountY->validate (textCountY, pos) == QValidator::Acceptable) &&
484 (m_validatorStartY->validate (textStartY, pos) == QValidator::Acceptable) &&
485 (m_validatorStepY->validate (textStepY, pos) == QValidator::Acceptable) &&
486 (m_validatorStopY->validate (textStopY, pos) == QValidator::Acceptable);
490 void DlgSettingsGridRemoval::updatePreview ()
double closeDistance() const
Get method for close distance.
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.
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.
QPixmap pixmap() const
Return the image that is being digitized.
double stepY() const
Get method for y step.
GridCoordDisable gridCoordDisableY() const
Get method for y coord parameter to disable.
void setStartX(double startX)
Set method for x start.
virtual void handleOk()
Process slotOk.
void setCountY(int countY)
Set method for y count.
DlgSettingsGridRemoval(MainWindow &mainWindow)
Single constructor.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
void setStepX(double stepX)
Set method for x step.
double stopX() const
Get method for x stop.
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.
void setGridCoordDisableY(GridCoordDisable gridCoordDisable)
Set method for y coord parameter to disable.
Command for DlgSettingsGridRemoval.
void setGridCoordDisableX(GridCoordDisable gridCoordDisable)
Set method for x coord parameter to disable.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
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.
Abstract base class for all Settings dialogs.
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...
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void setStopX(double stopX)
Set method for x stop.