A radial graph used to display data in polar plots. More...
Public Types | |
enum | LineStyle |
Public Functions | |
QCPPolarGraph (QCPPolarAxisAngular *keyAxis, QCPPolarAxisRadial *valueAxis) | |
QString | name () const |
bool | antialiasedFill () const |
bool | antialiasedScatters () const |
QPen | pen () const |
QBrush | brush () const |
bool | periodic () const |
QCPPolarAxisAngular * | keyAxis () const |
QCPPolarAxisRadial * | valueAxis () const |
QCP::SelectionType | selectable () const |
bool | selected () const |
QCPDataSelection | selection () const |
QSharedPointer< QCPGraphDataContainer > | data () const |
LineStyle | lineStyle () const |
QCPScatterStyle | scatterStyle () const |
void | setName (const QString &name) |
void | setAntialiasedFill (bool enabled) |
void | setAntialiasedScatters (bool enabled) |
void | setPen (const QPen &pen) |
void | setBrush (const QBrush &brush) |
void | setPeriodic (bool enabled) |
void | setKeyAxis (QCPPolarAxisAngular *axis) |
void | setValueAxis (QCPPolarAxisRadial *axis) |
Q_SLOT void | setSelectable (QCP::SelectionType selectable) |
Q_SLOT void | setSelection (QCPDataSelection selection) |
void | setData (QSharedPointer< QCPGraphDataContainer > data) |
void | setData (const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false) |
void | setLineStyle (LineStyle ls) |
void | setScatterStyle (const QCPScatterStyle &style) |
void | addData (const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false) |
void | addData (double key, double value) |
void | coordsToPixels (double key, double value, double &x, double &y) const |
const QPointF | coordsToPixels (double key, double value) const |
void | pixelsToCoords (double x, double y, double &key, double &value) const |
void | pixelsToCoords (const QPointF &pixelPos, double &key, double &value) const |
void | rescaleAxes (bool onlyEnlarge=false) const |
void | rescaleKeyAxis (bool onlyEnlarge=false) const |
void | rescaleValueAxis (bool onlyEnlarge=false, bool inKeyRange=false) const |
bool | addToLegend (QCPLegend *legend) |
bool | addToLegend () |
bool | removeFromLegend (QCPLegend *legend) const |
bool | removeFromLegend () const |
virtual double | selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const |
virtual QCPPlottableInterface1D * | interface1D () |
virtual QCPRange | getKeyRange (bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const |
virtual QCPRange | getValueRange (bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const |
![]() | |
QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=nullptr) | |
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 |
Signals | |
void | selectionChanged (bool selected) |
void | selectionChanged (const QCPDataSelection &selection) |
void | selectableChanged (QCP::SelectionType selectable) |
![]() | |
void | layerChanged (QCPLayer *newLayer) |
Protected Functions | |
virtual QRect | clipRect () const |
virtual void | draw (QCPPainter *painter) |
virtual QCP::Interaction | selectionCategory () const |
void | applyDefaultAntialiasingHint (QCPPainter *painter) const |
virtual void | selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) |
virtual void | deselectEvent (bool *selectionStateChanged) |
virtual void | drawLinePlot (QCPPainter *painter, const QVector< QPointF > &lines) const |
virtual void | drawFill (QCPPainter *painter, QVector< QPointF > *lines) const |
virtual void | drawScatterPlot (QCPPainter *painter, const QVector< QPointF > &scatters, const QCPScatterStyle &style) const |
virtual void | drawLegendIcon (QCPPainter *painter, const QRectF &rect) const |
void | applyFillAntialiasingHint (QCPPainter *painter) const |
void | applyScattersAntialiasingHint (QCPPainter *painter) const |
double | pointDistance (const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const |
virtual int | dataCount () const |
void | getDataSegments (QList< QCPDataRange > &selectedSegments, QList< QCPDataRange > &unselectedSegments) const |
void | drawPolyline (QCPPainter *painter, const QVector< QPointF > &lineData) const |
void | getVisibleDataBounds (QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const |
void | getLines (QVector< QPointF > *lines, const QCPDataRange &dataRange) const |
void | getScatters (QVector< QPointF > *scatters, const QCPDataRange &dataRange) const |
void | getOptimizedLineData (QVector< QCPGraphData > *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const |
void | getOptimizedScatterData (QVector< QCPGraphData > *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const |
QVector< QPointF > | dataToLines (const QVector< QCPGraphData > &data) const |
![]() | |
virtual void | parentPlotInitialized (QCustomPlot *parentPlot) |
virtual void | mousePressEvent (QMouseEvent *event, const QVariant &details) |
virtual void | mouseMoveEvent (QMouseEvent *event, const QPointF &startPos) |
virtual void | mouseReleaseEvent (QMouseEvent *event, const QPointF &startPos) |
virtual void | mouseDoubleClickEvent (QMouseEvent *event, const QVariant &details) |
virtual void | wheelEvent (QWheelEvent *event) |
void | initializeParentPlot (QCustomPlot *parentPlot) |
void | setParentLayerable (QCPLayerable *parentLayerable) |
bool | moveToLayer (QCPLayer *layer, bool prepend) |
void | applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const |
A radial graph used to display data in polar plots.
Defines how the graph's line is represented visually in the plot. The line is drawn with the current pen of the graph (setPen).
Enumerator | |
---|---|
lsNone | data points are not connected with any lines (e.g. data only represented with symbols according to the scatter style, see setScatterStyle) |
lsLine | data points are connected by a straight line |
QCPPolarGraph::QCPPolarGraph | ( | QCPPolarAxisAngular * | keyAxis, |
QCPPolarAxisRadial * | valueAxis | ||
) |
Constructs a graph which uses keyAxis as its angular and valueAxis as its radial axis. keyAxis and valueAxis must reside in the same QCustomPlot, and the radial axis must be associated with the angular axis. If either of these restrictions is violated, a corresponding message is printed to the debug output (qDebug), the construction is not aborted, though.
The created QCPPolarGraph is automatically registered with the QCustomPlot instance inferred from keyAxis. This QCustomPlot instance takes ownership of the QCPPolarGraph, so do not delete it manually but use QCPPolarAxisAngular::removeGraph() instead.
To directly create a QCPPolarGraph inside a plot, you shoud use the QCPPolarAxisAngular::addGraph method.
void QCPPolarGraph::setName | ( | const QString & | name | ) |
The name is the textual representation of this plottable as it is displayed in the legend (QCPLegend). It may contain any UTF-8 characters, including newlines.
void QCPPolarGraph::setAntialiasedFill | ( | bool | enabled | ) |
Sets whether fills of this plottable are drawn antialiased or not.
Note that this setting may be overridden by QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.
void QCPPolarGraph::setAntialiasedScatters | ( | bool | enabled | ) |
Sets whether the scatter symbols of this plottable are drawn antialiased or not.
Note that this setting may be overridden by QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.
void QCPPolarGraph::setPen | ( | const QPen & | pen | ) |
void QCPPolarGraph::setBrush | ( | const QBrush & | brush | ) |
void QCPPolarGraph::setKeyAxis | ( | QCPPolarAxisAngular * | axis | ) |
The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal to the plottable's value axis. This function performs no checks to make sure this is the case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the y-axis (QCustomPlot::yAxis) as value axis.
Normally, the key and value axes are set in the constructor of the plottable (or QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface).
void QCPPolarGraph::setValueAxis | ( | QCPPolarAxisRadial * | axis | ) |
The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal to the plottable's key axis. This function performs no checks to make sure this is the case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the y-axis (QCustomPlot::yAxis) as value axis.
Normally, the key and value axes are set in the constructor of the plottable (or QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface).
void QCPPolarGraph::setSelectable | ( | QCP::SelectionType | selectable | ) |
Sets whether and to which granularity this plottable can be selected.
A selection can happen by clicking on the QCustomPlot surface (When QCustomPlot::setInteractions contains QCP::iSelectPlottables), by dragging a selection rect (When QCustomPlot::setSelectionRectMode is QCP::srmSelect), or programmatically by calling setSelection.
void QCPPolarGraph::setSelection | ( | QCPDataSelection | selection | ) |
Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently (e.g. color) in the plot. This can be controlled via the selection decorator (see selectionDecorator).
The entire selection mechanism for plottables is handled automatically when QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when you wish to change the selection state programmatically.
Using setSelectable you can further specify for each plottable whether and to which granularity it is selectable. If selection is not compatible with the current QCP::SelectionType set via setSelectable, the resulting selection will be adjusted accordingly (see QCPDataSelection::enforceType).
emits the selectionChanged signal when selected is different from the previous selection state.
void QCPPolarGraph::setData | ( | QSharedPointer< QCPGraphDataContainer > | data | ) |
This is an overloaded function.
Replaces the current data container with the provided data container.
Since a QSharedPointer is used, multiple QCPPolarGraphs may share the same data container safely. Modifying the data in the container will then affect all graphs that share the container. Sharing can be achieved by simply exchanging the data containers wrapped in shared pointers:
If you do not wish to share containers, but create a copy from an existing container, rather use the QCPDataContainer<DataType>::set method on the graph's data container directly:
void QCPPolarGraph::setData | ( | const QVector< double > & | keys, |
const QVector< double > & | values, | ||
bool | alreadySorted = false |
||
) |
This is an overloaded function.
Replaces the current data with the provided points in keys and values. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.
If you can guarantee that the passed data points are sorted by keys in ascending order, you can set alreadySorted to true, to improve performance by saving a sorting run.
void QCPPolarGraph::setLineStyle | ( | LineStyle | ls | ) |
Sets how the single data points are connected in the plot. For scatter-only plots, set ls to lsNone and setScatterStyle to the desired scatter style.
void QCPPolarGraph::setScatterStyle | ( | const QCPScatterStyle & | style | ) |
Sets the visual appearance of single data points in the plot. If set to QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only-plots with appropriate line style).
void QCPPolarGraph::coordsToPixels | ( | double | key, |
double | value, | ||
double & | x, | ||
double & | y | ||
) | const |
Use this method to set an own QCPSelectionDecorator (subclass) instance. This allows you to customize the visual representation of selected data ranges further than by using the default QCPSelectionDecorator.
The plottable takes ownership of the decorator.
The currently set decorator can be accessed via selectionDecorator.
|
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.
In the case of 1D Plottables (QCPAbstractPlottable1D, like QCPGraph or QCPBars) details will be set to a QCPDataSelection, describing the closest data point to pos.
You may pass nullptr
as details to indicate that you are not interested in those selection details.
Reimplemented from QCPLayerable.
|
protectedvirtual |
Returns the clipping rectangle of this layerable object. By default, this is the viewport of the parent QCustomPlot. Specific subclasses may reimplement this function to provide different clipping rects.
The returned clipping rect is set on the painter before the draw function of the respective object is called.
Reimplemented from QCPLayerable.
|
protectedvirtual |
This function draws the layerable with the specified painter. It is only called by QCustomPlot, if the layerable is visible (setVisible).
Before this function is called, the painter's antialiasing state is set via applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was set to clipRect.
Implements QCPLayerable.
|
protectedvirtual |
Returns the selection category this layerable shall belong to. The selection category is used in conjunction with QCustomPlot::setInteractions to control which objects are selectable and which aren't.
Subclasses that don't fit any of the normal QCP::Interaction values can use QCP::iSelectOther. This is what the default implementation returns.
Reimplemented from QCPLayerable.
|
protectedvirtual |
This function applies the default antialiasing setting to the specified painter, using the function applyAntialiasingHint. It is the antialiasing state the painter is put in, when draw is called on the layerable. If the layerable has multiple entities whose antialiasing setting may be specified individually, this function should set the antialiasing state of the most prominent entity. In this case however, the draw function usually calls the specialized versions of this function before drawing each entity, effectively overriding the setting of the default antialiasing hint.
First example: QCPGraph has multiple entities that have an antialiasing setting: The graph line, fills and scatters. Those can be configured via QCPGraph::setAntialiased, QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw calls the respective specialized applyAntialiasingHint function.
Second example: QCPItemLine consists only of a line so there is only one antialiasing setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the respective layerable subclass.) Consequently it only has the normal QCPItemLine::applyDefaultAntialiasingHint. The QCPItemLine::draw function doesn't need to care about setting any antialiasing states, because the default antialiasing hint is already set on the painter when the draw function is called, and that's the state it wants to draw the line with.
Implements QCPLayerable.
|
protectedvirtual |
This event is called when the layerable shall be selected, as a consequence of a click by the user. Subclasses should react to it by setting their selection state appropriately. The default implementation does nothing.
event is the mouse event that caused the selection. additive indicates, whether the user was holding the multi-select-modifier while performing the selection (see QCustomPlot::setMultiSelectModifier). if additive is true, the selection state must be toggled (i.e. become selected when unselected and unselected when selected).
Every selectEvent is preceded by a call to selectTest, which has returned positively (i.e. returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). The details data you output from selectTest is fed back via details here. You may use it to transport any kind of information from the selectTest to the possibly subsequent selectEvent. Usually details is used to transfer which part was clicked, if it is a layerable that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need to do the calculation again to find out which part was actually clicked.
selectionStateChanged is an output parameter. If the pointer is non-null, this function must set the value either to true or false, depending on whether the selection state of this layerable was actually changed. For layerables that only are selectable as a whole and not in parts, this is simple: if additive is true, selectionStateChanged must also be set to true, because the selection toggles. If additive is false, selectionStateChanged is only set to true, if the layerable was previously unselected and now is switched to the selected state.
Reimplemented from QCPLayerable.
|
protectedvirtual |
This event is called when the layerable shall be deselected, either as consequence of a user interaction or a call to QCustomPlot::deselectAll. Subclasses should react to it by unsetting their selection appropriately.
just as in selectEvent, the output parameter selectionStateChanged (if non-null), must return true or false when the selection state of this layerable has changed or not changed, respectively.
Reimplemented from QCPLayerable.
|
protectedvirtual |
Draws lines between the points in lines, given in pixel coordinates.
|
protectedvirtual |
Draws the fill of the graph using the specified painter, with the currently set brush.
Depending on whether a normal fill or a channel fill (setChannelFillGraph) is needed, getFillPolygon or getChannelFillPolygon are used to find the according fill polygons.
In order to handle NaN Data points correctly (the fill needs to be split into disjoint areas), this method first determines a list of non-NaN segments with getNonNanSegments, on which to operate. In the channel fill case, getOverlappingSegments is used to consolidate the non-NaN segments of the two involved graphs, before passing the overlapping pairs to getChannelFillPolygon.
Pass the points of this graph's line as lines, in pixel coordinates.
|
protectedvirtual |
Draws scatter symbols at every point passed in scatters, given in pixel coordinates. The scatters will be drawn with painter and have the appearance as specified in style.
|
protected |
This method retrieves an optimized set of data points via getOptimizedLineData, an branches out to the line style specific functions such as dataToLines, dataToStepLeftLines, etc. according to the line style of the graph.
lines will be filled with points in pixel coordinates, that can be drawn with the according draw functions like drawLinePlot and drawImpulsePlot. The points returned in lines aren't necessarily the original data points. For example, step line styles require additional points to form the steps when drawn. If the line style of the graph is lsNone, the lines vector will be empty.
dataRange specifies the beginning and ending data indices that will be taken into account for conversion. In this function, the specified range may exceed the total data bounds without harm: a correspondingly trimmed data range will be used. This takes the burden off the user of this function to check for valid indices in dataRange, e.g. when extending ranges coming from getDataSegments.
|
protected |
Takes raw data points in plot coordinates as data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style lsLine.
The source of data is usually getOptimizedLineData, and this method is called in getLines if the line style is set accordingly.