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 <QDoubleValidator>
14 #include <QGridLayout>
16 #include <QHBoxLayout>
19 #include <QVBoxLayout>
20 #include "Transformation.h"
22 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
24 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
26 const bool IS_X_THETA =
true;
27 const bool IS_NOT_X_THETA =
false;
32 const QCursor &cursorShape,
34 const double *xInitialValue,
35 const double *yInitialValue) :
36 QDialog (&mainWindow),
37 m_cursorShape (cursorShape),
38 m_modelCoords (modelCoords)
40 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::DlgEditPoint";
46 connect (
this, SIGNAL (
signalSetOverrideCursor (QCursor)), &mainWindow, SLOT (slotSetOverrideCursor (QCursor)));
48 QVBoxLayout *layout =
new QVBoxLayout;
51 setCursor (QCursor (Qt::ArrowCursor));
53 setWindowTitle (tr (
"Edit Axis Point"));
55 createCoords (layout);
56 createOkCancel (layout);
58 initializeGraphCoordinates (xInitialValue,
65 DlgEditPoint::~DlgEditPoint()
67 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::~DlgEditPoint";
72 void DlgEditPoint::createCoords (QVBoxLayout *layoutOuter)
92 QString description = QString (
"Graph Coordinates (%1, %2)%3%4%5%6%7%8 as (%9, %10):")
95 .arg (isConstraintX || isConstraintY ?
" with " :
"")
96 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
97 .arg (isConstraintX ?
" > 0" :
"")
98 .arg (isConstraintX && isConstraintY ?
" and " :
"")
99 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
100 .arg ( isConstraintY ?
" > 0" :
"")
101 .arg (unitsType (IS_X_THETA))
102 .arg (unitsType (IS_NOT_X_THETA));
103 QGroupBox *panel =
new QGroupBox (description,
this);
104 layoutOuter->addWidget (panel);
106 QHBoxLayout *layout =
new QHBoxLayout (panel);
107 panel->setLayout (layout);
110 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
111 layout->addWidget(labelGraphParLeft, 0);
113 m_editGraphX =
new QLineEdit;
114 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
115 m_editGraphX->setAlignment (ALIGNMENT);
116 m_editGraphX->setValidator (m_validatorGraphX);
118 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n"
119 "For cartesian plots this is X. For polar plots this is the radius R."));
120 layout->addWidget(m_editGraphX, 0);
121 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
123 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
124 layout->addWidget(labelGraphComma, 0);
126 m_editGraphY =
new QLineEdit;
127 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
128 m_editGraphY->setAlignment (ALIGNMENT);
129 m_editGraphY->setValidator (m_validatorGraphY);
131 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n"
132 "For cartesian plots this is Y. For plot plots this is the angle Theta."));
133 layout->addWidget(m_editGraphY, 0);
134 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
136 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
137 layout->addWidget(labelGraphParRight, 0);
140 void DlgEditPoint::createOkCancel (QVBoxLayout *layoutOuter)
142 QWidget *panel =
new QWidget (
this);
143 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
145 QHBoxLayout *layout =
new QHBoxLayout (panel);
146 panel->setLayout (layout);
148 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
149 layout->addWidget(m_btnOk);
150 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
152 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
153 layout->addWidget(m_btnCancel);
154 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
157 void DlgEditPoint::initializeGraphCoordinates (
const double *xInitialValue,
158 const double *yInitialValue,
161 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPoint::initializeGraphCoordinates";
163 QString xTheta, yRadius;
164 if ((xInitialValue != 0) &&
165 (yInitialValue != 0)) {
176 m_editGraphX->setText (xTheta);
177 m_editGraphY->setText (yRadius);
180 bool DlgEditPoint::isCartesian ()
const
182 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
185 QChar DlgEditPoint::nameXTheta ()
const
187 return (isCartesian () ? QChar (
'X') : THETA);
190 QChar DlgEditPoint::nameYRadius ()
const
192 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
197 double xTheta, yRadius;
202 m_editGraphY->text(),
207 return QPointF (xTheta,
211 void DlgEditPoint::slotTextChanged (
const QString &)
216 QString DlgEditPoint::unitsType (
bool isXTheta)
const
218 if (isCartesian ()) {
220 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
222 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
226 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
228 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
233 void DlgEditPoint::updateControls ()
236 QString textX = m_editGraphX->text();
237 QString textY = m_editGraphY->text();
239 m_btnOk->setEnabled (!textX.isEmpty () &&
241 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
242 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
DlgEditPoint(MainWindow &mainWindow, DigitizeStateAbstractBase &digitizeState, const DocumentModelCoords &modelCoords, 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...
DlgValidatorAbstract * createCartesianOrPolarWithPolarPolar(CoordScale coordScale, bool isCartesian, CoordUnitsNonPolarTheta coordUnitsCartesian, CoordUnitsPolarTheta coordUnitsPolar, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime) const
Factory method for generating validators for either cartesian or polar case, when polar format is spe...
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.
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.
CoordsType coordsType() const
Get method for coordinates type.
DlgValidatorAbstract * createCartesianOrPolarWithNonPolarPolar(CoordScale coordScale, bool isCartesian, CoordUnitsNonPolarTheta coordUnitsCartesian, CoordUnitsNonPolarTheta coordUnitsPolar, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime) const
Factory method for generating validators for either cartesian or polar case, when polar format is spe...
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordUnitsDate coordUnitsDate() const
Get method for date format when used.
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.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.