ACF $AcfVersion:0$
CGraphData2d.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 <QtCore/QVector>
7#include <QtCore/QString>
8#include <QtGui/QColor>
9
10// ACF includes
11#include <i2d/CObject2dBase.h>
12#include <i2d/CVector2d.h>
13#include <i2d/CRectangle.h>
14
15
16namespace i2d
17{
18
19
26{
28
29public:
36
40 struct Curve
41 {
42 QString name;
43 QVector<CVector2d> points;
44 QColor color;
45
46 Curve() : color(Qt::blue) {}
47 };
48
49 static QByteArray GetTypeName();
50
52
56 int GetCurvesCount() const;
57
61 const Curve& GetCurve(int index) const;
62
67 Curve& GetCurveRef(int index);
68
72 void AddCurve(const Curve& curve);
73
77 void RemoveCurve(int index);
78
83
87 const QString& GetXAxisLabel() const;
88
92 void SetXAxisLabel(const QString& label);
93
97 const QString& GetYAxisLabel() const;
98
102 void SetYAxisLabel(const QString& label);
103
107 const QString& GetTitle() const;
108
112 void SetTitle(const QString& title);
113
118
122 void SetXAxisRange(const istd::CRange& range);
123
128
132 void SetYAxisRange(const istd::CRange& range);
133
137 bool IsLegendVisible() const;
138
142 void SetLegendVisible(bool visible = true);
143
147 bool IsGridVisible() const;
148
152 void SetGridVisible(bool visible = true);
153
154 // reimplemented (i2d::IObject2d)
155 virtual CVector2d GetCenter() const override;
156 virtual void MoveCenterTo(const CVector2d& position) override;
157 virtual CRectangle GetBoundingBox() const override;
158 virtual bool Transform(
159 const ITransformation2d& transformation,
161 double* errorFactorPtr = NULL) override;
162 virtual bool InvTransform(
163 const ITransformation2d& transformation,
165 double* errorFactorPtr = NULL) override;
166 virtual bool GetTransformed(
167 const ITransformation2d& transformation,
168 IObject2d& result,
170 double* errorFactorPtr = NULL) const override;
171 virtual bool GetInvTransformed(
172 const ITransformation2d& transformation,
173 IObject2d& result,
175 double* errorFactorPtr = NULL) const override;
176
177 // reimplemented (iser::IObject)
178 virtual QByteArray GetFactoryId() const override;
179
180 // reimplemented (iser::ISerializable)
181 virtual bool Serialize(iser::IArchive& archive) override;
182
183 // reimplemented (istd::IChangeable)
184 virtual int GetSupportedOperations() const override;
185 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
187
188private:
192 void CalculateAutoRanges(istd::CRange& xRange, istd::CRange& yRange) const;
193
197 bool SerializeCurve(iser::IArchive& archive, Curve& curve);
198
199 QVector<Curve> m_curves;
200 QString m_xAxisLabel;
201 QString m_yAxisLabel;
202 QString m_title;
203 istd::CRange m_xAxisRange;
204 istd::CRange m_yAxisRange;
205 bool m_isLegendVisible;
206 bool m_isGridVisible;
207};
208
209
210// inline methods
211
213{
214 return m_curves.count();
215}
216
217
218inline const CGraphData2d::Curve& CGraphData2d::GetCurve(int index) const
219{
220 return m_curves.at(index);
221}
222
223
225{
226 return m_curves[index];
227}
228
229
230inline const QString& CGraphData2d::GetXAxisLabel() const
231{
232 return m_xAxisLabel;
233}
234
235
236inline const QString& CGraphData2d::GetYAxisLabel() const
237{
238 return m_yAxisLabel;
239}
240
241
242inline const QString& CGraphData2d::GetTitle() const
243{
244 return m_title;
245}
246
247
249{
250 return m_isLegendVisible;
251}
252
253
255{
256 return m_isGridVisible;
257}
258
259
260} // namespace i2d
261
262
Data model for a 2D graph plot supporting multiple curves.
const QString & GetTitle() const
Get the graph title.
const QString & GetXAxisLabel() const
Get the X-axis label.
void SetYAxisLabel(const QString &label)
Set the Y-axis label.
void SetXAxisLabel(const QString &label)
Set the X-axis label.
void RemoveCurve(int index)
Remove a curve by index.
virtual CVector2d GetCenter() const override
Returns center of this 2D-object.
virtual istd::TUniqueInterfacePtr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
const Curve & GetCurve(int index) const
Get a curve by index.
virtual CRectangle GetBoundingBox() const override
Get bounding box of this shape.
istd::CRange GetYAxisRange() const
Get Y-axis range.
bool IsLegendVisible() const
Check if legend should be shown.
virtual bool Transform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) override
Transform this object using some transformation.
virtual void MoveCenterTo(const CVector2d &position) override
Move object to position position.
int GetCurvesCount() const
Get the number of curves in the graph.
void SetXAxisRange(const istd::CRange &range)
Set X-axis range.
virtual bool GetInvTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const override
Calulate inverse transformation of the object into second one.
virtual bool GetTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const override
Calulate transformation of the object into second one.
virtual QByteArray GetFactoryId() const override
Curve & GetCurveRef(int index)
Get reference to a curve by index.
istd::CRange GetXAxisRange() const
Get X-axis range.
bool IsGridVisible() const
Check if grid should be shown.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual bool InvTransform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) override
Do inverse transformation of this object.
void SetGridVisible(bool visible=true)
Set whether grid should be shown.
void ClearCurves()
Clear all curves.
void AddCurve(const Curve &curve)
Add a new curve to the graph.
virtual int GetSupportedOperations() const override
Get set of flags for supported operations.
static QByteArray GetTypeName()
void SetYAxisRange(const istd::CRange &range)
Set Y-axis range.
void SetTitle(const QString &title)
Set the graph title.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
void SetLegendVisible(bool visible=true)
Set whether legend should be shown.
const QString & GetYAxisLabel() const
Get the Y-axis label.
@ CF_GRAPH_DATA
Graph data (curves, points) changed.
@ CF_GRAPH_APPEARANCE
Graph appearance (colors, names, labels) changed.
@ CF_GRAPH_DISPLAY_OPTIONS
Display options (legend, grid visibility) changed.
Base class for 2D-objects implementing interface i2d::IObject2d.
Definition of rectangle area orthogonal to axis of coordination system.
Definition CRectangle.h:27
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Common interface for describing the 2D-objects.
Definition IObject2d.h:26
Common interface for all calibration objects.
@ EM_NONE
There are no preferences, should be automatically selected.
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
Unique ownership smart pointer for interface types.
#define NULL
Definition istd.h:74
Contains the 2D objects.
Definition CAffine2d.h:11
Structure representing a single curve in the graph.
QString name
Name of the curve (for legend)
QVector< CVector2d > points
Points defining the curve.
QColor color
Color for drawing the curve.