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.9 6.8
Change-Id: If306e415f87f2366ae0d82f6fd5c9a9a5e356f85
Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io>
Reviewed-by: Alexei Cazacov <alexei.cazacov@qt.io>
(cherry picked from commit 818613a0ee)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
7660f32149
commit
2cca8ce8c5
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1354,11 +1354,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
|
||||
|
|
@ -1392,11 +1396,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