22#include <QGraphicsRectItem>
23#include <QGraphicsScene>
63 "DlgSettingsCurveProperties",
65 m_modelMainWindow (mainWindow.modelMainWindow()),
66 m_scenePreview (nullptr),
67 m_viewPreview (nullptr),
68 m_modelCurveStylesBefore (nullptr),
69 m_modelCurveStylesAfter (nullptr)
76 setMinimumWidth (740);
84void DlgSettingsCurveProperties::createCurveName (QGridLayout *layout,
89 QLabel *labelCurveName =
new QLabel (QString (
"%1:").arg (tr (
"Curve Name")));
90 layout->addWidget (labelCurveName, row, 1);
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 &)));
95 layout->addWidget (m_cmbCurveName, row++, 2);
98void DlgSettingsCurveProperties::createLine (QGridLayout *layout,
103 m_groupLine =
new QGroupBox (tr (
"Line"));
104 layout->addWidget (m_groupLine, row++, 2);
106 QGridLayout *layoutGroup =
new QGridLayout;
107 m_groupLine->setLayout (layoutGroup);
109 QLabel *labelLineWidth =
new QLabel (QString (
"%1:").arg (tr (
"Width")));
110 layoutGroup->addWidget (labelLineWidth, 0, 0);
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);
119 QLabel *labelLineColor =
new QLabel (QString (
"%1:").arg (tr (
"Color")));
120 layoutGroup->addWidget (labelLineColor, 1, 0);
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."));
126 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
127 layoutGroup->addWidget (m_cmbLineColor, 1, 1);
129 QLabel *labelLineType =
new QLabel (QString (
"%1:").arg (tr (
"Connect as")));
130 layoutGroup->addWidget (labelLineType, 2, 0);
132 m_cmbLineType =
new QComboBox (m_groupLine);
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 "
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 &)));
150 layoutGroup->addWidget (m_cmbLineType, 2, 1);
153void DlgSettingsCurveProperties::createPoint (QGridLayout *layout,
158 m_groupPoint =
new QGroupBox (tr (
"Point"));
159 layout->addWidget (m_groupPoint, row++, 1);
161 QGridLayout *layoutGroup =
new QGridLayout;
162 m_groupPoint->setLayout (layoutGroup);
164 QLabel *labelPointShape =
new QLabel(QString (
"%1:").arg (tr (
"Shape")));
165 layoutGroup->addWidget (labelPointShape, 0, 0);
167 m_cmbPointShape =
new QComboBox (m_groupPoint);
168 m_cmbPointShape->setWhatsThis (tr (
"Select a shape for the points"));
185 connect (m_cmbPointShape, SIGNAL (activated (
const QString &)),
this, SLOT (slotPointShape (
const QString &)));
186 layoutGroup->addWidget (m_cmbPointShape, 0, 1);
188 QLabel *labelPointRadius =
new QLabel (QString (
"%1:").arg (tr (
"Radius")));
189 layoutGroup->addWidget (labelPointRadius, 1, 0);
191 m_spinPointRadius =
new QSpinBox (m_groupPoint);
192 m_spinPointRadius->setWhatsThis (tr (
"Select a radius, in pixels, for the points"));
193 m_spinPointRadius->setMinimum (1);
194 connect (m_spinPointRadius, SIGNAL (valueChanged (
int)),
this, SLOT (slotPointRadius (
int)));
195 layoutGroup->addWidget (m_spinPointRadius, 1, 1);
197 QLabel *labelPointLineWidth =
new QLabel (QString (
"%1:").arg (tr (
"Line width")));
198 layoutGroup->addWidget (labelPointLineWidth, 2, 0);
200 m_spinPointLineWidth =
new QSpinBox (m_groupPoint);
201 m_spinPointLineWidth->setWhatsThis (tr (
"Select a line width, in pixels, for the points.\n\n"
202 "A larger width results in a thicker line, with the exception of a value of zero "
203 "which always results in a line that is one pixel wide (which is easy to see even "
204 "when zoomed far out)"));
205 m_spinPointLineWidth->setMinimum (0);
206 connect (m_spinPointLineWidth, SIGNAL (valueChanged (
int)),
this, SLOT (slotPointLineWidth (
int)));
207 layoutGroup->addWidget (m_spinPointLineWidth, 2, 1);
209 QLabel *labelPointColor =
new QLabel (QString (
"%1:").arg (tr (
"Color")));
210 layoutGroup->addWidget (labelPointColor, 3, 0);
212 m_cmbPointColor =
new QComboBox (m_groupPoint);
213 m_cmbPointColor->setWhatsThis (tr (
"Select a color for the line used to draw the point shapes"));
215 connect (m_cmbPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotPointColor (
const QString &)));
216 layoutGroup->addWidget (m_cmbPointColor, 3, 1);
223 m_btnSaveDefault =
new QPushButton (
"Save As Default");
224 m_btnSaveDefault->setWhatsThis (tr (
"Save the visible curve settings for use as future defaults, according to the curve name selection.\n\n"
225 "If the visible settings are for the axes curve, then they will be used for future "
226 "axes curves, until new settings are saved as the defaults.\n\n"
227 "If the visible settings are for the Nth graph curve in the curve list, then they will be used for future "
228 "graph curves that are also the Nth graph curve in their curve list, until new settings are saved as the defaults."));
229 connect (m_btnSaveDefault, SIGNAL (released ()),
this, SLOT (slotSaveDefault ()));
230 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
233void DlgSettingsCurveProperties::createPreview (QGridLayout *layout,
238 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
239 layout->addWidget (labelPreview, row++, 0, 1, 4);
241 m_scenePreview =
new QGraphicsScene (
this);
245 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the points and line of the selected curve.\n\n"
246 "The X coordinate is in the horizontal direction, and the Y coordinate is in the vertical direction. A "
247 "function can have only one Y value, at most, for any X value, but a relation can have multiple Y values "
248 "for one X value."));
249 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
250 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
252 m_viewPreview->setRenderHint (QPainter::Antialiasing);
254 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
261 QWidget *subPanel =
new QWidget ();
262 QGridLayout *layout =
new QGridLayout (subPanel);
263 subPanel->setLayout (layout);
266 createCurveName (layout, row);
268 int rowLeft = row, rowRight = row++;
269 createPoint (layout, rowLeft);
270 createLine (layout, rowRight);
271 createPreview (layout, row);
273 layout->setColumnStretch(0, 1);
274 layout->setColumnStretch(1, 0);
275 layout->setColumnStretch(2, 0);
276 layout->setColumnStretch(3, 1);
278 layout->setRowStretch (0, 1);
283void DlgSettingsCurveProperties::drawLine (
bool isRelation,
286 const double Z_LINE = -1.0;
303 vector<SplinePair> xy;
312 path.cubicTo (QPointF (spline.p1(0).x(),
314 QPointF (spline.p2(0).x(),
317 path.cubicTo (QPointF (spline.p1(1).x(),
319 QPointF (spline.p2(1).x(),
328 QGraphicsPathItem *line =
new QGraphicsPathItem (path);
331 line->setZValue (Z_LINE);
332 m_scenePreview->addItem (line);
335void DlgSettingsCurveProperties::drawPoints (
const PointStyle &pointStyle)
337 const QString NULL_IDENTIFIER;
347 NULL_GEOMETRY_WINDOW);
355 NULL_GEOMETRY_WINDOW);
363 NULL_GEOMETRY_WINDOW);
376 *m_modelCurveStylesBefore,
377 *m_modelCurveStylesAfter);
390 delete m_modelCurveStylesBefore;
391 delete m_modelCurveStylesAfter;
398 m_cmbCurveName->clear ();
401 QStringList::const_iterator itr;
402 for (itr = curveNames.begin (); itr != curveNames.end (); itr++) {
404 QString curveName = *itr;
405 m_cmbCurveName->addItem (curveName);
408 loadForCurveName (
mainWindow().selectedGraphCurve());
414void DlgSettingsCurveProperties::loadForCurveName (
const QString &curveName)
416 int indexCurveName = m_cmbCurveName->findText(curveName);
418 m_cmbCurveName->setCurrentIndex(indexCurveName);
420 int indexPointShape = m_cmbPointShape->findData (QVariant (m_modelCurveStylesAfter->
pointShape (curveName)));
422 m_cmbPointShape->setCurrentIndex (indexPointShape);
424 m_spinPointRadius->setValue (m_modelCurveStylesAfter->
pointRadius(curveName));
425 m_spinPointLineWidth->setValue (m_modelCurveStylesAfter->
pointLineWidth(curveName));
427 int indexPointColor = m_cmbPointColor->findData (QVariant (m_modelCurveStylesAfter->
pointColor(curveName)));
429 m_cmbPointColor->setCurrentIndex (indexPointColor);
431 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelCurveStylesAfter->
lineColor(curveName)));
433 m_cmbLineColor->setCurrentIndex (indexLineColor);
435 m_spinLineWidth->setValue (m_modelCurveStylesAfter->
lineWidth(curveName));
437 int indexCurveConnectAs = m_cmbLineType->findData (QVariant (m_modelCurveStylesAfter->
lineConnectAs (curveName)));
438 if (indexCurveConnectAs >= 0) {
440 m_cmbLineType->setCurrentIndex (indexCurveConnectAs);
452void DlgSettingsCurveProperties::resetSceneRectangle ()
460 QGraphicsRectItem *itemPerimeter =
new QGraphicsRectItem(rect);
461 itemPerimeter->setVisible(
false);
462 m_scenePreview->addItem (itemPerimeter);
463 m_viewPreview->centerOn (QPointF (0.0, 0.0));
468 m_cmbCurveName->setCurrentText (curveName);
469 loadForCurveName (curveName);
479void DlgSettingsCurveProperties::slotCurveName(
const QString &curveName)
486 if (!curveName.isEmpty () && (m_modelCurveStylesAfter !=
nullptr)) {
488 loadForCurveName (curveName);
492void DlgSettingsCurveProperties::slotLineColor(
const QString &lineColor)
494 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotLineColor color=" << lineColor.toLatin1().data();
498 m_modelCurveStylesAfter->
setLineColor(m_cmbCurveName->currentText(),
499 static_cast<ColorPalette> (m_cmbLineColor->currentData().toInt()));
504void DlgSettingsCurveProperties::slotLineWidth(
int width)
510 m_modelCurveStylesAfter->
setLineWidth(m_cmbCurveName->currentText(),
516void DlgSettingsCurveProperties::slotLineType(
const QString &lineType)
518 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotLineType lineType=" << lineType.toLatin1().data();
523 static_cast<CurveConnectAs> (m_cmbLineType->currentData().toInt ()));
528void DlgSettingsCurveProperties::slotPointColor(
const QString &pointColor)
530 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotPointColor pointColor=" << pointColor.toLatin1().data();
534 m_modelCurveStylesAfter->
setPointColor(m_cmbCurveName->currentText(),
535 static_cast<ColorPalette> (m_cmbPointColor->currentData().toInt ()));
540void DlgSettingsCurveProperties::slotPointLineWidth(
int lineWidth)
542 LOG4CPP_INFO_S ((*
mainCat)) <<
"DlgSettingsCurveProperties::slotPointLineWidth lineWidth=" << lineWidth;
552void DlgSettingsCurveProperties::slotPointRadius(
int radius)
558 m_modelCurveStylesAfter->
setPointRadius(m_cmbCurveName->currentText(),
564void DlgSettingsCurveProperties::slotPointShape(
const QString &)
570 m_modelCurveStylesAfter->
setPointShape(m_cmbCurveName->currentText(),
571 static_cast<PointShape> (m_cmbPointShape->currentData().toInt ()));
576void DlgSettingsCurveProperties::slotSaveDefault()
580 QString curve = m_cmbCurveName->currentText ();
591 settings.beginGroup (groupName);
598 m_modelCurveStylesAfter->
lineColor(curve));
602 m_modelCurveStylesAfter->
lineWidth(curve));
609 settings.endGroup ();
612void DlgSettingsCurveProperties::updateControls()
614 bool isGoodState = !m_spinPointRadius->text().isEmpty () &&
615 !m_spinPointLineWidth->text().isEmpty () &&
616 !m_spinLineWidth->text().isEmpty ();
617 m_cmbCurveName->setEnabled (isGoodState);
618 enableOk (isGoodState && m_isDirty);
621void DlgSettingsCurveProperties::updatePreview()
623 m_scenePreview->clear();
625 QString currentCurve = m_cmbCurveName->currentText();
634 drawPoints (pointStyle);
635 drawLine (isRelation,
638 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 if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
#define ENGAUGE_CHECK_PTR(ptr)
#endif
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.
LineStyle lineStyle() const
Get method for LineStyle.
PointStyle pointStyle() const
Get method for PointStyle.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
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.
void setPointLineWidth(const QString &curveName, int width)
Set method for curve point perimeter line width.
void setPointColor(const QString &curveName, ColorPalette curveColor)
Set method 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.
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
CurveConnectAs lineConnectAs(const QString &curveName) const
Get method for connect as method for lines in specified curve.
void setLineColor(const QString &curveName, ColorPalette lineColor)
Set method for line color in specified curve.
int lineWidth(const QString &curveName) const
Get method for line width in specified curve.
void setPointShape(const QString &curveName, PointShape shape)
Set method for curve point shape in specified curve.
void setLineWidth(const QString &curveName, int width)
Set method for line width in specified curve.
PointShape pointShape(const QString &curveName) const
Get method for curve point shape.
void setLineConnectAs(const QString &curveName, CurveConnectAs curveConnectAs)
Set method for connect as method for lines in specified curve.
Abstract base class for all Settings dialogs.
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 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.
Window that displays the geometry information, as a table, for the current curve.
Factor for generating GraphicsPointAbstractBase class objects.
GraphicsPoint * createPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const PointStyle &pointStyle, GeometryWindow *geometryWindow)
Create circle or polygon point according to the PointStyle.
Graphics item for drawing a circular or polygonal Point.
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.
Manage storage and retrieval of the settings for the curves.
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.
Single X/Y pair for cubic spline interpolation initialization and calculations.
Cubic interpolation given independent and dependent value vectors.
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)