7 #include "CallbackBoundingRects.h" 8 #include "CmdMediator.h" 9 #include "CmdSettingsCoords.h" 10 #include "CoordUnitsDate.h" 11 #include "CoordUnitsTime.h" 12 #include "DlgSettingsCoords.h" 13 #include "DlgValidatorAbstract.h" 14 #include "DlgValidatorFactory.h" 15 #include "DocumentModelCoords.h" 16 #include "EngaugeAssert.h" 18 #include "MainWindow.h" 22 #include <QDoubleValidator> 23 #include <QGraphicsRectItem> 24 #include <QGridLayout> 26 #include <QGraphicsScene> 30 #include <QRadioButton> 31 #include <QStackedWidget> 32 #include <QVBoxLayout> 33 #include "Transformation.h" 34 #include "ViewPreview.h" 36 const QString OVERRIDDEN_VALUE(
"");
38 const int COLUMN_0 = 0;
39 const int COLUMN_1 = 1;
41 const int STEPS_PER_CYCLE = 4;
42 const int STEPS_CYCLE_COUNT = 4;
43 const int NUM_COORD_STEPS = 1 + STEPS_PER_CYCLE * STEPS_CYCLE_COUNT;
45 const int MAX_WIDTH_EDIT_ORIGIN_RADIUS = 140;
47 const int CARTESIAN_COORD_MAX = 100;
48 const int CARTESIAN_COORD_MIN = -100;
49 const double CARTESIAN_COORD_STEP = (CARTESIAN_COORD_MAX - CARTESIAN_COORD_MIN) / (NUM_COORD_STEPS - 1.0);
51 const int POLAR_RADIUS = CARTESIAN_COORD_MAX;
52 const double POLAR_STEP = POLAR_RADIUS / (NUM_COORD_STEPS - 1.0);
54 const int POLAR_THETA_MAX = 360;
55 const int POLAR_THETA_MIN = 0;
56 const double POLAR_THETA_STEP = (POLAR_THETA_MAX - POLAR_THETA_MIN) / (NUM_COORD_STEPS - 1.0);
58 const double XCENTER = (CARTESIAN_COORD_MIN + CARTESIAN_COORD_MAX) / 2.0;
59 const double YCENTER = (CARTESIAN_COORD_MIN + CARTESIAN_COORD_MAX) / 2.0;
61 const double LINE_WIDTH_THIN = 0.0;
62 const double LINE_WIDTH_THICK = 2.0;
64 const double PI = 3.1415926535;
65 const double DEG_2_RAD = PI / 180.0;
67 const int FONT_SIZE = 6;
69 const double POWER_FOR_LOG = 10.0;
71 const int MINIMUM_DIALOG_WIDTH_COORDS = 800;
72 const int MINIMUM_HEIGHT = 540;
80 m_validatorOriginRadius (0),
85 m_modelCoordsBefore (0),
86 m_modelCoordsAfter (0)
88 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::DlgSettingsCoords";
92 MINIMUM_DIALOG_WIDTH_COORDS);
95 DlgSettingsCoords::~DlgSettingsCoords()
97 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::~DlgSettingsCoords";
100 void DlgSettingsCoords::annotateAngles (
const QFont &defaultFont) {
103 for (
int direction = 0; direction < 4; direction++) {
106 CoordUnitsPolarTheta thetaUnits = (CoordUnitsPolarTheta) m_cmbXThetaUnits->currentData().toInt();
108 switch (thetaUnits) {
109 case COORD_UNITS_POLAR_THETA_DEGREES:
110 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
111 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
112 angle = QString::number (90.0 * direction);
115 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
116 angle = QString::number (90.0 * direction);
117 if (direction == 1) {
119 }
else if (direction == 3) {
124 case COORD_UNITS_POLAR_THETA_GRADIANS:
125 angle = QString::number (100.0 * direction);
128 case COORD_UNITS_POLAR_THETA_RADIANS:
130 static QString radiansUnits [] = {
"0",
"PI / 2",
"PI",
"3 * PI / 2"};
131 ENGAUGE_ASSERT (direction < 4);
132 angle = radiansUnits [direction];
136 case COORD_UNITS_POLAR_THETA_TURNS:
138 static QString turnsUnits [] = {
"0",
"1 / 4",
"1 / 2",
"3 / 4"};
139 ENGAUGE_ASSERT (direction < 4);
140 angle = turnsUnits [direction];
148 QGraphicsTextItem *textAngle = m_scenePreview->addText (angle);
149 textAngle->setFont (QFont (defaultFont.defaultFamily(), FONT_SIZE));
153 x = CARTESIAN_COORD_MAX - textAngle->boundingRect().width ();
157 x = XCENTER - textAngle->boundingRect().width () / 2.0;
160 x = CARTESIAN_COORD_MIN;
169 y = CARTESIAN_COORD_MIN;
172 y = CARTESIAN_COORD_MAX - textAngle->boundingRect().height ();
176 textAngle->setPos (x, y);
180 void DlgSettingsCoords::annotateRadiusAtOrigin(
const QFont &defaultFont) {
182 QGraphicsTextItem *textRadius = m_scenePreview->addText (m_editOriginRadius->text());
183 textRadius->setFont (QFont (defaultFont.defaultFamily(), FONT_SIZE));
184 textRadius->setPos (XCENTER - textRadius->boundingRect().width () / 2.0,
188 void DlgSettingsCoords::boundingRectGraph (
CmdMediator &cmdMediator,
190 QPointF &boundingRectGraphMin,
191 QPointF &boundingRectGraphMax)
const 196 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
209 boundingRectGraphMin = ftor.boundingRectGraphMin (isEmpty);
210 boundingRectGraphMax = ftor.boundingRectGraphMax (isEmpty);
213 void DlgSettingsCoords::createDateTime (QGridLayout *layout,
216 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createDateTime";
218 QLabel *label =
new QLabel(QString (
"%1:").arg (tr (
"Date/Time")));
219 layout->addWidget (label, row, 1);
221 QWidget *widgetCombos =
new QWidget;
222 layout->addWidget (widgetCombos, row++, 2);
223 QHBoxLayout *layoutCombos =
new QHBoxLayout;
224 widgetCombos->setLayout (layoutCombos);
227 m_cmbDate =
new QComboBox;
228 m_cmbDate->setWhatsThis (tr (
"Date format to be used for date values, and date portion of mixed date/time values, " 229 "during input and output.\n\n" 230 "Setting the format to an empty value results in just the time portion appearing in output."));
231 connect (m_cmbDate, SIGNAL (activated (
const QString &)),
this, SLOT (slotDate (
const QString &)));
232 layoutCombos->addWidget (m_cmbDate);
234 m_cmbTime =
new QComboBox;
235 m_cmbTime->setWhatsThis (tr (
"Time format to be used for time values, and time portion of mixed date/time values, " 236 "during input and output.\n\n" 237 "Setting the format to an empty value results in just the date portion appearing in output."));
238 connect (m_cmbTime, SIGNAL (activated (
const QString &)),
this, SLOT (slotTime (
const QString &)));
239 layoutCombos->addWidget (m_cmbTime);
242 void DlgSettingsCoords::createGroupCoordsType (QGridLayout *layout,
245 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createGroupCoordsType";
247 m_boxCoordsType =
new QGroupBox(tr (
"Coordinates Types"));
248 layout->addWidget (m_boxCoordsType, row++, 1, 1, 2);
250 QVBoxLayout *layoutGroup =
new QVBoxLayout (m_boxCoordsType);
252 QString polarButtonText = QString(tr (
"Polar") +
" (") + THETA + QString(
", " + tr (
"R") +
")");
254 m_btnCartesian =
new QRadioButton (tr (
"Cartesian (X, Y)"), m_boxCoordsType);
255 m_btnCartesian->setWhatsThis (QString(tr(
"Select cartesian coordinates.\n\n" 256 "The X and Y coordinates will be used")));
257 connect (m_btnCartesian, SIGNAL (toggled(
bool)),
this, SLOT (slotCartesianPolar (
bool)));
258 layoutGroup->addWidget (m_btnCartesian);
260 m_btnPolar =
new QRadioButton (polarButtonText, m_boxCoordsType);
261 m_btnPolar->setWhatsThis (QString(tr(
"Select polar coordinates.\n\n" 262 "The Theta and R coordinates will be used.\n\n" 263 "Polar coordinates are not allowed with log scale for Theta")));
264 connect (m_btnPolar, SIGNAL (toggled(
bool)),
this, SLOT (slotCartesianPolar (
bool)));
265 layoutGroup->addWidget (m_btnPolar);
268 void DlgSettingsCoords::createGroupXTheta (QGridLayout *layout,
271 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createGroupXTheta";
273 m_boxXTheta =
new QGroupBox(OVERRIDDEN_VALUE);
274 layout->addWidget (m_boxXTheta, row, 1, 1, 1);
276 QGridLayout *layoutXTheta =
new QGridLayout (m_boxXTheta);
277 m_boxXTheta->setLayout (layoutXTheta);
280 QLabel *labelScale =
new QLabel (QString (
"%1:").arg (tr (
"Scale")));
281 layoutXTheta->addWidget (labelScale, rowGroup++, COLUMN_0);
283 m_xThetaLinear =
new QRadioButton (tr (
"Linear"), m_boxXTheta);
284 m_xThetaLinear->setWhatsThis (QString(tr(
"Specifies linear scale for the X or Theta coordinate")));
285 connect (m_xThetaLinear, SIGNAL (released ()),
this, SLOT (slotXThetaLinear()));
286 layoutXTheta->addWidget (m_xThetaLinear, rowGroup++, COLUMN_0);
288 m_xThetaLog =
new QRadioButton (tr (
"Log"), m_boxXTheta);
289 m_xThetaLog->setWhatsThis (QString(tr(
"Specifies logarithmic scale for the X or Theta coordinate.\n\n" 290 "Log scale is not allowed if there are negative coordinates.\n\n" 291 "Log scale is not allowed for the Theta coordinate.")));
292 connect (m_xThetaLog, SIGNAL (released ()),
this, SLOT (slotXThetaLog()));
293 layoutXTheta->addWidget (m_xThetaLog, rowGroup++, COLUMN_0);
295 QLabel *labelThetaUnits =
new QLabel(QString (
"%1:").arg (tr (
"Units")));
296 layoutXTheta->addWidget (labelThetaUnits, rowGroup++, COLUMN_0);
298 m_cmbXThetaUnits =
new QComboBox;
299 connect (m_cmbXThetaUnits, SIGNAL (activated (
const QString &)),
this, SLOT (slotUnitsXTheta(
const QString &)));
300 layoutXTheta->addWidget (m_cmbXThetaUnits, rowGroup++, COLUMN_0, 1, 2);
303 void DlgSettingsCoords::createGroupYRadius (QGridLayout *layout,
306 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createGroupYRadius";
308 m_boxYRadius =
new QGroupBox (OVERRIDDEN_VALUE);
309 layout->addWidget (m_boxYRadius, row++, 2, 1, 1);
311 QGridLayout *layoutYRadius =
new QGridLayout (m_boxYRadius);
312 m_boxYRadius->setLayout (layoutYRadius);
315 QLabel *labelScale =
new QLabel (QString (
"%1:").arg (tr (
"Scale")));
316 layoutYRadius->addWidget (labelScale, rowGroup++, COLUMN_0);
318 m_yRadiusLinear =
new QRadioButton (tr (
"Linear"), m_boxYRadius);
319 m_yRadiusLinear->setWhatsThis (QString(tr(
"Specifies linear scale for the Y or R coordinate")));
320 connect (m_yRadiusLinear, SIGNAL(released()),
this, SLOT (slotYRadiusLinear()));
321 layoutYRadius->addWidget (m_yRadiusLinear, rowGroup, COLUMN_0);
323 QLabel *labelOriginRadius =
new QLabel(QString (
"%1:").arg (tr (
"Origin radius value")));
324 layoutYRadius->addWidget (labelOriginRadius, rowGroup++, COLUMN_1);
326 m_yRadiusLog =
new QRadioButton (tr (
"Log"), m_boxYRadius);
327 m_yRadiusLog->setWhatsThis (QString(tr(
"Specifies logarithmic scale for the Y or R coordinate\n\n" 328 "Log scale is not allowed if there are negative coordinates.")));
329 connect (m_yRadiusLog, SIGNAL(released ()),
this, SLOT (slotYRadiusLog ()));
330 layoutYRadius->addWidget (m_yRadiusLog, rowGroup, COLUMN_0);
332 m_editOriginRadius =
new QLineEdit (m_boxYRadius);
333 m_editOriginRadius->setMaximumWidth (MAX_WIDTH_EDIT_ORIGIN_RADIUS);
334 m_editOriginRadius->setWhatsThis (QString(tr(
"Specify radius value at origin.\n\n" 335 "Normally the radius at the origin is 0, but a nonzero value may be applied in other cases " 336 "(like when the radial units are decibels).")));
337 connect (m_editOriginRadius, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotPolarOriginRadius(
const QString &)));
338 layoutYRadius->addWidget (m_editOriginRadius, rowGroup++, COLUMN_1);
340 QLabel *labelUnits =
new QLabel(QString (
"%1:").arg (tr (
"Units")));
341 layoutYRadius->addWidget (labelUnits, rowGroup++, COLUMN_0);
343 m_cmbYRadiusUnits =
new QComboBox;
344 connect (m_cmbYRadiusUnits, SIGNAL (activated (
const QString &)),
this, SLOT (slotUnitsYRadius(
const QString &)));
345 layoutYRadius->addWidget (m_cmbYRadiusUnits, rowGroup++, COLUMN_0, 1, 2);
352 void DlgSettingsCoords::createPreview (QGridLayout *layout,
355 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createPreview";
357 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
358 layout->addWidget (labelPreview, row++, 0, 1, 4);
360 m_scenePreview =
new QGraphicsScene (
this);
362 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
364 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the coordinate system."));
365 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
366 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
369 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
374 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createSubPanel";
376 QWidget *subPanel =
new QWidget ();
378 QGridLayout *layout =
new QGridLayout (subPanel);
379 subPanel->setLayout (layout);
381 layout->setColumnStretch(0, 1);
382 layout->setColumnStretch(1, 0);
383 layout->setColumnStretch(2, 0);
384 layout->setColumnStretch(3, 1);
387 createGroupCoordsType(layout, row);
388 createGroupXTheta (layout, row);
389 createGroupYRadius (layout, row);
390 createDateTime (layout, row);
391 createPreview (layout, row);
396 void DlgSettingsCoords::drawCartesianLinearX ()
398 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLinearX";
401 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
402 double x = CARTESIAN_COORD_MIN + step * CARTESIAN_COORD_STEP;
403 QGraphicsLineItem *line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
404 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
405 line->setPen(QPen (QBrush ((isHighlighted ? Qt::gray : Qt::lightGray)),
407 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
409 line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
410 line->setPen(QPen (QBrush (Qt::black),
417 void DlgSettingsCoords::drawCartesianLinearY ()
419 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLinearY";
422 for (
int step = NUM_COORD_STEPS - 1; step >= 0; step--) {
423 double y = CARTESIAN_COORD_MIN + step * CARTESIAN_COORD_STEP;
424 QGraphicsLineItem *line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
425 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
426 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
428 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
430 line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
431 line->setPen(QPen (QBrush (Qt::black),
438 void DlgSettingsCoords::drawCartesianLogX ()
440 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLogX";
443 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
444 double s = (exp (step / (NUM_COORD_STEPS - 1.0)) - 1.0) /
446 double x = (1.0 - s) * CARTESIAN_COORD_MIN + s * CARTESIAN_COORD_MAX;
447 QGraphicsLineItem *line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
448 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
449 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
451 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
453 line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
454 line->setPen(QPen (QBrush (Qt::black),
461 void DlgSettingsCoords::drawCartesianLogY ()
463 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLogY";
466 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
467 double s = (pow (POWER_FOR_LOG, step / (NUM_COORD_STEPS - 1.0)) - 1.0) /
468 (pow (POWER_FOR_LOG, 1.0) - 1.0);
469 double y = (1.0 - s) * CARTESIAN_COORD_MAX + s * CARTESIAN_COORD_MIN;
470 QGraphicsLineItem *line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
471 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
472 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
474 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
476 line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
477 line->setPen(QPen (QBrush (Qt::black),
484 void DlgSettingsCoords::drawPolarLinearRadius ()
486 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawPolarLinearRadius";
488 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
489 double radius = step * POLAR_STEP;
490 QGraphicsEllipseItem *line = m_scenePreview->addEllipse (XCENTER - radius,
494 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
495 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
497 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
501 void DlgSettingsCoords::drawPolarLogRadius ()
503 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawPolarLogRadius";
505 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
506 double s = (pow (POWER_FOR_LOG, step / (NUM_COORD_STEPS - 1.0)) - 1.0) /
507 (pow (POWER_FOR_LOG, 1.0) - 1.0);
508 double radius = (s * (NUM_COORD_STEPS - 1.0)) * POLAR_STEP;
509 QGraphicsEllipseItem *line = m_scenePreview->addEllipse (XCENTER - radius,
513 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
514 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
516 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
520 void DlgSettingsCoords::drawPolarTheta ()
522 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawPolarTheta";
525 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
526 double theta = POLAR_THETA_MIN + step * POLAR_THETA_STEP;
527 double x = POLAR_RADIUS * cos (theta * DEG_2_RAD);
528 double y = POLAR_RADIUS * sin (theta * DEG_2_RAD);
529 QGraphicsLineItem *line = m_scenePreview->addLine (XCENTER, YCENTER, XCENTER + x, YCENTER + y);
530 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
531 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
533 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
535 line = m_scenePreview->addLine (XCENTER, YCENTER, XCENTER + x, YCENTER + y);
536 line->setPen(QPen (QBrush (Qt::black),
545 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::handleOk";
549 *m_modelCoordsBefore,
550 *m_modelCoordsAfter);
558 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::load";
564 QPointF boundingRectGraphMin, boundingRectGraphMax;
567 boundingRectGraphMin,
568 boundingRectGraphMax);
569 bool xThetaGoesNegative = !isEmpty && (boundingRectGraphMin.x() <= 0);
570 bool yRGoesNegative = !isEmpty && (boundingRectGraphMin.y() <= 0);
571 m_xThetaLinear->setEnabled (!xThetaGoesNegative);
572 m_xThetaLog->setEnabled (!xThetaGoesNegative);
573 m_yRadiusLinear->setEnabled (!yRGoesNegative);
574 m_yRadiusLog->setEnabled (!yRGoesNegative);
577 delete m_modelCoordsBefore;
578 delete m_modelCoordsAfter;
586 m_validatorOriginRadius = dlgValidatorFactory.createWithNonPolar (m_modelCoordsAfter->
coordScaleYRadius(),
591 m_editOriginRadius->setValidator (m_validatorOriginRadius);
592 m_editOriginRadius->setText (QString::number (m_modelCoordsAfter->
originRadius ()));
594 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
595 m_btnCartesian->setChecked (
true);
597 m_btnPolar->setChecked (
true);
604 m_xThetaLinear->setChecked (m_modelCoordsAfter->
coordScaleXTheta() == COORD_SCALE_LINEAR);
605 m_xThetaLog->setChecked (m_modelCoordsAfter->
coordScaleXTheta() == COORD_SCALE_LOG);
606 m_yRadiusLinear->setChecked (m_modelCoordsAfter->
coordScaleYRadius() == COORD_SCALE_LINEAR);
607 m_yRadiusLog->setChecked (m_modelCoordsAfter->
coordScaleYRadius() == COORD_SCALE_LOG);
614 void DlgSettingsCoords::loadComboBoxDate()
616 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxDate";
620 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_SKIP),
621 QVariant (COORD_UNITS_DATE_SKIP));
622 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_MONTH_DAY_YEAR),
623 QVariant (COORD_UNITS_DATE_MONTH_DAY_YEAR));
624 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_DAY_MONTH_YEAR),
625 QVariant (COORD_UNITS_DATE_DAY_MONTH_YEAR));
626 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_YEAR_MONTH_DAY),
627 QVariant (COORD_UNITS_DATE_YEAR_MONTH_DAY));
629 ENGAUGE_ASSERT (m_cmbDate->count() == NUM_COORD_UNITS_DATE);
631 int index = m_cmbDate->findData (QVariant (m_modelCoordsAfter->
coordUnitsDate()));
632 m_cmbDate->setCurrentIndex (index);
635 void DlgSettingsCoords::loadComboBoxTime()
637 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxTime";
641 m_cmbTime->addItem (coordUnitsTimeToString (COORD_UNITS_TIME_SKIP),
642 QVariant (COORD_UNITS_TIME_SKIP));
643 m_cmbTime->addItem (coordUnitsTimeToString (COORD_UNITS_TIME_HOUR_MINUTE),
644 QVariant (COORD_UNITS_TIME_HOUR_MINUTE));
645 m_cmbTime->addItem (coordUnitsTimeToString (COORD_UNITS_TIME_HOUR_MINUTE_SECOND),
646 QVariant (COORD_UNITS_TIME_HOUR_MINUTE_SECOND));
648 ENGAUGE_ASSERT (m_cmbTime->count() == NUM_COORD_UNITS_TIME);
650 int index = m_cmbTime->findData (QVariant (m_modelCoordsAfter->
coordUnitsTime()));
651 m_cmbTime->setCurrentIndex (index);
654 void DlgSettingsCoords::loadComboBoxUnitsNonPolar (QComboBox &cmb,
655 CoordUnitsNonPolarTheta coordUnits)
657 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxUnitsNonPolar";
661 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_NUMBER),
662 QVariant (COORD_UNITS_NON_POLAR_THETA_NUMBER));
663 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_DATE_TIME),
664 QVariant (COORD_UNITS_NON_POLAR_THETA_DATE_TIME));
665 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS),
666 QVariant (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS));
667 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW),
668 QVariant (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW));
670 ENGAUGE_ASSERT (cmb.count() == NUM_COORD_UNITS_NON_POLAR_THETA);
672 cmb.setWhatsThis (QString (tr (
"Numbers have the simplest and most general format.\n\n" 673 "Date and time values have date and/or time components.\n\n" 674 "Degrees Minutes Seconds (DDD MM SS.S) format uses two integer number for degrees and minutes, and a real number for " 675 "seconds. There are 60 seconds per minute. During input, spaces must be inserted between the three numbers.")));
677 int index = cmb.findData (coordUnits);
678 cmb.setCurrentIndex (index);
681 void DlgSettingsCoords::loadComboBoxUnitsPolar (QComboBox &cmb,
682 CoordUnitsPolarTheta coordUnits)
684 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxUnitsPolar";
688 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES),
689 QVariant (COORD_UNITS_POLAR_THETA_DEGREES));
690 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES),
691 QVariant (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES));
692 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS),
693 QVariant (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS));
694 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW),
695 QVariant (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW));
696 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_GRADIANS),
697 QVariant (COORD_UNITS_POLAR_THETA_GRADIANS));
698 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_RADIANS),
699 QVariant (COORD_UNITS_POLAR_THETA_RADIANS));
700 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_TURNS),
701 QVariant (COORD_UNITS_POLAR_THETA_TURNS));
703 ENGAUGE_ASSERT (cmb.count() == NUM_COORD_UNITS_POLAR_THETA);
705 cmb.setWhatsThis (QString (tr (
"Degrees (DDD.DDDDD) format uses a single real number. One complete revolution is 360 degrees.\n\n" 706 "Degrees Minutes (DDD MM.MMM) format uses one integer number for degrees, and a real number for minutes. There are " 707 "60 minutes per degree. During input, a space must be inserted between the two numbers.\n\n" 708 "Degrees Minutes Seconds (DDD MM SS.S) format uses two integer number for degrees and minutes, and a real number for " 709 "seconds. There are 60 seconds per minute. During input, spaces must be inserted between the three numbers.\n\n" 710 "Gradians format uses a single real number. One complete revolution is 400 gradians.\n\n" 711 "Radians format uses a single real number. One complete revolution is 2*pi radians.\n\n" 712 "Turns format uses a single real number. One complete revolution is one turn.")));
714 int index = cmb.findData (coordUnits);
715 cmb.setCurrentIndex (index);
718 void DlgSettingsCoords::resetSceneRectangle ()
720 QRect rect (CARTESIAN_COORD_MIN - CARTESIAN_COORD_STEP / 2.0,
721 CARTESIAN_COORD_MIN - CARTESIAN_COORD_STEP / 2.0,
722 CARTESIAN_COORD_MAX - CARTESIAN_COORD_MIN + CARTESIAN_COORD_STEP,
723 CARTESIAN_COORD_MAX - CARTESIAN_COORD_MIN + CARTESIAN_COORD_STEP);
725 QGraphicsRectItem *itemPerimeter =
new QGraphicsRectItem(rect);
726 itemPerimeter->setVisible(
false);
727 m_scenePreview->addItem (itemPerimeter);
728 m_viewPreview->centerOn (QPointF (0.0, 0.0));
734 setMinimumHeight (MINIMUM_HEIGHT);
738 void DlgSettingsCoords::slotCartesianPolar (
bool)
740 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotCartesian";
742 if (m_btnCartesian->isChecked ()) {
752 void DlgSettingsCoords::slotDate(
const QString &)
754 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotDate";
756 CoordUnitsDate coordUnits = (CoordUnitsDate) m_cmbDate->currentData ().toInt();
762 void DlgSettingsCoords::slotPolarOriginRadius(
const QString &)
764 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotPolarOriginRadius";
766 QString numberText = m_editOriginRadius->text();
773 void DlgSettingsCoords::slotTime(
const QString &)
775 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotTime";
777 CoordUnitsTime coordUnits = (CoordUnitsTime) m_cmbTime->currentData ().toInt();
783 void DlgSettingsCoords::slotUnitsXTheta(
const QString &)
785 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotUnitsXTheta";
787 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
788 CoordUnitsNonPolarTheta coordUnits = (CoordUnitsNonPolarTheta) m_cmbXThetaUnits->currentData ().toInt ();
791 CoordUnitsPolarTheta coordUnits = (CoordUnitsPolarTheta) m_cmbXThetaUnits->currentData ().toInt ();
798 void DlgSettingsCoords::slotUnitsYRadius(
const QString &)
800 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotUnitsYRadius";
802 CoordUnitsNonPolarTheta coordUnits = (CoordUnitsNonPolarTheta) m_cmbYRadiusUnits->currentData ().toInt ();
803 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
812 void DlgSettingsCoords::slotXThetaLinear()
814 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotXThetaLinear";
821 void DlgSettingsCoords::slotXThetaLog()
823 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotXThetaLog";
830 void DlgSettingsCoords::slotYRadiusLinear()
832 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotYRadiusLinear";
834 delete m_validatorOriginRadius;
842 m_editOriginRadius->setValidator (m_validatorOriginRadius);
849 void DlgSettingsCoords::slotYRadiusLog()
851 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotYRadiusLog";
853 delete m_validatorOriginRadius;
861 m_editOriginRadius->setValidator (m_validatorOriginRadius);
868 void DlgSettingsCoords::updateControls ()
872 QString textOriginRadius = m_editOriginRadius->text();
873 int posOriginRadius = 0;
875 bool goodOriginRadius =
true;
876 if (m_editOriginRadius->isEnabled ()) {
879 goodOriginRadius = (m_validatorOriginRadius->
validate (textOriginRadius,
880 posOriginRadius) == QValidator::Acceptable);
885 m_boxCoordsType->setEnabled (!m_xThetaLog->isChecked ());
887 m_xThetaLinear->setEnabled (!m_btnPolar->isChecked ());
888 m_xThetaLog->setEnabled (!m_btnPolar->isChecked ());
889 if (m_btnCartesian->isChecked()) {
890 m_yRadiusLinear->setEnabled (
true);
891 m_yRadiusLog->setEnabled (
true);
901 int posOriginRadiusOther;
902 bool goodOriginRadiusOther = (dlg->
validate (textOriginRadius, posOriginRadiusOther) == QValidator::Acceptable);
906 m_yRadiusLinear->setEnabled (goodOriginRadius && goodOriginRadiusOther);
907 m_yRadiusLog->setEnabled (goodOriginRadius && goodOriginRadiusOther);
909 m_editOriginRadius->setEnabled (m_btnPolar->isChecked ());
911 QString captionXTheta = (m_btnCartesian->isChecked () ?
913 THETA) + QString (
" %1")
914 .arg (tr (
"Coordinates"));
915 QString captionYRadius = (m_btnCartesian->isChecked () ?
917 QString (tr (
"R"))) + QString (
" %1")
918 .arg (tr (
"Coordinates"));
920 if (m_boxXTheta->title() != captionXTheta) {
921 m_boxXTheta->setTitle (captionXTheta);
924 if (m_boxYRadius->title () != captionYRadius) {
925 m_boxYRadius->setTitle (captionYRadius);
929 if (m_btnCartesian->isChecked()) {
930 enableDateTime = (((CoordUnitsNonPolarTheta) m_cmbXThetaUnits->currentData ().toInt() == COORD_UNITS_NON_POLAR_THETA_DATE_TIME) ||
931 ((CoordUnitsNonPolarTheta) m_cmbYRadiusUnits->currentData ().toInt() == COORD_UNITS_NON_POLAR_THETA_DATE_TIME));
933 enableDateTime = ((CoordUnitsNonPolarTheta) m_cmbYRadiusUnits->currentData ().toInt() == COORD_UNITS_NON_POLAR_THETA_DATE_TIME);
935 m_cmbDate->setEnabled (enableDateTime);
936 m_cmbTime->setEnabled (enableDateTime);
938 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::updateControls" 939 <<
" textOriginRadius=" << textOriginRadius.toLatin1().data()
940 <<
" goodOriginRadius=" << (goodOriginRadius ?
"true" :
"false")
941 <<
" originRadius=" << posOriginRadius
942 <<
" btnPolarChecked=" << (m_btnPolar->isChecked() ?
"true" :
"false")
943 <<
" enableDateTime=" << (enableDateTime ?
"true" :
"false");
946 void DlgSettingsCoords::updateCoordUnits()
949 if (m_btnCartesian->isChecked()) {
950 loadComboBoxUnitsNonPolar (*m_cmbXThetaUnits,
952 loadComboBoxUnitsNonPolar (*m_cmbYRadiusUnits,
955 loadComboBoxUnitsPolar (*m_cmbXThetaUnits,
957 loadComboBoxUnitsNonPolar (*m_cmbYRadiusUnits,
962 void DlgSettingsCoords::updatePreview()
964 m_scenePreview->clear();
972 if (m_btnCartesian->isChecked()) {
975 if (m_xThetaLinear->isChecked()) {
976 drawCartesianLinearX ();
978 drawCartesianLogX ();
981 if (m_yRadiusLinear->isChecked()) {
982 drawCartesianLinearY ();
984 drawCartesianLogY ();
991 if (m_yRadiusLinear->isChecked()) {
992 drawPolarLinearRadius ();
994 drawPolarLogRadius ();
998 annotateRadiusAtOrigin (defaultFont);
999 annotateAngles (defaultFont);
1002 resetSceneRectangle();
void setCoordUnitsTime(CoordUnitsTime coordUnits)
Set method for time units.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
void setCoordUnitsDate(CoordUnitsDate coordUnits)
Set method for date units.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
void setCoordUnitsY(CoordUnitsNonPolarTheta coordUnits)
Set method for y units.
void setCoordUnitsX(CoordUnitsNonPolarTheta coordUnits)
Set method for x units.
DlgValidatorAbstract * createWithNonPolar(CoordScale coordScale, CoordUnitsNonPolarTheta coordUnits, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime, const QLocale &locale) const
Factory method for generating validators when cartesian/polar case handling is handled externally...
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
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.
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.
Abstract validator for all numeric formats.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
Transformation transformation() const
Return read-only copy of transformation.
Command for DlgSettingsCoords.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
CoordUnitsTime coordUnitsTime() const
Get method for time format when used.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
void setCoordUnitsTheta(CoordUnitsPolarTheta coordUnits)
Set method for theta units.
CoordUnitsDate coordUnitsDate() const
Get method for date format when used.
Model for DlgSettingsCoords and CmdSettingsCoords.
void setOriginRadius(double originRadius)
Set method for origin radius in polar mode.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
void setCoordUnitsRadius(CoordUnitsNonPolarTheta coordUnits)
Set method for radius units.
MainWindowModel modelMainWindow() const
Get method for main window model.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
QLocale locale() const
Get method for locale.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
CoordsType coordsType() const
Get method for coordinates type.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
Abstract base class for all Settings dialogs.
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
double originRadius() const
Get method for origin radius in polar mode.
Callback for computing the bounding rectangles of the screen and graph coordinates of the points in t...
MainWindow & mainWindow()
Get method for MainWindow.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
virtual void handleOk()
Process slotOk.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.
DlgSettingsCoords(MainWindow &mainWindow)
Single constructor.
void setCoordsType(CoordsType coordsType)
Set method for coordinates type.