7 #include "DlgEditPointGraph.h" 8 #include "DlgEditPointGraphLineEdit.h" 9 #include "DlgValidatorAbstract.h" 10 #include "DlgValidatorFactory.h" 11 #include "DocumentModelCoords.h" 12 #include "DocumentModelGeneral.h" 13 #include "FormatCoordsUnits.h" 15 #include "MainWindow.h" 16 #include "MainWindowModel.h" 19 #include <QPushButton> 20 #include "QtToString.h" 21 #include <QVBoxLayout> 22 #include "Transformation.h" 24 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
26 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
33 const double *xInitialValue,
34 const double *yInitialValue) :
35 QDialog (&mainWindow),
37 m_modelCoords (modelCoords),
38 m_modelGeneral (modelGeneral),
39 m_modelMainWindow (modelMainWindow)
41 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointGraph::DlgEditPointGraph";
43 QVBoxLayout *layout =
new QVBoxLayout;
46 setCursor (QCursor (Qt::ArrowCursor));
48 setWindowTitle (tr (
"Edit Curve Point(s)"));
50 createCoords (layout);
52 createOkCancel (layout);
54 initializeGraphCoordinates (xInitialValue,
62 DlgEditPointGraph::~DlgEditPointGraph()
64 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointGraph::~DlgEditPointGraph";
67 void DlgEditPointGraph::createCoords (QVBoxLayout *layoutOuter)
79 m_modelMainWindow.
locale());
86 m_modelMainWindow.
locale());
89 QString description = QString (
"%1 (%2, %3)%4%5%6%7%8%9 %10:")
90 .arg (tr (
"Graph Coordinates"))
93 .arg (isConstraintX || isConstraintY ?
" with " :
"")
94 .arg (isConstraintX ? QString (nameXTheta ()) :
"")
95 .arg (isConstraintX ?
" > 0" :
"")
96 .arg (isConstraintX && isConstraintY ?
" and " :
"")
97 .arg ( isConstraintY ? QString (nameYRadius ()) :
"")
98 .arg ( isConstraintY ?
" > 0" :
"")
100 QGroupBox *panel =
new QGroupBox (description,
this);
101 layoutOuter->addWidget (panel);
103 QHBoxLayout *layout =
new QHBoxLayout (panel);
104 panel->setLayout (layout);
107 QLabel *labelGraphParLeft =
new QLabel (tr (
"("),
this);
108 layout->addWidget(labelGraphParLeft, 0);
111 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
112 m_editGraphX->setAlignment (ALIGNMENT);
113 m_editGraphX->setValidator (m_validatorGraphX);
115 m_editGraphX->setWhatsThis (tr (
"Enter the first graph coordinate value to be applied to the graph points.\n\n" 116 "Leave this field empty if no value is to be applied to the graph points.\n\n" 117 "For cartesian plots this is the X coordinate. For polar plots this is the radius R.\n\n" 118 "The expected format of the coordinate value is determined by the locale setting. If " 119 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
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);
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 value to be applied to the graph points.\n\n" 132 "Leave this field empty if no value is to be applied to the graph points.\n\n" 133 "For cartesian plots this is the Y coordinate. For polar plots this is the angle Theta.\n\n" 134 "The expected format of the coordinate value is determined by the locale setting. If " 135 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
136 layout->addWidget(m_editGraphY, 0);
137 connect (m_editGraphY, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotTextChanged (
const QString &)));
139 QLabel *labelGraphParRight =
new QLabel (tr (
")"),
this);
140 layout->addWidget(labelGraphParRight, 0);
143 void DlgEditPointGraph::createHint (QVBoxLayout *layoutOuter)
148 QWidget *widget =
new QWidget;
149 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
151 QHBoxLayout *layout =
new QHBoxLayout;
152 widget->setLayout (layout);
154 QString locale = QLocaleToString (m_modelMainWindow.
locale ());
155 QString hint = QString (
"%1: %2")
156 .arg (tr (
"Number format"))
158 QLabel *label =
new QLabel (hint);
159 layout->addWidget (label);
162 void DlgEditPointGraph::createOkCancel (QVBoxLayout *layoutOuter)
164 QWidget *panel =
new QWidget (
this);
165 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
167 QHBoxLayout *layout =
new QHBoxLayout (panel);
168 panel->setLayout (layout);
170 m_btnOk =
new QPushButton (tr (
"Ok"),
this);
171 layout->addWidget(m_btnOk);
172 connect (m_btnOk, SIGNAL (released ()),
this, SLOT (accept ()));
174 m_btnCancel =
new QPushButton (tr (
"Cancel"),
this);
175 layout->addWidget(m_btnCancel);
176 connect (m_btnCancel, SIGNAL (released ()),
this, SLOT (reject ()));
179 void DlgEditPointGraph::initializeGraphCoordinates (
const double *xInitialValue,
180 const double *yInitialValue,
183 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgEditPointGraph::initializeGraphCoordinates";
185 QString xTheta, yRadius;
186 if ((xInitialValue != 0) &&
187 (yInitialValue != 0)) {
200 m_editGraphX->setText (xTheta);
201 m_editGraphY->setText (yRadius);
204 bool DlgEditPointGraph::isCartesian ()
const 206 return (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN);
209 QChar DlgEditPointGraph::nameXTheta ()
const 211 return (isCartesian () ? QChar (
'X') : THETA);
214 QChar DlgEditPointGraph::nameYRadius ()
const 216 return (isCartesian () ? QChar (
'Y') : QChar (
'R'));
227 QString xTextNotEmpty = QString (
"%1").arg (m_editGraphX->text().isEmpty () ?
"0" : m_editGraphX->text());
228 QString yTextNotEmpty = QString (
"%1").arg (m_editGraphY->text().isEmpty () ?
"0" : m_editGraphY->text());
237 isX = !m_editGraphX->text().isEmpty();
238 isY = !m_editGraphY->text().isEmpty();
241 void DlgEditPointGraph::slotTextChanged (
const QString &)
247 QString DlgEditPointGraph::unitsType (
bool isXTheta)
const 249 if (isCartesian ()) {
251 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsX());
253 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsY());
257 return coordUnitsPolarThetaToBriefType (m_modelCoords.
coordUnitsTheta());
259 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.
coordUnitsRadius());
264 void DlgEditPointGraph::updateControls ()
266 QString textX = m_editGraphX->text();
267 QString textY = m_editGraphY->text();
279 bool test2 = (!textX.isEmpty() || !textY.isEmpty());
283 if (!textX.isEmpty()) {
284 test3 &= (m_validatorGraphX->
validate(textX, posX) == QValidator::Acceptable);
286 if (!textY.isEmpty()) {
287 test3 &= (m_validatorGraphY->
validate(textY, posY) == QValidator::Acceptable);
290 m_btnOk->setEnabled (m_changed && test2 && test3);
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Adds hover highlighting to QLineEdit.
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
void updateBackground()
Update background given the current state.
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.
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.
void posGraph(bool &isX, double &x, bool &isY, double &y) const
Return one or both coordinates. Only applies if dialog was accepted.
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
DlgEditPointGraph(MainWindow &mainWindow, const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, 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...
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...