summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/data/qsurfacedataproxy.cpp
diff options
context:
space:
mode:
authorMika Salmela <mika.salmela@digia.com>2013-11-26 15:48:51 +0200
committerMika Salmela <mika.salmela@digia.com>2013-11-27 11:30:44 +0200
commitde3661089cb85701d7444bbf517711783df3aa49 (patch)
treee833426f16198da680101c9720c00ab4bcd2a678 /src/datavisualization/data/qsurfacedataproxy.cpp
parent7c942cc0f497fe7e61ce6a10fce45771c0858e09 (diff)
Better proxy API for surface
Part 1, row change. More is on the way. Change-Id: I4e152a5160275f2d629e7793d4d40b85082a2fc2 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization/data/qsurfacedataproxy.cpp')
-rw-r--r--src/datavisualization/data/qsurfacedataproxy.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/datavisualization/data/qsurfacedataproxy.cpp b/src/datavisualization/data/qsurfacedataproxy.cpp
index b55fea97..aba2e288 100644
--- a/src/datavisualization/data/qsurfacedataproxy.cpp
+++ b/src/datavisualization/data/qsurfacedataproxy.cpp
@@ -36,6 +36,11 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
*
* All rows must have the same number of items.
*
+ * QSurfaceDataProxy takes ownership of all QSurfaceDataRows passed to it, whether directly or
+ * in a QSurfaceDataArray container.
+ * If you use QSurfaceDataRow pointers to directly modify data after adding the array to the proxy,
+ * you must also emit proper signal to make the graph update.
+ *
* When determining what rows and columns are visible, the first item in each row and the first item in
* each column determine if the whole row or column is visible, even if other items in the row or column
* individually have different X- or Z-coordinates.
@@ -130,6 +135,29 @@ void QSurfaceDataProxy::resetArray(QSurfaceDataArray *newArray)
}
/*!
+ * Changes existing row by replacing a row at \a rowIndex with a new \a row. The \a row can be
+ * the same as the existing row already stored at the \a rowIndex. The new \a row must have
+ * the same number of columns as the row it is replacing.
+ */
+void QSurfaceDataProxy::setRow(int rowIndex, QSurfaceDataRow *row)
+{
+ dptr()->setRow(rowIndex, row);
+ emit rowsChanged(rowIndex, 1);
+}
+
+/*!
+ * Changes existing rows by replacing a rows starting at \a rowIndex with \a rows.
+ * The rows in the \a rows array can be the same as the existing rows already
+ * stored at the \a rowIndex. The new rows must have the same number of columns
+ * as the rows they are replacing.
+ */
+void QSurfaceDataProxy::setRows(int rowIndex, const QSurfaceDataArray &rows)
+{
+ dptr()->setRows(rowIndex, rows);
+ emit rowsChanged(rowIndex, rows.size());
+}
+
+/*!
* \return pointer to the data array.
*/
const QSurfaceDataArray *QSurfaceDataProxy::array() const
@@ -219,6 +247,32 @@ void QSurfaceDataProxyPrivate::resetArray(QSurfaceDataArray *newArray)
}
}
+void QSurfaceDataProxyPrivate::setRow(int rowIndex, QSurfaceDataRow *row)
+{
+ Q_ASSERT(rowIndex >= 0 && rowIndex < m_dataArray->size());
+ Q_ASSERT(m_dataArray->at(rowIndex)->size() == row->size());
+
+ if (row != m_dataArray->at(rowIndex)) {
+ clearRow(rowIndex);
+ (*m_dataArray)[rowIndex] = row;
+ }
+}
+
+void QSurfaceDataProxyPrivate::setRows(int rowIndex, const QSurfaceDataArray &rows)
+{
+ QSurfaceDataArray &dataArray = *m_dataArray;
+ Q_ASSERT(rowIndex >= 0 && (rowIndex + rows.size()) <= dataArray.size());
+ Q_ASSERT(m_dataArray->at(rowIndex)->size() == rows.at(0)->size());
+
+ for (int i = 0; i < rows.size(); i++) {
+ if (rows.at(i) != dataArray.at(rowIndex)) {
+ clearRow(rowIndex);
+ dataArray[rowIndex] = rows.at(i);
+ }
+ rowIndex++;
+ }
+}
+
QSurfaceDataProxy *QSurfaceDataProxyPrivate::qptr()
{
return static_cast<QSurfaceDataProxy *>(q_ptr);