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);
53 m_viewPreview =
new ViewPreview (m_scenePreview,
this);
54 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect grid removal"));
55 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
56 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
61 void DlgSettingsGridRemoval::createRemoveGridLines (QGridLayout *layout,
int &row)
63 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLines";
65 m_chkRemoveGridLines =
new QCheckBox (
"Remove pixels close to defined grid lines");
66 m_chkRemoveGridLines->setWhatsThis (
"Check this box to have pixels close to regularly spaced gridlines removed.\n\n"
67 "This option is only available when the axis points have all been defined.");
68 connect (m_chkRemoveGridLines, SIGNAL (stateChanged (
int)),
this, SLOT (slotRemoveGridLines (
int)));
69 layout->addWidget (m_chkRemoveGridLines, row++, 1, 1, 3);
71 QLabel *labelCloseDistance =
new QLabel (
"Close distance (pixels):");
72 layout->addWidget (labelCloseDistance, row, 2);
74 m_editCloseDistance =
new QLineEdit;
75 m_editCloseDistance->setWhatsThis (
"Set closeness distance in pixels.\n\n"
76 "Pixels that are closer to the regularly spaced gridlines, than this distance, "
77 "will be removed.\n\n"
78 "This value cannot be negative. A zero value disables this feature. Decimal values are allowed");
79 m_validatorCloseDistance =
new QDoubleValidator (CLOSE_DISTANCE_MIN, CLOSE_DISTANCE_MAX, CLOSE_DECIMALS);
80 m_editCloseDistance->setValidator (m_validatorCloseDistance);
81 connect (m_editCloseDistance, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCloseDistance (
const QString &)));
82 layout->addWidget (m_editCloseDistance, row++, 3);
84 createRemoveGridLinesX (layout, row);
85 createRemoveGridLinesY (layout, row);
88 void DlgSettingsGridRemoval::createRemoveGridLinesX (QGridLayout *layout,
int &row)
90 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLinesX";
92 QString titleX =
"X Grid Lines";
94 titleX = QString (QChar (0x98, 0x03)) + QString (
" Grid Lines");
96 QGroupBox *groupX =
new QGroupBox (titleX);
97 layout->addWidget (groupX, row, 2);
99 QGridLayout *layoutGroup =
new QGridLayout;
100 groupX->setLayout (layoutGroup);
102 QLabel *labelDisable =
new QLabel (
"Disable:");
103 layoutGroup->addWidget (labelDisable, 0, 0);
105 m_cmbDisableX =
new QComboBox;
106 m_cmbDisableX->setWhatsThis (
"Disabled value.\n\n"
107 "The X grid lines are specified using only three values at a time. For flexibility, four values "
108 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
109 "updated as the other values change");
110 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
111 QVariant (GRID_COORD_DISABLE_COUNT));
112 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
113 QVariant (GRID_COORD_DISABLE_START));
114 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
115 QVariant (GRID_COORD_DISABLE_STEP));
116 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
117 QVariant (GRID_COORD_DISABLE_STOP));
118 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
119 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
121 QLabel *labelCount =
new QLabel (
"Count:");
122 layoutGroup->addWidget (labelCount, 1, 0);
124 m_editCountX =
new QLineEdit;
125 m_editCountX->setWhatsThis (
"Number of X grid lines.\n\n"
126 "The number of X grid lines must be entered as an integer greater than zero");
127 m_validatorCountX =
new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
128 m_editCountX->setValidator (m_validatorCountX);
129 connect (m_editCountX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountX (
const QString &)));
130 layoutGroup->addWidget (m_editCountX, 1, 1);
132 QLabel *labelStart =
new QLabel (
"Start:");
133 layoutGroup->addWidget (labelStart, 2, 0);
135 m_editStartX =
new QLineEdit;
136 m_editStartX->setWhatsThis (
"Value of the first X grid line.\n\n"
137 "The start value cannot be greater than the stop value");
138 m_validatorStartX =
new QDoubleValidator;
139 m_editStartX->setValidator (m_validatorStartX);
140 connect (m_editStartX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartX (
const QString &)));
141 layoutGroup->addWidget (m_editStartX, 2, 1);
143 QLabel *labelStep =
new QLabel (
"Step:");
144 layoutGroup->addWidget (labelStep, 3, 0);
146 m_editStepX =
new QLineEdit;
147 m_editStepX->setWhatsThis (
"Difference in value between two successive X grid lines.\n\n"
148 "The step value must be greater than zero");
149 m_validatorStepX =
new QDoubleValidator;
150 m_editStepX->setValidator (m_validatorStepX);
151 connect (m_editStepX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepX (
const QString &)));
152 layoutGroup->addWidget (m_editStepX, 3, 1);
154 QLabel *labelStop =
new QLabel (
"Stop:");
155 layoutGroup->addWidget (labelStop, 4, 0);
157 m_editStopX =
new QLineEdit;
158 m_editStopX->setWhatsThis (
"Value of the last X grid line.\n\n"
159 "The stop value cannot be less than the start value");
160 m_validatorStopX =
new QDoubleValidator;
161 m_editStopX->setValidator (m_validatorStopX);
162 connect (m_editStopX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopX (
const QString &)));
163 layoutGroup->addWidget (m_editStopX, 4, 1);
166 void DlgSettingsGridRemoval::createRemoveGridLinesY (QGridLayout *layout,
int &row)
168 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLinesY";
170 QString titleY =
"Y Grid Lines";
172 titleY = QString (
"R Grid Lines");
174 QGroupBox *groupY =
new QGroupBox (titleY);
175 layout->addWidget (groupY, row++, 3);
177 QGridLayout *layoutGroup =
new QGridLayout;
178 groupY->setLayout (layoutGroup);
180 QLabel *labelDisable =
new QLabel (
"Disable:");
181 layoutGroup->addWidget (labelDisable, 0, 0);
183 m_cmbDisableY =
new QComboBox;
184 m_cmbDisableY->setWhatsThis (
"Disabled value.\n\n"
185 "The Y grid lines are specified using only three values at a time. For flexibility, four values "
186 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
187 "updated as the other values change");
188 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
189 QVariant (GRID_COORD_DISABLE_COUNT));
190 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
191 QVariant (GRID_COORD_DISABLE_START));
192 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
193 QVariant (GRID_COORD_DISABLE_STEP));
194 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
195 QVariant (GRID_COORD_DISABLE_STOP));
196 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
197 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
199 QLabel *labelCount =
new QLabel (
"Count:");
200 layoutGroup->addWidget (labelCount, 1, 0);
202 m_editCountY =
new QLineEdit;
203 m_editCountY->setWhatsThis (
"Number of Y grid lines.\n\n"
204 "The number of Y grid lines must be entered as an integer greater than zero");
205 m_validatorCountY =
new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
206 m_editCountY->setValidator (m_validatorCountY);
207 connect (m_editCountY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountY (
const QString &)));
208 layoutGroup->addWidget (m_editCountY, 1, 1);
210 QLabel *labelStart =
new QLabel (
"Start:");
211 layoutGroup->addWidget (labelStart, 2, 0);
213 m_editStartY =
new QLineEdit;
214 m_editStartY->setWhatsThis (
"Value of the first Y grid line.\n\n"
215 "The start value cannot be greater than the stop value");
216 m_validatorStartY =
new QDoubleValidator;
217 m_editStartY->setValidator (m_validatorStartY);
218 connect (m_editStartY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartY (
const QString &)));
219 layoutGroup->addWidget (m_editStartY, 2, 1);
221 QLabel *labelStep =
new QLabel (
"Step:");
222 layoutGroup->addWidget (labelStep, 3, 0);
224 m_editStepY =
new QLineEdit;
225 m_editStepY->setWhatsThis (
"Difference in value between two successive Y grid lines.\n\n"
226 "The step value must be greater than zero");
227 m_validatorStepY =
new QDoubleValidator;
228 m_editStepY->setValidator (m_validatorStepY);
229 connect (m_editStepY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepY (
const QString &)));
230 layoutGroup->addWidget (m_editStepY, 3, 1);
232 QLabel *labelStop =
new QLabel (
"Stop:");
233 layoutGroup->addWidget (labelStop, 4, 0);
235 m_editStopY =
new QLineEdit;
236 m_editStopY->setWhatsThis (
"Value of the last Y grid line.\n\n"
237 "The stop value cannot be less than the start value");
238 m_validatorStopY =
new QDoubleValidator;
239 m_editStopY->setValidator (m_validatorStopY);
240 connect (m_editStopY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopY (
const QString &)));
241 layoutGroup->addWidget (m_editStopY, 4, 1);
246 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createSubPanel";
248 const int COLUMN_CHECKBOX_WIDTH = 60;
250 QWidget *subPanel =
new QWidget ();
251 QGridLayout *layout =
new QGridLayout (subPanel);
252 subPanel->setLayout (layout);
254 layout->setColumnStretch(0, 1);
255 layout->setColumnStretch(1, 0);
256 layout->setColumnMinimumWidth(1, COLUMN_CHECKBOX_WIDTH);
257 layout->setColumnStretch(2, 0);
258 layout->setColumnStretch(3, 0);
259 layout->setColumnStretch(4, 1);
262 createRemoveGridLines (layout, row);
263 createPreview (layout, row);
270 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::handleOk";
277 *m_modelGridRemovalBefore,
278 *m_modelGridRemovalAfter);
286 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::load";
291 if (m_modelGridRemovalBefore != 0) {
292 delete m_modelGridRemovalBefore;
294 if (m_modelGridRemovalAfter != 0) {
295 delete m_modelGridRemovalAfter;
303 ENGAUGE_ASSERT (CLOSE_DISTANCE_MIN <= m_modelGridRemovalAfter->closeDistance());
304 ENGAUGE_ASSERT (CLOSE_DISTANCE_MAX >= m_modelGridRemovalAfter->
closeDistance());
309 m_editCloseDistance->setText (QString::number (m_modelGridRemovalAfter->
closeDistance()));
311 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->
gridCoordDisableX()));
312 m_cmbDisableX->setCurrentIndex (indexDisableX);
314 m_editCountX->setText(QString::number(m_modelGridRemovalAfter->
countX()));
315 m_editStartX->setText(QString::number(m_modelGridRemovalAfter->
startX()));
316 m_editStepX->setText(QString::number(m_modelGridRemovalAfter->
stepX()));
317 m_editStopX->setText(QString::number(m_modelGridRemovalAfter->
stopX()));
319 int indexDisableY = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->
gridCoordDisableY()));
320 m_cmbDisableY->setCurrentIndex (indexDisableY);
322 m_editCountY->setText(QString::number(m_modelGridRemovalAfter->
countY()));
323 m_editStartY->setText(QString::number(m_modelGridRemovalAfter->
startY()));
324 m_editStepY->setText(QString::number(m_modelGridRemovalAfter->
stepY()));
325 m_editStopY->setText(QString::number(m_modelGridRemovalAfter->
stopY()));
327 m_scenePreview->clear();
335 void DlgSettingsGridRemoval::slotCloseDistance(
const QString &)
337 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCloseDistance";
339 m_modelGridRemovalAfter->
setCloseDistance(m_editCloseDistance->text().toDouble());
344 void DlgSettingsGridRemoval::slotCountX(
const QString &count)
346 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCountX";
348 m_modelGridRemovalAfter->
setCountX(count.toInt());
353 void DlgSettingsGridRemoval::slotCountY(
const QString &count)
355 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCountY";
357 m_modelGridRemovalAfter->
setCountY(count.toInt());
362 void DlgSettingsGridRemoval::slotDisableX(
const QString &)
364 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotDisableX";
366 GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
372 void DlgSettingsGridRemoval::slotDisableY(
const QString &)
374 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotDisableY";
376 GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
382 void DlgSettingsGridRemoval::slotRemoveGridLines (
int state)
384 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotRemoveGridLines";
391 void DlgSettingsGridRemoval::slotStartX(
const QString &startX)
393 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStartX";
395 m_modelGridRemovalAfter->
setStartX(startX.toDouble());
400 void DlgSettingsGridRemoval::slotStartY(
const QString &startY)
402 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStartY";
404 m_modelGridRemovalAfter->
setStartY(startY.toDouble());
409 void DlgSettingsGridRemoval::slotStepX(
const QString &stepX)
411 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStepX";
413 m_modelGridRemovalAfter->
setStepX(stepX.toDouble());
418 void DlgSettingsGridRemoval::slotStepY(
const QString &stepY)
420 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStepY";
422 m_modelGridRemovalAfter->
setStepY(stepY.toDouble());
427 void DlgSettingsGridRemoval::slotStopX(
const QString &stopX)
429 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStopX";
431 m_modelGridRemovalAfter->
setStopX(stopX.toDouble());
436 void DlgSettingsGridRemoval::slotStopY(
const QString &stopY)
438 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStopY";
440 m_modelGridRemovalAfter->
setStopY(stopY.toDouble());
445 void DlgSettingsGridRemoval::updateControls ()
447 m_editCloseDistance->setEnabled (m_chkRemoveGridLines->isChecked ());
449 m_cmbDisableX->setEnabled (m_chkRemoveGridLines->isChecked ());
451 GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
452 m_editCountX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_COUNT));
453 m_editStartX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_START));
454 m_editStepX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STEP));
455 m_editStopX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STOP));
457 m_cmbDisableY->setEnabled (m_chkRemoveGridLines->isChecked ());
459 GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
460 m_editCountY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_COUNT));
461 m_editStartY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_START));
462 m_editStepY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STEP));
463 m_editStopY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STOP));
465 QString textCloseDistance = m_editCloseDistance->text();
466 QString textCountX = m_editCountX->text();
467 QString textStartX = m_editStartX->text();
468 QString textStepX = m_editStepX->text();
469 QString textStopX = m_editStopX->text();
470 QString textCountY = m_editCountY->text();
471 QString textStartY = m_editStartY->text();
472 QString textStepY = m_editStepY->text();
473 QString textStopY = m_editStopY->text();
476 bool isOk = (m_validatorCloseDistance->validate (textCloseDistance, pos) == QValidator::Acceptable) &&
477 (m_validatorCountX->validate (textCountX, pos) == QValidator::Acceptable) &&
478 (m_validatorStartX->validate (textStartX, pos) == QValidator::Acceptable) &&
479 (m_validatorStepX->validate (textStepX, pos) == QValidator::Acceptable) &&
480 (m_validatorStopX->validate (textStopX, pos) == QValidator::Acceptable) &&
481 (m_validatorCountY->validate (textCountY, pos) == QValidator::Acceptable) &&
482 (m_validatorStartY->validate (textStartY, pos) == QValidator::Acceptable) &&
483 (m_validatorStepY->validate (textStepY, pos) == QValidator::Acceptable) &&
484 (m_validatorStopY->validate (textStopY, pos) == QValidator::Acceptable);
488 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.