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