diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-09-26 11:16:12 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-09-27 08:05:12 +0300 |
commit | f2a5c09144f17f3240ae6a7e7b48237f1b234d9b (patch) | |
tree | 28f40212cd228f66277e8db84885ddef0ebb6c5a /src/datavisualization/data/qsurfacedataproxy.cpp | |
parent | b776b6d3aa287b973c9346736badc6181e50cbc7 (diff) |
Allow resetting with existing array for surface
Improves performance when doing stuff like resetting image data.
Task-number: QTRD-2335
Change-Id: I9e8ce49fd520b67125305a7614afc550b2244169
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization/data/qsurfacedataproxy.cpp')
-rw-r--r-- | src/datavisualization/data/qsurfacedataproxy.cpp | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/src/datavisualization/data/qsurfacedataproxy.cpp b/src/datavisualization/data/qsurfacedataproxy.cpp index 1a2e29ce..98998f10 100644 --- a/src/datavisualization/data/qsurfacedataproxy.cpp +++ b/src/datavisualization/data/qsurfacedataproxy.cpp @@ -143,23 +143,29 @@ QSurfaceDataProxy::~QSurfaceDataProxy() } /*! - * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer - * to further modify data after QSurfaceDataProxy assumes ownership of it, as such modifications will - * not trigger proper signals. - * Passing null array clears all data. - * Row and column ranges are reset to defaults. + * 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. + * All rows in \a newArray must be of same length. + * Row and column ranges are reset to defaults, unless \a newArray is the same as the old array. + * In that case, old row and column ranges are kept. */ void QSurfaceDataProxy::resetArray(QSurfaceDataArray *newArray) { - if (dptr()->resetArray(newArray, defaultMinValue, defaultMaxValue, defaultMinValue, defaultMaxValue)) - emit arrayReset(); + if (dptr()->m_dataArray != newArray) { + dptr()->resetArray(newArray, defaultMinValue, defaultMaxValue, defaultMinValue, + defaultMaxValue); + } + emit arrayReset(); } /*! - * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer - * to further modify data after QSurfaceDataProxy 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 and updates row/column values. + * Passing null array deletes the old array and creates a new empty array. + * All rows in \a newArray must be of same length. * Row and column ranges are set to values defined by the rest of the parameters: \a minValueRows, * \a maxValueRows, \a minValueColumns, and \a maxValueColumns. */ @@ -167,8 +173,8 @@ void QSurfaceDataProxy::resetArray(QSurfaceDataArray *newArray, qreal minValueRo qreal maxValueRows, qreal minValueColumns, qreal maxValueColumns) { - if (dptr()->resetArray(newArray, minValueRows, maxValueRows, minValueColumns, maxValueColumns)) - emit arrayReset(); + dptr()->resetArray(newArray, minValueRows, maxValueRows, minValueColumns, maxValueColumns); + emit arrayReset(); } /*! @@ -346,30 +352,20 @@ QSurfaceDataProxyPrivate::~QSurfaceDataProxyPrivate() clearArray(); } -bool QSurfaceDataProxyPrivate::resetArray(QSurfaceDataArray *newArray, qreal minValueRows, +void QSurfaceDataProxyPrivate::resetArray(QSurfaceDataArray *newArray, qreal minValueRows, qreal maxValueRows, qreal minValueColumns, qreal maxValueColumns) { - if (!m_dataArray->size() && (!newArray || !newArray->size())) - return false; - - clearArray(); + if (!newArray) + newArray = new QSurfaceDataArray; - if (newArray) { - for (int i = 0; i < newArray->size(); i++) { - Q_ASSERT_X((newArray->at(i) && newArray->at(i)->size() == newArray->at(0)->size()), - __FUNCTION__, - "All rows of QSurfaceDataArray mustn't be NULL and must be of equal size."); - } + if (newArray != m_dataArray) { + clearArray(); m_dataArray = newArray; - } else { - m_dataArray = new QSurfaceDataArray; } setValueRangeRows(minValueRows, maxValueRows); setValueRangeColumns(minValueColumns, maxValueColumns); - - return true; } void QSurfaceDataProxyPrivate::setValueRangeRows(qreal min, qreal max) |