|
QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
|
A class for drawing scales 更多...
#include <qwt_scale_draw.h>
类 | |
| struct | CornerTargets |
| Corner miter target positions in device coordinates 更多... | |
| class | PrivateData |
Public 类型 | |
| enum | Alignment { BottomScale , TopScale , LeftScale , RightScale } |
| Alignment of the scale draw 更多... | |
| enum | CornerMiterFlag { NoMiter = 0x0 , MiterAtStart = 0x1 , MiterAtEnd = 0x2 } |
| Corner miter flags 更多... | |
Public 类型 继承自 QwtAbstractScaleDraw | |
| enum | ScaleComponent { Backbone = 0x01 , Ticks = 0x02 , Labels = 0x04 } |
| Components of a scale 更多... | |
Public 成员函数 | |
| QwtScaleDraw () | |
| Constructor | |
| void | setCornerMiter (CornerMiter miter) |
| Set the corner miter flags | |
| CornerMiter | cornerMiter () const |
| Get the corner miter flags | |
| void | setCornerTargets (const CornerTargets &targets) |
| Set the corner miter target positions (device coordinates) | |
| CornerTargets | cornerTargets () const |
| Get the corner miter target positions | |
| void | getBorderDistHint (const QFont &, int &start, int &end) const |
| Get the border distance hint | |
| int | minLabelDist (const QFont &) const |
| Get the minimum label distance | |
| int | minLength (const QFont &) const |
| Get the minimum length | |
| virtual double | extent (const QFont &) const override |
| Calculate the width/height that is needed for a vertical/horizontal scale | |
| void | move (double x, double y) |
| Move the position of the scale | |
| void | move (const QPointF &) |
| Move the position of the scale | |
| void | setLength (double length) |
| Set the length of the backbone | |
| Alignment | alignment () const |
| Return alignment of the scale | |
| void | setAlignment (Alignment) |
| Set the alignment | |
| Qt::Orientation | orientation () const |
| Return the orientation | |
| QPointF | pos () const |
| Get origin of the scale | |
| double | length () const |
| Get the length of the backbone | |
| void | setLabelAlignment (Qt::Alignment) |
| Set the label alignment | |
| Qt::Alignment | labelAlignment () const |
| Get the label flags | |
| void | setLabelRotation (double rotation) |
| Set the label rotation | |
| double | labelRotation () const |
| Get the label rotation | |
| int | maxLabelHeight (const QFont &) const |
| Get the maximum label height | |
| int | maxLabelWidth (const QFont &) const |
| Get the maximum label width | |
| QPointF | labelPosition (double value) const |
| Get the label position for a value | |
| QRectF | labelRect (const QFont &, double value) const |
| Get the label rectangle for a value | |
| QSizeF | labelSize (const QFont &, double value) const |
| Get the label size for a value | |
| QRect | boundingLabelRect (const QFont &, double value) const |
| Get the bounding label rectangle | |
| void | drawTicksInside (QPainter *, const QRectF &canvasRect, const QwtScaleMap &) const |
| Draw the ticks from the edges of a canvas towards its interior | |
Public 成员函数 继承自 QwtAbstractScaleDraw | |
| QwtAbstractScaleDraw () | |
| Constructor for QwtAbstractScaleDraw | |
| void | setScaleDiv (const QwtScaleDiv &) |
| Set the scale division | |
| const QwtScaleDiv & | scaleDiv () const |
| Return the scale division | |
| void | setTransformation (QwtTransform *) |
| Set the scale transformation | |
| const QwtScaleMap & | scaleMap () const |
| Return the scale map (const version) | |
| QwtScaleMap & | scaleMap () |
| Return the scale map (non-const version) | |
| void | enableComponent (ScaleComponent, bool enable=true) |
| Enable or disable a scale component | |
| bool | hasComponent (ScaleComponent) const |
| Check if a component is enabled | |
| void | setTickLength (QwtScaleDiv::TickType, double length) |
| Set the length of the ticks | |
| double | tickLength (QwtScaleDiv::TickType) const |
| Get the length of the ticks | |
| double | maxTickLength () const |
| Get the length of the longest tick | |
| void | setSpacing (double) |
| Set the spacing between tick and labels | |
| double | spacing () const |
| Get the spacing | |
| void | setPenWidthF (qreal width) |
| Specify the width of the scale pen | |
| qreal | penWidthF () const |
| Get the scale pen width | |
| void | setSelected (bool on) |
| Set whether the scale draw is selected | |
| bool | isSelected () const |
| Check if the scale draw is selected | |
| void | setSelectedPenWidthOffset (qreal offset=1) |
| Set the pen width offset for the axis when it is in selected state | |
| qreal | selectedPenWidthOffset () const |
| Get the current pen width offset for the axis when it is in selected state | |
| virtual void | draw (QPainter *, const QPalette &) const |
| Draw the scale | |
| virtual QwtText | label (double) const |
| Convert a value into its representing label | |
| void | setMinimumExtent (double) |
| Set a minimum for the extent | |
| double | minimumExtent () const |
| Get the minimum extent | |
| void | invalidateCache () |
| Invalidate the cache used by tickLabel() | |
Protected 成员函数 | |
| QTransform | labelTransformation (const QPointF &, const QSizeF &) const |
| Calculate the transformation that is needed to paint a label | |
| virtual void | drawTick (QPainter *, double value, double len) const override |
| Draw a tick | |
| virtual void | drawBackbone (QPainter *) const override |
| Draws the baseline of the scale | |
| virtual void | drawLabel (QPainter *, double value) const override |
| Draws the label for a major scale tick | |
Protected 成员函数 继承自 QwtAbstractScaleDraw | |
| const QwtText & | tickLabel (const QFont &, double value) const |
| Convert a value into its representing label and cache it | |
| qreal | effectivePenWidthF () const |
| Pen width including the offset of the selected state | |
A class for drawing scales
QwtScaleDraw can be used to draw linear or logarithmic scales. A scale has a position, an alignment and a length, which can be specified. The labels can be rotated and aligned to the ticks using setLabelRotation() and setLabelAlignment().
After a scale division has been specified as a QwtScaleDiv object using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
Corner miter flags
When a miter flag is set, the backbone is extended beyond the corresponding end of the scale into a corner shared with a perpendicular scale, so that both backbones intersect instead of ending in a diagonal step. The extension reaches the far edge of the perpendicular backbone band closest to the canvas when a target has been set with setCornerTargets(), so that the whole corner square is covered for any pen width; otherwise it falls back to one pixel beyond the end of the scale. For vertical scales AtStart/AtEnd refer to the top/bottom end, for horizontal scales to the left/right end.
| 枚举值 | |
|---|---|
| NoMiter | Do not extend the backbone |
| MiterAtStart | Extend the backbone beyond the start of the scale |
| MiterAtEnd | Extend the backbone beyond the end of the scale |
| QwtScaleDraw::QwtScaleDraw | ( | ) |
Constructor
The range of the scale is initialized to [0, 100], the position is at (0, 0) with a length of 100. The orientation is QwtAbstractScaleDraw::Bottom.
| QwtScaleDraw::Alignment QwtScaleDraw::alignment | ( | ) | const |
| QRect QwtScaleDraw::boundingLabelRect | ( | const QFont & | font, |
| double | value | ||
| ) | const |
Get the bounding label rectangle
Find the bounding rectangle for the label
The coordinates of the rectangle are absolute ( calculated from pos() ) in direction of the tick.
| font | Font used for painting |
| value | Value |
| QwtScaleDraw::CornerMiter QwtScaleDraw::cornerMiter | ( | ) | const |
Get the corner miter flags
| QwtScaleDraw::CornerTargets QwtScaleDraw::cornerTargets | ( | ) | const |
Get the corner miter target positions
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Draw a tick
| painter | Painter |
| value | Value of the tick |
| len | Length of the tick |
实现了 QwtAbstractScaleDraw.
| void QwtScaleDraw::drawTicksInside | ( | QPainter * | painter, |
| const QRectF & | canvasRect, | ||
| const QwtScaleMap & | map | ||
| ) | const |
Draw the ticks from the edges of a canvas towards its interior
| painter | Painter |
| canvasRect | Canvas rectangle in painter coordinates |
| map | Scale map of the axis on the canvas |
Used by QwtPlot for axes with QwtPlot::TickInside. The ticks start at the canvas edge adjacent to the backbone band and grow into the canvas, following the same device pixel rules as the backbone and the outside ticks of draw(): the thickness is qMax( 1, round( pen width ) ) device pixels without being scaled by the device pixel ratio, and every tick is aligned to the device pixel grid. Stroking a pen of a fractional logical width instead would make the ticks thicker than the backbone at device pixel ratios above one and rasterize ticks at different subpixel positions with different widths.
|
overridevirtual |
Calculate the width/height that is needed for a vertical/horizontal scale
The extent is calculated from the pen width of the backbone, the major tick length, the spacing and the maximum width/height of the labels.
| font | Font used for painting the labels |
实现了 QwtAbstractScaleDraw.
| void QwtScaleDraw::getBorderDistHint | ( | const QFont & | font, |
| int & | start, | ||
| int & | end | ||
| ) | const |
Get the border distance hint
Determine the minimum border distance
This member function returns the minimum space needed to draw the mark labels at the scale's endpoints.
| font | Font |
| start | Start border distance |
| end | End border distance |
| Qt::Alignment QwtScaleDraw::labelAlignment | ( | ) | const |
| QPointF QwtScaleDraw::labelPosition | ( | double | value | ) | const |
Get the label position for a value
Find the position, where to paint a label
The position has a distance that depends on the length of the ticks in direction of the alignment().
| value | Value |
| QRectF QwtScaleDraw::labelRect | ( | const QFont & | font, |
| double | value | ||
| ) | const |
Get the label rectangle for a value
Find the bounding rectangle for the label
The coordinates of the rectangle are relative to spacing + tick length from the backbone in direction of the tick.
| font | Font used for painting |
| value | Value |
| double QwtScaleDraw::labelRotation | ( | ) | const |
Get the label rotation
| QSizeF QwtScaleDraw::labelSize | ( | const QFont & | font, |
| double | value | ||
| ) | const |
Get the label size for a value
Calculate the size that is needed to draw a label
| font | Label font |
| value | Value |
|
protected |
Calculate the transformation that is needed to paint a label
Calculate the transformation that is needed to paint a label depending on its alignment and rotation.
| pos | Position where to paint the label |
| size | Size of the label |
| double QwtScaleDraw::length | ( | ) | const |
| int QwtScaleDraw::maxLabelHeight | ( | const QFont & | font | ) | const |
Get the maximum label height
Get the maximum height of a label
| font | Font |
| int QwtScaleDraw::maxLabelWidth | ( | const QFont & | font | ) | const |
Get the maximum label width
Get the maximum width of a label
| font | Font |
| int QwtScaleDraw::minLabelDist | ( | const QFont & | font | ) | const |
Get the minimum label distance
Determine the minimum distance between two labels
Determine the minimum distance between two labels, that is necessary that the texts don't overlap.
| font | Font |
| int QwtScaleDraw::minLength | ( | const QFont & | font | ) | const |
Get the minimum length
Calculate the minimum length that is needed to draw the scale
| font | Font used for painting the labels |
| void QwtScaleDraw::move | ( | const QPointF & | pos | ) |
Move the position of the scale
The meaning of the parameter pos depends on the alignment:
| pos | Origin of the scale |
|
inline |
| Qt::Orientation QwtScaleDraw::orientation | ( | ) | const |
Return the orientation
TopScale, BottomScale are horizontal (Qt::Horizontal) scales, LeftScale, RightScale are vertical (Qt::Vertical) scales.
| QPointF QwtScaleDraw::pos | ( | ) | const |
| void QwtScaleDraw::setAlignment | ( | Alignment | align | ) |
Set the alignment
Set the alignment of the scale
| align | Alignment of the scale |
The default alignment is QwtScaleDraw::BottomScale
| void QwtScaleDraw::setCornerMiter | ( | CornerMiter | miter | ) |
Set the corner miter flags
| miter | Flags specifying which ends of the backbone are extended into a corner shared with a perpendicular scale |
QwtScaleWidget sets the flags from the visibility of the perpendicular axes of the plot; standalone use keeps NoMiter.
| void QwtScaleDraw::setCornerTargets | ( | const CornerTargets & | targets | ) |
Set the corner miter target positions (device coordinates)
Set the corner miter target positions
| targets | Target positions in device coordinates |
When a miter flag is set and its target is valid, the backbone is extended exactly to that position instead of one pixel beyond the end of the scale; border ticks snap to the same target. The target is the near edge of the perpendicular backbone band closest to the canvas. QwtScaleWidget and QwtPlotRenderer compute the targets from the geometry of the perpendicular axes; standalone use keeps them unset and the historical fallback.
| void QwtScaleDraw::setLabelAlignment | ( | Qt::Alignment | alignment | ) |
Set the label alignment
Change the label flags
Labels are aligned to the point tick length + spacing away from the backbone.
The alignment is relative to the orientation of the label text. In case of an flags of 0 the label will be aligned depending on the orientation of the scale:
Changing the alignment is often necessary for rotated labels.
| alignment | Or'd Qt::AlignmentFlags see <qnamespace.h> |
| void QwtScaleDraw::setLabelRotation | ( | double | rotation | ) |
Set the label rotation
Rotate all labels
When changing the rotation, it might be necessary to adjust the label flags too. Finding a useful combination is often the result of try and error.
| rotation | Angle in degrees. When changing the label rotation, the label flags often needs to be adjusted too. |
| void QwtScaleDraw::setLength | ( | double | length | ) |
Set the length of the backbone
The length doesn't include the space needed for overlapping labels.
| length | Length of the backbone |