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";
49 void DlgSettingsGridRemoval::createPreview (QGridLayout *layout,
int &row)
51 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createPreview";
53 QLabel *labelPreview =
new QLabel (
"Preview");
54 layout->addWidget (labelPreview, row++, 0, 1, 5);
56 m_scenePreview =
new QGraphicsScene (
this);
58 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
60 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect grid removal"));
61 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
62 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
64 layout->addWidget (m_viewPreview, row++, 0, 1, 5);
67 void DlgSettingsGridRemoval::createRemoveGridLines (QGridLayout *layout,
int &row)
69 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLines";
71 m_chkRemoveGridLines =
new QCheckBox (
"Remove pixels close to defined grid lines");
72 m_chkRemoveGridLines->setWhatsThis (
"Check this box to have pixels close to regularly spaced gridlines removed.\n\n"
73 "This option is only available when the axis points have all been defined.");
74 connect (m_chkRemoveGridLines, SIGNAL (stateChanged (
int)),
this, SLOT (slotRemoveGridLines (
int)));
75 layout->addWidget (m_chkRemoveGridLines, row++, 1, 1, 3);
77 QLabel *labelCloseDistance =
new QLabel (
"Close distance (pixels):");
78 layout->addWidget (labelCloseDistance, row, 2);
80 m_editCloseDistance =
new QLineEdit;
81 m_editCloseDistance->setWhatsThis (
"Set closeness distance in pixels.\n\n"
82 "Pixels that are closer to the regularly spaced gridlines, than this distance, "
83 "will be removed.\n\n"
84 "This value cannot be negative. A zero value disables this feature. Decimal values are allowed");
85 m_validatorCloseDistance =
new QDoubleValidator (CLOSE_DISTANCE_MIN, CLOSE_DISTANCE_MAX, CLOSE_DECIMALS);
86 m_editCloseDistance->setValidator (m_validatorCloseDistance);
87 connect (m_editCloseDistance, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCloseDistance (
const QString &)));
88 layout->addWidget (m_editCloseDistance, row++, 3);
90 createRemoveGridLinesX (layout, row);
91 createRemoveGridLinesY (layout, row);
94 void DlgSettingsGridRemoval::createRemoveGridLinesX (QGridLayout *layout,
int &row)
96 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLinesX";
98 QString titleX =
"X Grid Lines";
100 titleX = QString (QChar (0x98, 0x03)) + QString (
" Grid Lines");
102 QGroupBox *groupX =
new QGroupBox (titleX);
103 layout->addWidget (groupX, row, 2);
105 QGridLayout *layoutGroup =
new QGridLayout;
106 groupX->setLayout (layoutGroup);
108 QLabel *labelDisable =
new QLabel (
"Disable:");
109 layoutGroup->addWidget (labelDisable, 0, 0);
111 m_cmbDisableX =
new QComboBox;
112 m_cmbDisableX->setWhatsThis (
"Disabled value.\n\n"
113 "The X grid lines are specified using only three values at a time. For flexibility, four values "
114 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
115 "updated as the other values change");
116 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
117 QVariant (GRID_COORD_DISABLE_COUNT));
118 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
119 QVariant (GRID_COORD_DISABLE_START));
120 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
121 QVariant (GRID_COORD_DISABLE_STEP));
122 m_cmbDisableX->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
123 QVariant (GRID_COORD_DISABLE_STOP));
124 connect (m_cmbDisableX, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableX (
const QString &)));
125 layoutGroup->addWidget (m_cmbDisableX, 0, 1);
127 QLabel *labelCount =
new QLabel (
"Count:");
128 layoutGroup->addWidget (labelCount, 1, 0);
130 m_editCountX =
new QLineEdit;
131 m_editCountX->setWhatsThis (
"Number of X grid lines.\n\n"
132 "The number of X grid lines must be entered as an integer greater than zero");
133 m_validatorCountX =
new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
134 m_editCountX->setValidator (m_validatorCountX);
135 connect (m_editCountX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountX (
const QString &)));
136 layoutGroup->addWidget (m_editCountX, 1, 1);
138 QLabel *labelStart =
new QLabel (
"Start:");
139 layoutGroup->addWidget (labelStart, 2, 0);
141 m_editStartX =
new QLineEdit;
142 m_editStartX->setWhatsThis (
"Value of the first X grid line.\n\n"
143 "The start value cannot be greater than the stop value");
144 m_validatorStartX =
new QDoubleValidator;
145 m_editStartX->setValidator (m_validatorStartX);
146 connect (m_editStartX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartX (
const QString &)));
147 layoutGroup->addWidget (m_editStartX, 2, 1);
149 QLabel *labelStep =
new QLabel (
"Step:");
150 layoutGroup->addWidget (labelStep, 3, 0);
152 m_editStepX =
new QLineEdit;
153 m_editStepX->setWhatsThis (
"Difference in value between two successive X grid lines.\n\n"
154 "The step value must be greater than zero");
155 m_validatorStepX =
new QDoubleValidator;
156 m_editStepX->setValidator (m_validatorStepX);
157 connect (m_editStepX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepX (
const QString &)));
158 layoutGroup->addWidget (m_editStepX, 3, 1);
160 QLabel *labelStop =
new QLabel (
"Stop:");
161 layoutGroup->addWidget (labelStop, 4, 0);
163 m_editStopX =
new QLineEdit;
164 m_editStopX->setWhatsThis (
"Value of the last X grid line.\n\n"
165 "The stop value cannot be less than the start value");
166 m_validatorStopX =
new QDoubleValidator;
167 m_editStopX->setValidator (m_validatorStopX);
168 connect (m_editStopX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopX (
const QString &)));
169 layoutGroup->addWidget (m_editStopX, 4, 1);
172 void DlgSettingsGridRemoval::createRemoveGridLinesY (QGridLayout *layout,
int &row)
174 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createRemoveGridLinesY";
176 QString titleY =
"Y Grid Lines";
178 titleY = QString (
"R Grid Lines");
180 QGroupBox *groupY =
new QGroupBox (titleY);
181 layout->addWidget (groupY, row++, 3);
183 QGridLayout *layoutGroup =
new QGridLayout;
184 groupY->setLayout (layoutGroup);
186 QLabel *labelDisable =
new QLabel (
"Disable:");
187 layoutGroup->addWidget (labelDisable, 0, 0);
189 m_cmbDisableY =
new QComboBox;
190 m_cmbDisableY->setWhatsThis (
"Disabled value.\n\n"
191 "The Y grid lines are specified using only three values at a time. For flexibility, four values "
192 "are offered so you must chose which value is disabled. Once disabled, that value is simply "
193 "updated as the other values change");
194 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_COUNT),
195 QVariant (GRID_COORD_DISABLE_COUNT));
196 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_START),
197 QVariant (GRID_COORD_DISABLE_START));
198 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STEP),
199 QVariant (GRID_COORD_DISABLE_STEP));
200 m_cmbDisableY->addItem(gridCoordDisableToString (GRID_COORD_DISABLE_STOP),
201 QVariant (GRID_COORD_DISABLE_STOP));
202 connect (m_cmbDisableY, SIGNAL (activated (
const QString &)),
this, SLOT (slotDisableY (
const QString &)));
203 layoutGroup->addWidget (m_cmbDisableY, 0, 1);
205 QLabel *labelCount =
new QLabel (
"Count:");
206 layoutGroup->addWidget (labelCount, 1, 0);
208 m_editCountY =
new QLineEdit;
209 m_editCountY->setWhatsThis (
"Number of Y grid lines.\n\n"
210 "The number of Y grid lines must be entered as an integer greater than zero");
211 m_validatorCountY =
new QDoubleValidator (COUNT_MIN, COUNT_MAX, COUNT_DECIMALS);
212 m_editCountY->setValidator (m_validatorCountY);
213 connect (m_editCountY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotCountY (
const QString &)));
214 layoutGroup->addWidget (m_editCountY, 1, 1);
216 QLabel *labelStart =
new QLabel (
"Start:");
217 layoutGroup->addWidget (labelStart, 2, 0);
219 m_editStartY =
new QLineEdit;
220 m_editStartY->setWhatsThis (
"Value of the first Y grid line.\n\n"
221 "The start value cannot be greater than the stop value");
222 m_validatorStartY =
new QDoubleValidator;
223 m_editStartY->setValidator (m_validatorStartY);
224 connect (m_editStartY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStartY (
const QString &)));
225 layoutGroup->addWidget (m_editStartY, 2, 1);
227 QLabel *labelStep =
new QLabel (
"Step:");
228 layoutGroup->addWidget (labelStep, 3, 0);
230 m_editStepY =
new QLineEdit;
231 m_editStepY->setWhatsThis (
"Difference in value between two successive Y grid lines.\n\n"
232 "The step value must be greater than zero");
233 m_validatorStepY =
new QDoubleValidator;
234 m_editStepY->setValidator (m_validatorStepY);
235 connect (m_editStepY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStepY (
const QString &)));
236 layoutGroup->addWidget (m_editStepY, 3, 1);
238 QLabel *labelStop =
new QLabel (
"Stop:");
239 layoutGroup->addWidget (labelStop, 4, 0);
241 m_editStopY =
new QLineEdit;
242 m_editStopY->setWhatsThis (
"Value of the last Y grid line.\n\n"
243 "The stop value cannot be less than the start value");
244 m_validatorStopY =
new QDoubleValidator;
245 m_editStopY->setValidator (m_validatorStopY);
246 connect (m_editStopY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotStopY (
const QString &)));
247 layoutGroup->addWidget (m_editStopY, 4, 1);
252 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::createSubPanel";
254 const int COLUMN_CHECKBOX_WIDTH = 60;
256 QWidget *subPanel =
new QWidget ();
257 QGridLayout *layout =
new QGridLayout (subPanel);
258 subPanel->setLayout (layout);
260 layout->setColumnStretch(0, 1);
261 layout->setColumnStretch(1, 0);
262 layout->setColumnMinimumWidth(1, COLUMN_CHECKBOX_WIDTH);
263 layout->setColumnStretch(2, 0);
264 layout->setColumnStretch(3, 0);
265 layout->setColumnStretch(4, 1);
268 createRemoveGridLines (layout, row);
269 createPreview (layout, row);
276 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::handleOk";
283 *m_modelGridRemovalBefore,
284 *m_modelGridRemovalAfter);
292 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::load";
297 if (m_modelGridRemovalBefore != 0) {
298 delete m_modelGridRemovalBefore;
300 if (m_modelGridRemovalAfter != 0) {
301 delete m_modelGridRemovalAfter;
309 ENGAUGE_ASSERT (CLOSE_DISTANCE_MIN <= m_modelGridRemovalAfter->closeDistance());
310 ENGAUGE_ASSERT (CLOSE_DISTANCE_MAX >= m_modelGridRemovalAfter->
closeDistance());
315 m_editCloseDistance->setText (QString::number (m_modelGridRemovalAfter->
closeDistance()));
317 int indexDisableX = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->
gridCoordDisableX()));
318 m_cmbDisableX->setCurrentIndex (indexDisableX);
320 m_editCountX->setText(QString::number(m_modelGridRemovalAfter->
countX()));
321 m_editStartX->setText(QString::number(m_modelGridRemovalAfter->
startX()));
322 m_editStepX->setText(QString::number(m_modelGridRemovalAfter->
stepX()));
323 m_editStopX->setText(QString::number(m_modelGridRemovalAfter->
stopX()));
325 int indexDisableY = m_cmbDisableX->findData (QVariant (m_modelGridRemovalAfter->
gridCoordDisableY()));
326 m_cmbDisableY->setCurrentIndex (indexDisableY);
328 m_editCountY->setText(QString::number(m_modelGridRemovalAfter->
countY()));
329 m_editStartY->setText(QString::number(m_modelGridRemovalAfter->
startY()));
330 m_editStepY->setText(QString::number(m_modelGridRemovalAfter->
stepY()));
331 m_editStopY->setText(QString::number(m_modelGridRemovalAfter->
stopY()));
333 m_scenePreview->clear();
341 void DlgSettingsGridRemoval::slotCloseDistance(
const QString &)
343 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCloseDistance";
345 m_modelGridRemovalAfter->
setCloseDistance(m_editCloseDistance->text().toDouble());
350 void DlgSettingsGridRemoval::slotCountX(
const QString &count)
352 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCountX";
354 m_modelGridRemovalAfter->
setCountX(count.toInt());
359 void DlgSettingsGridRemoval::slotCountY(
const QString &count)
361 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotCountY";
363 m_modelGridRemovalAfter->
setCountY(count.toInt());
368 void DlgSettingsGridRemoval::slotDisableX(
const QString &)
370 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotDisableX";
372 GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
378 void DlgSettingsGridRemoval::slotDisableY(
const QString &)
380 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotDisableY";
382 GridCoordDisable gridCoordDisable = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
388 void DlgSettingsGridRemoval::slotRemoveGridLines (
int state)
390 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotRemoveGridLines";
397 void DlgSettingsGridRemoval::slotStartX(
const QString &startX)
399 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStartX";
401 m_modelGridRemovalAfter->
setStartX(startX.toDouble());
406 void DlgSettingsGridRemoval::slotStartY(
const QString &startY)
408 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStartY";
410 m_modelGridRemovalAfter->
setStartY(startY.toDouble());
415 void DlgSettingsGridRemoval::slotStepX(
const QString &stepX)
417 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStepX";
419 m_modelGridRemovalAfter->
setStepX(stepX.toDouble());
424 void DlgSettingsGridRemoval::slotStepY(
const QString &stepY)
426 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStepY";
428 m_modelGridRemovalAfter->
setStepY(stepY.toDouble());
433 void DlgSettingsGridRemoval::slotStopX(
const QString &stopX)
435 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStopX";
437 m_modelGridRemovalAfter->
setStopX(stopX.toDouble());
442 void DlgSettingsGridRemoval::slotStopY(
const QString &stopY)
444 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsGridRemoval::slotStopY";
446 m_modelGridRemovalAfter->
setStopY(stopY.toDouble());
451 void DlgSettingsGridRemoval::updateControls ()
453 m_editCloseDistance->setEnabled (m_chkRemoveGridLines->isChecked ());
455 m_cmbDisableX->setEnabled (m_chkRemoveGridLines->isChecked ());
457 GridCoordDisable disableX = (GridCoordDisable) m_cmbDisableX->currentData().toInt();
458 m_editCountX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_COUNT));
459 m_editStartX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_START));
460 m_editStepX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STEP));
461 m_editStopX->setEnabled (m_chkRemoveGridLines->isChecked () && (disableX != GRID_COORD_DISABLE_STOP));
463 m_cmbDisableY->setEnabled (m_chkRemoveGridLines->isChecked ());
465 GridCoordDisable disableY = (GridCoordDisable) m_cmbDisableY->currentData().toInt();
466 m_editCountY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_COUNT));
467 m_editStartY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_START));
468 m_editStepY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STEP));
469 m_editStopY->setEnabled (m_chkRemoveGridLines->isChecked () && (disableY != GRID_COORD_DISABLE_STOP));
471 QString textCloseDistance = m_editCloseDistance->text();
472 QString textCountX = m_editCountX->text();
473 QString textStartX = m_editStartX->text();
474 QString textStepX = m_editStepX->text();
475 QString textStopX = m_editStopX->text();
476 QString textCountY = m_editCountY->text();
477 QString textStartY = m_editStartY->text();
478 QString textStepY = m_editStepY->text();
479 QString textStopY = m_editStopY->text();
482 bool isOk = (m_validatorCloseDistance->validate (textCloseDistance, pos) == QValidator::Acceptable) &&
483 (m_validatorCountX->validate (textCountX, pos) == QValidator::Acceptable) &&
484 (m_validatorStartX->validate (textStartX, pos) == QValidator::Acceptable) &&
485 (m_validatorStepX->validate (textStepX, pos) == QValidator::Acceptable) &&
486 (m_validatorStopX->validate (textStopX, pos) == QValidator::Acceptable) &&
487 (m_validatorCountY->validate (textCountY, pos) == QValidator::Acceptable) &&
488 (m_validatorStartY->validate (textStartY, pos) == QValidator::Acceptable) &&
489 (m_validatorStepY->validate (textStepY, pos) == QValidator::Acceptable) &&
490 (m_validatorStopY->validate (textStopY, pos) == QValidator::Acceptable);
494 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.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
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.