summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/data/qscatterdataproxy.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-27 11:04:58 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-27 11:39:25 +0300
commitd4d99e49c147f4f61c0d5e84e59c023789fae17d (patch)
treeba01feecf4a818b95b5260d6419589c7b5536768 /src/datavisualization/data/qscatterdataproxy.cpp
parent2d9dbd6bcb2c1a75f0a4230868854c495b2d530a (diff)
Allow resetting with existing array for bars and scatter
Improves performance when array dimensions do not change Task-number: QTRD-2335 Change-Id: I2733ff3552009a19cf285bc91426f595b64795dd Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data/qscatterdataproxy.cpp')
-rw-r--r--src/datavisualization/data/qscatterdataproxy.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/datavisualization/data/qscatterdataproxy.cpp b/src/datavisualization/data/qscatterdataproxy.cpp
index f020ac12..50328d1a 100644
--- a/src/datavisualization/data/qscatterdataproxy.cpp
+++ b/src/datavisualization/data/qscatterdataproxy.cpp
@@ -91,15 +91,17 @@ QScatterDataProxy::~QScatterDataProxy()
}
/*!
- * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer
- * to further modify data after QScatterDataProxy assumes ownership of it, as such modifications will
- * not trigger proper signals.
- * Passing null array clears all data.
+ * Takes ownership of the \a newArray. Clears the existing array and if the \a newArray is
+ * different than the existing array. If it's the same array, this just triggers arrayReset()
+ * signal.
+ * Passing null array deletes the old array and creates a new empty array.
*/
void QScatterDataProxy::resetArray(QScatterDataArray *newArray)
{
- if (dptr()->resetArray(newArray))
- emit arrayReset();
+ if (dptr()->m_dataArray != newArray)
+ dptr()->resetArray(newArray);
+
+ emit arrayReset();
}
/*!
@@ -220,18 +222,24 @@ const QScatterDataProxyPrivate *QScatterDataProxy::dptrc() const
* \fn void QScatterDataProxy::arrayReset()
*
* Emitted when data array is reset.
+ * If you change the whole array contents without calling resetArray(), you need to
+ * emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QScatterDataProxy::itemsAdded(int startIndex, int count)
*
* Emitted when items have been added. Provides \a startIndex and \a count of items added.
+ * If you add items directly to the array without calling addItem() or addItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QScatterDataProxy::itemsChanged(int startIndex, int count)
*
* Emitted when items have changed. Provides \a startIndex and \a count of changed items.
+ * If you change items directly in the array without calling setItem() or setItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
@@ -239,12 +247,16 @@ const QScatterDataProxyPrivate *QScatterDataProxy::dptrc() const
*
* Emitted when items have been removed. Provides \a startIndex and \a count of items removed.
* Index may be over current array size if removed from end.
+ * If you remove items directly from the array without calling removeItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QScatterDataProxy::itemsInserted(int startIndex, int count)
*
* Emitted when items have been inserted. Provides \a startIndex and \a count of inserted items.
+ * If you insert items directly into the array without calling insertItem() or insertItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
// QScatterDataProxyPrivate
@@ -262,20 +274,16 @@ QScatterDataProxyPrivate::~QScatterDataProxyPrivate()
delete m_dataArray;
}
-bool QScatterDataProxyPrivate::resetArray(QScatterDataArray *newArray)
+void QScatterDataProxyPrivate::resetArray(QScatterDataArray *newArray)
{
- if (!m_dataArray->size() && (!newArray || !newArray->size()))
- return false;
-
- m_dataArray->clear();
- delete m_dataArray;
+ if (!newArray)
+ newArray = new QScatterDataArray;
- if (newArray)
+ if (newArray != m_dataArray) {
+ m_dataArray->clear();
+ delete m_dataArray;
m_dataArray = newArray;
- else
- m_dataArray = new QScatterDataArray;
-
- return true;
+ }
}
void QScatterDataProxyPrivate::setItem(int index, const QScatterDataItem &item)