1 #include "CmdMediator.h"
2 #include "CmdSettingsCurveProperties.h"
3 #include "ColorPalette.h"
4 #include "DlgSettingsCurveProperties.h"
5 #include "EngaugeAssert.h"
7 #include "GraphicsPoint.h"
8 #include "GraphicsPointFactory.h"
9 #include "GraphicsView.h"
11 #include "MainWindow.h"
14 #include <QGraphicsRectItem>
15 #include <QGraphicsScene>
16 #include <QGridLayout>
20 #include <QListWidget>
22 #include <QPushButton>
26 #include "SplinePair.h"
28 #include "ViewPreview.h"
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");
37 const double PREVIEW_WIDTH = 100.0;
38 const double PREVIEW_HEIGHT = 100.0;
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);
49 "DlgSettingsCurveProperties",
53 m_modelCurveStylesBefore (0),
54 m_modelCurveStylesAfter (0)
56 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::DlgSettingsCurveProperties";
61 setMinimumWidth (740);
64 DlgSettingsCurveProperties::~DlgSettingsCurveProperties()
66 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::~DlgSettingsCurveProperties";
69 void DlgSettingsCurveProperties::createCurveName (QGridLayout *layout,
72 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::createCurveName";
74 QLabel *labelCurveName =
new QLabel (
"Curve Name:");
75 layout->addWidget (labelCurveName, row, 1);
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 &)));
80 layout->addWidget (m_cmbCurveName, row++, 2);
83 void DlgSettingsCurveProperties::createLine (QGridLayout *layout,
86 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::createLine";
88 m_groupLine =
new QGroupBox (
"Line");
89 layout->addWidget (m_groupLine, row++, 2);
91 QGridLayout *layoutGroup =
new QGridLayout;
92 m_groupLine->setLayout (layoutGroup);
94 QLabel *labelLineWidth =
new QLabel (
"Width:");
95 layoutGroup->addWidget (labelLineWidth, 0, 0);
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);
104 QLabel *labelLineColor =
new QLabel (
"Color:");
105 layoutGroup->addWidget (labelLineColor, 1, 0);
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."));
111 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
112 layoutGroup->addWidget (m_cmbLineColor, 1, 1);
114 QLabel *labelLineType =
new QLabel (
"Connect as:");
115 layoutGroup->addWidget (labelLineType, 2, 0);
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 "
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 &)));
134 layoutGroup->addWidget (m_cmbLineType, 2, 1);
137 void DlgSettingsCurveProperties::createPoint (QGridLayout *layout,
140 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::createPoint";
142 m_groupPoint =
new QGroupBox (
"Point");
143 layout->addWidget (m_groupPoint, row++, 1);
145 QGridLayout *layoutGroup =
new QGridLayout;
146 m_groupPoint->setLayout (layoutGroup);
148 QLabel *labelPointShape =
new QLabel(
"Shape:");
149 layoutGroup->addWidget (labelPointShape, 0, 0);
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),
155 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_CROSS),
157 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_DIAMOND),
158 POINT_SHAPE_DIAMOND);
159 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_SQUARE),
161 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_TRIANGLE),
162 POINT_SHAPE_TRIANGLE);
163 m_cmbPointShape->addItem (pointShapeToString (POINT_SHAPE_X),
165 connect (m_cmbPointShape, SIGNAL (activated (
const QString &)),
this, SLOT (slotPointShape (
const QString &)));
166 layoutGroup->addWidget (m_cmbPointShape, 0, 1);
168 QLabel *labelPointRadius =
new QLabel (
"Radius:");
169 layoutGroup->addWidget (labelPointRadius, 1, 0);
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);
177 QLabel *labelPointLineWidth =
new QLabel (
"Line width:");
178 layoutGroup->addWidget (labelPointLineWidth, 2, 0);
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);
189 QLabel *labelPointColor =
new QLabel (
"Color:");
190 layoutGroup->addWidget (labelPointColor, 3, 0);
192 m_cmbPointColor =
new QComboBox (m_groupPoint);
193 m_cmbPointColor->setWhatsThis (tr (
"Select a color for the line used to draw the point shapes"));
195 connect (m_cmbPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotPointColor (
const QString &)));
196 layoutGroup->addWidget (m_cmbPointColor, 3, 1);
199 void DlgSettingsCurveProperties::createPreview (QGridLayout *layout,
202 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::createPreview";
204 QLabel *labelPreview =
new QLabel (
"Preview");
205 layout->addWidget (labelPreview, row++, 0, 1, 4);
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);
216 m_viewPreview->setRenderHint (QPainter::Antialiasing);
218 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
223 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::createSubPanel";
225 QWidget *subPanel =
new QWidget ();
226 QGridLayout *layout =
new QGridLayout (subPanel);
227 subPanel->setLayout (layout);
230 createCurveName (layout, row);
232 int rowLeft = row, rowRight = row;
233 createPoint (layout, rowLeft);
234 createLine (layout, rowRight);
236 row = qMax (rowLeft, rowRight);
237 createPreview (layout, row);
239 layout->setColumnStretch(0, 1);
240 layout->setColumnStretch(1, 0);
241 layout->setColumnStretch(2, 0);
242 layout->setColumnStretch(3, 1);
244 layout->setRowStretch (0, 1);
249 void DlgSettingsCurveProperties::drawLine (
bool isRelation,
252 const double Z_LINE = -1.0;
256 QPointF p0 (POS_LEFT), p1 (POS_CENTER), p2 (POS_RIGHT);
269 vector<SplinePair> xy;
278 path.cubicTo (QPointF (spline.p1(0).x(),
280 QPointF (spline.p2(0).x(),
283 path.cubicTo (QPointF (spline.p1(1).x(),
285 QPointF (spline.p2(1).x(),
294 QGraphicsPathItem *line =
new QGraphicsPathItem (path);
295 line->setPen (QPen (QBrush (ColorPaletteToQColor (lineStyle.
paletteColor())),
297 line->setZValue (Z_LINE);
298 m_scenePreview->addItem (line);
301 void DlgSettingsCurveProperties::drawPoints (
const PointStyle &pointStyle)
303 const QString NULL_IDENTIFIER;
331 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::handleOk";
333 ENGAUGE_CHECK_PTR (m_modelCurveStylesBefore);
334 ENGAUGE_CHECK_PTR (m_modelCurveStylesAfter);
338 *m_modelCurveStylesBefore,
339 *m_modelCurveStylesAfter);
347 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::load";
352 if (m_modelCurveStylesBefore != 0) {
353 delete m_modelCurveStylesBefore;
355 if (m_modelCurveStylesAfter != 0) {
356 delete m_modelCurveStylesAfter;
364 m_cmbCurveName->clear ();
365 m_cmbCurveName->addItem (AXIS_CURVE_NAME);
367 QStringList::const_iterator itr;
368 for (itr = curveNames.begin (); itr != curveNames.end (); itr++) {
370 QString curveName = *itr;
371 m_cmbCurveName->addItem (curveName);
374 loadForCurveName (
mainWindow().selectedGraphCurve());
380 void DlgSettingsCurveProperties::loadForCurveName (
const QString &curveName)
382 int indexCurveName = m_cmbCurveName->findText(curveName);
383 ENGAUGE_ASSERT (indexCurveName >= 0);
384 m_cmbCurveName->setCurrentIndex(indexCurveName);
386 int indexPointShape = m_cmbPointShape->findData (QVariant (m_modelCurveStylesAfter->
pointShape (curveName)));
387 ENGAUGE_ASSERT (indexPointShape >= 0);
388 m_cmbPointShape->setCurrentIndex (indexPointShape);
390 m_spinPointRadius->setValue (m_modelCurveStylesAfter->
pointRadius(curveName));
391 m_spinPointLineWidth->setValue (m_modelCurveStylesAfter->
pointLineWidth(curveName));
393 int indexPointColor = m_cmbPointColor->findData (QVariant (m_modelCurveStylesAfter->
pointColor(curveName)));
394 ENGAUGE_ASSERT (indexPointColor >= 0);
395 m_cmbPointColor->setCurrentIndex (indexPointColor);
397 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelCurveStylesAfter->
lineColor(curveName)));
398 ENGAUGE_ASSERT (indexLineColor >= 0);
399 m_cmbLineColor->setCurrentIndex (indexLineColor);
401 m_spinLineWidth->setValue (m_modelCurveStylesAfter->
lineWidth(curveName));
403 int indexCurveConnectAs = m_cmbLineType->findData (QVariant (m_modelCurveStylesAfter->
lineConnectAs (curveName)));
404 if (indexCurveConnectAs >= 0) {
406 m_cmbLineType->setCurrentIndex (indexCurveConnectAs);
410 m_cmbLineColor->setEnabled (curveName != AXIS_CURVE_NAME);
411 m_spinLineWidth->setEnabled (curveName != AXIS_CURVE_NAME);
412 m_cmbLineType->setEnabled (curveName != AXIS_CURVE_NAME);
418 void DlgSettingsCurveProperties::resetSceneRectangle ()
426 QGraphicsRectItem *itemPerimeter =
new QGraphicsRectItem(rect);
427 itemPerimeter->setVisible(
false);
428 m_scenePreview->addItem (itemPerimeter);
429 m_viewPreview->centerOn (QPointF (0.0, 0.0));
434 m_cmbCurveName->setCurrentText (curveName);
435 loadForCurveName (curveName);
438 void DlgSettingsCurveProperties::slotCurveName(
const QString &curveName)
440 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotCurveName";
445 if (!curveName.isEmpty () && (m_modelCurveStylesAfter != 0)) {
447 loadForCurveName (curveName);
451 void DlgSettingsCurveProperties::slotLineColor(
const QString &lineColor)
453 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotLineColor color=" << lineColor.toLatin1().data();
457 m_modelCurveStylesAfter->
setLineColor(m_cmbCurveName->currentText(),
458 (ColorPalette) m_cmbLineColor->currentData().toInt());
463 void DlgSettingsCurveProperties::slotLineWidth(
int width)
465 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotLineWidth width=" << width;
469 m_modelCurveStylesAfter->
setLineWidth(m_cmbCurveName->currentText(),
475 void DlgSettingsCurveProperties::slotLineType(
const QString &lineType)
477 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotLineType lineType=" << lineType.toLatin1().data();
482 (CurveConnectAs) m_cmbLineType->currentData().toInt ());
487 void DlgSettingsCurveProperties::slotPointColor(
const QString &pointColor)
489 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotPointColor pointColor=" << pointColor.toLatin1().data();
493 m_modelCurveStylesAfter->
setPointColor(m_cmbCurveName->currentText(),
494 (ColorPalette) m_cmbPointColor->currentData().toInt ());
499 void DlgSettingsCurveProperties::slotPointLineWidth(
int lineWidth)
501 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotPointLineWidth lineWidth=" << lineWidth;
511 void DlgSettingsCurveProperties::slotPointRadius(
int radius)
513 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotPointRadius radius=" << radius;
517 m_modelCurveStylesAfter->
setPointRadius(m_cmbCurveName->currentText(),
523 void DlgSettingsCurveProperties::slotPointShape(
const QString &)
525 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsCurveProperties::slotPointShape";
529 m_modelCurveStylesAfter->
setPointShape(m_cmbCurveName->currentText(),
530 (PointShape) m_cmbPointShape->currentData().toInt ());
535 void DlgSettingsCurveProperties::updateControls()
537 bool isGoodState = !m_spinPointRadius->text().isEmpty () &&
538 !m_spinPointLineWidth->text().isEmpty () &&
539 !m_spinLineWidth->text().isEmpty ();
540 m_cmbCurveName->setEnabled (isGoodState);
541 enableOk (isGoodState && m_isDirty);
544 void DlgSettingsCurveProperties::updatePreview()
546 m_scenePreview->clear();
548 QString currentCurve = m_cmbCurveName->currentText();
554 bool isRelation = (lineStyle.
curveConnectAs() == CONNECT_AS_RELATION_SMOOTH ||
557 drawPoints (pointStyle);
558 drawLine (isRelation,
561 resetSceneRectangle();
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.
Cubic interpolation given independent and dependent value vectors.
void setPointLineWidth(const QString &curveName, int width)
Set method for curve point perimeter line width.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
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.
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.
DlgSettingsCurveProperties(MainWindow &mainWindow)
Single constructor.
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.
ColorPalette lineColor(const QString &curveName) const
Get method for line color in specified curve.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
Details for a specific Point.
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.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
Details for a specific Line.
PointShape pointShape(const QString &curveName) const
Get method for curve point shape.
Graphics item for drawing a circular or polygonal Point.
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.
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
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.
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...
Single X/Y pair for cubic spline interpolation initialization and calculations.
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.