QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_plot_layout_engine.h
1#ifndef QWTPLOTLAYOUTENGINE_H
2#define QWTPLOTLAYOUTENGINE_H
3#include <QRectF>
4#include <QFont>
5class QWidget;
6// qwt
7#include "qwt_global.h"
8#include "qwt_axis.h"
9#include "qwt_axis_id.h"
10#include "qwt_text.h"
11#include "qwt_plot.h"
13class QwtTextLabel;
14class QwtScaleWidget;
20class QWT_EXPORT QwtPlotLayoutEngine
21{
22public:
28 {
29 // Constructor
30 Dimensions();
31
32 // Get the dimension for a specific axis
33 int dimAxis(QwtAxisId axisId) const;
34
35 // Set the dimension for a specific axis
36 void setDimAxis(QwtAxisId axisId, int dim);
37
38 // Get the dimension for an axis position (YLeft, YRight, XTop, XBottom)
39 int dimAxes(int axisPos) const;
40
41 // Get the total width of left and right Y axes
42 int dimYAxes() const;
43
44 // Get the total height of top and bottom X axes
45 int dimXAxes() const;
46
47 // Center a label rectangle within available space after accounting for Y axes
48 QRectF centered(const QRectF& rect, const QRectF& labelRect) const;
49
50 // Calculate inner rectangle after reserving space for all axes
51 QRectF innerRect(const QRectF& rect) const;
52
53 int dimTitle;
54 int dimFooter;
55
56 private:
57 int m_dimAxes[ QwtAxis::AxisPositions ];
58 };
59
65 {
66 public:
72 {
73 // Initialize legend data from a QwtAbstractLegend
74 void init(const QwtAbstractLegend* legend);
75
76 // Calculate optimal legend size for the given rectangle
77 QSize legendHint(const QwtAbstractLegend* legend, const QRectF& rect) const;
78
79 int frameWidth;
80 int hScrollExtent;
81 int vScrollExtent;
82 QSize hint;
83 };
84
89 struct LabelData
90 {
91 // Initialize label data from a QwtTextLabel
92 void init(const QwtTextLabel* label);
93
94 QwtText text;
95 int frameWidth;
96 };
97
103 {
104 // Initialize scale data from a QwtScaleWidget
105 void init(const QwtScaleWidget* axisWidget);
106
107 // Reset scale data to default values
108 void reset();
109
110 bool isVisible;
111 const QwtScaleWidget* scaleWidget;
112 QFont scaleFont;
113 int start;
114 int end;
115 int baseLineOffset;
116 double tickOffset;
117 int dimWithoutTitle;
118 int edgeMargin;
119 };
120
126 {
127 // Initialize canvas data from a QWidget
128 void init(const QWidget* canvas);
129
130 int contentsMargins[ QwtAxis::AxisPositions ];
131 };
132
137 enum Label
138 {
141
142 NumLabels
143 };
144
145 // Construct LayoutData from a QwtPlot
146 LayoutData(const QwtPlot* plot);
147
148 // Check if left and right Y axes have the same visibility state
149 bool hasSymmetricYAxes() const;
150
151 // Get mutable scale data for a specific axis
152 ScaleData& axisData(QwtAxisId axisId);
153
154 // Get const scale data for a specific axis
155 const ScaleData& axisData(QwtAxisId axisId) const;
156
157 // Get tick offset for a specific axis position
158 double tickOffset(int axisPos) const;
159
160 LegendData legendData;
161 LabelData labelData[ NumLabels ];
162 CanvasData canvasData;
163
164 private:
165 ScaleData m_scaleData[ QwtAxis::AxisPositions ];
166 };
167
168public:
169 // Constructor
171
172 // Calculate and return the legend rectangle within the available space
173 QRectF layoutLegend(int plotLayoutOptions,
174 const LayoutData::LegendData& legendData,
175 const QRectF& rect,
176 const QSize& legendHint) const;
177
178 // Align the legend rectangle relative to the canvas
179 QRectF alignLegend(const QSize& legendHint, const QRectF& canvasRect, const QRectF& legendRect) const;
180
181 // Align scale rectangles with the canvas, adjusting positions for proper layout
182 void alignScales(int plotLayoutOptions,
183 const LayoutData& layoutData,
184 QRectF& canvasRect,
185 QRectF scaleRect[ QwtAxis::AxisPositions ]) const;
186
187 // Align scale rectangles to canvas boundaries
188 void alignScalesToCanvas(int plotLayoutOptions,
189 const LayoutData& layoutData,
190 const QRectF& canvasRect,
191 QRectF scaleRect[ QwtAxis::AxisPositions ]) const;
192
193 // Calculate layout dimensions for title, footer, and all axes
194 Dimensions layoutDimensions(int plotLayoutOptions, const LayoutData& layoutData, const QRectF& rect) const;
195
196 // Set the spacing between plot components
197 void setSpacing(unsigned int spacing);
198
199 // Get the spacing between plot components
200 unsigned int spacing() const;
201
202 // Set whether the canvas should align to the scale at a given axis position
203 void setAlignCanvas(int axisPos, bool on);
204
205 // Check if the canvas is aligned to the scale at a given axis position
206 bool alignCanvas(int axisPos) const;
207
208 // Set the margin between canvas and scale at a given axis position
209 void setCanvasMargin(int axisPos, int margin);
210
211 // Get the margin between canvas and scale at a given axis position
212 int canvasMargin(int axisPos) const;
213
214 // Set the legend position
215 void setLegendPos(QwtPlot::LegendPosition pos);
216
217 // Get the legend position
218 QwtPlot::LegendPosition legendPos() const;
219
220 // Set the legend ratio for size calculation
221 void setLegendRatio(double ratio);
222
223 // Get the legend ratio for size calculation
224 double legendRatio() const;
225
226private:
230 int heightForWidth(LayoutData::Label labelType,
231 const LayoutData& layoutData,
232 int plotLayoutOptions,
233 double width,
234 int axesWidth) const;
235
236 QwtPlot::LegendPosition m_legendPos;
237 double m_legendRatio;
238
239 unsigned int m_canvasMargin[ QwtAxis::AxisPositions ] = { 0, 0, 0, 0 };
240 bool m_alignCanvas[ QwtAxis::AxisPositions ];
241
242 unsigned int m_spacing;
243};
244
245#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:65
Label
Label type enumeration
Definition qwt_plot_layout_engine.h:138
@ Title
Title label
Definition qwt_plot_layout_engine.h:139
@ Footer
Footer label
Definition qwt_plot_layout_engine.h:140
Layout engine for QwtPlot components
Definition qwt_plot_layout_engine.h:21
A 2-D plotting widget
Definition qwt_plot.h:99
LegendPosition
Position of the legend, relative to the canvas
Definition qwt_plot.h:116
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:28
Data for canvas layout calculation
Definition qwt_plot_layout_engine.h:126
Data for title/footer label layout calculation
Definition qwt_plot_layout_engine.h:90
Data for legend layout calculation
Definition qwt_plot_layout_engine.h:72
Data for axis scale widget layout calculation
Definition qwt_plot_layout_engine.h:103