00001
00002
00003
00004
00005
00006
00007 #include "DlgEditPointAxis.h"
00008 #include "DlgValidatorAbstract.h"
00009 #include "DlgValidatorFactory.h"
00010 #include "DocumentAxesPointsRequired.h"
00011 #include "DocumentModelCoords.h"
00012 #include "DocumentModelGeneral.h"
00013 #include "EngaugeAssert.h"
00014 #include "FormatCoordsUnits.h"
00015 #include "FormatDateTime.h"
00016 #include "FormatDegreesMinutesSecondsNonPolarTheta.h"
00017 #include "FormatDegreesMinutesSecondsPolarTheta.h"
00018 #include "Logger.h"
00019 #include "MainWindow.h"
00020 #include "MainWindowModel.h"
00021 #include <QDoubleValidator>
00022 #include <QGridLayout>
00023 #include <QGroupBox>
00024 #include <QHBoxLayout>
00025 #include <QLabel>
00026 #include <QRect>
00027 #include "QtToString.h"
00028 #include <QVBoxLayout>
00029 #include "Transformation.h"
00030
00031 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
00032
00033 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
00034
00035 const bool IS_X_THETA = true;
00036 const bool IS_NOT_X_THETA = false;
00037
00038 DlgEditPointAxis::DlgEditPointAxis (MainWindow &mainWindow,
00039 const DocumentModelCoords &modelCoords,
00040 const DocumentModelGeneral &modelGeneral,
00041 const MainWindowModel &modelMainWindow,
00042 const Transformation &transformation,
00043 DocumentAxesPointsRequired documentAxesPointsRequired,
00044 bool isXOnly,
00045 const double *xInitialValue,
00046 const double *yInitialValue) :
00047 QDialog (&mainWindow),
00048 m_documentAxesPointsRequired (documentAxesPointsRequired),
00049 m_modelCoords (modelCoords),
00050 m_modelGeneral (modelGeneral),
00051 m_modelMainWindow (modelMainWindow)
00052 {
00053 LOG4CPP_INFO_S ((*mainCat)) << "DlgEditPointAxis::DlgEditPointAxis";
00054
00055
00056 bool isX = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || isXOnly;
00057 bool isY = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) || !isXOnly;
00058
00059 QVBoxLayout *layout = new QVBoxLayout;
00060 setLayout (layout);
00061
00062 setCursor (QCursor (Qt::ArrowCursor));
00063 setModal(true);
00064 setWindowTitle (tr ("Edit Axis Point"));
00065
00066 createCoords (layout);
00067 createHint (layout);
00068 createOkCancel (layout);
00069
00070 initializeGraphCoordinates (xInitialValue,
00071 yInitialValue,
00072 transformation,
00073 isX,
00074 isY);
00075
00076 updateControls ();
00077 }
00078
00079 DlgEditPointAxis::~DlgEditPointAxis()
00080 {
00081 LOG4CPP_INFO_S ((*mainCat)) << "DlgEditPointAxis::~DlgEditPointAxis";
00082 }
00083
00084 void DlgEditPointAxis::createCoords (QVBoxLayout *layoutOuter)
00085 {
00086
00087 bool isConstraintX = (m_modelCoords.coordScaleXTheta() == COORD_SCALE_LOG);
00088 bool isConstraintY = (m_modelCoords.coordScaleYRadius() == COORD_SCALE_LOG);
00089 DlgValidatorFactory dlgValidatorFactory;
00090 m_validatorGraphX = dlgValidatorFactory.createCartesianOrPolarWithPolarPolar (m_modelCoords.coordScaleXTheta(),
00091 isCartesian (),
00092 m_modelCoords.coordUnitsX(),
00093 m_modelCoords.coordUnitsTheta(),
00094 m_modelCoords.coordUnitsDate(),
00095 m_modelCoords.coordUnitsTime(),
00096 m_modelMainWindow.locale());
00097 m_validatorGraphY = dlgValidatorFactory.createCartesianOrPolarWithNonPolarPolar (m_modelCoords.coordScaleYRadius(),
00098 isCartesian (),
00099 m_modelCoords.coordUnitsY(),
00100 m_modelCoords.coordUnitsRadius(),
00101 m_modelCoords.coordUnitsDate(),
00102 m_modelCoords.coordUnitsTime(),
00103 m_modelMainWindow.locale());
00104
00105
00106 QString description = QString ("%1 (%2, %3)%4%5%6%7%8%9 %10 (%11, %12):")
00107 .arg (tr ("Graph Coordinates"))
00108 .arg (nameXTheta ())
00109 .arg (nameYRadius ())
00110 .arg (isConstraintX || isConstraintY ? " with " : "")
00111 .arg (isConstraintX ? QString (nameXTheta ()) : "")
00112 .arg (isConstraintX ? " > 0" : "")
00113 .arg (isConstraintX && isConstraintY ? " and " : "")
00114 .arg ( isConstraintY ? QString (nameYRadius ()) : "")
00115 .arg ( isConstraintY ? " > 0" : "")
00116 .arg (tr ("as"))
00117 .arg (unitsType (IS_X_THETA))
00118 .arg (unitsType (IS_NOT_X_THETA));
00119 QGroupBox *panel = new QGroupBox (description, this);
00120 layoutOuter->addWidget (panel);
00121
00122 QHBoxLayout *layout = new QHBoxLayout (panel);
00123 panel->setLayout (layout);
00124
00125
00126 QLabel *labelGraphParLeft = new QLabel (tr ("("), this);
00127 layout->addWidget(labelGraphParLeft, 0);
00128
00129 m_editGraphX = new QLineEdit;
00130 m_editGraphX->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
00131 m_editGraphX->setAlignment (ALIGNMENT);
00132 m_editGraphX->setValidator (m_validatorGraphX);
00133
00134 m_editGraphX->setWhatsThis (tr ("Enter the first graph coordinate of the axis point.\n\n"
00135 "For cartesian plots this is X. For polar plots this is the radius R.\n\n"
00136 "The expected format of the coordinate value is determined by the locale setting. If "
00137 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
00138 layout->addWidget(m_editGraphX, 0);
00139 connect (m_editGraphX, SIGNAL (textChanged (const QString &)), this, SLOT (slotTextChanged (const QString &)));
00140
00141 QLabel *labelGraphComma = new QLabel (tr (", "), this);
00142 layout->addWidget(labelGraphComma, 0);
00143
00144 m_editGraphY = new QLineEdit;
00145 m_editGraphY->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
00146 m_editGraphY->setAlignment (ALIGNMENT);
00147 m_editGraphY->setValidator (m_validatorGraphY);
00148
00149 m_editGraphY->setWhatsThis (tr ("Enter the second graph coordinate of the axis point.\n\n"
00150 "For cartesian plots this is Y. For plot plots this is the angle Theta.\n\n"
00151 "The expected format of the coordinate value is determined by the locale setting. If "
00152 "typed values are not recognized as expected, check the locale setting in Settings / Main Window..."));
00153 layout->addWidget(m_editGraphY, 0);
00154 connect (m_editGraphY, SIGNAL (textChanged (const QString &)), this, SLOT (slotTextChanged (const QString &)));
00155
00156 QLabel *labelGraphParRight = new QLabel (tr (")"), this);
00157 layout->addWidget(labelGraphParRight, 0);
00158 }
00159
00160 void DlgEditPointAxis::createHint (QVBoxLayout *layoutOuter)
00161 {
00162
00163
00164
00165 QWidget *widget = new QWidget;
00166 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
00167
00168 QHBoxLayout *layout = new QHBoxLayout;
00169 widget->setLayout (layout);
00170
00171 QString locale = QLocaleToString (m_modelMainWindow.locale ());
00172 QString hint = QString ("%1: %2")
00173 .arg (tr ("Number format"))
00174 .arg (locale);
00175 QLabel *label = new QLabel (hint);
00176 layout->addWidget (label);
00177 }
00178
00179 void DlgEditPointAxis::createOkCancel (QVBoxLayout *layoutOuter)
00180 {
00181 QWidget *panel = new QWidget (this);
00182 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
00183
00184 QHBoxLayout *layout = new QHBoxLayout (panel);
00185 panel->setLayout (layout);
00186
00187 m_btnOk = new QPushButton (tr ("Ok"), this);
00188 layout->addWidget(m_btnOk);
00189 connect (m_btnOk, SIGNAL (released ()), this, SLOT (accept ()));
00190
00191 m_btnCancel = new QPushButton (tr ("Cancel"), this);
00192 layout->addWidget(m_btnCancel);
00193 connect (m_btnCancel, SIGNAL (released ()), this, SLOT (reject ()));
00194 }
00195
00196 void DlgEditPointAxis::initializeGraphCoordinates (const double *xInitialValue,
00197 const double *yInitialValue,
00198 const Transformation &transformation,
00199 bool isX,
00200 bool isY)
00201 {
00202 LOG4CPP_INFO_S ((*mainCat)) << "DlgEditPointAxis::initializeGraphCoordinates";
00203
00204 QString xTheta, yRadius;
00205 if ((xInitialValue != 0) &&
00206 (yInitialValue != 0)) {
00207
00208 FormatCoordsUnits format;
00209 format.unformattedToFormatted (*xInitialValue,
00210 *yInitialValue,
00211 m_modelCoords,
00212 m_modelGeneral,
00213 m_modelMainWindow,
00214 xTheta,
00215 yRadius,
00216 transformation);
00217 }
00218
00219 if (isX) {
00220 m_editGraphX->setText (xTheta);
00221 } else {
00222 m_editGraphX->setText ("");
00223 }
00224
00225 if (isY) {
00226 m_editGraphY->setText (yRadius);
00227 } else {
00228 m_editGraphY->setText ("");
00229 }
00230 }
00231
00232 bool DlgEditPointAxis::isCartesian () const
00233 {
00234 return (m_modelCoords.coordsType() == COORDS_TYPE_CARTESIAN);
00235 }
00236
00237 QChar DlgEditPointAxis::nameXTheta () const
00238 {
00239 return (isCartesian () ? QChar ('X') : THETA);
00240 }
00241
00242 QChar DlgEditPointAxis::nameYRadius () const
00243 {
00244 return (isCartesian () ? QChar ('Y') : QChar ('R'));
00245 }
00246
00247 QPointF DlgEditPointAxis::posGraph (bool &isXOnly) const
00248 {
00249 double xTheta, yRadius;
00250
00251 FormatCoordsUnits format;
00252
00253 format.formattedToUnformatted (m_editGraphX->text(),
00254 m_editGraphY->text(),
00255 m_modelCoords,
00256 m_modelMainWindow,
00257 xTheta,
00258 yRadius);
00259
00260
00261 isXOnly = m_editGraphY->text().isEmpty();
00262
00263 return QPointF (xTheta,
00264 yRadius);
00265 }
00266
00267 void DlgEditPointAxis::slotTextChanged (const QString &)
00268 {
00269 updateControls ();
00270 }
00271
00272 QString DlgEditPointAxis::unitsType (bool isXTheta) const
00273 {
00274 if (isCartesian ()) {
00275 if (isXTheta) {
00276 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.coordUnitsX());
00277 } else {
00278 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.coordUnitsY());
00279 }
00280 } else {
00281 if (isXTheta) {
00282 return coordUnitsPolarThetaToBriefType (m_modelCoords.coordUnitsTheta());
00283 } else {
00284 return coordUnitsNonPolarThetaToBriefType (m_modelCoords.coordUnitsRadius());
00285 }
00286 }
00287 }
00288
00289 void DlgEditPointAxis::updateControls ()
00290 {
00291 QString textX = m_editGraphX->text();
00292 QString textY = m_editGraphY->text();
00293
00294 int posX, posY;
00295
00296 if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4) {
00297
00298 bool gotX = (!textX.isEmpty() &&
00299 (m_validatorGraphX->validate(textX, posX) == QValidator::Acceptable));
00300 bool gotY = (!textY.isEmpty() &&
00301 (m_validatorGraphY->validate(textY, posY) == QValidator::Acceptable));
00302
00303
00304 m_btnOk->setEnabled ((textX.isEmpty() && gotY) ||
00305 (textY.isEmpty() && gotX));
00306
00307 } else {
00308
00309
00310 m_btnOk->setEnabled (!textX.isEmpty () &&
00311 !textY.isEmpty () &&
00312 (m_validatorGraphX->validate(textX, posX) == QValidator::Acceptable) &&
00313 (m_validatorGraphY->validate(textY, posY) == QValidator::Acceptable));
00314
00315 }
00316 }