Kstars
qcustomplot.cpp
14////////////////////////////////////////////////////////////////////////////////////////////////////
16////////////////////////////////////////////////////////////////////////////////////////////////////
59 Returns the angle of the vector in radians. The angle is measured between the positive x line and
81 Returns whether this vector is null. A vector is null if \c qIsNull returns true for both x and y
167 Returns the squared shortest distance of this vector (interpreted as a point) to the finite line
172double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const
191 Returns the squared shortest distance of this vector (interpreted as a point) to the finite line
207double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const
259////////////////////////////////////////////////////////////////////////////////////////////////////
261////////////////////////////////////////////////////////////////////////////////////////////////////
266 This QPainter subclass is used to provide some extended functionality e.g. for tweaking position
270 \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and
272 QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because
288 Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just
319 Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of
333 Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of
364 antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for
373 if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs
393 Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a
394 device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5,
476////////////////////////////////////////////////////////////////////////////////////////////////////
478////////////////////////////////////////////////////////////////////////////////////////////////////
490 clean up if necessary. Before rendering a frame, each paint buffer is usually filled with a color
525 Fills the entire buffer with the provided \a color. To have an empty transparent buffer, use the
528 This method must not be called if there is currently a painter (acquired with \ref startPainting)
552 paint buffer subclasses may use this method to perform any type of cleanup that is necessary. The
561 Subclasses must call their \ref reallocateBuffer implementation in their respective constructors.
577 The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained
596 layer, i.e. an isolated repaint of only that layer (and its dedicated paint buffer) is requested,
597 QCustomPlot will decide depending on the invalidated flags of other paint buffers whether it also
601 were added or removed from this buffer, or if they were reordered. It is set to false as soon as
613 The ratio is automatically set to the device pixel ratio used by the parent QCustomPlot instance.
615 The buffer is reallocated (by calling \ref reallocateBuffer), so any painters that were obtained
634////////////////////////////////////////////////////////////////////////////////////////////////////
636////////////////////////////////////////////////////////////////////////////////////////////////////
706////////////////////////////////////////////////////////////////////////////////////////////////////
708////////////////////////////////////////////////////////////////////////////////////////////////////
717 The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are
729QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) :
748 qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
753 result->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
801////////////////////////////////////////////////////////////////////////////////////////////////////
803////////////////////////////////////////////////////////////////////////////////////////////////////
806 \brief A paint buffer based on OpenGL frame buffers objects, using hardware accelerated rendering
812 The OpenGL paint buffers are used if \ref QCustomPlot::setOpenGl is set to true, and if they are
820 All frame buffer objects shall share one OpenGL context and paint device, which need to be set up
825QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer<QOpenGLContext> glContext, QWeakPointer<QOpenGLPaintDevice> glPaintDevice) :
857 qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
866 result->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
890 qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
907 qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
963////////////////////////////////////////////////////////////////////////////////////////////////////
965////////////////////////////////////////////////////////////////////////////////////////////////////
985 selection rect (\ref QCustomPlot::selectionRect). The next two layers "axes" and "legend" contain
986 the default axes and legend, so they will be drawn above plottables. In the middle, there is the
989 layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong
998 you want the layerable to be in, e.g. above "main", with \ref QCustomPlot::addLayer. Then set the
1001 setting. Alternatively you could have also ignored the current layer setting and just moved the
1004 It is also possible to move whole layers. For example, If you want the grid to be shown in front
1011 When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below
1017 layer by calling \ref replot. In certain situations this can provide better replot performance,
1033 Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be
1063 // If child layerables are still on this layer, detach them, so they don't try to reach back to this
1064 // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted
1065 // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to
1066 // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.)
1072 qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or nullptr beforehand.";
1076 Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this
1080 QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the
1095 Layers which are set to \ref lmLogical (the default) are used only to define the rendering order
1102 example would be a layer which contains certain layerables (e.g. items) that need to be changed
1103 and thus replotted regularly, while all other layerables on other layers stay static. By default,
1142 Draws the contents of this layer into the paint buffer which is associated with this layer. The
1143 association is established by the parent QCustomPlot, which manages all paint buffers (see \ref
1168 the layerables on this specific layer, without the need to replot all other layers (as a call to
1171 QCustomPlot also makes sure to replot all layers instead of only this one, if the layer ordering
1175 If the layer mode is \ref lmLogical however, this method simply calls \ref QCustomPlot::replot on
1198 Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will
1224 This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer
1240////////////////////////////////////////////////////////////////////////////////////////////////////
1242////////////////////////////////////////////////////////////////////////////////////////////////////
1250 Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking
1261 visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables
1280 \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing
1282 most prominent entity. In this case however, the \ref draw function usually calls the specialized
1283 versions of this function before drawing each entity, effectively overriding the setting of the
1286 <b>First example:</b> QCPGraph has multiple entities that have an antialiasing setting: The graph
1288 QCPGraph::setAntialiasedFill and QCPGraph::setAntialiasedScatters. Consequently, there isn't only
1291 QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw
1295 setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by
1296 all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the
1299 care about setting any antialiasing states, because the default antialiasing hint is already set
1300 on the painter when the \ref draw function is called, and that's the state it wants to draw the
1320 This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to
1331 Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the
1334 If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a
1338 It is possible to provide \c nullptr as \a plot. In that case, you should assign a parent plot at
1344 parentLayerable does not become the QObject-parent (for memory management) of this layerable, \a
1345 plot does. It is not uncommon to set the QObject-parent to something else in the constructors of
1348QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) :
1375 Sets the visibility of this layerable object. If an object is not visible, it will not be drawn
1385 Sets the \a layer of this layerable object. The object will be placed on top of the other objects
1432 Returns whether this layerable is visible, taking the visibility of the layerable parent and the
1433 visibility of this layerable's layer into account. This is the method that is consulted to decide
1437 subclasses, like in the case of \ref QCPLayoutElement), this function returns true only if this
1438 layerable has its visibility set to true and the parent layerable's \ref realVisibility returns
1443 return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility());
1451 distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the
1456 these cases this function thus returns a constant value greater zero but still below the parent
1464 parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified
1471 objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked
1476 In the case of 1D Plottables (\ref QCPAbstractPlottable1D, like \ref QCPGraph or \ref QCPBars) \a
1479 You may pass \c nullptr as \a details to indicate that you are not interested in those selection
1485double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const
1495 Sets the parent plot of this layerable. Use this function once to set the parent plot if you have
1496 passed \c nullptr in the constructor. It can not be used to move a layerable from one QCustomPlot
1506 The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized
1527 Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not
1531 layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be
1543 Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to
1576 localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref
1577 QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is
1580void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const
1592 This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting
1593 of a parent plot. This is the case when \c nullptr was passed as parent plot in the constructor,
1597 QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level
1599 propagate the parent plot to all the children of the hierarchy, the top level element then uses
1613 Returns the selection category this layerable shall belong to. The selection category is used in
1629 Returns the clipping rectangle of this layerable object. By default, this is the viewport of the
1647 user. Subclasses should react to it by setting their selection state appropriately. The default
1652 QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled
1655 Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e.
1656 returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot).
1659 selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable
1660 that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need
1663 \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must
1664 set the value either to true or false, depending on whether the selection state of this layerable
1665 was actually changed. For layerables that only are selectable as a whole and not in parts, this
1666 is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the
1667 selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the
1672void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
1703 event->pos(). The parameter \a details contains layerable-specific details about the hit, which
1704 were generated in the previous call to \ref selectTest. For example, One-dimensional plottables
1705 like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as
1710 layerable doesn't reimplement the \ref mousePressEvent or explicitly calls \c event->ignore() in
1711 its reimplementation, the event will be propagated to the next layerable in the stacking order.
1714 will receive all following calls to \ref mouseMoveEvent or \ref mouseReleaseEvent for this mouse
1747 This event gets called when the user releases the mouse button, after this layerable has become
1774 event->pos(). The parameter \a details contains layerable-specific details about the hit, which
1775 were generated in the previous call to \ref selectTest. For example, One-dimensional plottables
1776 like \ref QCPGraph or \ref QCPBars convey the clicked data point in the \a details parameter, as
1780 Similarly to \ref mousePressEvent, once a layerable has accepted the \ref mouseDoubleClickEvent,
1782 and \ref mouseReleaseEvent for this mouse interaction (a "mouse interaction" in this context ends
1804 The \c event->angleDelta() indicates how far the mouse wheel was turned, which is usually +/- 120
1806 accumulate to one event, making the delta larger. On the other hand, if the wheel has very smooth
1823////////////////////////////////////////////////////////////////////////////////////////////////////
1825////////////////////////////////////////////////////////////////////////////////////////////////////
1849 Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values are
1886 values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to
1895 Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers,
1899 values that will appear in the plot)! It is intended only as a bound to compare against, e.g. to
1931 Expands this range such that \a otherRange is contained in the new range. It is assumed that both
1934 If this range contains NaN as lower or upper bound, it will be replaced by the respective bound
1975 If this range contains NaN as lower or upper bound, the returned range's bound will be taken from
1992 If this range contains NaN as lower or upper bound, the returned range's bound will be set to \a
2005 Returns this range, possibly modified to not exceed the bounds provided as \a lowerBound and \a
2044 \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval
2052 // can't have range spanning negative and positive values in log plot, so change range to fix it
2071 // find out whether negative or positive interval is wider to decide which sign domain will be chosen
2145////////////////////////////////////////////////////////////////////////////////////////////////////
2147////////////////////////////////////////////////////////////////////////////////////////////////////
2152 QCPDataRange holds two integers describing the begin (\ref setBegin) and end (\ref setEnd) index
2153 of a contiguous set of data points. The \a end index corresponds to the data point just after the
2156 Data Ranges are not bound to a certain plottable, thus they can be freely exchanged, created and
2158 used, which holds and manages multiple instances of \ref QCPDataRange. In most situations, \ref
2163 contains. Further, addition and subtraction operators (defined in \ref QCPDataSelection) can be
2164 used to join/subtract data ranges and data selections (or mixtures), to retrieve a corresponding
2167 %QCustomPlot's \ref dataselection "data selection mechanism" is based on \ref QCPDataSelection and
2170 \note Do not confuse \ref QCPDataRange with \ref QCPRange. A \ref QCPRange describes an interval
2191 Sets the begin of this data range. The \a begin index points to the first data point that is part
2211 Returns whether this range is valid. A valid range has a begin index greater or equal to 0, and
2214 \note Invalid ranges should be avoided and are never the result of any of QCustomPlot's methods
2215 (unless they are themselves fed with invalid ranges). Do not pass invalid ranges to QCustomPlot's
2217 invalid begin/end values while manipulating the range. An invalid range is not necessarily empty
2260 This method is very similar to \ref intersection, with one distinction: If this range and the \a
2261 other range share no intersection, the returned data range will be empty with begin and end set
2262 to the respective boundary side of \a other, at which this range is residing. (\ref intersection
2268 if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value
2289 This method is very similar to \ref bounded, with one distinction: If this range and the \a other
2290 range share no intersection, the returned data range will be empty with begin and end set to 0.
2291 (\ref bounded would return a range with begin and end set to one of the boundaries of \a other,
2328////////////////////////////////////////////////////////////////////////////////////////////////////
2330////////////////////////////////////////////////////////////////////////////////////////////////////
2335 QCPDataSelection manages multiple instances of QCPDataRange in order to represent any (possibly
2340 \ref clear. Read access is provided by \ref dataRange, \ref dataRanges, \ref dataRangeCount, etc.
2345 addDataRange, with the parameter \a simplify explicitly set to false. This is useful if many data
2350 Use \ref enforceType to bring the data selection into a state complying with the constraints for
2369 Returns the number of ranges that make up the data selection. The ranges can be accessed by \ref
2377 Returns all data ranges that make up the data selection. If the data selection is simplified (the
2378 usual state of the selection, see \ref simplify), the ranges are sorted by ascending data point
2413 Note that both data selections must be in simplified state (the usual state of the selection, see
2440 Adds the data range \a other to this data selection, and then simplifies this data selection (see
2475 break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this
2477 if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored
2553 performance if adding a very large amount of data ranges successively. In this case, make sure to
2574 Sorts all data ranges by range begin index in ascending order, and then joins directly adjacent
2575 or overlapping ranges. This can reduce the number of individual data ranges in the selection, and
2578 This method is automatically called when using the addition/subtraction operators. The only case
2579 when \ref simplify is left to the user, is when calling \ref addDataRange, with the parameter \a
2610 Makes sure this data selection conforms to the specified \a type selection type. Before the type
2613 Depending on \a type, enforcing means adding new data points that were previously not part of the
2614 selection, or removing data points from the selection. If the current selection already conforms
2631 // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods)
2679 return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this
2683 Returns a data selection containing the points which are both in this data selection and in the
2686 A common use case is to limit an unknown data selection to the valid range of a data container,
2687 using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned
2700 Returns a data selection containing the points which are both in this data selection and in the
2717 For example, this method can be used to retrieve all unselected segments by setting \a outerRange
2718 to the full data range of the plottable, and calling this method on a data selection holding the
2733 result.addDataRange(QCPDataRange(mDataRanges.at(i-1).end(), mDataRanges.at(i).begin()), false);
2746////////////////////////////////////////////////////////////////////////////////////////////////////
2748////////////////////////////////////////////////////////////////////////////////////////////////////
2756 according rect shape is drawn. At the begin, during, and after completion of the interaction, it
2759 The QCustomPlot instance connects own slots to the current selection rect instance, in order to
2767 If you wish to provide custom behaviour, e.g. a different visual representation of the selection
2796 Note that \a rect may have a negative width or height, if the selection is being dragged to the
2805 The user may cancel the selection interaction by pressing the escape key. In this case, \a event
2808 Note that \a rect may have a negative width or height, if the selection is being dragged to the
2817 Note that \a rect may have a negative width or height, if the selection is being dragged to the
2871 Sets the brush that will be used to fill the selection rect. By default the selection rect is not
2896 This method is called by QCustomPlot to indicate that a selection rect interaction was initiated.
2909 This method is called by QCustomPlot to indicate that an ongoing selection rect interaction needs
2922 This method is called by QCustomPlot to indicate that an ongoing selection rect interaction has
2935 This method is called by QCustomPlot when a key has been pressed by the user while the selection
2936 rect interaction is active. The default implementation allows to \ref cancel the interaction by
2975////////////////////////////////////////////////////////////////////////////////////////////////////
2977////////////////////////////////////////////////////////////////////////////////////////////////////
2980 \brief A margin group allows synchronization of margin sides if working with multiple layout elements.
2982 QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that
2990 layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will
2991 provide a cleaner look to the user if the left and right margins of the two axis rects are of the
2992 same size. The left axis of the top axis rect will then be at the same horizontal position as the
2997 QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call
3014 Returns a list of all layout elements that have their margin \a side associated with this margin
3039 Returns whether this margin group is empty. If this function returns true, no layout elements use
3055 Clears this margin group. The synchronization of the margin sides that use this margin group is
3073 Returns the synchronized common margin for \a side. This is the margin value that will be used by
3078 group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into
3123////////////////////////////////////////////////////////////////////////////////////////////////////
3125////////////////////////////////////////////////////////////////////////////////////////////////////
3128 \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system".
3130 This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses.
3134 between outer and inner rect is called its margin. The margin can either be set to automatic or
3135 manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be
3136 set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic,
3139 Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level
3147 something. For example, QCPAxisRect, QCPLegend and QCPTextElement are of this category. This does
3162 Returns the inner rect of this layout element. The inner rect is the outer rect (\ref outerRect, \ref
3166 area is used to display peripheral graphics while the main content is in the inner rect. This is
3177 Returns the outer rect of this layout element. The outer rect is the inner rect expanded by the
3190 QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout)
3207 if (qobject_cast<QCPLayout*>(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor
3212 Sets the outer rect of this layout element. If the layout element is inside a layout, the layout
3218 The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect.
3233 sides, this function is used to manually set the margin on those sides. Sides that are still set
3255 The minimum values are not enforced on margin sides that were set to be under manual control via
3270 automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is
3273 Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref
3284 Sets the minimum size of this layout element. A parent layout tries to respect the \a size here
3287 If the parent layout size is not sufficient to satisfy all minimum size constraints of its child
3289 propagates the layout's size constraints to the outside by setting its own minimum QWidget size
3318 Sets the maximum size of this layout element. A parent layout tries to respect the \a size here
3350 The outer rect (\ref outerRect) includes the margins (e.g. in the case of a QCPAxisRect the axis
3368 Margin groups allow synchronizing specified margins across layout elements, see the documentation
3407 Updates the layout element and sub-elements. This function is automatically called before every
3409 UpdatePhase. The phases are run through in the order of the enum values. For details about what
3415 The default implementation executes the automatic margin mechanism in the \ref upMargins phase.
3424 // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group:
3426 const QList<QCP::MarginSide> allMarginSides = QList<QCP::MarginSide>() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom;
3432 QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group
3434 QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly
3446 Returns the suggested minimum size this layout element (the \ref outerRect) may be compressed to,
3449 if a minimum size (\ref setMinimumSize) was not set manually, parent layouts use the returned size
3455 The default implementation simply returns the sum of the horizontal margins for the width and the
3465 Returns the suggested maximum size this layout element (the \ref outerRect) may be expanded to,
3474 The default implementation simply returns \c QWIDGETSIZE_MAX for both width and height, implying
3504 QCPLayoutElement subclasses may reimplement this method to provide more specific selection test
3507double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const
3543 Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a
3570////////////////////////////////////////////////////////////////////////////////////////////////////
3572////////////////////////////////////////////////////////////////////////////////////////////////////
3577 This is an abstract base class for layout elements whose main purpose is to define the position
3583 QCPLayout introduces a common interface for accessing and manipulating the child elements. Those
3585 simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions
3587 QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid
3612 QCPLayoutGrid), so this function may return \c nullptr in those cases. You may use this function
3624 Note that some layouts don't remove the respective cell right away but leave an empty cell after
3636 Note that some layouts don't remove the respective cell right away but leave an empty cell after
3711 Removes and deletes the element at the provided \a index. Returns true on success. If \a index is
3714 This function internally uses \ref takeAt to remove the element from the layout and then deletes
3715 the returned element. Note that some layouts don't remove the respective cell right away but leave an
3732 Removes and deletes the provided \a element. Returns true on success. If \a element is not in the
3735 This function internally uses \ref takeAt to remove the element from the layout and then deletes
3753 Removes and deletes all layout elements in this layout. Finally calls \ref simplify to make sure
3772 sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of
3773 QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout,
3786 Subclasses reimplement this method to update the position and sizes of the child elements/cells
3787 via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing.
3789 The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay
3803 Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the
3809 This method is used by subclass specific methods that add elements to the layout. Note that this
3810 method only changes properties in \a el. The removal from the old layout and the insertion into
3829 Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout
3833 This method is used by subclass specific methods that remove elements from the layout (e.g. \ref
3853 It calculates the sizes of one-dimensional sections with provided constraints on maximum section
3854 sizes, minimum section sizes, relative stretch factors and the final total size of all sections.
3862 imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than
3863 \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words,
3864 not exceeding the allowed total size is taken to be more important than not going below minimum
3868 shall be scaled equally, set all values equal. If the first section shall be double the size of
3869 each individual other section, set the first number of \a stretchFactors to double the value of
3878QVector<int> QCPLayout::getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const
3882 qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors;
3889 // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections):
3910 while (!unfinishedSections.isEmpty() && outerIterations < sectionCount*2) // the iteration check ist just a failsafe in case something really strange happens
3914 while (!unfinishedSections.isEmpty() && innerIterations < sectionCount*2) // the iteration check ist just a failsafe in case something really strange happens
3929 // check if that maximum is actually within the bounds of the total size (i.e. can we stretch all remaining sections so far that the found section
3935 if (nextMax < nextMaxLimit) // next maximum is actually hit, move forward to that point and fix the size of that section
3942 unfinishedSections.removeOne(nextId); // exclude the section that is now at maximum from further changes
3951 qDebug() << Q_FUNC_INFO << "Exceeded maximum expected inner iteration count, layouting aborted. Input was:" << maxSizes << minSizes << stretchFactors << totalSize;
3971 if (!minimumLockedSections.contains(i)) // only put sections that haven't hit their minimum back into the pool
3974 freeSize -= sectionSizes.at(i); // remove size of minimum locked sections from available space in next round
3976 // reset all section sizes to zero that are in unfinished sections (all others have been set to their minimum):
3994 It returns the minimum size that should finally be used for the outer rect of the passed layout
3999 QCPLayoutElement::setSizeConstraintRect), as well as the minimum size hint, if no manual minimum
4005 QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0)
4019 It returns the maximum size that should finally be used for the outer rect of the passed layout
4024 QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum
4030 QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX)
4031 if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect)
4033 if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect)
4041////////////////////////////////////////////////////////////////////////////////////////////////////
4043////////////////////////////////////////////////////////////////////////////////////////////////////
4048 Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor,
4051 Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or
4052 column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref
4053 hasElement, that element can be retrieved with \ref element. If rows and columns that only have
4059 column, the grid layout will choose the position according to the current \ref setFillOrder and
4096 // clear all child layout elements. This is important because only the specific layouts know how
4104 Returns \c nullptr if either the row/column is invalid or if the cell is empty. In those cases, a
4105 qDebug message is printed. To check whether a cell exists and isn't empty, use \ref hasElement.
4129 Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it
4136 Use the overload of this method without explicit row/column index to place the element according
4198 Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't
4214 Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond
4238 Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond
4256 qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << mColumnStretchFactors.at(i);
4267 Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond
4291 Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond
4309 qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << mRowStretchFactors.at(i);
4339 addElement(QCPLayoutElement*) will start to fill the next row or column, respectively. It depends
4345 rearrange set to true (the actual fill order doesn't need to be changed for the rearranging to be
4363 The specified \a order defines whether rows or columns are filled first. Using \ref setWrap, you
4364 can control at which row/column count wrapping into the next column/row will occur. If you set it
4369 If you want to have all current elements arranged in the new order, set \a rearrange to true. The
4410 Expands the layout to have \a newRowCount rows and \a newColumnCount columns. So the last valid
4413 If the current column/row count is already larger or equal to \a newColumnCount/\a newRowCount,
4470 newIndex range from 0 (inserts a column at the left) to \a columnCount (appends a column at the
4498 indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices
4501 For the returned index to be valid, \a row and \a column must be valid indices themselves, i.e.
4529 indices increase left to right and then top to bottom. If it is \ref foColumnsFirst, the indices
4579 QVector<int> colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing);
4580 QVector<int> rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing);
4703 if (mElements.isEmpty()) // removed last element, also remove stretch factor (wouldn't happen below because also columnCount changed to 0 now)
4781void QCPLayoutGrid::getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const
4807 row. The maximum width of a column is the smallest maximum width of any element's outer rect in
4814void QCPLayoutGrid::getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const
4835////////////////////////////////////////////////////////////////////////////////////////////////////
4837////////////////////////////////////////////////////////////////////////////////////////////////////
4846 addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset
4847 placement will default to \ref ipBorderAligned and the element will be aligned according to the
4848 \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at
4851 The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively.
4875 // clear all child layout elements. This is important because only the specific layouts know how
4958 If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the
4961 \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1)
4962 will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right
5005 else insetRect.moveLeft(int( rect().x()+rect().width()*0.5-finalMinSize.width()*0.5 )); // default to Qt::AlignHCenter
5068 sensitive. If the selectTest method of any of the child elements returns a positive number for \a
5070 tolerance. The inset layout is not selectable itself by default. So if \a onlySelectable is true,
5075double QCPLayoutInset::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const
5122 \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1)
5123 will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right
5148////////////////////////////////////////////////////////////////////////////////////////////////////
5150////////////////////////////////////////////////////////////////////////////////////////////////////
5157 For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine
5160 The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can
5162 the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item.
5163 For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite
5186QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) :
5214 Sets the length of the ending decoration, if the style supports it. On arrows, for example, the
5225 Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point
5228 Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or
5242 This is relevant for clipping. Only omit painting of the decoration when the position where the
5275 both have the same \ref setLength value, because the spike arrow has an inward curved back, which
5308 Draws the line ending with the specified \a painter at the position \a pos. The direction of the
5311void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const
5417 if (!qFuzzyIsNull(painter->pen().widthF()) || painter->modes().testFlag(QCPPainter::pmNonCosmetic))
5443////////////////////////////////////////////////////////////////////////////////////////////////////
5445////////////////////////////////////////////////////////////////////////////////////////////////////
5555void QCPLabelPainterPrivate::drawTickLabel(QCPPainter *painter, const QPointF &tickPos, const QString &text)
5560 // for circular axes, the anchor side is determined depending on the quadrant of tickPos with respect to mCircularReference
5564 } else if (mAnchorMode == amSkewedRotated) // in this mode every label is individually rotated to match circle tangent
5572 realSide = rotationCorrectedSide(realSide, realRotation); // rotation angles may change the true anchor side of the label
5573 drawLabelMaybeCached(painter, mFont, mColor, getAnchorPos(tickPos), realSide, realRotation, text);
5578 Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone
5597 result += QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width();
5602 // calculate size of axis label (only height needed, because left/right labels are rotated by 90 degrees):