summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/data
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
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')
-rw-r--r--src/datavisualization/data/qbardataproxy.cpp2
-rw-r--r--src/datavisualization/data/qsurface3dseries.cpp2
-rw-r--r--src/datavisualization/data/qsurfacedataproxy.cpp54
-rw-r--r--src/datavisualization/data/qsurfacedataproxy.h4
-rw-r--r--src/datavisualization/data/qsurfacedataproxy_p.h3
5 files changed, 63 insertions, 2 deletions
diff --git a/src/datavisualization/data/qbardataproxy.cpp b/src/datavisualization/data/qbardataproxy.cpp
index 88c08556..2529eeac 100644
--- a/src/datavisualization/data/qbardataproxy.cpp
+++ b/src/datavisualization/data/qbardataproxy.cpp
@@ -159,7 +159,7 @@ void QBarDataProxy::resetArray(QBarDataArray *newArray, const QStringList &rowLa
}
/*!
- * Changes existing rows by replacing a row at \a rowIndex with \a row. The \a row can be
+ * Changes existing rows 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.
* Existing row labels are not affected.
*/
diff --git a/src/datavisualization/data/qsurface3dseries.cpp b/src/datavisualization/data/qsurface3dseries.cpp
index d71962c3..2e850b03 100644
--- a/src/datavisualization/data/qsurface3dseries.cpp
+++ b/src/datavisualization/data/qsurface3dseries.cpp
@@ -242,6 +242,8 @@ void QSurface3DSeriesPrivate::connectControllerAndProxy(Abstract3DController *ne
QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::arrayReset, controller,
&Surface3DController::handleArrayReset);
+ QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::rowsChanged, controller,
+ &Surface3DController::handleRowsChanged);
QObject::connect(q_ptr, &QAbstract3DSeries::visibilityChanged, controller,
&Abstract3DController::handleSeriesVisibilityChanged);
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);
diff --git a/src/datavisualization/data/qsurfacedataproxy.h b/src/datavisualization/data/qsurfacedataproxy.h
index ed594963..d8808ded 100644
--- a/src/datavisualization/data/qsurfacedataproxy.h
+++ b/src/datavisualization/data/qsurfacedataproxy.h
@@ -50,8 +50,12 @@ public:
void resetArray(QSurfaceDataArray *newArray);
+ void setRow(int rowIndex, QSurfaceDataRow *row);
+ void setRows(int rowIndex, const QSurfaceDataArray &rows);
+
signals:
void arrayReset();
+ void rowsChanged(int startIndex, int count);
void seriesChanged(QSurface3DSeries *series);
protected:
diff --git a/src/datavisualization/data/qsurfacedataproxy_p.h b/src/datavisualization/data/qsurfacedataproxy_p.h
index 066df629..38d92be1 100644
--- a/src/datavisualization/data/qsurfacedataproxy_p.h
+++ b/src/datavisualization/data/qsurfacedataproxy_p.h
@@ -44,7 +44,8 @@ public:
virtual ~QSurfaceDataProxyPrivate();
void resetArray(QSurfaceDataArray *newArray);
-
+ void setRow(int rowIndex, QSurfaceDataRow *row);
+ void setRows(int rowIndex, const QSurfaceDataArray &rows);
void limitValues(QVector3D &minValues, QVector3D &maxValues) const;
virtual void setSeries(QAbstract3DSeries *series);