1 #include "DigitizeStateAbstractBase.h"
2 #include "DlgEditPoint.h"
3 #include "DlgValidatorAbstract.h"
4 #include "DlgValidatorFactory.h"
5 #include "DocumentModelCoords.h"
6 #include "EngaugeAssert.h"
7 #include "FormatCoordsUnits.h"
8 #include "FormatDateTime.h"
9 #include "FormatDegreesMinutesSecondsNonPolarTheta.h"
10 #include "FormatDegreesMinutesSecondsPolarTheta.h"
12 #include "MainWindow.h"
13 #include "MainWindowModel.h"
14 #include <QDoubleValidator>
15 #include <QGridLayout>
17 #include <QHBoxLayout>
20 #include <QVBoxLayout>
21 #include "Transformation.h"
23 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
25 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
27 const bool IS_X_THETA =
true;
28 const bool IS_NOT_X_THETA =
false;
34 const QCursor &cursorShape,
36 const double *xInitialValue,
37 const double *yInitialValue) :
38 QDialog (&mainWindow),
39 m_cursorShape (cursorShape),
40 m_modelCoords (modelCoords),
41 m_modelMainWindow (modelMainWindow)
43 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::DlgEditPoint";
49 connect (
this, SIGNAL (
signalSetOverrideCursor (QCursor)), &mainWindow, SLOT (slotSetOverrideCursor (QCursor)));
51 QVBoxLayout *layout =
new QVBoxLayout;
54 setCursor (QCursor (Qt::ArrowCursor));
56 setWindowTitle (tr (
"Edit Axis Point"));
58 createCoords (layout);
59 createOkCancel (layout);
61 initializeGraphCoordinates (xInitialValue,
68 DlgEditPoint::~DlgEditPoint()
70 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::~DlgEditPoint";
75 void DlgEditPoint::createCoords (QVBoxLayout *layoutOuter)
87 m_modelMainWindow.
locale());
94 m_modelMainWindow.
locale());
97 QString description = QString (
"Graph Coordinates (%1, %2)%3%4%5%6%7%8 as (%9, %10):")
100 .arg (isConstraintX || isConstraintY ?
" with " :
"")
101 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
102 .arg (isConstraintX ?
" > 0" :
"")
103 .arg (isConstraintX && isConstraintY ?
" and " :
"")
104 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
105 .arg ( isConstraintY ?
" > 0" :
"")
106 .arg (unitsType (IS_X_THETA))
107 .arg (unitsType (IS_NOT_X_THETA));
108 QGroupBox *panel =
new QGroupBox (description,
this);
109 layoutOuter->addWidget (panel);
111 QHBoxLayout *layout =
new QHBoxLayout (panel);
112 panel->setLayout (layout);
115 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
116 layout->addWidget(labelGraphParLeft, 0);
118 m_editGraphX =
new QLineEdit;
119 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
120 m_editGraphX->setAlignment (ALIGNMENT);
121 m_editGraphX->setValidator (m_validatorGraphX);
123 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n"
124 "For cartesian plots this is X. For polar plots this is the radius R."));
125 layout->addWidget(m_editGraphX, 0);
126 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
128 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
129 layout->addWidget(labelGraphComma, 0);
131 m_editGraphY =
new QLineEdit;
132 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
133 m_editGraphY->setAlignment (ALIGNMENT);
134 m_editGraphY->setValidator (m_validatorGraphY);
136 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n"
137 "For cartesian plots this is Y. For plot plots this is the angle Theta."));
138 layout->addWidget(m_editGraphY, 0);
139 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
141 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
142 layout->addWidget(labelGraphParRight, 0);
145 void DlgEditPoint::createOkCancel (QVBoxLayout *layoutOuter)
147 QWidget *panel =
new QWidget (
this);
148 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
150 QHBoxLayout *layout =
new QHBoxLayout (panel);
151 panel->setLayout (layout);
153 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
154 layout->addWidget(m_btnOk);
155 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
157 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
158 layout->addWidget(m_btnCancel);
159 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
162 void DlgEditPoint::initializeGraphCoordinates (
const double *xInitialValue,
163 const double *yInitialValue,
166 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::initializeGraphCoordinates";
168 QString xTheta, yRadius;
169 if ((xInitialValue != 0) &&
170 (yInitialValue != 0)) {
182 m_editGraphX->setText (xTheta);
183 m_editGraphY->setText (yRadius);
186 bool DlgEditPoint::isCartesian ()
const
188 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
191 QChar DlgEditPoint::nameXTheta ()
const
193 return (isCartesian () ? QChar (
'X') : THETA);
196 QChar DlgEditPoint::nameYRadius ()
const
198 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
203 double xTheta, yRadius;
208 m_editGraphY->text(),
214 return QPointF (xTheta,
218 void DlgEditPoint::slotTextChanged (
const QString &)
223 QString DlgEditPoint::unitsType (
bool isXTheta)
const
225 if (isCartesian ()) {
227 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
229 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
233 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
235 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
240 void DlgEditPoint::updateControls ()
243 QString textX = m_editGraphX->text();
244 QString textY = m_editGraphY->text();
246 m_btnOk->setEnabled (!textX.isEmpty () &&
248 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
249 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
DlgEditPoint(MainWindow &mainWindow, DigitizeStateAbstractBase &digitizeState, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const QCursor &cursorShape, const Transformation &transformation, const double *xInitialValue=0, const double *yInitialValue=0)
Constructor for existing point which already has graph coordinates (which may be changed using this d...
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.
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.
QPointF posGraph() const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
CoordUnitsNonPolarTheta coordUnitsY() const
Get method for x units.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsMainWindow and CmdSettingsMainWindow.
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.