7 #include "DlgEditPointAxis.h" 8 #include "DlgValidatorAbstract.h" 9 #include "DlgValidatorFactory.h" 10 #include "DocumentAxesPointsRequired.h" 11 #include "DocumentModelCoords.h" 12 #include "DocumentModelGeneral.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;
43 DocumentAxesPointsRequired documentAxesPointsRequired,
45 const double *xInitialValue,
46 const double *yInitialValue) :
47 QDialog (&mainWindow),
48 m_documentAxesPointsRequired (documentAxesPointsRequired),
49 m_modelCoords (modelCoords),
50 m_modelGeneral (modelGeneral),
51 m_modelMainWindow (modelMainWindow)
53 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::DlgEditPointAxis";
56 bool isX = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || isXOnly;
57 bool isY = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || !isXOnly;
59 QVBoxLayout *layout =
new QVBoxLayout;
62 setCursor (QCursor (Qt::ArrowCursor));
64 setWindowTitle (tr (
"Edit Axis Point"));
66 createCoords (layout);
68 createOkCancel (layout);
70 initializeGraphCoordinates (xInitialValue,
79 DlgEditPointAxis::~DlgEditPointAxis()
81 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::~DlgEditPointAxis";
84 void DlgEditPointAxis::createCoords (QVBoxLayout *layoutOuter)
96 m_modelMainWindow.
locale());
103 m_modelMainWindow.
locale());
106 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10 (%11, %12):")
107 .arg (tr (
"Graph Coordinates"))
109 .arg (nameYRadius ())
110 .arg (isConstraintX || isConstraintY ?
" with " :
"")
111 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
112 .arg (isConstraintX ?
" > 0" :
"")
113 .arg (isConstraintX && isConstraintY ?
" and " :
"")
114 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
115 .arg ( isConstraintY ?
" > 0" :
"")
117 .arg (unitsType (IS_X_THETA))
118 .arg (unitsType (IS_NOT_X_THETA));
119 QGroupBox *panel =
new QGroupBox (description,
this);
120 layoutOuter->addWidget (panel);
122 QHBoxLayout *layout =
new QHBoxLayout (panel);
123 panel->setLayout (layout);
126 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
127 layout->addWidget(labelGraphParLeft, 0);
129 m_editGraphX =
new QLineEdit;
130 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
131 m_editGraphX->setAlignment (ALIGNMENT);
132 m_editGraphX->setValidator (m_validatorGraphX);
134 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n" 135 "For cartesian plots this is X. For polar plots this is the radius R.\n\n" 136 "The expected format of the coordinate value is determined by the locale setting. If " 137 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
138 layout->addWidget(m_editGraphX, 0);
139 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
141 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
142 layout->addWidget(labelGraphComma, 0);
144 m_editGraphY =
new QLineEdit;
145 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
146 m_editGraphY->setAlignment (ALIGNMENT);
147 m_editGraphY->setValidator (m_validatorGraphY);
149 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n" 150 "For cartesian plots this is Y. For polar plots this is the angle Theta.\n\n" 151 "The expected format of the coordinate value is determined by the locale setting. If " 152 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
153 layout->addWidget(m_editGraphY, 0);
154 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
156 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
157 layout->addWidget(labelGraphParRight, 0);
160 void DlgEditPointAxis::createHint (QVBoxLayout *layoutOuter)
165 QWidget *widget =
new QWidget;
166 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
168 QHBoxLayout *layout =
new QHBoxLayout;
169 widget->setLayout (layout);
171 QString locale = QLocaleToString (m_modelMainWindow.
locale ());
172 QString hint = QString (
"%1: %2")
173 .arg (tr (
"Number format"))
175 QLabel *label =
new QLabel (hint);
176 layout->addWidget (label);
179 void DlgEditPointAxis::createOkCancel (QVBoxLayout *layoutOuter)
181 QWidget *panel =
new QWidget (
this);
182 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
184 QHBoxLayout *layout =
new QHBoxLayout (panel);
185 panel->setLayout (layout);
187 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
188 layout->addWidget(m_btnOk);
189 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
191 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
192 layout->addWidget(m_btnCancel);
193 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
196 void DlgEditPointAxis::initializeGraphCoordinates (
const double *xInitialValue,
197 const double *yInitialValue,
202 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::initializeGraphCoordinates";
204 QString xTheta, yRadius;
205 if ((xInitialValue != 0) &&
206 (yInitialValue != 0)) {
220 m_editGraphX->setText (xTheta);
222 m_editGraphX->setText (
"");
226 m_editGraphY->setText (yRadius);
228 m_editGraphY->setText (
"");
232 bool DlgEditPointAxis::isCartesian ()
const 234 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
237 QChar DlgEditPointAxis::nameXTheta ()
const 239 return (isCartesian () ? QChar (
'X') : THETA);
242 QChar DlgEditPointAxis::nameYRadius ()
const 244 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
249 double xTheta, yRadius;
254 m_editGraphY->text(),
261 isXOnly = m_editGraphY->text().isEmpty();
263 return QPointF (xTheta,
267 void DlgEditPointAxis::slotTextChanged (
const QString &)
272 QString DlgEditPointAxis::unitsType (
bool isXTheta)
const 274 if (isCartesian ()) {
276 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
278 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
282 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
284 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
289 void DlgEditPointAxis::updateControls ()
291 QString textX = m_editGraphX->text();
292 QString textY = m_editGraphY->text();
296 if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4) {
298 bool gotX = (!textX.isEmpty() &&
299 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable));
300 bool gotY = (!textY.isEmpty() &&
301 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
304 m_btnOk->setEnabled ((textX.isEmpty() && gotY) ||
305 (textY.isEmpty() && gotX));
308 m_editGraphX->setEnabled (!gotY);
309 m_editGraphY->setEnabled (!gotX);
314 m_btnOk->setEnabled (!textX.isEmpty () &&
316 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
317 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
Model for DlgSettingsGeneral and CmdSettingsGeneral.
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
CoordUnitsNonPolarTheta coordUnitsY() const
Get method for x units.
virtual QValidator::State validate(QString &input, int &pos) const =0
Validate according to the numeric format specific to the leaf class.
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.
DlgEditPointAxis(MainWindow &mainWindow, const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, 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...
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.
Model for DlgSettingsMainWindow.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
CoordUnitsDate coordUnitsDate() const
Get method for date format when used.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
QLocale locale() const
Get method for locale.
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...
CoordsType coordsType() const
Get method for coordinates type.
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
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...
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...