1 #include "CallbackBoundingRects.h"
2 #include "CmdMediator.h"
3 #include "CmdSettingsCoords.h"
4 #include "CoordUnitsDate.h"
5 #include "CoordUnitsTime.h"
6 #include "DlgSettingsCoords.h"
7 #include "DlgValidatorAbstract.h"
8 #include "DlgValidatorFactory.h"
9 #include "DocumentModelCoords.h"
10 #include "EngaugeAssert.h"
12 #include "MainWindow.h"
16 #include <QDoubleValidator>
17 #include <QGraphicsRectItem>
18 #include <QGridLayout>
20 #include <QGraphicsScene>
24 #include <QRadioButton>
25 #include <QStackedWidget>
26 #include <QVBoxLayout>
27 #include "Transformation.h"
28 #include "ViewPreview.h"
30 const QString OVERRIDDEN_VALUE(
"");
32 const int COLUMN_0 = 0;
33 const int COLUMN_1 = 1;
35 const int STEPS_PER_CYCLE = 4;
36 const int STEPS_CYCLE_COUNT = 4;
37 const int NUM_COORD_STEPS = 1 + STEPS_PER_CYCLE * STEPS_CYCLE_COUNT;
39 const int MAX_WIDTH_EDIT_ORIGIN_RADIUS = 140;
41 const int CARTESIAN_COORD_MAX = 100;
42 const int CARTESIAN_COORD_MIN = -100;
43 const double CARTESIAN_COORD_STEP = (CARTESIAN_COORD_MAX - CARTESIAN_COORD_MIN) / (NUM_COORD_STEPS - 1.0);
45 const int POLAR_RADIUS = CARTESIAN_COORD_MAX;
46 const double POLAR_STEP = POLAR_RADIUS / (NUM_COORD_STEPS - 1.0);
48 const int POLAR_THETA_MAX = 360;
49 const int POLAR_THETA_MIN = 0;
50 const double POLAR_THETA_STEP = (POLAR_THETA_MAX - POLAR_THETA_MIN) / (NUM_COORD_STEPS - 1.0);
52 const double XCENTER = (CARTESIAN_COORD_MIN + CARTESIAN_COORD_MAX) / 2.0;
53 const double YCENTER = (CARTESIAN_COORD_MIN + CARTESIAN_COORD_MAX) / 2.0;
55 const double LINE_WIDTH_THIN = 0.0;
56 const double LINE_WIDTH_THICK = 2.0;
58 const double PI = 3.1415926535;
59 const double DEG_2_RAD = PI / 180.0;
61 const int FONT_SIZE = 6;
63 const double POWER_FOR_LOG = 10.0;
71 m_validatorOriginRadius (0),
76 m_modelCoordsBefore (0),
77 m_modelCoordsAfter (0)
79 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::DlgSettingsCoords";
85 DlgSettingsCoords::~DlgSettingsCoords()
87 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::~DlgSettingsCoords";
90 void DlgSettingsCoords::annotateAngles (
const QFont &defaultFont) {
93 for (
int direction = 0; direction < 4; direction++) {
96 CoordUnitsPolarTheta thetaUnits = (CoordUnitsPolarTheta) m_cmbXThetaUnits->currentData().toInt();
99 case COORD_UNITS_POLAR_THETA_DEGREES:
100 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
101 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
102 angle = QString::number (90.0 * direction);
105 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
106 angle = QString::number (90.0 * direction);
107 if (direction == 1) {
109 }
else if (direction == 3) {
114 case COORD_UNITS_POLAR_THETA_GRADIANS:
115 angle = QString::number (100.0 * direction);
118 case COORD_UNITS_POLAR_THETA_RADIANS:
120 static QString radiansUnits [] = {
"0",
"PI / 2",
"PI",
"3 * PI / 2"};
121 ENGAUGE_ASSERT (direction < 4);
122 angle = radiansUnits [direction];
126 case COORD_UNITS_POLAR_THETA_TURNS:
128 static QString turnsUnits [] = {
"0",
"1 / 4",
"1 / 2",
"3 / 4"};
129 ENGAUGE_ASSERT (direction < 4);
130 angle = turnsUnits [direction];
138 QGraphicsTextItem *textAngle = m_scenePreview->addText (angle);
139 textAngle->setFont (QFont (defaultFont.defaultFamily(), FONT_SIZE));
143 x = CARTESIAN_COORD_MAX - textAngle->boundingRect().width ();
147 x = XCENTER - textAngle->boundingRect().width () / 2.0;
150 x = CARTESIAN_COORD_MIN;
159 y = CARTESIAN_COORD_MIN;
162 y = CARTESIAN_COORD_MAX - textAngle->boundingRect().height ();
166 textAngle->setPos (x, y);
170 void DlgSettingsCoords::annotateRadiusAtOrigin(
const QFont &defaultFont) {
172 QGraphicsTextItem *textRadius = m_scenePreview->addText (m_editOriginRadius->text());
173 textRadius->setFont (QFont (defaultFont.defaultFamily(), FONT_SIZE));
174 textRadius->setPos (XCENTER - textRadius->boundingRect().width () / 2.0,
178 QRectF DlgSettingsCoords::boundingRectGraph (
CmdMediator &cmdMediator,
183 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
196 return ftor.boundingRectGraph(isEmpty);
199 void DlgSettingsCoords::createDateTime (QGridLayout *layout,
202 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createDateTime";
204 QLabel *label =
new QLabel(
"Date/Time:");
205 layout->addWidget (label, row, 1);
207 QWidget *widgetCombos =
new QWidget;
208 layout->addWidget (widgetCombos, row++, 2);
209 QHBoxLayout *layoutCombos =
new QHBoxLayout;
210 widgetCombos->setLayout (layoutCombos);
213 m_cmbDate =
new QComboBox;
214 m_cmbDate->setWhatsThis (
"Date format to be used for date values, and date portion of mixed date/time values, "
215 "during input and output.\n\n"
216 "Setting the format to an empty value results in just the time portion appearing in output.");
217 connect (m_cmbDate, SIGNAL (activated (
const QString &)),
this, SLOT (slotDate (
const QString &)));
218 layoutCombos->addWidget (m_cmbDate);
220 m_cmbTime =
new QComboBox;
221 m_cmbTime->setWhatsThis (
"Time format to be used for time values, and time portion of mixed date/time values, "
222 "during input and output.\n\n"
223 "Setting the format to an empty value results in just the date portion appearing in output.");
224 connect (m_cmbTime, SIGNAL (activated (
const QString &)),
this, SLOT (slotTime (
const QString &)));
225 layoutCombos->addWidget (m_cmbTime);
228 void DlgSettingsCoords::createGroupCoordsType (QGridLayout *layout,
231 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createGroupCoordsType";
233 m_boxCoordsType =
new QGroupBox(
"Coordinates Types");
234 layout->addWidget (m_boxCoordsType, row++, 1, 1, 2);
236 QVBoxLayout *layoutGroup =
new QVBoxLayout (m_boxCoordsType);
238 QString polarButtonText = QString(
"Polar (") + THETA + QString(
", R)");
240 m_btnCartesian =
new QRadioButton (
"Cartesian (X, Y)", m_boxCoordsType);
241 m_btnCartesian->setWhatsThis (QString(tr(
"Select cartesian coordinates.\n\n"
242 "The X and Y coordinates will be used")));
243 connect (m_btnCartesian, SIGNAL (toggled(
bool)),
this, SLOT (slotCartesianPolar (
bool)));
244 layoutGroup->addWidget (m_btnCartesian);
246 m_btnPolar =
new QRadioButton (polarButtonText, m_boxCoordsType);
247 m_btnPolar->setWhatsThis (QString(tr(
"Select polar coordinates.\n\n"
248 "The Theta and R coordinates will be used.\n\n"
249 "Polar coordinates are not allowed with log scale for Theta")));
250 connect (m_btnPolar, SIGNAL (toggled(
bool)),
this, SLOT (slotCartesianPolar (
bool)));
251 layoutGroup->addWidget (m_btnPolar);
254 void DlgSettingsCoords::createGroupXTheta (QGridLayout *layout,
257 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createGroupXTheta";
259 m_boxXTheta =
new QGroupBox(OVERRIDDEN_VALUE);
260 layout->addWidget (m_boxXTheta, row++, 1, 1, 2);
262 QGridLayout *layoutXTheta =
new QGridLayout (m_boxXTheta);
263 m_boxXTheta->setLayout (layoutXTheta);
266 QLabel *labelScale =
new QLabel (
"Scale:");
267 layoutXTheta->addWidget (labelScale, rowGroup++, COLUMN_0);
269 m_xThetaLinear =
new QRadioButton (
"Linear", m_boxXTheta);
270 m_xThetaLinear->setWhatsThis (QString(tr(
"Specifies linear scale for the X or Theta coordinate")));
271 connect (m_xThetaLinear, SIGNAL (released ()),
this, SLOT (slotXThetaLinear()));
272 layoutXTheta->addWidget (m_xThetaLinear, rowGroup++, COLUMN_0);
274 m_xThetaLog =
new QRadioButton (
"Log", m_boxXTheta);
275 m_xThetaLog->setWhatsThis (QString(tr(
"Specifies logarithmic scale for the X or Theta coordinate.\n\n"
276 "Log scale is not allowed if there are negative coordinates.\n\n"
277 "Log scale is not allowed for the Theta coordinate.")));
278 connect (m_xThetaLog, SIGNAL (released ()),
this, SLOT (slotXThetaLog()));
279 layoutXTheta->addWidget (m_xThetaLog, rowGroup++, COLUMN_0);
281 QLabel *labelThetaUnits =
new QLabel(
"Units:");
282 layoutXTheta->addWidget (labelThetaUnits, rowGroup++, COLUMN_0);
284 m_cmbXThetaUnits =
new QComboBox;
285 connect (m_cmbXThetaUnits, SIGNAL (activated (
const QString &)),
this, SLOT (slotUnitsXTheta(
const QString &)));
286 layoutXTheta->addWidget (m_cmbXThetaUnits, rowGroup++, COLUMN_0, 1, 2);
289 void DlgSettingsCoords::createGroupYRadius (QGridLayout *layout,
292 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createGroupYRadius";
294 m_boxYRadius =
new QGroupBox (OVERRIDDEN_VALUE);
295 layout->addWidget (m_boxYRadius, row++, 1, 1, 2);
297 QGridLayout *layoutYRadius =
new QGridLayout (m_boxYRadius);
298 m_boxYRadius->setLayout (layoutYRadius);
301 QLabel *labelScale =
new QLabel (
"Scale:");
302 layoutYRadius->addWidget (labelScale, rowGroup++, COLUMN_0);
304 m_yRadiusLinear =
new QRadioButton (
"Linear", m_boxYRadius);
305 m_yRadiusLinear->setWhatsThis (QString(tr(
"Specifies linear scale for the Y or R coordinate")));
306 connect (m_yRadiusLinear, SIGNAL(released()),
this, SLOT (slotYRadiusLinear()));
307 layoutYRadius->addWidget (m_yRadiusLinear, rowGroup++, COLUMN_0);
309 m_yRadiusLog =
new QRadioButton (
"Log", m_boxYRadius);
310 m_yRadiusLog->setWhatsThis (QString(tr(
"Specifies logarithmic scale for the Y or R coordinate\n\n"
311 "Log scale is not allowed if there are negative coordinates.")));
312 connect (m_yRadiusLog, SIGNAL(released ()),
this, SLOT (slotYRadiusLog ()));
313 layoutYRadius->addWidget (m_yRadiusLog, rowGroup++, COLUMN_0);
315 QLabel *labelUnits =
new QLabel(
"Units:");
316 layoutYRadius->addWidget (labelUnits, rowGroup++, COLUMN_0);
318 m_cmbYRadiusUnits =
new QComboBox;
319 connect (m_cmbYRadiusUnits, SIGNAL (activated (
const QString &)),
this, SLOT (slotUnitsYRadius(
const QString &)));
320 layoutYRadius->addWidget (m_cmbYRadiusUnits, rowGroup++, COLUMN_0, 1, 2);
323 QLabel *labelOriginRadius =
new QLabel(
"Origin radius value:");
324 layoutYRadius->addWidget (labelOriginRadius, rowGroup++, COLUMN_1);
326 m_editOriginRadius =
new QLineEdit (m_boxYRadius);
327 m_editOriginRadius->setMaximumWidth (MAX_WIDTH_EDIT_ORIGIN_RADIUS);
328 m_editOriginRadius->setWhatsThis (QString(tr(
"Specify radius value at origin.\n\n"
329 "Normally the radius at the origin is 0, but a nonzero value may be applied in other cases "
330 "(like when the radial units are decibels).")));
331 connect (m_editOriginRadius, SIGNAL (textChanged (
const QString &)),
this, SLOT (slotPolarOriginRadius(
const QString &)));
332 layoutYRadius->addWidget (m_editOriginRadius, rowGroup++, COLUMN_1);
335 void DlgSettingsCoords::createPreview (QGridLayout *layout,
338 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createPreview";
340 QLabel *labelPreview =
new QLabel (
"Preview");
341 layout->addWidget (labelPreview, row++, 0, 1, 4);
343 m_scenePreview =
new QGraphicsScene (
this);
344 m_viewPreview =
new ViewPreview (m_scenePreview,
this);
345 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the coordinate system."));
346 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
347 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
350 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
355 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::createSubPanel";
357 QWidget *subPanel =
new QWidget ();
358 QGridLayout *layout =
new QGridLayout (subPanel);
359 subPanel->setLayout (layout);
361 layout->setColumnStretch(0, 1);
362 layout->setColumnStretch(1, 0);
363 layout->setColumnStretch(2, 0);
364 layout->setColumnStretch(3, 1);
367 createGroupCoordsType(layout, row);
368 createGroupXTheta (layout, row);
369 createGroupYRadius (layout, row);
370 createDateTime (layout, row);
371 createPreview (layout, row);
376 void DlgSettingsCoords::drawCartesianLinearX ()
378 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLinearX";
381 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
382 double x = CARTESIAN_COORD_MIN + step * CARTESIAN_COORD_STEP;
383 QGraphicsLineItem *line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
384 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
385 line->setPen(QPen (QBrush ((isHighlighted ? Qt::gray : Qt::lightGray)),
387 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
389 line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
390 line->setPen(QPen (QBrush (Qt::black),
397 void DlgSettingsCoords::drawCartesianLinearY ()
399 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLinearY";
402 for (
int step = NUM_COORD_STEPS - 1; step >= 0; step--) {
403 double y = CARTESIAN_COORD_MIN + step * CARTESIAN_COORD_STEP;
404 QGraphicsLineItem *line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
405 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
406 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
408 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
410 line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
411 line->setPen(QPen (QBrush (Qt::black),
418 void DlgSettingsCoords::drawCartesianLogX ()
420 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLogX";
423 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
424 double s = (exp (step / (NUM_COORD_STEPS - 1.0)) - 1.0) /
426 double x = (1.0 - s) * CARTESIAN_COORD_MIN + s * CARTESIAN_COORD_MAX;
427 QGraphicsLineItem *line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
428 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
429 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
431 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
433 line = m_scenePreview->addLine (x, CARTESIAN_COORD_MIN, x, CARTESIAN_COORD_MAX);
434 line->setPen(QPen (QBrush (Qt::black),
441 void DlgSettingsCoords::drawCartesianLogY ()
443 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawCartesianLogY";
446 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
447 double s = (pow (POWER_FOR_LOG, step / (NUM_COORD_STEPS - 1.0)) - 1.0) /
448 (pow (POWER_FOR_LOG, 1.0) - 1.0);
449 double y = (1.0 - s) * CARTESIAN_COORD_MAX + s * CARTESIAN_COORD_MIN;
450 QGraphicsLineItem *line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
451 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
452 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
454 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
456 line = m_scenePreview->addLine (CARTESIAN_COORD_MIN, y, CARTESIAN_COORD_MAX, y);
457 line->setPen(QPen (QBrush (Qt::black),
464 void DlgSettingsCoords::drawPolarLinearRadius ()
466 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawPolarLinearRadius";
468 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
469 double radius = step * POLAR_STEP;
470 QGraphicsEllipseItem *line = m_scenePreview->addEllipse (XCENTER - radius,
474 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
475 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
477 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
481 void DlgSettingsCoords::drawPolarLogRadius ()
483 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawPolarLogRadius";
485 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
486 double s = (pow (POWER_FOR_LOG, step / (NUM_COORD_STEPS - 1.0)) - 1.0) /
487 (pow (POWER_FOR_LOG, 1.0) - 1.0);
488 double radius = (s * (NUM_COORD_STEPS - 1.0)) * POLAR_STEP;
489 QGraphicsEllipseItem *line = m_scenePreview->addEllipse (XCENTER - radius,
493 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
494 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
496 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
500 void DlgSettingsCoords::drawPolarTheta ()
502 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::drawPolarTheta";
505 for (
int step = 0; step < NUM_COORD_STEPS; step++) {
506 double theta = POLAR_THETA_MIN + step * POLAR_THETA_STEP;
507 double x = POLAR_RADIUS * cos (theta * DEG_2_RAD);
508 double y = POLAR_RADIUS * sin (theta * DEG_2_RAD);
509 QGraphicsLineItem *line = m_scenePreview->addLine (XCENTER, YCENTER, XCENTER + x, YCENTER + y);
510 bool isHighlighted = (step % STEPS_PER_CYCLE == 0);
511 line->setPen(QPen (QBrush (isHighlighted ? Qt::gray : Qt::lightGray),
513 (isHighlighted ? Qt::SolidLine : Qt::DashLine)));
515 line = m_scenePreview->addLine (XCENTER, YCENTER, XCENTER + x, YCENTER + y);
516 line->setPen(QPen (QBrush (Qt::black),
525 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::handleOk";
528 cmdMediator ().document(),
529 *m_modelCoordsBefore,
530 *m_modelCoordsAfter);
538 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::load";
544 QRectF rectGraph = boundingRectGraph (cmdMediator,
546 bool xThetaGoesNegative = !isEmpty && (rectGraph.x() <= 0);
547 bool yRGoesNegative = !isEmpty && (rectGraph.y() <= 0);
548 m_xThetaLinear->setEnabled (!xThetaGoesNegative);
549 m_xThetaLog->setEnabled (!xThetaGoesNegative);
550 m_yRadiusLinear->setEnabled (!yRGoesNegative);
551 m_yRadiusLog->setEnabled (!yRGoesNegative);
554 if (m_modelCoordsBefore != 0) {
555 delete m_modelCoordsBefore;
557 if (m_modelCoordsAfter != 0) {
558 delete m_modelCoordsAfter;
567 m_validatorOriginRadius = dlgValidatorFactory.createWithNonPolar (m_modelCoordsAfter->
coordScaleYRadius(),
571 m_editOriginRadius->setValidator (m_validatorOriginRadius);
572 m_editOriginRadius->setText (QString::number (m_modelCoordsAfter->
originRadius ()));
574 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
575 m_btnCartesian->setChecked (
true);
577 m_btnPolar->setChecked (
true);
581 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
582 loadComboBoxUnitsNonPolar (*m_cmbXThetaUnits,
584 loadComboBoxUnitsNonPolar (*m_cmbYRadiusUnits,
587 loadComboBoxUnitsPolar (*m_cmbXThetaUnits,
589 loadComboBoxUnitsNonPolar (*m_cmbYRadiusUnits,
596 m_xThetaLinear->setChecked (m_modelCoordsAfter->
coordScaleXTheta() == COORD_SCALE_LINEAR);
597 m_xThetaLog->setChecked (m_modelCoordsAfter->
coordScaleXTheta() == COORD_SCALE_LOG);
598 m_yRadiusLinear->setChecked (m_modelCoordsAfter->
coordScaleYRadius() == COORD_SCALE_LINEAR);
599 m_yRadiusLog->setChecked (m_modelCoordsAfter->
coordScaleYRadius() == COORD_SCALE_LOG);
606 void DlgSettingsCoords::loadComboBoxDate()
608 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxDate";
612 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_SKIP),
613 QVariant (COORD_UNITS_DATE_SKIP));
614 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_MONTH_DAY_YEAR),
615 QVariant (COORD_UNITS_DATE_MONTH_DAY_YEAR));
616 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_DAY_MONTH_YEAR),
617 QVariant (COORD_UNITS_DATE_DAY_MONTH_YEAR));
618 m_cmbDate->addItem (coordUnitsDateToString (COORD_UNITS_DATE_YEAR_MONTH_DAY),
619 QVariant (COORD_UNITS_DATE_YEAR_MONTH_DAY));
621 ENGAUGE_ASSERT (m_cmbDate->count() == NUM_COORD_UNITS_DATE);
623 int index = m_cmbDate->findData (QVariant (m_modelCoordsAfter->
coordUnitsDate()));
624 m_cmbDate->setCurrentIndex (index);
627 void DlgSettingsCoords::loadComboBoxTime()
629 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxTime";
633 m_cmbTime->addItem (coordUnitsTimeToString (COORD_UNITS_TIME_SKIP),
634 QVariant (COORD_UNITS_TIME_SKIP));
635 m_cmbTime->addItem (coordUnitsTimeToString (COORD_UNITS_TIME_HOUR_MINUTE),
636 QVariant (COORD_UNITS_TIME_HOUR_MINUTE));
637 m_cmbTime->addItem (coordUnitsTimeToString (COORD_UNITS_TIME_HOUR_MINUTE_SECOND),
638 QVariant (COORD_UNITS_TIME_HOUR_MINUTE_SECOND));
640 ENGAUGE_ASSERT (m_cmbTime->count() == NUM_COORD_UNITS_TIME);
642 int index = m_cmbTime->findData (QVariant (m_modelCoordsAfter->
coordUnitsTime()));
643 m_cmbTime->setCurrentIndex (index);
646 void DlgSettingsCoords::loadComboBoxUnitsNonPolar (QComboBox &cmb,
647 CoordUnitsNonPolarTheta coordUnits)
649 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxUnitsNonPolar";
653 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_NUMBER),
654 QVariant (COORD_UNITS_NON_POLAR_THETA_NUMBER));
655 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_DATE_TIME),
656 QVariant (COORD_UNITS_NON_POLAR_THETA_DATE_TIME));
657 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS),
658 QVariant (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS));
659 cmb.addItem (coordUnitsNonPolarThetaToString (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW),
660 QVariant (COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW));
662 ENGAUGE_ASSERT (cmb.count() == NUM_COORD_UNITS_NON_POLAR_THETA);
664 cmb.setWhatsThis (QString (tr (
"Numbers have the simplest and most general format.\n\n"
665 "Date and time values have date and/or time components.\n\n"
666 "Degrees Minutes Seconds (DDD MM SS.S) format uses two integer number for degrees and minutes, and a real number for "
667 "seconds. There are 60 seconds per minute. During input, spaces must be inserted between the three numbers.")));
669 int index = cmb.findData (coordUnits);
670 cmb.setCurrentIndex (index);
673 void DlgSettingsCoords::loadComboBoxUnitsPolar (QComboBox &cmb,
674 CoordUnitsPolarTheta coordUnits)
676 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::loadComboBoxUnitsPolar";
680 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES),
681 QVariant (COORD_UNITS_POLAR_THETA_DEGREES));
682 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES),
683 QVariant (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES));
684 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS),
685 QVariant (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS));
686 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW),
687 QVariant (COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW));
688 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_GRADIANS),
689 QVariant (COORD_UNITS_POLAR_THETA_GRADIANS));
690 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_RADIANS),
691 QVariant (COORD_UNITS_POLAR_THETA_RADIANS));
692 cmb.addItem (coordUnitsPolarThetaToString (COORD_UNITS_POLAR_THETA_TURNS),
693 QVariant (COORD_UNITS_POLAR_THETA_TURNS));
695 ENGAUGE_ASSERT (cmb.count() == NUM_COORD_UNITS_POLAR_THETA);
697 cmb.setWhatsThis (QString (tr (
"Degrees (DDD.DDDDD) format uses a single real number. One complete revolution is 360 degrees.\n\n"
698 "Degrees Minutes (DDD MM.MMM) format uses one integer number for degrees, and a real number for minutes. There are "
699 "60 minutes per degree. During input, a space must be inserted between the two numbers.\n\n"
700 "Degrees Minutes Seconds (DDD MM SS.S) format uses two integer number for degrees and minutes, and a real number for "
701 "seconds. There are 60 seconds per minute. During input, spaces must be inserted between the three numbers.\n\n"
702 "Gradians format uses a single real number. One complete revolution is 400 gradians.\n\n"
703 "Radians format uses a single real number. One complete revolution is 2*pi radians.\n\n"
704 "Turns format uses a single real number. One complete revolution is one turn.")));
706 int index = cmb.findData (coordUnits);
707 cmb.setCurrentIndex (index);
710 void DlgSettingsCoords::resetSceneRectangle ()
712 QRect rect (CARTESIAN_COORD_MIN - CARTESIAN_COORD_STEP / 2.0,
713 CARTESIAN_COORD_MIN - CARTESIAN_COORD_STEP / 2.0,
714 CARTESIAN_COORD_MAX - CARTESIAN_COORD_MIN + CARTESIAN_COORD_STEP,
715 CARTESIAN_COORD_MAX - CARTESIAN_COORD_MIN + CARTESIAN_COORD_STEP);
717 QGraphicsRectItem *itemPerimeter =
new QGraphicsRectItem(rect);
718 itemPerimeter->setVisible(
false);
719 m_scenePreview->addItem (itemPerimeter);
720 m_viewPreview->centerOn (QPointF (0.0, 0.0));
723 void DlgSettingsCoords::slotCartesianPolar (
bool)
725 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotCartesian";
727 if (m_btnCartesian->isChecked ()) {
736 void DlgSettingsCoords::slotDate(
const QString &)
738 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotDate";
740 CoordUnitsDate coordUnits = (CoordUnitsDate) m_cmbDate->currentData ().toInt();
746 void DlgSettingsCoords::slotPolarOriginRadius(
const QString &)
748 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotPolarOriginRadius";
750 QString numberText = m_editOriginRadius->text();
757 void DlgSettingsCoords::slotTime(
const QString &)
759 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotTime";
761 CoordUnitsTime coordUnits = (CoordUnitsTime) m_cmbTime->currentData ().toInt();
767 void DlgSettingsCoords::slotUnitsXTheta(
const QString &)
769 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotUnitsXTheta";
771 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
772 CoordUnitsNonPolarTheta coordUnits = (CoordUnitsNonPolarTheta) m_cmbXThetaUnits->currentData ().toInt ();
775 CoordUnitsPolarTheta coordUnits = (CoordUnitsPolarTheta) m_cmbXThetaUnits->currentData ().toInt ();
782 void DlgSettingsCoords::slotUnitsYRadius(
const QString &)
784 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotUnitsYRadius";
786 CoordUnitsNonPolarTheta coordUnits = (CoordUnitsNonPolarTheta) m_cmbYRadiusUnits->currentData ().toInt ();
787 if (m_modelCoordsAfter->
coordsType() == COORDS_TYPE_CARTESIAN) {
796 void DlgSettingsCoords::slotXThetaLinear()
798 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotXThetaLinear";
805 void DlgSettingsCoords::slotXThetaLog()
807 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotXThetaLog";
814 void DlgSettingsCoords::slotYRadiusLinear()
816 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotYRadiusLinear";
818 delete m_validatorOriginRadius;
825 m_editOriginRadius->setValidator (m_validatorOriginRadius);
832 void DlgSettingsCoords::slotYRadiusLog()
834 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::slotYRadiusLog";
836 delete m_validatorOriginRadius;
843 m_editOriginRadius->setValidator (m_validatorOriginRadius);
850 void DlgSettingsCoords::updateControls ()
854 QString textOriginRadius = m_editOriginRadius->text();
855 int posOriginRadius = 0;
857 bool goodOriginRadius =
true;
858 if (m_editOriginRadius->isEnabled ()) {
861 goodOriginRadius = (m_validatorOriginRadius->
validate (textOriginRadius,
862 posOriginRadius) == QValidator::Acceptable);
867 m_boxCoordsType->setEnabled (!m_xThetaLog->isChecked ());
869 m_xThetaLinear->setEnabled (!m_btnPolar->isChecked ());
870 m_xThetaLog->setEnabled (!m_btnPolar->isChecked ());
871 if (m_btnCartesian->isChecked()) {
872 m_yRadiusLinear->setEnabled (
true);
873 m_yRadiusLog->setEnabled (
true);
882 int posOriginRadiusOther;
883 bool goodOriginRadiusOther = (dlg->
validate (textOriginRadius, posOriginRadiusOther) == QValidator::Acceptable);
887 m_yRadiusLinear->setEnabled (goodOriginRadius && goodOriginRadiusOther);
888 m_yRadiusLog->setEnabled (goodOriginRadius && goodOriginRadiusOther);
890 m_editOriginRadius->setEnabled (m_btnPolar->isChecked ());
892 QString captionXTheta = (m_btnCartesian->isChecked () ?
894 THETA) + QString (
" Coordinates");
895 QString captionYRadius = (m_btnCartesian->isChecked () ?
897 QString (
"R")) + QString (
" Coordinates");
899 if (m_boxXTheta->title() != captionXTheta) {
900 m_boxXTheta->setTitle (captionXTheta);
903 if (m_boxYRadius->title () != captionYRadius) {
904 m_boxYRadius->setTitle (captionYRadius);
908 if (m_btnCartesian->isChecked()) {
909 enableDateTime = (((CoordUnitsNonPolarTheta) m_cmbXThetaUnits->currentData ().toInt() == COORD_UNITS_NON_POLAR_THETA_DATE_TIME) ||
910 ((CoordUnitsNonPolarTheta) m_cmbYRadiusUnits->currentData ().toInt() == COORD_UNITS_NON_POLAR_THETA_DATE_TIME));
912 enableDateTime = ((CoordUnitsNonPolarTheta) m_cmbYRadiusUnits->currentData ().toInt() == COORD_UNITS_NON_POLAR_THETA_DATE_TIME);
914 m_cmbDate->setEnabled (enableDateTime);
915 m_cmbTime->setEnabled (enableDateTime);
917 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCoords::updateControls"
918 <<
" textOriginRadius=" << textOriginRadius.toLatin1().data()
919 <<
" goodOriginRadius=" << (goodOriginRadius ?
"true" :
"false")
920 <<
" originRadius=" << posOriginRadius
921 <<
" btnPolarChecked=" << (m_btnPolar->isChecked() ?
"true" :
"false")
922 <<
" enableDateTime=" << (enableDateTime ?
"true" :
"false");
925 void DlgSettingsCoords::updatePreview()
927 m_scenePreview->clear();
935 if (m_btnCartesian->isChecked()) {
938 if (m_xThetaLinear->isChecked()) {
939 drawCartesianLinearX ();
941 drawCartesianLogX ();
944 if (m_yRadiusLinear->isChecked()) {
945 drawCartesianLinearY ();
947 drawCartesianLogY ();
954 if (m_yRadiusLinear->isChecked()) {
955 drawPolarLinearRadius ();
957 drawPolarLogRadius ();
961 annotateRadiusAtOrigin (defaultFont);
962 annotateAngles (defaultFont);
965 resetSceneRectangle();
void setCoordUnitsTime(CoordUnitsTime coordUnits)
Set method for time units.
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.
void setCoordUnitsY(CoordUnitsNonPolarTheta coordUnits)
Set method for y units.
void setCoordUnitsX(CoordUnitsNonPolarTheta coordUnits)
Set method for x units.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
virtual QValidator::State validate(QString &input, int &pos) const =0
Validate according to the numeric format specific to the leaf class.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
CoordUnitsNonPolarTheta coordUnitsRadius() const
Get method for radius units.
Abstract validator for all numeric formats.
CoordUnitsTime coordUnitsTime() const
Get method for time format when used.
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...
CoordUnitsNonPolarTheta coordUnitsY() const
Get method for x units.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
void setCoordUnitsTheta(CoordUnitsPolarTheta coordUnits)
Set method for theta units.
CoordsType coordsType() const
Get method for coordinates type.
CoordUnitsNonPolarTheta coordUnitsX() const
Get method for x units.
Model for DlgSettingsCoords and CmdSettingsCoords.
void setOriginRadius(double originRadius)
Set method for origin radius in polar mode.
CoordUnitsDate coordUnitsDate() const
Get method for date format when used.
DlgValidatorAbstract * createWithNonPolar(CoordScale coordScale, CoordUnitsNonPolarTheta coordUnits, CoordUnitsDate coordUnitsDate, CoordUnitsTime coordUnitsTime) const
Factory method for generating validators when cartesian/polar case handling is handled externally...
void setCoordUnitsRadius(CoordUnitsNonPolarTheta coordUnits)
Set method for radius units.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
Abstract base class for all Settings dialogs.
Callback for computing the bounding rectangles of the screen and graph coordinates of the points in t...
MainWindow & mainWindow()
Get method for MainWindow.
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.
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.
void setCoordsType(CoordsType coordsType)
Set method for coordinates type.