23#include <QGraphicsRectItem>
24#include <QGraphicsScene>
65 "DlgSettingsCurveProperties",
67 m_modelMainWindow (
mainWindow.modelMainWindow()),
68 m_scenePreview (nullptr),
69 m_viewPreview (nullptr),
70 m_modelCurveStylesBefore (nullptr),
71 m_modelCurveStylesAfter (nullptr)
78 setMinimumWidth (740);
86void DlgSettingsCurveProperties::createCurveName (QGridLayout *layout,
91 QLabel *labelCurveName =
new QLabel (QString (
"%1:").arg (tr (
"Curve Name")));
92 layout->addWidget (labelCurveName, row, 1, 1, 1);
94 m_cmbCurveName =
new QComboBox ();
95 m_cmbCurveName->setWhatsThis (tr (
"Name of the curve that is currently selected for editing"));
96 connect (m_cmbCurveName, SIGNAL (activated (
const QString &)),
this, SLOT (slotCurveName (
const QString &)));
97 layout->addWidget (m_cmbCurveName, row, 2, 1, 1);
105void DlgSettingsCurveProperties::createLine (QGridLayout *layout,
110 m_groupLine =
new QGroupBox (tr (
"Line"));
111 layout->addWidget (m_groupLine, row++, 2);
113 QGridLayout *layoutGroup =
new QGridLayout;
114 m_groupLine->setLayout (layoutGroup);
116 QLabel *labelLineWidth =
new QLabel (QString (
"%1:").arg (tr (
"Width")));
117 layoutGroup->addWidget (labelLineWidth, 0, 0);
119 m_spinLineWidth =
new QSpinBox (m_groupLine);
120 m_spinLineWidth->setWhatsThis (tr (
"Select a width for the lines drawn between points.\n\n"
121 "This applies only to graph curves. No lines are ever drawn between axis points."));
122 m_spinLineWidth->setMinimum(1);
123 connect (m_spinLineWidth, SIGNAL (valueChanged (
int)),
this, SLOT (slotLineWidth (
int)));
124 layoutGroup->addWidget (m_spinLineWidth, 0, 1);
126 QLabel *labelLineColor =
new QLabel (QString (
"%1:").arg (tr (
"Color")));
127 layoutGroup->addWidget (labelLineColor, 1, 0);
129 m_cmbLineColor =
new QComboBox (m_groupLine);
130 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the lines drawn between points.\n\n"
131 "This applies only to graph curves. No lines are ever drawn between axis points."));
133 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
134 layoutGroup->addWidget (m_cmbLineColor, 1, 1);
136 QLabel *labelLineType =
new QLabel (QString (
"%1:").arg (tr (
"Connect as")));
137 layoutGroup->addWidget (labelLineType, 2, 0);
139 m_cmbLineType =
new QComboBox (m_groupLine);
144 m_cmbLineType->setWhatsThis (tr (
"Select rule for connecting points with lines.\n\n"
145 "If the curve is connected as a single-valued function then the points are ordered by "
146 "increasing value of the independent variable.\n\n"
147 "If the curve is connected as a closed contour, then the points are ordered by age, except for "
148 "points placed along an existing line. Any point placed on top of any existing line is inserted "
149 "between the two endpoints of that line - as if its age was between the ages of the two "
151 "Lines are drawn between successively ordered points.\n\n"
152 "Straight curves are drawn with straight lines between successive points. Smooth curves are drawn "
153 "with smooth lines between successive points, using natural cubic splines of (x,y) pairs versus "
154 "scalar ordinal (t) values.\n\n"
155 "This applies only to graph curves. No lines are ever drawn between axis points."));
156 connect (m_cmbLineType, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineType (
const QString &)));
157 layoutGroup->addWidget (m_cmbLineType, 2, 1);
160void DlgSettingsCurveProperties::createPoint (QGridLayout *layout,
165 m_groupPoint =
new QGroupBox (tr (
"Point"));
166 layout->addWidget (m_groupPoint, row++, 1);
168 QGridLayout *layoutGroup =
new QGridLayout;
169 m_groupPoint->setLayout (layoutGroup);
171 QLabel *labelPointShape =
new QLabel(QString (
"%1:").arg (tr (
"Shape")));
172 layoutGroup->addWidget (labelPointShape, 0, 0);
174 m_cmbPointShape =
new QComboBox (m_groupPoint);
175 m_cmbPointShape->setWhatsThis (tr (
"Select a shape for the points"));
192 connect (m_cmbPointShape, SIGNAL (activated (
const QString &)),
this, SLOT (slotPointShape (
const QString &)));
193 layoutGroup->addWidget (m_cmbPointShape, 0, 1);
195 QLabel *labelPointRadius =
new QLabel (QString (
"%1:").arg (tr (
"Radius")));
196 layoutGroup->addWidget (labelPointRadius, 1, 0);
198 m_spinPointRadius =
new QSpinBox (m_groupPoint);
199 m_spinPointRadius->setWhatsThis (tr (
"Select a radius, in pixels, for the points"));
200 m_spinPointRadius->setMinimum (1);
201 connect (m_spinPointRadius, SIGNAL (valueChanged (
int)),
this, SLOT (slotPointRadius (
int)));
202 layoutGroup->addWidget (m_spinPointRadius, 1, 1);
204 QLabel *labelPointLineWidth =
new QLabel (QString (
"%1:").arg (tr (
"Line width")));
205 layoutGroup->addWidget (labelPointLineWidth, 2, 0);
207 m_spinPointLineWidth =
new QSpinBox (m_groupPoint);
208 m_spinPointLineWidth->setWhatsThis (tr (
"Select a line width, in pixels, for the points.\n\n"
209 "A larger width results in a thicker line, with the exception of a value of zero "
210 "which always results in a line that is one pixel wide (which is easy to see even "
211 "when zoomed far out)"));
212 m_spinPointLineWidth->setMinimum (0);
213 connect (m_spinPointLineWidth, SIGNAL (valueChanged (
int)),
this, SLOT (slotPointLineWidth (
int)));
214 layoutGroup->addWidget (m_spinPointLineWidth, 2, 1);
216 QLabel *labelPointColor =
new QLabel (QString (
"%1:").arg (tr (
"Color")));
217 layoutGroup->addWidget (labelPointColor, 3, 0);
219 m_cmbPointColor =
new QComboBox (m_groupPoint);
220 m_cmbPointColor->setWhatsThis (tr (
"Select a color for the line used to draw the point shapes"));
222 connect (m_cmbPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotPointColor (
const QString &)));
223 layoutGroup->addWidget (m_cmbPointColor, 3, 1);
230 m_btnSaveDefault =
new QPushButton (
"Save As Default");
231 m_btnSaveDefault->setWhatsThis (tr (
"Save the visible curve settings for use as future defaults, according to the curve name selection.\n\n"
232 "If the visible settings are for the axes curve, then they will be used for future "
233 "axes curves, until new settings are saved as the defaults.\n\n"
234 "If the visible settings are for the Nth graph curve in the curve list, then they will be used for future "
235 "graph curves that are also the Nth graph curve in their curve list, until new settings are saved as the defaults."));
236 connect (m_btnSaveDefault, SIGNAL (released ()),
this, SLOT (slotSaveDefault ()));
237 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
240void DlgSettingsCurveProperties::createPreview (QGridLayout *layout,
245 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
246 layout->addWidget (labelPreview, row++, 0, 1, 4);
248 m_scenePreview =
new QGraphicsScene (
this);
252 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the points and line of the selected curve.\n\n"
253 "The X coordinate is in the horizontal direction, and the Y coordinate is in the vertical direction. A "
254 "function can have only one Y value, at most, for any X value, but a relation can have multiple Y values "
255 "for one X value."));
256 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
257 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
259 m_viewPreview->setRenderHint (QPainter::Antialiasing);
261 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
268 QWidget *subPanel =
new QWidget ();
269 QGridLayout *layout =
new QGridLayout (subPanel);
270 subPanel->setLayout (layout);
273 createCurveName (layout, row);
275 int rowLeft = row, rowRight = row++;
276 createPoint (layout, rowLeft);
277 createLine (layout, rowRight);
278 createPreview (layout, row);
280 layout->setColumnStretch(0, 1);
281 layout->setColumnStretch(1, 0);
282 layout->setColumnStretch(2, 0);
283 layout->setColumnStretch(3, 1);
285 layout->setRowStretch (0, 1);
290void DlgSettingsCurveProperties::drawLine (
bool isRelation,
293 const double Z_LINE = -1.0;
310 vector<SplinePair> xy;
314 xy.push_back (SplinePair (p0.x(), p0.y()));
315 xy.push_back (SplinePair (p1.x(), p1.y()));
316 xy.push_back (SplinePair (p2.x(), p2.y()));
317 Spline spline (t, xy);
319 path.cubicTo (QPointF (spline.p1(0).x(),
321 QPointF (spline.p2(0).x(),
324 path.cubicTo (QPointF (spline.p1(1).x(),
326 QPointF (spline.p2(1).x(),
335 QGraphicsPathItem *line =
new QGraphicsPathItem (path);
338 line->setZValue (Z_LINE);
339 m_scenePreview->addItem (line);
342void DlgSettingsCurveProperties::drawPoints (
const PointStyle &pointStyle)
344 const QString NULL_IDENTIFIER;
345 GeometryWindow *NULL_GEOMETRY_WINDOW =
nullptr;
347 GraphicsPointFactory pointFactory;
350 GraphicsPoint *pointLeft = pointFactory.
createPoint (*m_scenePreview,
354 NULL_GEOMETRY_WINDOW);
358 GraphicsPoint *pointCenter = pointFactory.
createPoint (*m_scenePreview,
362 NULL_GEOMETRY_WINDOW);
366 GraphicsPoint *pointRight = pointFactory.
createPoint (*m_scenePreview,
370 NULL_GEOMETRY_WINDOW);
383 *m_modelCurveStylesBefore,
384 *m_modelCurveStylesAfter);
397 delete m_modelCurveStylesBefore;
398 delete m_modelCurveStylesAfter;
405 m_cmbCurveName->clear ();
407 QStringList curveNames =
cmdMediator.curvesGraphsNames();
408 QStringList::const_iterator itr;
409 for (itr = curveNames.begin (); itr != curveNames.end (); itr++) {
411 QString curveName = *itr;
412 m_cmbCurveName->addItem (curveName);
415 loadForCurveName (
mainWindow().selectedGraphCurve());
421void DlgSettingsCurveProperties::loadForCurveName (
const QString &curveName)
423 int indexCurveName = m_cmbCurveName->findText(curveName);
425 m_cmbCurveName->setCurrentIndex(indexCurveName);
427 int indexPointShape = m_cmbPointShape->findData (QVariant (m_modelCurveStylesAfter->
pointShape (curveName)));
429 m_cmbPointShape->setCurrentIndex (indexPointShape);
431 m_spinPointRadius->setValue (m_modelCurveStylesAfter->
pointRadius(curveName));
432 m_spinPointLineWidth->setValue (m_modelCurveStylesAfter->
pointLineWidth(curveName));
434 int indexPointColor = m_cmbPointColor->findData (QVariant (m_modelCurveStylesAfter->
pointColor(curveName)));
436 m_cmbPointColor->setCurrentIndex (indexPointColor);
438 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelCurveStylesAfter->
lineColor(curveName)));
440 m_cmbLineColor->setCurrentIndex (indexLineColor);
442 m_spinLineWidth->setValue (m_modelCurveStylesAfter->
lineWidth(curveName));
444 int indexCurveConnectAs = m_cmbLineType->findData (QVariant (m_modelCurveStylesAfter->
lineConnectAs (curveName)));
445 if (indexCurveConnectAs >= 0) {
447 m_cmbLineType->setCurrentIndex (indexCurveConnectAs);
459void DlgSettingsCurveProperties::resetSceneRectangle ()
467 QGraphicsRectItem *itemPerimeter =
new QGraphicsRectItem(rect);
468 itemPerimeter->setVisible(
false);
469 m_scenePreview->addItem (itemPerimeter);
470 m_viewPreview->centerOn (QPointF (0.0, 0.0));
475 m_cmbCurveName->setCurrentText (curveName);
476 loadForCurveName (curveName);
486void DlgSettingsCurveProperties::slotCurveName(
const QString &curveName)
493 if (!curveName.isEmpty () && (m_modelCurveStylesAfter !=
nullptr)) {
495 loadForCurveName (curveName);
499void DlgSettingsCurveProperties::slotLineColor(
const QString &lineColor)
501 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotLineColor color=" << lineColor.toLatin1().data();
505 m_modelCurveStylesAfter->setLineColor(m_cmbCurveName->currentText(),
506 static_cast<ColorPalette> (m_cmbLineColor->currentData().toInt()));
511void DlgSettingsCurveProperties::slotLineWidth(
int width)
517 m_modelCurveStylesAfter->setLineWidth(m_cmbCurveName->currentText(),
523void DlgSettingsCurveProperties::slotLineType(
const QString &lineType)
525 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotLineType lineType=" << lineType.toLatin1().data();
529 m_modelCurveStylesAfter->setLineConnectAs(m_cmbCurveName->currentText(),
530 static_cast<CurveConnectAs> (m_cmbLineType->currentData().toInt ()));
535void DlgSettingsCurveProperties::slotPointColor(
const QString &pointColor)
537 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotPointColor pointColor=" << pointColor.toLatin1().data();
541 m_modelCurveStylesAfter->setPointColor(m_cmbCurveName->currentText(),
542 static_cast<ColorPalette> (m_cmbPointColor->currentData().toInt ()));
547void DlgSettingsCurveProperties::slotPointLineWidth(
int lineWidth)
549 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotPointLineWidth lineWidth=" << lineWidth;
553 m_modelCurveStylesAfter->setPointLineWidth(m_cmbCurveName->currentText(),
559void DlgSettingsCurveProperties::slotPointRadius(
int radius)
565 m_modelCurveStylesAfter->setPointRadius(m_cmbCurveName->currentText(),
571void DlgSettingsCurveProperties::slotPointShape(
const QString &)
577 m_modelCurveStylesAfter->setPointShape(m_cmbCurveName->currentText(),
578 static_cast<PointShape> (m_cmbPointShape->currentData().toInt ()));
583void DlgSettingsCurveProperties::slotSaveDefault()
587 QString curve = m_cmbCurveName->currentText ();
596 SettingsForGraph settingsForGraph;
598 settings.beginGroup (groupName);
603 m_modelCurveStylesAfter->pointShape(curve));
605 m_modelCurveStylesAfter->lineColor(curve));
607 m_modelCurveStylesAfter->lineConnectAs(curve));
609 m_modelCurveStylesAfter->lineWidth(curve));
611 m_modelCurveStylesAfter->pointColor (curve));
613 m_modelCurveStylesAfter->pointLineWidth(curve));
615 m_modelCurveStylesAfter->pointRadius(curve));
616 settings.endGroup ();
619void DlgSettingsCurveProperties::slotWhatsThis ()
621 QWhatsThis::enterWhatsThisMode();
624void DlgSettingsCurveProperties::updateControls()
626 bool isGoodState = !m_spinPointRadius->text().isEmpty () &&
627 !m_spinPointLineWidth->text().isEmpty () &&
628 !m_spinLineWidth->text().isEmpty ();
629 m_cmbCurveName->setEnabled (isGoodState);
630 enableOk (isGoodState && m_isDirty);
633void DlgSettingsCurveProperties::updatePreview()
635 m_scenePreview->clear();
637 QString currentCurve = m_cmbCurveName->currentText();
639 const PointStyle pointStyle = m_modelCurveStylesAfter->curveStyle (currentCurve).pointStyle();
640 const LineStyle lineStyle = m_modelCurveStylesAfter->curveStyle (currentCurve).lineStyle();
646 drawPoints (pointStyle);
647 drawLine (isRelation,
650 resetSceneRectangle();
const QString AXIS_CURVE_NAME
@ CONNECT_AS_FUNCTION_STRAIGHT
@ CONNECT_AS_RELATION_STRAIGHT
@ CONNECT_AS_RELATION_SMOOTH
@ CONNECT_AS_FUNCTION_SMOOTH
const QString CONNECT_AS_FUNCTION_SMOOTH_STR("Function - Smooth")
const double PREVIEW_WIDTH
const QString CONNECT_AS_FUNCTION_STRAIGHT_STR("Function - Straight")
const QString CONNECT_AS_RELATION_SMOOTH_STR("Relation - Smooth")
const QPointF POS_RIGHT(2.0 *PREVIEW_WIDTH/3.0, PREVIEW_HEIGHT *2.0/3.0)
const QString CONNECT_AS_RELATION_STRAIGHT_STR("Relation - Straight")
const QPointF POS_CENTER(PREVIEW_WIDTH/2.0, PREVIEW_HEIGHT/3.0)
const QPointF POS_LEFT(PREVIEW_WIDTH/3.0, PREVIEW_HEIGHT *2.0/3.0)
const double PREVIEW_HEIGHT
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
#define ENGAUGE_CHECK_PTR(ptr)
Drop in replacement for Q_CHECK_PTR.
QColor ColorPaletteToQColor(ColorPalette color)
log4cpp::Category * mainCat
QString pointShapeToString(PointShape pointShape)
const QString SETTINGS_ENGAUGE
const QString SETTINGS_GROUP_CURVE_AXES
const QString SETTINGS_CURVE_POINT_COLOR
const QString SETTINGS_CURVE_LINE_WIDTH
const QString SETTINGS_CURVE_POINT_LINE_WIDTH
const QString SETTINGS_CURVE_POINT_SHAPE
const QString SETTINGS_CURVE_POINT_RADIUS
const QString SETTINGS_CURVE_LINE_CONNECT_AS
const QString SETTINGS_CURVE_LINE_COLOR
const QString SETTINGS_DIGITIZER
Command for DlgSettingsCurveProperties.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
ColorPalette pointColor(const QString &curveName) const
Get method for curve point color in specified curve.
ColorPalette lineColor(const QString &curveName) const
Get method for line color in specified curve.
int pointRadius(const QString &curveName) const
Get method for curve point radius.
int pointLineWidth(const QString &curveName) const
Get method for curve point line width.
CurveConnectAs lineConnectAs(const QString &curveName) const
Get method for connect as method for lines in specified curve.
int lineWidth(const QString &curveName) const
Get method for line width in specified curve.
PointShape pointShape(const QString &curveName) const
Get method for curve point shape.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
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 populateColorComboWithTransparent(QComboBox &combo)
Add colors in color palette to combobox, with transparent entry at end.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
DlgSettingsCurveProperties(MainWindow &mainWindow)
Single constructor.
virtual void handleOk()
Process slotOk.
virtual ~DlgSettingsCurveProperties()
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
void setCurveName(const QString &curveName)
Load information for the specified curve name. When called externally, the load method must have been...
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
GraphicsPoint * createPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const PointStyle &pointStyle, GeometryWindow *geometryWindow)
Create circle or polygon point according to the PointStyle.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
Details for a specific Line.
CurveConnectAs curveConnectAs() const
Get method for connect type.
unsigned int width() const
Width of line.
ColorPalette paletteColor() const
Line color.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Details for a specific Point.
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
@ VIEW_ASPECT_RATIO_ONE_TO_ONE
#define LOG4CPP_INFO_S(logger)