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