ACF $AcfVersion:0$
CGraphPlotShape.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtGui/QPainter>
7
8// ACF includes
10#include <i2d/CGraphData2d.h>
11
12
13namespace iview
14{
15
16
29{
30public:
32
34
38 int GetPlotMargin() const;
39
43 void SetPlotMargin(int margin);
44
48 int GetAxisLabelFontSize() const;
49
53 void SetAxisLabelFontSize(int size);
54
58 int GetTickLabelFontSize() const;
59
63 void SetTickLabelFontSize(int size);
64
68 int GetCurveLineWidth() const;
69
73 void SetCurveLineWidth(int width);
74
75 // reimplemented (imod::IObserver)
76 virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask) override;
77
78 // reimplemented (iview::ITouchable)
79 virtual TouchState IsTouched(istd::CIndex2d position) const override;
80
81protected:
82 // reimplemented (iview::CRectControlledShapeBase)
83 virtual void EnsureValidNodes() const override;
84 virtual bool IsCurveTouched(istd::CIndex2d position) const override;
85 virtual void DrawFigure(QPainter& drawContext) const override;
86
87 // reimplemented (iview::CShapeBase)
88 virtual i2d::CRect CalcBoundingBox() const override;
89
90private:
94 void DrawAxes(QPainter& drawContext, const QRectF& plotRect, const i2d::CGraphData2d* graphPtr) const;
95
99 void DrawGrid(QPainter& drawContext, const QRectF& plotRect, const i2d::CGraphData2d* graphPtr) const;
100
104 void DrawCurves(QPainter& drawContext, const QRectF& plotRect, const i2d::CGraphData2d* graphPtr) const;
105
109 void DrawLegend(QPainter& drawContext, const QRectF& plotRect, const i2d::CGraphData2d* graphPtr) const;
110
114 void DrawTitle(QPainter& drawContext, const QRectF& plotRect, const i2d::CGraphData2d* graphPtr) const;
115
119 QPointF DataToScreen(const i2d::CVector2d& dataPoint, const QRectF& plotRect,
120 const istd::CRange& xRange, const istd::CRange& yRange) const;
121
125 QVector<double> CalculateTickPositions(const istd::CRange& range, int maxTicks = 10) const;
126
130 QString FormatTickLabel(double value) const;
131
132 int m_plotMargin;
133 int m_axisLabelFontSize;
134 int m_tickLabelFontSize;
135 int m_curveLineWidth;
136};
137
138
139// inline methods
140
142{
143 return m_plotMargin;
144}
145
146
147inline void CGraphPlotShape::SetPlotMargin(int margin)
148{
149 if (m_plotMargin != margin){
150 m_plotMargin = margin;
151 Invalidate();
152 }
153}
154
155
157{
158 return m_axisLabelFontSize;
159}
160
161
163{
164 if (m_axisLabelFontSize != size){
165 m_axisLabelFontSize = size;
166 Invalidate();
167 }
168}
169
170
172{
173 return m_tickLabelFontSize;
174}
175
176
178{
179 if (m_tickLabelFontSize != size){
180 m_tickLabelFontSize = size;
181 Invalidate();
182 }
183}
184
185
187{
188 return m_curveLineWidth;
189}
190
191
193{
194 if (m_curveLineWidth != width){
195 m_curveLineWidth = width;
196 Invalidate();
197 }
198}
199
200
201} // namespace iview
202
203
Data model for a 2D graph plot supporting multiple curves.
Simple rectangle with integer bounds.
Definition CRect.h:22
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
Set of change flags (its IDs).
Definition IChangeable.h:36
Shape for displaying 2D graph plots with multiple curves.
CRectControlledShapeBase BaseClass
void SetCurveLineWidth(int width)
Set line width for curves (in pixels).
virtual void DrawFigure(QPainter &drawContext) const override
int GetCurveLineWidth() const
Get line width for curves (in pixels).
int GetPlotMargin() const
Get the margin around the plot area (in pixels).
int GetAxisLabelFontSize() const
Get the font size for axis labels.
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
Callback invoked when an observable model is about to be attached to this observer.
int GetTickLabelFontSize() const
Get the font size for tick labels.
virtual i2d::CRect CalcBoundingBox() const override
Calculate bounding box.
virtual void EnsureValidNodes() const override
virtual bool IsCurveTouched(istd::CIndex2d position) const override
virtual TouchState IsTouched(istd::CIndex2d position) const override
Check, if any shape is touched.
void SetTickLabelFontSize(int size)
Set the font size for tick labels.
void SetAxisLabelFontSize(int size)
Set the font size for axis labels.
void SetPlotMargin(int margin)
Set the margin around the plot area (in pixels).
virtual void Invalidate()
TouchState
Enumeration for possible shape touch states.
Definition ITouchable.h:25
In this library is defined 2D view concept and standard visualisation objects.