7 #include "DigitizeStateAbstractBase.h"
8 #include "DlgEditPoint.h"
9 #include "DlgValidatorAbstract.h"
10 #include "DlgValidatorFactory.h"
11 #include "DocumentAxesPointsRequired.h"
12 #include "DocumentModelCoords.h"
13 #include "EngaugeAssert.h"
14 #include "FormatCoordsUnits.h"
15 #include "FormatDateTime.h"
16 #include "FormatDegreesMinutesSecondsNonPolarTheta.h"
17 #include "FormatDegreesMinutesSecondsPolarTheta.h"
19 #include "MainWindow.h"
20 #include "MainWindowModel.h"
21 #include <QDoubleValidator>
22 #include <QGridLayout>
24 #include <QHBoxLayout>
27 #include "QtToString.h"
28 #include <QVBoxLayout>
29 #include "Transformation.h"
31 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
33 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
35 const bool IS_X_THETA =
true;
36 const bool IS_NOT_X_THETA =
false;
42 const QCursor &cursorShape,
44 DocumentAxesPointsRequired documentAxesPointsRequired,
46 const double *xInitialValue,
47 const double *yInitialValue) :
48 QDialog (&mainWindow),
49 m_cursorShape (cursorShape),
50 m_documentAxesPointsRequired (documentAxesPointsRequired),
51 m_modelCoords (modelCoords),
52 m_modelMainWindow (modelMainWindow)
54 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::DlgEditPoint";
57 bool isX = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || isXOnly;
58 bool isY = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || !isXOnly;
64 connect (
this, SIGNAL (
signalSetOverrideCursor (QCursor)), &mainWindow, SLOT (slotSetOverrideCursor (QCursor)));
66 QVBoxLayout *layout =
new QVBoxLayout;
69 setCursor (QCursor (Qt::ArrowCursor));
71 setWindowTitle (tr (
"Edit Axis Point"));
73 createCoords (layout);
75 createOkCancel (layout);
77 initializeGraphCoordinates (xInitialValue,
86 DlgEditPoint::~DlgEditPoint()
88 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::~DlgEditPoint";
93 void DlgEditPoint::createCoords (QVBoxLayout *layoutOuter)
105 m_modelMainWindow.
locale());
112 m_modelMainWindow.
locale());
115 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10 (%11, %12):")
116 .arg (tr (
"Graph Coordinates"))
118 .arg (nameYRadius ())
119 .arg (isConstraintX || isConstraintY ?
" with " :
"")
120 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
121 .arg (isConstraintX ?
" > 0" :
"")
122 .arg (isConstraintX && isConstraintY ?
" and " :
"")
123 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
124 .arg ( isConstraintY ?
" > 0" :
"")
126 .arg (unitsType (IS_X_THETA))
127 .arg (unitsType (IS_NOT_X_THETA));
128 QGroupBox *panel =
new QGroupBox (description,
this);
129 layoutOuter->addWidget (panel);
131 QHBoxLayout *layout =
new QHBoxLayout (panel);
132 panel->setLayout (layout);
135 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
136 layout->addWidget(labelGraphParLeft, 0);
138 m_editGraphX =
new QLineEdit;
139 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
140 m_editGraphX->setAlignment (ALIGNMENT);
141 m_editGraphX->setValidator (m_validatorGraphX);
143 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n"
144 "For cartesian plots this is X. For polar plots this is the radius R.\n\n"
145 "The expected format of the coordinate value is determined by the locale setting. If "
146 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
147 layout->addWidget(m_editGraphX, 0);
148 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
150 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
151 layout->addWidget(labelGraphComma, 0);
153 m_editGraphY =
new QLineEdit;
154 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
155 m_editGraphY->setAlignment (ALIGNMENT);
156 m_editGraphY->setValidator (m_validatorGraphY);
158 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n"
159 "For cartesian plots this is Y. For plot plots this is the angle Theta.\n\n"
160 "The expected format of the coordinate value is determined by the locale setting. If "
161 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
162 layout->addWidget(m_editGraphY, 0);
163 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
165 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
166 layout->addWidget(labelGraphParRight, 0);
169 void DlgEditPoint::createHint (QVBoxLayout *layoutOuter)
174 QWidget *widget =
new QWidget;
175 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
177 QHBoxLayout *layout =
new QHBoxLayout;
178 widget->setLayout (layout);
180 QString locale = QLocaleToString (m_modelMainWindow.
locale ());
181 QString hint = QString (
"%1: %2")
182 .arg (tr (
"Number format"))
184 QLabel *label =
new QLabel (hint);
185 layout->addWidget (label);
188 void DlgEditPoint::createOkCancel (QVBoxLayout *layoutOuter)
190 QWidget *panel =
new QWidget (
this);
191 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
193 QHBoxLayout *layout =
new QHBoxLayout (panel);
194 panel->setLayout (layout);
196 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
197 layout->addWidget(m_btnOk);
198 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
200 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
201 layout->addWidget(m_btnCancel);
202 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
205 void DlgEditPoint::initializeGraphCoordinates (
const double *xInitialValue,
206 const double *yInitialValue,
211 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::initializeGraphCoordinates";
213 QString xTheta, yRadius;
214 if ((xInitialValue != 0) &&
215 (yInitialValue != 0)) {
228 m_editGraphX->setText (xTheta);
230 m_editGraphX->setText (
"");
234 m_editGraphY->setText (yRadius);
236 m_editGraphY->setText (
"");
240 bool DlgEditPoint::isCartesian ()
const
242 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
245 QChar DlgEditPoint::nameXTheta ()
const
247 return (isCartesian () ? QChar (
'X') : THETA);
250 QChar DlgEditPoint::nameYRadius ()
const
252 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
257 double xTheta, yRadius;
262 m_editGraphY->text(),
269 isXOnly = m_editGraphY->text().isEmpty();
271 return QPointF (xTheta,
275 void DlgEditPoint::slotTextChanged (
const QString &)
280 QString DlgEditPoint::unitsType (
bool isXTheta)
const
282 if (isCartesian ()) {
284 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
286 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
290 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
292 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
297 void DlgEditPoint::updateControls ()
299 QString textX = m_editGraphX->text();
300 QString textY = m_editGraphY->text();
304 if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4) {
306 bool gotX = (!textX.isEmpty() &&
307 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable));
308 bool gotY = (!textY.isEmpty() &&
309 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
312 m_btnOk->setEnabled ((textX.isEmpty() && gotY) ||
313 (textY.isEmpty() && gotX));
318 m_btnOk->setEnabled (!textX.isEmpty () &&
320 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
321 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
virtual QValidator::State validate(QString &input, int &pos) const =0
Validate according to the numeric format specific to the leaf class.
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
CoordUnitsTime coordUnitsTime() const
Get method for time format when used.
DlgValidatorAbstract * createCartesianOrPolarWithPolarPolar(CoordScale coordScale, bool isCartesian, CoordUnitsNonPolarTheta coordUnitsCartesian, CoordUnitsPolarTheta coordUnitsPolar, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, const QLocale &locale) const
Factory method for generating validators for either cartesian or polar case, when polar format is spe...
void signalSetOverrideCursor(QCursor)
Send a signal to trigger the setting of the override cursor.
DlgEditPoint(MainWindow &mainWindow, DigitizeStateAbstractBase &digitizeState, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const QCursor &cursorShape, const Transformation &transformation, DocumentAxesPointsRequired documentAxesPointsRequired, bool isXOnly=false, const double *xInitialValue=0, const double *yInitialValue=0)
Constructor for existing point which already has graph coordinates (which may be changed using this d...
CoordUnitsNonPolarTheta coordUnitsY() const
Get method for x units.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsMainWindow.
CoordsType coordsType() const
Get method for coordinates type.
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordUnitsDate coordUnitsDate() const
Get method for date format when used.
DlgValidatorAbstract * createCartesianOrPolarWithNonPolarPolar(CoordScale coordScale, bool isCartesian, CoordUnitsNonPolarTheta coordUnitsCartesian, CoordUnitsNonPolarTheta coordUnitsPolar, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, const QLocale &locale) const
Factory method for generating validators for either cartesian or polar case, when polar format is spe...
void removeOverrideCursor()
Remove the override cursor if it is in use. This is called after a leave event, and prior to displayi...
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
QLocale locale() const
Get method for locale.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.