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