19 #include <QPushButton>
21 #include <QVBoxLayout>
33 const double *xInitialValue,
34 const double *yInitialValue) :
35 QDialog (&mainWindow),
37 m_modelCoords (modelCoords),
38 m_modelGeneral (modelGeneral),
39 m_modelMainWindow (modelMainWindow)
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,
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);
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);
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);
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,
185 QString xTheta, yRadius;
186 if ((xInitialValue !=
nullptr) &&
187 (yInitialValue !=
nullptr)) {
200 m_editGraphX->setText (xTheta);
201 m_editGraphY->setText (yRadius);
204 bool DlgEditPointGraph::isCartesian ()
const
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 ()) {
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);