Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgSettingsCurveProperties.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "ButtonWhatsThis.h"
8#include "CmdMediator.h"
10#include "ColorPalette.h"
12#include "EngaugeAssert.h"
13#include "EnumsToQt.h"
14#include "GeometryWindow.h"
15#include "GraphicsPoint.h"
17#include "GraphicsView.h"
18#include "Logger.h"
19#include "MainWindow.h"
20#include <QCheckBox>
21#include <QComboBox>
22#include <QDebug>
23#include <QGraphicsRectItem>
24#include <QGraphicsScene>
25#include <QGridLayout>
26#include <QGroupBox>
27#include <QLabel>
28#include <QLineEdit>
29#include <QListWidget>
30#include <qmath.h>
31#include <QPen>
32#include <QPushButton>
33#include <QSettings>
34#include <QSpacerItem>
35#include <QSpinBox>
36#include <QTransform>
37#include <QWhatsThis>
38#include "Settings.h"
39#include "SettingsForGraph.h"
40#include "Spline.h"
41#include "SplinePair.h"
42#include <vector>
43#include "ViewPreview.h"
44
45using namespace std;
46
47const QString CONNECT_AS_FUNCTION_SMOOTH_STR ("Function - Smooth");
48const QString CONNECT_AS_FUNCTION_STRAIGHT_STR ("Function - Straight");
49const QString CONNECT_AS_RELATION_SMOOTH_STR ("Relation - Smooth");
50const QString CONNECT_AS_RELATION_STRAIGHT_STR ("Relation - Straight");
51
52const double PREVIEW_WIDTH = 100.0;
53const double PREVIEW_HEIGHT = 100.0;
54const int MINIMUM_HEIGHT = 500;
55
56const QPointF POS_LEFT (PREVIEW_WIDTH / 3.0,
57 PREVIEW_HEIGHT * 2.0 / 3.0);
58const QPointF POS_CENTER (PREVIEW_WIDTH / 2.0,
59 PREVIEW_HEIGHT / 3.0);
60const QPointF POS_RIGHT (2.0 * PREVIEW_WIDTH / 3.0,
61 PREVIEW_HEIGHT * 2.0 / 3.0);
62
64 DlgSettingsAbstractBase (tr ("Curve Properties"),
65 "DlgSettingsCurveProperties",
67 m_modelMainWindow (mainWindow.modelMainWindow()),
68 m_scenePreview (nullptr),
69 m_viewPreview (nullptr),
70 m_modelCurveStylesBefore (nullptr),
71 m_modelCurveStylesAfter (nullptr)
72{
73 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::DlgSettingsCurveProperties";
74
75 QWidget *subPanel = createSubPanel ();
76 finishPanel (subPanel);
77
78 setMinimumWidth (740); // Override finishPanel width for room for m_cmbLineType and preview to be completely visible
79}
80
82{
83 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::~DlgSettingsCurveProperties";
84}
85
86void DlgSettingsCurveProperties::createCurveName (QGridLayout *layout,
87 int &row)
88{
89 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::createCurveName";
90
91 QLabel *labelCurveName = new QLabel (QString ("%1:").arg (tr ("Curve Name")));
92 layout->addWidget (labelCurveName, row, 1, 1, 1);
93
94 m_cmbCurveName = new QComboBox ();
95 m_cmbCurveName->setWhatsThis (tr ("Name of the curve that is currently selected for editing"));
96 connect (m_cmbCurveName, SIGNAL (activated (const QString &)), this, SLOT (slotCurveName (const QString &))); // activated() ignores code changes
97 layout->addWidget (m_cmbCurveName, row, 2, 1, 1);
98
99 createWhatsThis (layout,
100 m_btnWhatsThis,
101 row++,
102 3);
103}
104
105void DlgSettingsCurveProperties::createLine (QGridLayout *layout,
106 int &row)
107{
108 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::createLine";
109
110 m_groupLine = new QGroupBox (tr ("Line"));
111 layout->addWidget (m_groupLine, row++, 2);
112
113 QGridLayout *layoutGroup = new QGridLayout;
114 m_groupLine->setLayout (layoutGroup);
115
116 QLabel *labelLineWidth = new QLabel (QString ("%1:").arg (tr ("Width")));
117 layoutGroup->addWidget (labelLineWidth, 0, 0);
118
119 m_spinLineWidth = new QSpinBox (m_groupLine);
120 m_spinLineWidth->setWhatsThis (tr ("Select a width for the lines drawn between points.\n\n"
121 "This applies only to graph curves. No lines are ever drawn between axis points."));
122 m_spinLineWidth->setMinimum(1);
123 connect (m_spinLineWidth, SIGNAL (valueChanged (int)), this, SLOT (slotLineWidth (int)));
124 layoutGroup->addWidget (m_spinLineWidth, 0, 1);
125
126 QLabel *labelLineColor = new QLabel (QString ("%1:").arg (tr ("Color")));
127 layoutGroup->addWidget (labelLineColor, 1, 0);
128
129 m_cmbLineColor = new QComboBox (m_groupLine);
130 m_cmbLineColor->setWhatsThis (tr ("Select a color for the lines drawn between points.\n\n"
131 "This applies only to graph curves. No lines are ever drawn between axis points."));
132 populateColorComboWithTransparent (*m_cmbLineColor);
133 connect (m_cmbLineColor, SIGNAL (activated (const QString &)), this, SLOT (slotLineColor (const QString &))); // activated() ignores code changes
134 layoutGroup->addWidget (m_cmbLineColor, 1, 1);
135
136 QLabel *labelLineType = new QLabel (QString ("%1:").arg (tr ("Connect as")));
137 layoutGroup->addWidget (labelLineType, 2, 0);
138
139 m_cmbLineType = new QComboBox (m_groupLine);
140 m_cmbLineType->addItem (CONNECT_AS_FUNCTION_STRAIGHT_STR, QVariant (CONNECT_AS_FUNCTION_STRAIGHT));
141 m_cmbLineType->addItem (CONNECT_AS_FUNCTION_SMOOTH_STR, QVariant (CONNECT_AS_FUNCTION_SMOOTH));
142 m_cmbLineType->addItem (CONNECT_AS_RELATION_STRAIGHT_STR, QVariant (CONNECT_AS_RELATION_STRAIGHT));
143 m_cmbLineType->addItem (CONNECT_AS_RELATION_SMOOTH_STR, QVariant (CONNECT_AS_RELATION_SMOOTH));
144 m_cmbLineType->setWhatsThis (tr ("Select rule for connecting points with lines.\n\n"
145 "If the curve is connected as a single-valued function then the points are ordered by "
146 "increasing value of the independent variable.\n\n"
147 "If the curve is connected as a closed contour, then the points are ordered by age, except for "
148 "points placed along an existing line. Any point placed on top of any existing line is inserted "
149 "between the two endpoints of that line - as if its age was between the ages of the two "
150 "endpoints.\n\n"
151 "Lines are drawn between successively ordered points.\n\n"
152 "Straight curves are drawn with straight lines between successive points. Smooth curves are drawn "
153 "with smooth lines between successive points, using natural cubic splines of (x,y) pairs versus "
154 "scalar ordinal (t) values.\n\n"
155 "This applies only to graph curves. No lines are ever drawn between axis points."));
156 connect (m_cmbLineType, SIGNAL (activated (const QString &)), this, SLOT (slotLineType (const QString &))); // activated() ignores code changes
157 layoutGroup->addWidget (m_cmbLineType, 2, 1);
158}
159
160void DlgSettingsCurveProperties::createPoint (QGridLayout *layout,
161 int &row)
162{
163 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::createPoint";
164
165 m_groupPoint = new QGroupBox (tr ("Point"));
166 layout->addWidget (m_groupPoint, row++, 1);
167
168 QGridLayout *layoutGroup = new QGridLayout;
169 m_groupPoint->setLayout (layoutGroup);
170
171 QLabel *labelPointShape = new QLabel(QString ("%1:").arg (tr ("Shape")));
172 layoutGroup->addWidget (labelPointShape, 0, 0);
173
174 m_cmbPointShape = new QComboBox (m_groupPoint);
175 m_cmbPointShape->setWhatsThis (tr ("Select a shape for the points"));
176 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_CIRCLE),
178 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_CROSS),
180 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_DIAMOND),
182 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_HOURGLASS),
184 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_SQUARE),
186 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_TRIANGLE),
188 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_TRIANGLE2),
190 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_X),
192 connect (m_cmbPointShape, SIGNAL (activated (const QString &)), this, SLOT (slotPointShape (const QString &))); // activated() ignores code changes
193 layoutGroup->addWidget (m_cmbPointShape, 0, 1);
194
195 QLabel *labelPointRadius = new QLabel (QString ("%1:").arg (tr ("Radius")));
196 layoutGroup->addWidget (labelPointRadius, 1, 0);
197
198 m_spinPointRadius = new QSpinBox (m_groupPoint);
199 m_spinPointRadius->setWhatsThis (tr ("Select a radius, in pixels, for the points"));
200 m_spinPointRadius->setMinimum (1);
201 connect (m_spinPointRadius, SIGNAL (valueChanged (int)), this, SLOT (slotPointRadius (int)));
202 layoutGroup->addWidget (m_spinPointRadius, 1, 1);
203
204 QLabel *labelPointLineWidth = new QLabel (QString ("%1:").arg (tr ("Line width")));
205 layoutGroup->addWidget (labelPointLineWidth, 2, 0);
206
207 m_spinPointLineWidth = new QSpinBox (m_groupPoint);
208 m_spinPointLineWidth->setWhatsThis (tr ("Select a line width, in pixels, for the points.\n\n"
209 "A larger width results in a thicker line, with the exception of a value of zero "
210 "which always results in a line that is one pixel wide (which is easy to see even "
211 "when zoomed far out)"));
212 m_spinPointLineWidth->setMinimum (0);
213 connect (m_spinPointLineWidth, SIGNAL (valueChanged (int)), this, SLOT (slotPointLineWidth (int)));
214 layoutGroup->addWidget (m_spinPointLineWidth, 2, 1);
215
216 QLabel *labelPointColor = new QLabel (QString ("%1:").arg (tr ("Color")));
217 layoutGroup->addWidget (labelPointColor, 3, 0);
218
219 m_cmbPointColor = new QComboBox (m_groupPoint);
220 m_cmbPointColor->setWhatsThis (tr ("Select a color for the line used to draw the point shapes"));
221 populateColorComboWithoutTransparent (*m_cmbPointColor);
222 connect (m_cmbPointColor, SIGNAL (activated (const QString &)), this, SLOT (slotPointColor (const QString &))); // activated() ignores code changes
223 layoutGroup->addWidget (m_cmbPointColor, 3, 1);
224}
225
227{
228 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::createOptionalSaveDefault";
229
230 m_btnSaveDefault = new QPushButton ("Save As Default");
231 m_btnSaveDefault->setWhatsThis (tr ("Save the visible curve settings for use as future defaults, according to the curve name selection.\n\n"
232 "If the visible settings are for the axes curve, then they will be used for future "
233 "axes curves, until new settings are saved as the defaults.\n\n"
234 "If the visible settings are for the Nth graph curve in the curve list, then they will be used for future "
235 "graph curves that are also the Nth graph curve in their curve list, until new settings are saved as the defaults."));
236 connect (m_btnSaveDefault, SIGNAL (released ()), this, SLOT (slotSaveDefault ()));
237 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
238}
239
240void DlgSettingsCurveProperties::createPreview (QGridLayout *layout,
241 int &row)
242{
243 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::createPreview";
244
245 QLabel *labelPreview = new QLabel (tr ("Preview"));
246 layout->addWidget (labelPreview, row++, 0, 1, 4);
247
248 m_scenePreview = new QGraphicsScene (this);
249 m_viewPreview = new ViewPreview (m_scenePreview,
251 this);
252 m_viewPreview->setWhatsThis (tr ("Preview window that shows how current settings affect the points and line of the selected curve.\n\n"
253 "The X coordinate is in the horizontal direction, and the Y coordinate is in the vertical direction. A "
254 "function can have only one Y value, at most, for any X value, but a relation can have multiple Y values "
255 "for one X value."));
256 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
257 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
258 m_viewPreview->setMinimumHeight (MINIMUM_PREVIEW_HEIGHT);
259 m_viewPreview->setRenderHint (QPainter::Antialiasing);
260
261 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
262}
263
265{
266 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::createSubPanel";
267
268 QWidget *subPanel = new QWidget ();
269 QGridLayout *layout = new QGridLayout (subPanel);
270 subPanel->setLayout (layout);
271
272 int row = 0;
273 createCurveName (layout, row);
274
275 int rowLeft = row, rowRight = row++;
276 createPoint (layout, rowLeft);
277 createLine (layout, rowRight);
278 createPreview (layout, row);
279
280 layout->setColumnStretch(0, 1); // Empty first column
281 layout->setColumnStretch(1, 0); // Point group
282 layout->setColumnStretch(2, 0); // Line group
283 layout->setColumnStretch(3, 1); // Empty last column
284
285 layout->setRowStretch (0, 1); // Expand empty first row
286
287 return subPanel;
288}
289
290void DlgSettingsCurveProperties::drawLine (bool isRelation,
291 const LineStyle &lineStyle)
292{
293 const double Z_LINE = -1.0; // Looks nicer if line goes under the points, so points are unobscured
294
295 // Line between points. Start with function connection
296 QPainterPath path;
297 QPointF p0 (POS_LEFT), p1 (POS_CENTER), p2 (POS_RIGHT);
298 if (isRelation) {
299
300 // Relation connection
301 p1 = POS_RIGHT;
302 p2 = POS_CENTER;
303 }
304
305 // Draw straight or smooth
306 if (lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_SMOOTH ||
308
309 vector<double> t;
310 vector<SplinePair> xy;
311 t.push_back(0);
312 t.push_back(1);
313 t.push_back(2);
314 xy.push_back (SplinePair (p0.x(), p0.y()));
315 xy.push_back (SplinePair (p1.x(), p1.y()));
316 xy.push_back (SplinePair (p2.x(), p2.y()));
317 Spline spline (t, xy);
318 path.moveTo (p0);
319 path.cubicTo (QPointF (spline.p1(0).x(),
320 spline.p1(0).y()),
321 QPointF (spline.p2(0).x(),
322 spline.p2(0).y()),
323 p1);
324 path.cubicTo (QPointF (spline.p1(1).x(),
325 spline.p1(1).y()),
326 QPointF (spline.p2(1).x(),
327 spline.p2(1).y()),
328 p2);
329 } else {
330 path.moveTo (p0);
331 path.lineTo (p1);
332 path.lineTo (p2);
333 }
334
335 QGraphicsPathItem *line = new QGraphicsPathItem (path);
336 line->setPen (QPen (QBrush (ColorPaletteToQColor (lineStyle.paletteColor())),
337 lineStyle.width()));
338 line->setZValue (Z_LINE);
339 m_scenePreview->addItem (line);
340}
341
342void DlgSettingsCurveProperties::drawPoints (const PointStyle &pointStyle)
343{
344 const QString NULL_IDENTIFIER;
345 GeometryWindow *NULL_GEOMETRY_WINDOW = nullptr;
346
347 GraphicsPointFactory pointFactory;
348
349 // Left point
350 GraphicsPoint *pointLeft = pointFactory.createPoint (*m_scenePreview,
351 NULL_IDENTIFIER,
352 POS_LEFT,
353 pointStyle,
354 NULL_GEOMETRY_WINDOW);
355 pointLeft->setPointStyle (pointStyle);
356
357 // Center point
358 GraphicsPoint *pointCenter = pointFactory.createPoint (*m_scenePreview,
359 NULL_IDENTIFIER,
361 pointStyle,
362 NULL_GEOMETRY_WINDOW);
363 pointCenter->setPointStyle (pointStyle);
364
365 // Right point
366 GraphicsPoint *pointRight = pointFactory.createPoint (*m_scenePreview,
367 NULL_IDENTIFIER,
368 POS_RIGHT,
369 pointStyle,
370 NULL_GEOMETRY_WINDOW);
371 pointRight->setPointStyle (pointStyle);
372}
373
375{
376 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::handleOk";
377
378 ENGAUGE_CHECK_PTR (m_modelCurveStylesBefore);
379 ENGAUGE_CHECK_PTR (m_modelCurveStylesAfter);
380
382 cmdMediator ().document(),
383 *m_modelCurveStylesBefore,
384 *m_modelCurveStylesAfter);
385 cmdMediator ().push (cmd);
386
387 hide ();
388}
389
391{
392 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::load";
393
395
396 // Flush old data
397 delete m_modelCurveStylesBefore;
398 delete m_modelCurveStylesAfter;
399
400 // Save new data
401 m_modelCurveStylesBefore = new CurveStyles (cmdMediator.coordSystem());
402 m_modelCurveStylesAfter = new CurveStyles (cmdMediator.coordSystem());
403
404 // Populate controls. First load curve name combobox. The curve-specific controls get loaded in slotCurveName
405 m_cmbCurveName->clear ();
406 m_cmbCurveName->addItem (AXIS_CURVE_NAME);
407 QStringList curveNames = cmdMediator.curvesGraphsNames();
408 QStringList::const_iterator itr;
409 for (itr = curveNames.begin (); itr != curveNames.end (); itr++) {
410
411 QString curveName = *itr;
412 m_cmbCurveName->addItem (curveName);
413 }
414
415 loadForCurveName (mainWindow().selectedGraphCurve());
416
417 m_isDirty = false;
418 enableOk (false); // Disable Ok button since there not yet any changes
419}
420
421void DlgSettingsCurveProperties::loadForCurveName (const QString &curveName)
422{
423 int indexCurveName = m_cmbCurveName->findText(curveName);
424 ENGAUGE_ASSERT (indexCurveName >= 0);
425 m_cmbCurveName->setCurrentIndex(indexCurveName);
426
427 int indexPointShape = m_cmbPointShape->findData (QVariant (m_modelCurveStylesAfter->pointShape (curveName)));
428 ENGAUGE_ASSERT (indexPointShape >= 0);
429 m_cmbPointShape->setCurrentIndex (indexPointShape);
430
431 m_spinPointRadius->setValue (m_modelCurveStylesAfter->pointRadius(curveName));
432 m_spinPointLineWidth->setValue (m_modelCurveStylesAfter->pointLineWidth(curveName));
433
434 int indexPointColor = m_cmbPointColor->findData (QVariant (m_modelCurveStylesAfter->pointColor(curveName)));
435 ENGAUGE_ASSERT (indexPointColor >= 0);
436 m_cmbPointColor->setCurrentIndex (indexPointColor);
437
438 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelCurveStylesAfter->lineColor(curveName)));
439 ENGAUGE_ASSERT (indexLineColor >= 0);
440 m_cmbLineColor->setCurrentIndex (indexLineColor);
441
442 m_spinLineWidth->setValue (m_modelCurveStylesAfter->lineWidth(curveName));
443
444 int indexCurveConnectAs = m_cmbLineType->findData (QVariant (m_modelCurveStylesAfter->lineConnectAs (curveName)));
445 if (indexCurveConnectAs >= 0) {
446 // Value is not CONNECT_SKIP_FOR_AXIS_CURVE
447 m_cmbLineType->setCurrentIndex (indexCurveConnectAs);
448 }
449
450 // Disable line controls for axis curve since connecting with visible lines is better handled by Checker class
451 m_cmbLineColor->setEnabled (curveName != AXIS_CURVE_NAME);
452 m_spinLineWidth->setEnabled (curveName != AXIS_CURVE_NAME);
453 m_cmbLineType->setEnabled (curveName != AXIS_CURVE_NAME);
454
455 updateControls();
456 updatePreview();
457}
458
459void DlgSettingsCurveProperties::resetSceneRectangle ()
460{
461
462 QRect rect (0,
463 0,
464 qFloor (PREVIEW_WIDTH),
465 qFloor (PREVIEW_HEIGHT));
466
467 QGraphicsRectItem *itemPerimeter = new QGraphicsRectItem(rect);
468 itemPerimeter->setVisible(false);
469 m_scenePreview->addItem (itemPerimeter);
470 m_viewPreview->centerOn (QPointF (0.0, 0.0));
471}
472
473void DlgSettingsCurveProperties::setCurveName (const QString &curveName)
474{
475 m_cmbCurveName->setCurrentText (curveName);
476 loadForCurveName (curveName);
477}
478
480{
481 if (!smallDialogs) {
482 setMinimumHeight (MINIMUM_HEIGHT);
483 }
484}
485
486void DlgSettingsCurveProperties::slotCurveName(const QString &curveName)
487{
488 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotCurveName";
489
490 // Dirty flag is not set when simply changing to new curve
491
492 // Do nothing if combobox is getting cleared, or load has not been called yet
493 if (!curveName.isEmpty () && (m_modelCurveStylesAfter != nullptr)) {
494
495 loadForCurveName (curveName);
496 }
497}
498
499void DlgSettingsCurveProperties::slotLineColor(const QString &lineColor)
500{
501 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotLineColor color=" << lineColor.toLatin1().data();
502
503 m_isDirty = true;
504
505 m_modelCurveStylesAfter->setLineColor(m_cmbCurveName->currentText(),
506 static_cast<ColorPalette> (m_cmbLineColor->currentData().toInt()));
507 updateControls();
508 updatePreview();
509}
510
511void DlgSettingsCurveProperties::slotLineWidth(int width)
512{
513 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotLineWidth width=" << width;
514
515 m_isDirty = true;
516
517 m_modelCurveStylesAfter->setLineWidth(m_cmbCurveName->currentText(),
518 width);
519 updateControls ();
520 updatePreview();
521}
522
523void DlgSettingsCurveProperties::slotLineType(const QString &lineType)
524{
525 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotLineType lineType=" << lineType.toLatin1().data();
526
527 m_isDirty = true;
528
529 m_modelCurveStylesAfter->setLineConnectAs(m_cmbCurveName->currentText(),
530 static_cast<CurveConnectAs> (m_cmbLineType->currentData().toInt ()));
531 updateControls();
532 updatePreview();
533}
534
535void DlgSettingsCurveProperties::slotPointColor(const QString &pointColor)
536{
537 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotPointColor pointColor=" << pointColor.toLatin1().data();
538
539 m_isDirty = true;
540
541 m_modelCurveStylesAfter->setPointColor(m_cmbCurveName->currentText(),
542 static_cast<ColorPalette> (m_cmbPointColor->currentData().toInt ()));
543 updateControls();
544 updatePreview();
545}
546
547void DlgSettingsCurveProperties::slotPointLineWidth(int lineWidth)
548{
549 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotPointLineWidth lineWidth=" << lineWidth;
550
551 m_isDirty = true;
552
553 m_modelCurveStylesAfter->setPointLineWidth(m_cmbCurveName->currentText(),
554 lineWidth);
555 updateControls();
556 updatePreview();
557}
558
559void DlgSettingsCurveProperties::slotPointRadius(int radius)
560{
561 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotPointRadius radius=" << radius;
562
563 m_isDirty = true;
564
565 m_modelCurveStylesAfter->setPointRadius(m_cmbCurveName->currentText(),
566 radius);
567 updateControls();
568 updatePreview();
569}
570
571void DlgSettingsCurveProperties::slotPointShape(const QString &)
572{
573 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotPointShape";
574
575 m_isDirty = true;
576
577 m_modelCurveStylesAfter->setPointShape(m_cmbCurveName->currentText(),
578 static_cast<PointShape> (m_cmbPointShape->currentData().toInt ()));
579 updateControls();
580 updatePreview();
581}
582
583void DlgSettingsCurveProperties::slotSaveDefault()
584{
585 LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsCurveProperties::slotSaveDefault";
586
587 QString curve = m_cmbCurveName->currentText ();
588
589 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
590 if (curve == AXIS_CURVE_NAME) {
591
592 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
593
594 } else {
595
596 SettingsForGraph settingsForGraph;
597 QString groupName = settingsForGraph.groupNameForNthCurve(m_cmbCurveName->currentIndex());
598 settings.beginGroup (groupName);
599
600 }
601
602 settings.setValue (SETTINGS_CURVE_POINT_SHAPE,
603 m_modelCurveStylesAfter->pointShape(curve));
604 settings.setValue (SETTINGS_CURVE_LINE_COLOR,
605 m_modelCurveStylesAfter->lineColor(curve));
606 settings.setValue (SETTINGS_CURVE_LINE_CONNECT_AS,
607 m_modelCurveStylesAfter->lineConnectAs(curve));
608 settings.setValue (SETTINGS_CURVE_LINE_WIDTH,
609 m_modelCurveStylesAfter->lineWidth(curve));
610 settings.setValue (SETTINGS_CURVE_POINT_COLOR,
611 m_modelCurveStylesAfter->pointColor (curve));
612 settings.setValue (SETTINGS_CURVE_POINT_LINE_WIDTH,
613 m_modelCurveStylesAfter->pointLineWidth(curve));
614 settings.setValue (SETTINGS_CURVE_POINT_RADIUS,
615 m_modelCurveStylesAfter->pointRadius(curve));
616 settings.endGroup ();
617}
618
619void DlgSettingsCurveProperties::slotWhatsThis ()
620{
621 QWhatsThis::enterWhatsThisMode();
622}
623
624void DlgSettingsCurveProperties::updateControls()
625{
626 bool isGoodState = !m_spinPointRadius->text().isEmpty () &&
627 !m_spinPointLineWidth->text().isEmpty () &&
628 !m_spinLineWidth->text().isEmpty ();
629 m_cmbCurveName->setEnabled (isGoodState); // User needs to fix state before switching curves
630 enableOk (isGoodState && m_isDirty);
631}
632
633void DlgSettingsCurveProperties::updatePreview()
634{
635 m_scenePreview->clear();
636
637 QString currentCurve = m_cmbCurveName->currentText();
638
639 const PointStyle pointStyle = m_modelCurveStylesAfter->curveStyle (currentCurve).pointStyle();
640 const LineStyle lineStyle = m_modelCurveStylesAfter->curveStyle (currentCurve).lineStyle();
641
642 // Function or relation?
643 bool isRelation = (lineStyle.curveConnectAs() == CONNECT_AS_RELATION_SMOOTH ||
645
646 drawPoints (pointStyle);
647 drawLine (isRelation,
648 lineStyle);
649
650 resetSceneRectangle();
651}
const QString AXIS_CURVE_NAME
ColorPalette
CurveConnectAs
@ CONNECT_AS_FUNCTION_STRAIGHT
@ CONNECT_AS_RELATION_STRAIGHT
@ CONNECT_AS_RELATION_SMOOTH
@ CONNECT_AS_FUNCTION_SMOOTH
const int MINIMUM_HEIGHT
const QString CONNECT_AS_FUNCTION_SMOOTH_STR("Function - Smooth")
const double PREVIEW_WIDTH
const QString CONNECT_AS_FUNCTION_STRAIGHT_STR("Function - Straight")
const QString CONNECT_AS_RELATION_SMOOTH_STR("Relation - Smooth")
const QPointF POS_RIGHT(2.0 *PREVIEW_WIDTH/3.0, PREVIEW_HEIGHT *2.0/3.0)
const QString CONNECT_AS_RELATION_STRAIGHT_STR("Relation - Straight")
const QPointF POS_CENTER(PREVIEW_WIDTH/2.0, PREVIEW_HEIGHT/3.0)
const QPointF POS_LEFT(PREVIEW_WIDTH/3.0, PREVIEW_HEIGHT *2.0/3.0)
const double PREVIEW_HEIGHT
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
#define ENGAUGE_CHECK_PTR(ptr)
Drop in replacement for Q_CHECK_PTR.
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
log4cpp::Category * mainCat
Definition Logger.cpp:14
QString pointShapeToString(PointShape pointShape)
PointShape
Definition PointShape.h:12
@ POINT_SHAPE_X
Definition PointShape.h:18
@ POINT_SHAPE_DIAMOND
Definition PointShape.h:15
@ POINT_SHAPE_CIRCLE
Definition PointShape.h:13
@ POINT_SHAPE_TRIANGLE
Definition PointShape.h:17
@ POINT_SHAPE_TRIANGLE2
Definition PointShape.h:20
@ POINT_SHAPE_HOURGLASS
Definition PointShape.h:19
@ POINT_SHAPE_CROSS
Definition PointShape.h:14
@ POINT_SHAPE_SQUARE
Definition PointShape.h:16
const QString SETTINGS_ENGAUGE
const QString SETTINGS_GROUP_CURVE_AXES
const QString SETTINGS_CURVE_POINT_COLOR
const QString SETTINGS_CURVE_LINE_WIDTH
const QString SETTINGS_CURVE_POINT_LINE_WIDTH
const QString SETTINGS_CURVE_POINT_SHAPE
const QString SETTINGS_CURVE_POINT_RADIUS
const QString SETTINGS_CURVE_LINE_CONNECT_AS
const QString SETTINGS_CURVE_LINE_COLOR
const QString SETTINGS_DIGITIZER
Command queue stack.
Definition CmdMediator.h:24
Command for DlgSettingsCurveProperties.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition CurveStyles.h:23
ColorPalette pointColor(const QString &curveName) const
Get method for curve point color in specified curve.
ColorPalette lineColor(const QString &curveName) const
Get method for line color in specified curve.
int pointRadius(const QString &curveName) const
Get method for curve point radius.
int pointLineWidth(const QString &curveName) const
Get method for curve point line width.
CurveConnectAs lineConnectAs(const QString &curveName) const
Get method for connect as method for lines in specified curve.
int lineWidth(const QString &curveName) const
Get method for line width in specified curve.
PointShape pointShape(const QString &curveName) const
Get method for curve point shape.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
void populateColorComboWithTransparent(QComboBox &combo)
Add colors in color palette to combobox, with transparent entry at end.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
DlgSettingsCurveProperties(MainWindow &mainWindow)
Single constructor.
virtual void handleOk()
Process slotOk.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
void setCurveName(const QString &curveName)
Load information for the specified curve name. When called externally, the load method must have been...
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
GraphicsPoint * createPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const PointStyle &pointStyle, GeometryWindow *geometryWindow)
Create circle or polygon point according to the PointStyle.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
Details for a specific Line.
Definition LineStyle.h:20
CurveConnectAs curveConnectAs() const
Get method for connect type.
Definition LineStyle.cpp:63
unsigned int width() const
Width of line.
ColorPalette paletteColor() const
Line color.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
Details for a specific Point.
Definition PointStyle.h:21
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
Definition ViewPreview.h:15
@ VIEW_ASPECT_RATIO_ONE_TO_ONE
Definition ViewPreview.h:23
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18