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