|
| QCPAxis (QCPAxisRect *parent, AxisType type) |
|
virtual | ~QCPAxis () |
|
AxisType | axisType () const |
|
QCPAxisRect * | axisRect () const |
|
ScaleType | scaleType () const |
|
const QCPRange | range () const |
|
bool | rangeReversed () const |
|
QSharedPointer< QCPAxisTicker > | ticker () const |
|
bool | ticks () const |
|
bool | tickLabels () const |
|
int | tickLabelPadding () const |
|
QFont | tickLabelFont () const |
|
QColor | tickLabelColor () const |
|
double | tickLabelRotation () const |
|
LabelSide | tickLabelSide () const |
|
QString | numberFormat () const |
|
int | numberPrecision () const |
|
QVector< double > | tickVector () const |
|
QVector< QString > | tickVectorLabels () const |
|
int | tickLengthIn () const |
|
int | tickLengthOut () const |
|
bool | subTicks () const |
|
int | subTickLengthIn () const |
|
int | subTickLengthOut () const |
|
QPen | basePen () const |
|
QPen | tickPen () const |
|
QPen | subTickPen () const |
|
QFont | labelFont () const |
|
QColor | labelColor () const |
|
QString | label () const |
|
int | labelPadding () const |
|
int | padding () const |
|
int | offset () const |
|
SelectableParts | selectedParts () const |
|
SelectableParts | selectableParts () const |
|
QFont | selectedTickLabelFont () const |
|
QFont | selectedLabelFont () const |
|
QColor | selectedTickLabelColor () const |
|
QColor | selectedLabelColor () const |
|
QPen | selectedBasePen () const |
|
QPen | selectedTickPen () const |
|
QPen | selectedSubTickPen () const |
|
QCPLineEnding | lowerEnding () const |
|
QCPLineEnding | upperEnding () const |
|
QCPGrid * | grid () const |
|
Q_SLOT void | setScaleType (QCPAxis::ScaleType type) |
|
Q_SLOT void | setRange (const QCPRange &range) |
|
void | setRange (double lower, double upper) |
|
void | setRange (double position, double size, Qt::AlignmentFlag alignment) |
|
void | setRangeLower (double lower) |
|
void | setRangeUpper (double upper) |
|
void | setRangeReversed (bool reversed) |
|
void | setTicker (QSharedPointer< QCPAxisTicker > ticker) |
|
void | setTicks (bool show) |
|
void | setTickLabels (bool show) |
|
void | setTickLabelPadding (int padding) |
|
void | setTickLabelFont (const QFont &font) |
|
void | setTickLabelColor (const QColor &color) |
|
void | setTickLabelRotation (double degrees) |
|
void | setTickLabelSide (LabelSide side) |
|
void | setNumberFormat (const QString &formatCode) |
|
void | setNumberPrecision (int precision) |
|
void | setTickLength (int inside, int outside=0) |
|
void | setTickLengthIn (int inside) |
|
void | setTickLengthOut (int outside) |
|
void | setSubTicks (bool show) |
|
void | setSubTickLength (int inside, int outside=0) |
|
void | setSubTickLengthIn (int inside) |
|
void | setSubTickLengthOut (int outside) |
|
void | setBasePen (const QPen &pen) |
|
void | setTickPen (const QPen &pen) |
|
void | setSubTickPen (const QPen &pen) |
|
void | setLabelFont (const QFont &font) |
|
void | setLabelColor (const QColor &color) |
|
void | setLabel (const QString &str) |
|
void | setLabelPadding (int padding) |
|
void | setPadding (int padding) |
|
void | setOffset (int offset) |
|
void | setSelectedTickLabelFont (const QFont &font) |
|
void | setSelectedLabelFont (const QFont &font) |
|
void | setSelectedTickLabelColor (const QColor &color) |
|
void | setSelectedLabelColor (const QColor &color) |
|
void | setSelectedBasePen (const QPen &pen) |
|
void | setSelectedTickPen (const QPen &pen) |
|
void | setSelectedSubTickPen (const QPen &pen) |
|
Q_SLOT void | setSelectableParts (const QCPAxis::SelectableParts &selectableParts) |
|
Q_SLOT void | setSelectedParts (const QCPAxis::SelectableParts &selectedParts) |
|
void | setLowerEnding (const QCPLineEnding &ending) |
|
void | setUpperEnding (const QCPLineEnding &ending) |
|
virtual double | selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE |
|
Qt::Orientation | orientation () const |
|
int | pixelOrientation () const |
|
void | moveRange (double diff) |
|
void | scaleRange (double factor) |
|
void | scaleRange (double factor, double center) |
|
void | setScaleRatio (const QCPAxis *otherAxis, double ratio=1.0) |
|
void | rescale (bool onlyVisiblePlottables=false) |
|
double | pixelToCoord (double value) const |
|
double | coordToPixel (double value) const |
|
SelectablePart | getPartAt (const QPointF &pos) const |
|
QList< QCPAbstractPlottable * > | plottables () const |
|
QList< QCPGraph * > | graphs () const |
|
QList< QCPAbstractItem * > | items () const |
|
| QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0) |
|
virtual | ~QCPLayerable () |
|
bool | visible () const |
|
QCustomPlot * | parentPlot () const |
|
QCPLayerable * | parentLayerable () const |
|
QCPLayer * | layer () const |
|
bool | antialiased () const |
|
void | setVisible (bool on) |
|
Q_SLOT bool | setLayer (QCPLayer *layer) |
|
bool | setLayer (const QString &layerName) |
|
void | setAntialiased (bool enabled) |
|
bool | realVisibility () const |
|
|
virtual int | calculateMargin () |
|
virtual void | applyDefaultAntialiasingHint (QCPPainter *painter) const Q_DECL_OVERRIDE |
|
virtual void | draw (QCPPainter *painter) Q_DECL_OVERRIDE |
|
virtual QCP::Interaction | selectionCategory () const Q_DECL_OVERRIDE |
|
virtual void | selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE |
|
virtual void | deselectEvent (bool *selectionStateChanged) Q_DECL_OVERRIDE |
|
virtual void | mousePressEvent (QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE |
|
virtual void | mouseMoveEvent (QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE |
|
virtual void | mouseReleaseEvent (QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE |
|
virtual void | wheelEvent (QWheelEvent *event) Q_DECL_OVERRIDE |
|
void | setupTickVectors () |
|
QPen | getBasePen () const |
|
QPen | getTickPen () const |
|
QPen | getSubTickPen () const |
|
QFont | getTickLabelFont () const |
|
QFont | getLabelFont () const |
|
QColor | getTickLabelColor () const |
|
QColor | getLabelColor () const |
|
virtual void | parentPlotInitialized (QCustomPlot *parentPlot) |
|
virtual QRect | clipRect () const |
|
virtual void | mouseDoubleClickEvent (QMouseEvent *event, const QVariant &details) |
|
void | initializeParentPlot (QCustomPlot *parentPlot) |
|
void | setParentLayerable (QCPLayerable *parentLayerable) |
|
bool | moveToLayer (QCPLayer *layer, bool prepend) |
|
void | applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const |
|
Manages a single axis inside a QCustomPlot.
Usually doesn't need to be instantiated externally. Access QCustomPlot's default four axes via QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and QCustomPlot::yAxis2 (right).
Axes are always part of an axis rect, see QCPAxisRect.
Naming convention of axis parts
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line on the left represents the QCustomPlot widget border.Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and tick labels. You can access the currently installed ticker or set a new one (possibly one of the specialized subclasses, or your own subclass) via setTicker. For details, see the documentation of QCPAxisTicker.
void QCPAxis::mouseMoveEvent |
( |
QMouseEvent * |
event, |
|
|
const QPointF & |
startPos |
|
) |
| |
|
protectedvirtual |
void QCPAxis::mousePressEvent |
( |
QMouseEvent * |
event, |
|
|
const QVariant & |
details |
|
) |
| |
|
protectedvirtual |
This event gets called when the user presses a mouse button while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a preceding call to selectTest.
The current pixel position of the cursor on the QCustomPlot widget is accessible via event->pos()
. The parameter details contains layerable-specific details about the hit, which were generated in the previous call to selectTest. For example, One-dimensional plottables like QCPGraph or QCPBars convey the clicked data point in the details parameter, as QCPDataSelection packed as QVariant. Multi-part objects convey the specific SelectablePart
that was hit (e.g. QCPAxis::SelectablePart in the case of axes).
QCustomPlot uses an event propagation system that works the same as Qt's system. If your layerable doesn't reimplement the mousePressEvent or explicitly calls event->ignore()
in its reimplementation, the event will be propagated to the next layerable in the stacking order.
Once a layerable has accepted the mousePressEvent, it is considered the mouse grabber and will receive all following calls to mouseMoveEvent or mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends with the release).
The default implementation does nothing except explicitly ignoring the event with event->ignore()
.
- See also
- mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent
Reimplemented from QCPLayerable.
void QCPAxis::mouseReleaseEvent |
( |
QMouseEvent * |
event, |
|
|
const QPointF & |
startPos |
|
) |
| |
|
protectedvirtual |
int QCPAxis::pixelOrientation |
( |
| ) |
const |
|
inline |
Returns which direction points towards higher coordinate values/keys, in pixel space.
This method returns either 1 or -1. If it returns 1, then going in the positive direction along the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. On the other hand, if this method returns -1, going to smaller pixel values corresponds to going from lower to higher axis coordinates.
For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, without having to care about reversed or vertically aligned axes:
double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation());
newKey will then contain a key that is ten pixels towards higher keys, starting from oldKey.
void QCPAxis::rangeChanged |
( |
const QCPRange & |
newRange | ) |
|
|
signal |
This signal is emitted when the range of this axis has changed. You can connect it to the setRange slot of another axis to communicate the new range to the other axis, in order for it to be synchronized.
You may also manipulate/correct the range with setRange in a slot connected to this signal. This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper range shouldn't go beyond certain values (see QCPRange::bounded). For example, the following slot would limit the x axis to ranges between 0 and 10:
customPlot->xAxis->setRange(newRange.bounded(0, 10))
void QCPAxis::scaleRange |
( |
double |
factor | ) |
|
Scales the range of this axis by factor around the center of the current axis range. For example, if factor is 2.0, then the axis range will double its size, and the point at the axis range center won't have changed its position in the QCustomPlot widget (i.e. coordinates around the center will have moved symmetrically closer).
If you wish to scale around a different coordinate than the current axis range center, use the overload scaleRange(double factor, double center).
void QCPAxis::scaleRange |
( |
double |
factor, |
|
|
double |
center |
|
) |
| |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Scales the range of this axis by factor around the coordinate center. For example, if factor is 2.0, center is 1.0, then the axis range will double its size, and the point at coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates around 1.0 will have moved symmetrically closer to 1.0).
- See also
- scaleRange(double factor)
double QCPAxis::selectTest |
( |
const QPointF & |
pos, |
|
|
bool |
onlySelectable, |
|
|
QVariant * |
details = 0 |
|
) |
| const |
|
virtual |
This function is used to decide whether a click hits a layerable object or not.
pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the shortest pixel distance of this point to the object. If the object is either invisible or the distance couldn't be determined, -1.0 is returned. Further, if onlySelectable is true and the object is not selectable, -1.0 is returned, too.
If the object is represented not by single lines but by an area like a QCPItemText or the bars of a QCPBars plottable, a click inside the area should also be considered a hit. In these cases this function thus returns a constant value greater zero but still below the parent plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99).
Providing a constant value for area objects allows selecting line objects even when they are obscured by such area objects, by clicking close to the lines (i.e. closer than 0.99*selectionTolerance).
The actual setting of the selection state is not done by this function. This is handled by the parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified via the selectEvent/ deselectEvent methods.
details is an optional output parameter. Every layerable subclass may place any information in details. This information will be passed to selectEvent when the parent QCustomPlot decides on the basis of this selectTest call, that the object was successfully selected. The subsequent call to selectEvent will carry the details. This is useful for multi-part objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked is only done once in selectTest. The result (i.e. the actually clicked part) can then be placed in details. So in the subsequent selectEvent, the decision which part was selected doesn't have to be done a second time for a single selection operation.
You may pass 0 as details to indicate that you are not interested in those selection details.
- See also
- selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions
Reimplemented from QCPLayerable.
void QCPAxis::setNumberFormat |
( |
const QString & |
formatCode | ) |
|
Sets the number format for the numbers in tick labels. This formatCode is an extended version of the format code used e.g. by QString::number() and QLocale::toString(). For reference about that, see the "Argument Formats" section in the detailed description of the QString class.
formatCode is a string of one, two or three characters. The first character is identical to the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed format, 'g'/'G' scientific or fixed, whichever is shorter.
The second and third characters are optional and specific to QCustomPlot:
If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. "5.5e9", which is ugly in a plot. So when the second char of formatCode is set to 'b' (for "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5
[multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. If instead a cross should be shown (as is usual in the USA), the third char of formatCode can be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the cross and 183 (0xB7) for the dot.
Examples for formatCode:
g
normal format code behaviour. If number is small, fixed format is used, if number is large, normal scientific format is used
gb
If number is small, fixed format is used, if number is large, scientific format is used with beautifully typeset decimal powers and a dot as multiplication sign
ebc
All numbers are in scientific format with beautifully typeset decimal power and a cross as multiplication sign
fb
illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal powers. Format code will be reduced to 'f'.
hello
illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format code will not be changed.
void QCPAxis::setOffset |
( |
int |
offset | ) |
|
Sets the offset the axis has to its axis rect side.
If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, only the offset of the inner most axis has meaning (even if it is set to be invisible). The offset of the other, outer axes is controlled automatically, to place them at appropriate positions.
void QCPAxis::setRange |
( |
double |
lower, |
|
|
double |
upper |
|
) |
| |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the lower and upper bound of the axis range.
To invert the direction of an axis, use setRangeReversed.
There is also a slot to set a range, see setRange(const QCPRange &range).
void QCPAxis::setRange |
( |
double |
position, |
|
|
double |
size, |
|
|
Qt::AlignmentFlag |
alignment |
|
) |
| |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the range of the axis.
The position coordinate indicates together with the alignment parameter, where the new range will be positioned. size defines the size of the new axis range. alignment may be Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, or center of the range to be aligned with position. Any other values of alignment will default to Qt::AlignCenter.
void QCPAxis::setRangeReversed |
( |
bool |
reversed | ) |
|
Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal axes increase left to right, on vertical axes bottom to top. When reversed is set to true, the direction of increasing values is inverted.
Note that the range and data interface stays the same for reversed axes, e.g. the lower part of the setRange interface will still reference the mathematically smaller number than the upper part.
void QCPAxis::setScaleRatio |
( |
const QCPAxis * |
otherAxis, |
|
|
double |
ratio = 1.0 |
|
) |
| |
Scales the range of this axis to have a certain scale ratio to otherAxis. The scaling will be done around the center of the current axis range.
For example, if ratio is 1, this axis is the yAxis and otherAxis is xAxis, graphs plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the axis rect has.
This is an operation that changes the range of this axis once, it doesn't fix the scale ratio indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent will follow.
void QCPAxis::setTicker |
( |
QSharedPointer< QCPAxisTicker > |
ticker | ) |
|
The axis ticker is responsible for generating the tick positions and tick labels. See the documentation of QCPAxisTicker for details on how to work with axis tickers.
You can change the tick positioning/labeling behaviour of this axis by setting a different QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis ticker, access it via ticker.
Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis ticker simply by passing the same shared pointer to multiple axes.
- See also
- ticker
void QCPAxis::setTickLabelRotation |
( |
double |
degrees | ) |
|
Sets the rotation of the tick labels. If degrees is zero, the labels are drawn normally. Else, the tick labels are drawn rotated by degrees clockwise. The specified angle is bound to values from -90 to 90 degrees.
If degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For other angles, the label is drawn with an offset such that it seems to point toward or away from the tick mark.
Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is responsible for generating the tick positions and tick labels of this axis. You can access the QCPAxisTicker with this method and modify basic properties such as the approximate tick count (QCPAxisTicker::setTickCount).
You can gain more control over the axis ticks by setting a different QCPAxisTicker subclass, see the documentation there. A new axis ticker can be set with setTicker.
Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis ticker simply by passing the same shared pointer to multiple axes.
- See also
- setTicker
void QCPAxis::wheelEvent |
( |
QWheelEvent * |
event | ) |
|
|
protectedvirtual |
This event gets called when the user turns the mouse scroll wheel while the cursor is over the layerable. Whether a cursor is over the layerable is decided by a preceding call to selectTest.
The current pixel position of the cursor on the QCustomPlot widget is accessible via event->pos()
.
The event->delta()
indicates how far the mouse wheel was turned, which is usually +/- 120 for single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may accumulate to one event, making event->delta()
larger. On the other hand, if the wheel has very smooth steps or none at all, the delta may be smaller.
The default implementation does nothing.
- See also
- mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent
Reimplemented from QCPLayerable.