7 #include "DlgEditPointGraph.h" 8 #include "DlgEditPointGraphLineEdit.h" 9 #include "DlgValidatorAbstract.h" 10 #include "DlgValidatorFactory.h" 11 #include "DocumentModelCoords.h" 12 #include "FormatCoordsUnits.h" 14 #include "MainWindow.h" 15 #include "MainWindowModel.h" 18 #include <QPushButton> 19 #include "QtToString.h" 20 #include <QVBoxLayout> 21 #include "Transformation.h" 23 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
25 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
31 const double *xInitialValue,
32 const double *yInitialValue) :
33 QDialog (&mainWindow),
35 m_modelCoords (modelCoords),
36 m_modelMainWindow (modelMainWindow)
38 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointGraph::DlgEditPointGraph";
40 QVBoxLayout *layout =
new QVBoxLayout;
43 setCursor (QCursor (Qt::ArrowCursor));
45 setWindowTitle (tr (
"Edit Curve Point(s)"));
47 createCoords (layout);
49 createOkCancel (layout);
51 initializeGraphCoordinates (xInitialValue,
59 DlgEditPointGraph::~DlgEditPointGraph()
61 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointGraph::~DlgEditPointGraph";
64 void DlgEditPointGraph::createCoords (QVBoxLayout *layoutOuter)
76 m_modelMainWindow.
locale());
83 m_modelMainWindow.
locale());
86 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10:")
87 .arg (tr (
"Graph Coordinates"))
90 .arg (isConstraintX || isConstraintY ?
" with " :
"")
91 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
92 .arg (isConstraintX ?
" > 0" :
"")
93 .arg (isConstraintX && isConstraintY ?
" and " :
"")
94 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
95 .arg ( isConstraintY ?
" > 0" :
"")
97 QGroupBox *panel =
new QGroupBox (description,
this);
98 layoutOuter->addWidget (panel);
100 QHBoxLayout *layout =
new QHBoxLayout (panel);
101 panel->setLayout (layout);
104 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
105 layout->addWidget(labelGraphParLeft, 0);
108 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
109 m_editGraphX->setAlignment (ALIGNMENT);
110 m_editGraphX->setValidator (m_validatorGraphX);
112 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate value to be applied to the graph points.\n\n" 113 "Leave this field empty if no value is to be applied to the graph points.\n\n" 114 "For cartesian plots this is the X coordinate. For polar plots this is the radius R.\n\n" 115 "The expected format of the coordinate value is determined by the locale setting. If " 116 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
117 layout->addWidget(m_editGraphX, 0);
118 connect (m_editGraphX, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
120 QLabel *labelGraphComma =
new QLabel (tr (
", "),
this);
121 layout->addWidget(labelGraphComma, 0);
124 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
125 m_editGraphY->setAlignment (ALIGNMENT);
126 m_editGraphY->setValidator (m_validatorGraphY);
128 m_editGraphY->setWhatsThis (tr (
"Enter the second graph coordinate value to be applied to the graph points.\n\n" 129 "Leave this field empty if no value is to be applied to the graph points.\n\n" 130 "For cartesian plots this is the Y coordinate. For plot plots this is the angle Theta.\n\n" 131 "The expected format of the coordinate value is determined by the locale setting. If " 132 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
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 DlgEditPointGraph::createHint (QVBoxLayout *layoutOuter)
145 QWidget *widget =
new QWidget;
146 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
148 QHBoxLayout *layout =
new QHBoxLayout;
149 widget->setLayout (layout);
151 QString locale = QLocaleToString (m_modelMainWindow.
locale ());
152 QString hint = QString (
"%1: %2")
153 .arg (tr (
"Number format"))
155 QLabel *label =
new QLabel (hint);
156 layout->addWidget (label);
159 void DlgEditPointGraph::createOkCancel (QVBoxLayout *layoutOuter)
161 QWidget *panel =
new QWidget (
this);
162 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
164 QHBoxLayout *layout =
new QHBoxLayout (panel);
165 panel->setLayout (layout);
167 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
168 layout->addWidget(m_btnOk);
169 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
171 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
172 layout->addWidget(m_btnCancel);
173 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
176 void DlgEditPointGraph::initializeGraphCoordinates (
const double *xInitialValue,
177 const double *yInitialValue,
180 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointGraph::initializeGraphCoordinates";
182 QString xTheta, yRadius;
183 if ((xInitialValue != 0) &&
184 (yInitialValue != 0)) {
196 m_editGraphX->setText (xTheta);
197 m_editGraphY->setText (yRadius);
200 bool DlgEditPointGraph::isCartesian ()
const 202 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
205 QChar DlgEditPointGraph::nameXTheta ()
const 207 return (isCartesian () ? QChar (
'X') : THETA);
210 QChar DlgEditPointGraph::nameYRadius ()
const 212 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
223 QString xTextNotEmpty = QString (
"%1").arg (m_editGraphX->text().isEmpty () ?
"0" : m_editGraphX->text());
224 QString yTextNotEmpty = QString (
"%1").arg (m_editGraphY->text().isEmpty () ?
"0" : m_editGraphY->text());
233 isX = !m_editGraphX->text().isEmpty();
234 isY = !m_editGraphY->text().isEmpty();
237 void DlgEditPointGraph::slotTextChanged (
const QString &)
243 QString DlgEditPointGraph::unitsType (
bool isXTheta)
const 245 if (isCartesian ()) {
247 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
249 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
253 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
255 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
260 void DlgEditPointGraph::updateControls ()
262 QString textX = m_editGraphX->text();
263 QString textY = m_editGraphY->text();
275 bool test2 = (!textX.isEmpty() || !textY.isEmpty());
279 if (!textX.isEmpty()) {
280 test3 &= (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable);
282 if (!textY.isEmpty()) {
283 test3 &= (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable);
286 m_btnOk->setEnabled (m_changed && test2 && test3);
Adds hover highlighting to QLineEdit.
virtual QValidator::State validate(QString &input, int &pos) const =0
Validate according to the numeric format specific to the leaf class.
void updateBackground()
Update background given the current state.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
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 posGraph(bool &isX, double &x, bool &isY, double &y) const
Return one or both coordinates. 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.
DlgEditPointGraph(MainWindow &mainWindow, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, 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...
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.