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