mirror of https://github.com/qt/qtgraphs.git
2D: Warn when axis added to multiple graphs
Adding the same axis to multiple graphs is not supported. It will result to crash since graphsview destructor tries to set axis' associated graph to nullptr. Fixes: QTBUG-138822 Pick-to: 6.8 6.9 6.10 Change-Id: If306e415f87f2366ae0d82f6fd5c9a9a5e356f85 Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io> Reviewed-by: Alexei Cazacov <alexei.cazacov@qt.io>
This commit is contained in:
parent
2a5f3540d2
commit
818613a0ee
|
|
@ -625,11 +625,17 @@ QAbstractAxisPrivate::~QAbstractAxisPrivate()
|
|||
m_graph->removeAxis(q);
|
||||
}
|
||||
|
||||
void QAbstractAxisPrivate::setGraph(QGraphsView *graph)
|
||||
{
|
||||
if (m_graph && graph)
|
||||
qCWarning(lcAxis2D, "%p axis already associated with %p", this, m_graph);
|
||||
|
||||
m_graph = graph;
|
||||
}
|
||||
|
||||
void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
|
||||
{
|
||||
setRange(min,max);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public:
|
|||
~QAbstractAxisPrivate() override;
|
||||
|
||||
public:
|
||||
void setGraph(QGraphsView *graph) { m_graph = graph; }
|
||||
void setGraph(QGraphsView *graph);
|
||||
|
||||
//interface for manipulating range form base class
|
||||
virtual void setMin(const QVariant &min) = 0;
|
||||
|
|
|
|||
|
|
@ -1405,11 +1405,15 @@ void QGraphsView::updatePlotArea()
|
|||
\brief X-axis of this view.
|
||||
|
||||
The x-axis used for the series inside this view.
|
||||
|
||||
\note Setting the same axis to multiple QGraphsViews is not supported.
|
||||
*/
|
||||
/*!
|
||||
\qmlproperty AbstractAxis GraphsView::axisX
|
||||
The x-axis used for the series inside this view.
|
||||
\sa axisY
|
||||
|
||||
\note Setting the same axis to multiple GraphsViews is not supported.
|
||||
*/
|
||||
|
||||
QAbstractAxis *QGraphsView::axisX() const
|
||||
|
|
@ -1443,11 +1447,15 @@ void QGraphsView::setAxisX(QAbstractAxis *axis)
|
|||
\brief Y-axis of this view.
|
||||
|
||||
The y-axis used for the series inside this view.
|
||||
|
||||
\note Setting the same axis to multiple QGraphsViews is not supported.
|
||||
*/
|
||||
/*!
|
||||
\qmlproperty AbstractAxis GraphsView::axisY
|
||||
The y-axis used for the series inside this view.
|
||||
\sa axisX
|
||||
|
||||
\note Setting the same axis to multiple GraphsViews is not supported.
|
||||
*/
|
||||
|
||||
QAbstractAxis *QGraphsView::axisY() const
|
||||
|
|
|
|||
|
|
@ -48,7 +48,21 @@ Item {
|
|||
}
|
||||
|
||||
TestCase {
|
||||
name: "ValueAxis Initial"
|
||||
name: "ValueAxis with GraphsView"
|
||||
|
||||
GraphsView {id: graphsView1}
|
||||
GraphsView {id: graphsView2}
|
||||
ValueAxis {id: axis1}
|
||||
|
||||
function test_1_add_to_multiple() {
|
||||
ignoreWarning(/.*axis already associated with.*/)
|
||||
graphsView1.axisX = axis1
|
||||
graphsView2.axisX = axis1
|
||||
}
|
||||
}
|
||||
|
||||
TestCase {
|
||||
name: "valueaxis initial"
|
||||
|
||||
Text { id: dummy }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue