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> 28 #include "QtToString.h" 29 #include <QVBoxLayout> 30 #include "Transformation.h" 32 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
34 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
36 const bool IS_X_THETA =
true;
37 const bool IS_NOT_X_THETA =
false;
44 DocumentAxesPointsRequired documentAxesPointsRequired,
46 const double *xInitialValue,
47 const double *yInitialValue) :
48 QDialog (&mainWindow),
49 m_documentAxesPointsRequired (documentAxesPointsRequired),
50 m_modelCoords (modelCoords),
51 m_modelGeneral (modelGeneral),
52 m_modelMainWindow (modelMainWindow)
54 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::DlgEditPointAxis";
57 bool isX = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || isXOnly;
58 bool isY = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || !isXOnly;
60 QVBoxLayout *layout =
new QVBoxLayout;
63 setCursor (QCursor (Qt::ArrowCursor));
65 setWindowTitle (tr (
"Edit Axis Point"));
67 createCoords (layout);
69 documentAxesPointsRequired);
70 createOkCancel (layout);
72 initializeGraphCoordinates (xInitialValue,
81 DlgEditPointAxis::~DlgEditPointAxis()
83 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::~DlgEditPointAxis";
86 void DlgEditPointAxis::createCoords (QVBoxLayout *layoutOuter)
98 m_modelMainWindow.
locale());
105 m_modelMainWindow.
locale());
108 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10 (%11, %12):")
109 .arg (tr (
"Graph Coordinates"))
111 .arg (nameYRadius ())
112 .arg (isConstraintX || isConstraintY ?
" with " :
"")
113 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
114 .arg (isConstraintX ?
" > 0" :
"")
115 .arg (isConstraintX && isConstraintY ?
" and " :
"")
116 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
117 .arg ( isConstraintY ?
" > 0" :
"")
119 .arg (unitsType (IS_X_THETA))
120 .arg (unitsType (IS_NOT_X_THETA));
121 QGroupBox *panel =
new QGroupBox (description,
this);
122 layoutOuter->addWidget (panel);
124 QHBoxLayout *layout =
new QHBoxLayout (panel);
125 panel->setLayout (layout);
128 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
129 layout->addWidget(labelGraphParLeft, 0);
131 m_editGraphX =
new QLineEdit;
132 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
133 m_editGraphX->setAlignment (ALIGNMENT);
134 m_editGraphX->setValidator (m_validatorGraphX);
136 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate of the axis point.\n\n" 137 "For cartesian plots this is X. For polar plots this is the angle Theta.\n\n" 138 "The expected format of the coordinate value is determined by the locale setting. If " 139 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
140 layout->addWidget(m_editGraphX, 0);
141 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
143 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
144 layout->addWidget(labelGraphComma, 0);
146 m_editGraphY =
new QLineEdit;
147 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
148 m_editGraphY->setAlignment (ALIGNMENT);
149 m_editGraphY->setValidator (m_validatorGraphY);
151 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate of the axis point.\n\n" 152 "For cartesian plots this is Y. For polar plots this is the radius R.\n\n" 153 "The expected format of the coordinate value is determined by the locale setting. If " 154 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
155 layout->addWidget(m_editGraphY, 0);
156 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
158 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
159 layout->addWidget(labelGraphParRight, 0);
162 void DlgEditPointAxis::createHints (QVBoxLayout *layoutOuter,
163 DocumentAxesPointsRequired documentAxesPointsRequired)
170 const int MIN_EDIT_WIDTH = 180;
172 QWidget *widget =
new QWidget;
173 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
175 QGridLayout *layout =
new QGridLayout;
176 widget->setLayout (layout);
180 QLabel *labelNumberCoordinates =
new QLabel (tr (
"Number of coordinates per axis point:"));
181 layout->addWidget (labelNumberCoordinates, row, 0, 1, 1);
182 QLineEdit *editNumberCoordinates =
new QLineEdit;
183 editNumberCoordinates->setWhatsThis (tr (
"Three axis points with two coordinates each are normally used. " 184 "If each axis point has only one known coordinate, then start over " 185 "with File / Import (Advanced) / 4 Axis Points."));
186 editNumberCoordinates->setReadOnly (
true);
187 editNumberCoordinates->setText (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3 ?
190 editNumberCoordinates->setMinimumWidth (MIN_EDIT_WIDTH);
191 layout->addWidget (editNumberCoordinates, row++, 1, 1, 1);
194 QLabel *labelLocale =
new QLabel (tr (
"Number format:"));
195 layout->addWidget (labelLocale, row, 0, 1, 1);
196 QLineEdit *editLocale =
new QLineEdit;
197 editLocale->setWhatsThis (tr (
"Locale which determines the allowed number formats. This is set by Settings / Main Window."));
198 editLocale->setReadOnly (
true);
199 QString locale = QLocaleToString (m_modelMainWindow.
locale ());
200 editLocale->setText (locale);
201 editLocale->setMinimumWidth (MIN_EDIT_WIDTH);
202 layout->addWidget (editLocale, row++, 1, 1, 1);
205 void DlgEditPointAxis::createOkCancel (QVBoxLayout *layoutOuter)
207 QWidget *panel =
new QWidget (
this);
208 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
210 QHBoxLayout *layout =
new QHBoxLayout (panel);
211 panel->setLayout (layout);
213 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
214 layout->addWidget(m_btnOk);
215 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
217 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
218 layout->addWidget(m_btnCancel);
219 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
222 void DlgEditPointAxis::initializeGraphCoordinates (
const double *xInitialValue,
223 const double *yInitialValue,
228 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointAxis::initializeGraphCoordinates";
230 QString xTheta, yRadius;
231 if ((xInitialValue != 0) &&
232 (yInitialValue != 0)) {
246 m_editGraphX->setText (xTheta);
248 m_editGraphX->setText (
"");
252 m_editGraphY->setText (yRadius);
254 m_editGraphY->setText (
"");
258 bool DlgEditPointAxis::isCartesian ()
const 260 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
263 QChar DlgEditPointAxis::nameXTheta ()
const 265 return (isCartesian () ? QChar (
'X') : THETA);
268 QChar DlgEditPointAxis::nameYRadius ()
const 270 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
275 double xTheta, yRadius;
280 m_editGraphY->text(),
287 isXOnly = m_editGraphY->text().isEmpty();
289 return QPointF (xTheta,
293 void DlgEditPointAxis::slotTextChanged (
const QString &)
298 QString DlgEditPointAxis::unitsType (
bool isXTheta)
const 300 if (isCartesian ()) {
302 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
304 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
308 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
310 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
315 void DlgEditPointAxis::updateControls ()
317 QString textX = m_editGraphX->text();
318 QString textY = m_editGraphY->text();
322 if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4) {
324 bool gotX = (!textX.isEmpty() &&
325 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable));
326 bool gotY = (!textY.isEmpty() &&
327 (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable));
330 m_btnOk->setEnabled ((textX.isEmpty() && gotY) ||
331 (textY.isEmpty() && gotX));
334 m_editGraphX->setEnabled (!gotY);
335 m_editGraphY->setEnabled (!gotX);
340 m_btnOk->setEnabled (!textX.isEmpty () &&
342 (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable) &&
343 (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...