QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
qwt_plot_layout_engine.h
1#ifndef QWTPLOTLAYOUTENGINE_H
2#define QWTPLOTLAYOUTENGINE_H
3#include <QRectF>
4#include <QSize>
5#include <QFont>
6class QWidget;
7// qwt
8#include "qwt_global.h"
9#include "qwt_axis.h"
10#include "qwt_axis_id.h"
11#include "qwt_text.h"
12#include "qwt_plot.h"
14class QwtTextLabel;
15class QwtScaleWidget;
21class QWT_EXPORT QwtPlotLayoutEngine
22{
23public:
29 {
30 // Constructor
31 Dimensions();
32
33 // Get the dimension for a specific axis
34 int dimAxis(QwtAxisId axisId) const;
35
36 // Set the dimension for a specific axis
37 void setDimAxis(QwtAxisId axisId, int dim);
38
39 // Get the dimension for an axis position (YLeft, YRight, XTop, XBottom)
40 // Includes the extra caption band reserved for outside axis titles
41 int dimAxes(int axisPos) const;
42
43 // Get the extra caption band pixels reserved beyond the scale dimension
44 // of an axis position for outside axis titles (QwtScaleWidget::TitleOutside).
45 // The extra of the XBottom band also covers captions of the Y axes,
46 // which are painted below their scale widgets.
47 int captionExtra(int axisPos) const;
48
49 // Set the extra caption band pixels for an axis position
50 void setCaptionExtra(int axisPos, int extra);
51
52 // Get the total width of left and right Y axes
53 int dimYAxes() const;
54
55 // Get the total height of top and bottom X axes
56 int dimXAxes() const;
57
58 // Center a label rectangle within available space after accounting for Y axes
59 QRectF centered(const QRectF& rect, const QRectF& labelRect) const;
60
61 // Calculate inner rectangle after reserving space for all axes
62 QRectF innerRect(const QRectF& rect) const;
63
64 int dimTitle;
65 int dimFooter;
66
67 private:
68 int m_dimAxes[ QwtAxis::AxisPositions ];
69 int m_captionExtra[ QwtAxis::AxisPositions ];
70 };
71
77 {
78 public:
84 {
85 // Initialize legend data from a QwtAbstractLegend
86 void init(const QwtAbstractLegend* legend);
87
88 // Calculate optimal legend size for the given rectangle
89 QSize legendHint(const QwtAbstractLegend* legend, const QRectF& rect) const;
90
91 int frameWidth;
92 int hScrollExtent;
93 int vScrollExtent;
94 QSize hint;
95 };
96
102 {
103 // Initialize label data from a QwtTextLabel
104 void init(const QwtTextLabel* label);
105
106 QwtText text;
107 int frameWidth;
108 };
109
115 {
116 // Initialize scale data from a QwtScaleWidget
117 void init(const QwtScaleWidget* axisWidget);
118
119 // Reset scale data to default values
120 void reset();
121
122 bool isVisible;
123 const QwtScaleWidget* scaleWidget;
124 QFont scaleFont;
125 int start;
126 int end;
127 int baseLineOffset;
128 double tickOffset;
129 int dimWithoutTitle;
130 int edgeMargin;
131 };
132
138 {
139 // Initialize canvas data from a QWidget
140 void init(const QWidget* canvas);
141
142 int contentsMargins[ QwtAxis::AxisPositions ];
143 };
144
149 enum Label
150 {
153
154 NumLabels
155 };
156
157 // Construct LayoutData from a QwtPlot
158 LayoutData(const QwtPlot* plot);
159
160 // Check if left and right Y axes have the same visibility state
161 bool hasSymmetricYAxes() const;
162
163 // Get mutable scale data for a specific axis
164 ScaleData& axisData(QwtAxisId axisId);
165
166 // Get const scale data for a specific axis
167 const ScaleData& axisData(QwtAxisId axisId) const;
168
169 // Get tick offset for a specific axis position
170 double tickOffset(int axisPos) const;
171
172 LegendData legendData;
173 LabelData labelData[ NumLabels ];
174 CanvasData canvasData;
175
176 // Outside title caption heights (QwtScaleWidget::TitleOutside) demanded by
177 // the parasite plots sharing the bands of this plot, per axis position.
178 // 0 means no caption demand. For a host plot these demands are aggregated
179 // from all parasite plots in the constructor; parasite captions are painted
180 // into the same band as the host captions.
181 int parasiteCaptionHeight[ QwtAxis::AxisPositions ];
182
183 private:
184 ScaleData m_scaleData[ QwtAxis::AxisPositions ];
185 };
186
187public:
188 // Constructor
190
191 // Calculate and return the legend rectangle within the available space
192 QRectF layoutLegend(int plotLayoutOptions,
193 const LayoutData::LegendData& legendData,
194 const QRectF& rect,
195 const QSize& legendHint) const;
196
197 // Align the legend rectangle relative to the canvas
198 QRectF alignLegend(const QSize& legendHint, const QRectF& canvasRect, const QRectF& legendRect) const;
199
200 // Align scale rectangles with the canvas, adjusting positions for proper layout
201 void alignScales(int plotLayoutOptions,
202 const LayoutData& layoutData,
203 QRectF& canvasRect,
204 QRectF scaleRect[ QwtAxis::AxisPositions ]) const;
205
206 // Align scale rectangles to canvas boundaries
207 void alignScalesToCanvas(int plotLayoutOptions,
208 const LayoutData& layoutData,
209 const QRectF& canvasRect,
210 QRectF scaleRect[ QwtAxis::AxisPositions ]) const;
211
212 // Calculate layout dimensions for title, footer, and all axes
213 Dimensions layoutDimensions(int plotLayoutOptions, const LayoutData& layoutData, const QRectF& rect) const;
214
215 // Set the spacing between plot components
216 void setSpacing(unsigned int spacing);
217
218 // Get the spacing between plot components
219 unsigned int spacing() const;
220
221 // Set whether the canvas should align to the scale at a given axis position
222 void setAlignCanvas(int axisPos, bool on);
223
224 // Check if the canvas is aligned to the scale at a given axis position
225 bool alignCanvas(int axisPos) const;
226
227 // Enable/disable fixed canvas size for an axis direction.
228 // YLeft/YRight fix the canvas width; XBottom/XTop fix the canvas height.
229 // When enabled, the canvas dimension is captured on the next layout and
230 // held stable against axis label growth; overflowing labels are clipped.
231 void setFixedCanvas(int axisPos, bool on);
232
233 // Check if fixed canvas size is enabled for a given axis position
234 bool isFixedCanvas(int axisPos) const;
235
236 // Set a manual fixed canvas size, overriding the auto-captured value.
237 // A component < 0 means "use auto-capture" for that direction.
238 void setFixedCanvasSize(const QSize& size);
239
240 // Get the manual fixed canvas size (-1 component = auto-capture)
241 QSize fixedCanvasSize() const;
242
243 // True if canvas width is fixed (any Y axis fixed or manual width set)
244 bool isFixedCanvasWidth() const;
245
246 // True if canvas height is fixed (any X axis fixed or manual height set)
247 bool isFixedCanvasHeight() const;
248
249 // Set the margin between canvas and scale at a given axis position
250 void setCanvasMargin(int axisPos, int margin);
251
252 // Get the margin between canvas and scale at a given axis position
253 int canvasMargin(int axisPos) const;
254
255 // Set the legend position
256 void setLegendPos(QwtPlot::LegendPosition pos);
257
258 // Get the legend position
259 QwtPlot::LegendPosition legendPos() const;
260
261 // Set the legend ratio for size calculation
262 void setLegendRatio(double ratio);
263
264 // Get the legend ratio for size calculation
265 double legendRatio() const;
266
267private:
271 int heightForWidth(LayoutData::Label labelType,
272 const LayoutData& layoutData,
273 int plotLayoutOptions,
274 double width,
275 int axesWidth) const;
276
277 QwtPlot::LegendPosition m_legendPos;
278 double m_legendRatio;
279
280 unsigned int m_canvasMargin[ QwtAxis::AxisPositions ] = { 0, 0, 0, 0 };
281 bool m_alignCanvas[ QwtAxis::AxisPositions ];
282
283 bool m_fixedCanvas[ QwtAxis::AxisPositions ] = { false, false, false, false };
284 QSize m_fixedCanvasSize { -1, -1 };
285
286 unsigned int m_spacing;
287};
288
289#endif // QWTPLOTLAYOUTENGINE_H
Abstract base class for legend widgets.
Definition qwt_abstract_legend.h:47
Data structure for layout calculation.
Definition qwt_plot_layout_engine.h:77
Label
Label type enumeration.
Definition qwt_plot_layout_engine.h:150
@ Title
Title label.
Definition qwt_plot_layout_engine.h:151
@ Footer
Footer label.
Definition qwt_plot_layout_engine.h:152
Layout engine for QwtPlot components.
Definition qwt_plot_layout_engine.h:22
A 2-D plotting widget.
Definition qwt_plot.h:100
LegendPosition
Position of the legend, relative to the canvas.
Definition qwt_plot.h:117
A Widget which contains a scale.
Definition qwt_scale_widget.h:73
A Widget which displays a QwtText.
Definition qwt_text_label.h:47
A class representing a text.
Definition qwt_text.h:70
Structure holding dimension values for layout calculation.
Definition qwt_plot_layout_engine.h:29
Data for canvas layout calculation.
Definition qwt_plot_layout_engine.h:138
Data for title/footer label layout calculation.
Definition qwt_plot_layout_engine.h:102
Data for legend layout calculation.
Definition qwt_plot_layout_engine.h:84
Data for axis scale widget layout calculation.
Definition qwt_plot_layout_engine.h:115