7 #include "DlgEditPointAxis.h"
8 #include "DlgValidatorAbstract.h"
9 #include "DlgValidatorFactory.h"
10 #include "DocumentAxesPointsRequired.h"
11 #include "DocumentModelCoords.h"
12 #include "EngaugeAssert.h"
13 #include "FormatCoordsUnits.h"
14 #include "FormatDateTime.h"
15 #include "FormatDegreesMinutesSecondsNonPolarTheta.h"
16 #include "FormatDegreesMinutesSecondsPolarTheta.h"
18 #include "MainWindow.h"
19 #include "MainWindowModel.h"
20 #include <QDoubleValidator>
21 #include <QGridLayout>
23 #include <QHBoxLayout>
26 #include "QtToString.h"
27 #include <QVBoxLayout>
28 #include "Transformation.h"
30 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
32 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
34 const bool IS_X_THETA =
true;
35 const bool IS_NOT_X_THETA =
false;
41 DocumentAxesPointsRequired documentAxesPointsRequired,
43 const double *xInitialValue,
44 const double *yInitialValue) :
45 QDialog (&mainWindow),
46 m_documentAxesPointsRequired (documentAxesPointsRequired),
47 m_modelCoords (modelCoords),
48 m_modelMainWindow (modelMainWindow)
50 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::DlgEditPointAxis";
53 bool isX = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || isXOnly;
54 bool isY = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || !isXOnly;
56 QVBoxLayout *layout =
new QVBoxLayout;
59 setCursor (QCursor (Qt::ArrowCursor));
61 setWindowTitle (tr (
"Edit Axis Point"));
63 createCoords (layout);
65 createOkCancel (layout);
67 initializeGraphCoordinates (xInitialValue,
76 DlgEditPointAxis::~DlgEditPointAxis()
78 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::~DlgEditPointAxis";
81 void DlgEditPointAxis::createCoords (QVBoxLayout *layoutOuter)
93 m_modelMainWindow.
locale());
100 m_modelMainWindow.
locale());
103 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10 (%11, %12):")
104 .arg (tr (
"Graph Coordinates"))
106 .arg (nameYRadius ())
107 .arg (isConstraintX || isConstraintY ?
" with " :
"")
108 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
109 .arg (isConstraintX ?
" > 0" :
"")
110 .arg (isConstraintX && isConstraintY ?
" and " :
"")
111 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
112 .arg ( isConstraintY ?
" > 0" :
"")
114 .arg (unitsType (IS_X_THETA))
115 .arg (unitsType (IS_NOT_X_THETA));
116 QGroupBox *panel =
new QGroupBox (description,
this);
117 layoutOuter->addWidget (panel);
119 QHBoxLayout *layout =
new QHBoxLayout (panel);
120 panel->setLayout (layout);
123 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
124 layout->addWidget(labelGraphParLeft, 0);
126 m_editGraphX =
new QLineEdit;
127 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
128 m_editGraphX->setAlignment (ALIGNMENT);
129 m_editGraphX->setValidator (m_validatorGraphX);
131 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n"
132 "For cartesian plots this is X. For polar plots this is the radius R.\n\n"
133 "The expected format of the coordinate value is determined by the locale setting. If "
134 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
135 layout->addWidget(m_editGraphX, 0);
136 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
138 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
139 layout->addWidget(labelGraphComma, 0);
141 m_editGraphY =
new QLineEdit;
142 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
143 m_editGraphY->setAlignment (ALIGNMENT);
144 m_editGraphY->setValidator (m_validatorGraphY);
146 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n"
147 "For cartesian plots this is Y. For plot plots this is the angle Theta.\n\n"
148 "The expected format of the coordinate value is determined by the locale setting. If "
149 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
150 layout->addWidget(m_editGraphY, 0);
151 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
153 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
154 layout->addWidget(labelGraphParRight, 0);
157 void DlgEditPointAxis::createHint (QVBoxLayout *layoutOuter)
162 QWidget *widget =
new QWidget;
163 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
165 QHBoxLayout *layout =
new QHBoxLayout;
166 widget->setLayout (layout);
168 QString locale = QLocaleToString (m_modelMainWindow.
locale ());
169 QString hint = QString (
"%1: %2")
170 .arg (tr (
"Number format"))
172 QLabel *label =
new QLabel (hint);
173 layout->addWidget (label);
176 void DlgEditPointAxis::createOkCancel (QVBoxLayout *layoutOuter)
178 QWidget *panel =
new QWidget (
this);
179 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
181 QHBoxLayout *layout =
new QHBoxLayout (panel);
182 panel->setLayout (layout);
184 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
185 layout->addWidget(m_btnOk);
186 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
188 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
189 layout->addWidget(m_btnCancel);
190 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
193 void DlgEditPointAxis::initializeGraphCoordinates (
const double *xInitialValue,
194 const double *yInitialValue,
199 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::initializeGraphCoordinates";
201 QString xTheta, yRadius;
202 if ((xInitialValue != 0) &&
203 (yInitialValue != 0)) {
216 m_editGraphX->setText (xTheta);
218 m_editGraphX->setText (
"");
222 m_editGraphY->setText (yRadius);
224 m_editGraphY->setText (
"");
228 bool DlgEditPointAxis::isCartesian ()
const
230 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
233 QChar DlgEditPointAxis::nameXTheta ()
const
235 return (isCartesian () ? QChar (
'X') : THETA);
238 QChar DlgEditPointAxis::nameYRadius ()
const
240 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
245 double xTheta, yRadius;
250 m_editGraphY->text(),
257 isXOnly = m_editGraphY->text().isEmpty();
259 return QPointF (xTheta,
263 void DlgEditPointAxis::slotTextChanged (
const QString &)
268 QString DlgEditPointAxis::unitsType (
bool isXTheta)
const
270 if (isCartesian ()) {
272 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
274 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
278 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
280 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
285 void DlgEditPointAxis::updateControls ()
287 QString textX = m_editGraphX->text();
288 QString textY = m_editGraphY->text();
292 if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4) {
294 bool gotX = (!textX.isEmpty() &&
295 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable));
296 bool gotY = (!textY.isEmpty() &&
297 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
300 m_btnOk->setEnabled ((textX.isEmpty() && gotY) ||
301 (textY.isEmpty() && gotX));
306 m_btnOk->setEnabled (!textX.isEmpty () &&
308 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
309 (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.
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
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...
DlgEditPointAxis(MainWindow &mainWindow, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, 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...
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.