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