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