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>
28#include "Transformation.h"
30const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
32const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
34const bool IS_X_THETA =
true;
35const bool IS_NOT_X_THETA =
false;
41 const QCursor &cursorShape,
43 DocumentAxesPointsRequired documentAxesPointsRequired,
45 const double *xInitialValue,
46 const double *yInitialValue) :
47 QDialog (&mainWindow),
48 m_cursorShape (cursorShape),
49 m_documentAxesPointsRequired (documentAxesPointsRequired),
50 m_modelCoords (modelCoords),
51 m_modelMainWindow (modelMainWindow)
53 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::DlgEditPoint";
56 bool isX = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || isXOnly;
57 bool isY = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || !isXOnly;
63 connect (
this, SIGNAL (
signalSetOverrideCursor (QCursor)), &mainWindow, SLOT (slotSetOverrideCursor (QCursor)));
65 QVBoxLayout *layout =
new QVBoxLayout;
68 setCursor (QCursor (Qt::ArrowCursor));
70 setWindowTitle (tr (
"Edit Axis Point"));
72 createCoords (layout);
73 createOkCancel (layout);
75 initializeGraphCoordinates (xInitialValue,
84DlgEditPoint::~DlgEditPoint()
86 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::~DlgEditPoint";
91void DlgEditPoint::createCoords (QVBoxLayout *layoutOuter)
103 m_modelMainWindow.
locale());
110 m_modelMainWindow.
locale());
113 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10 (%11, %12):")
114 .arg (tr (
"Graph Coordinates"))
116 .arg (nameYRadius ())
117 .arg (isConstraintX || isConstraintY ?
" with " :
"")
118 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
119 .arg (isConstraintX ?
" > 0" :
"")
120 .arg (isConstraintX && isConstraintY ?
" and " :
"")
121 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
122 .arg ( isConstraintY ?
" > 0" :
"")
124 .arg (unitsType (IS_X_THETA))
125 .arg (unitsType (IS_NOT_X_THETA));
126 QGroupBox *panel =
new QGroupBox (description,
this);
127 layoutOuter->addWidget (panel);
129 QHBoxLayout *layout =
new QHBoxLayout (panel);
130 panel->setLayout (layout);
133 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
134 layout->addWidget(labelGraphParLeft, 0);
136 m_editGraphX =
new QLineEdit;
137 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
138 m_editGraphX->setAlignment (ALIGNMENT);
139 m_editGraphX->setValidator (m_validatorGraphX);
141 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n"
142 "For cartesian plots this is X. For polar plots this is the radius R.\n\n"
143 "The expected format of the coordinate value is determined by the locale setting. If "
144 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
145 layout->addWidget(m_editGraphX, 0);
146 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
148 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
149 layout->addWidget(labelGraphComma, 0);
151 m_editGraphY =
new QLineEdit;
152 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
153 m_editGraphY->setAlignment (ALIGNMENT);
154 m_editGraphY->setValidator (m_validatorGraphY);
156 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n"
157 "For cartesian plots this is Y. For plot plots this is the angle Theta.\n\n"
158 "The expected format of the coordinate value is determined by the locale setting. If "
159 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
160 layout->addWidget(m_editGraphY, 0);
161 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
163 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
164 layout->addWidget(labelGraphParRight, 0);
167void DlgEditPoint::createOkCancel (QVBoxLayout *layoutOuter)
169 QWidget *panel =
new QWidget (
this);
170 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
172 QHBoxLayout *layout =
new QHBoxLayout (panel);
173 panel->setLayout (layout);
175 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
176 layout->addWidget(m_btnOk);
177 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
179 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
180 layout->addWidget(m_btnCancel);
181 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
184void DlgEditPoint::initializeGraphCoordinates (
const double *xInitialValue,
185 const double *yInitialValue,
190 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::initializeGraphCoordinates";
192 QString xTheta, yRadius;
193 if ((xInitialValue != 0) &&
194 (yInitialValue != 0)) {
207 m_editGraphX->setText (xTheta);
209 m_editGraphX->setText (
"");
213 m_editGraphY->setText (yRadius);
215 m_editGraphY->setText (
"");
219bool DlgEditPoint::isCartesian ()
const
221 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
224QChar DlgEditPoint::nameXTheta ()
const
226 return (isCartesian () ? QChar (
'X') : THETA);
229QChar DlgEditPoint::nameYRadius ()
const
231 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
236 double xTheta, yRadius;
241 m_editGraphY->text(),
248 isXOnly = m_editGraphY->text().isEmpty();
250 return QPointF (xTheta,
254void DlgEditPoint::slotTextChanged (
const QString &)
259QString DlgEditPoint::unitsType (
bool isXTheta)
const
261 if (isCartesian ()) {
263 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
265 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
269 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
271 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
276void DlgEditPoint::updateControls ()
278 QString textX = m_editGraphX->text();
279 QString textY = m_editGraphY->text();
283 if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4) {
285 bool gotX = (!textX.isEmpty() &&
286 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable));
287 bool gotY = (!textY.isEmpty() &&
288 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
291 m_btnOk->setEnabled ((textX.isEmpty() && gotY) ||
292 (textY.isEmpty() && gotX));
297 m_btnOk->setEnabled (!textX.isEmpty () &&
299 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
300 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
void removeOverrideCursor()
Remove the override cursor if it is in use. This is called after a leave event, and prior to displayi...
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted.
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...
virtual QValidator::State validate(QString &input, int &pos) const =0
Validate according to the numeric format specific to the leaf class.
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...
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...
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
CoordUnitsNonPolarTheta coordUnitsY() const
Get method for x units.
CoordUnitsTime coordUnitsTime() const
Get method for time format when used.
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
CoordsType coordsType() const
Get method for coordinates type.
CoordUnitsDate coordUnitsDate() const
Get method for date format when used.
Model for DlgSettingsMainWindow.
QLocale locale() const
Get method for locale.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...