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