diff options
author | Mika Salmela <mika.salmela@digia.com> | 2013-12-04 10:56:39 +0200 |
---|---|---|
committer | Mika Salmela <mika.salmela@digia.com> | 2013-12-04 11:03:12 +0200 |
commit | 78d4deb0be21f22d74e3e01315686857ef8edf2e (patch) | |
tree | ed8c21056f913a7faadf27bd6d5a92ca2a168ee0 /src/datavisualization | |
parent | 01407a145ceb172727a27254108f9728a9537a3c (diff) |
Better proxy API for surface
Part 3, add, insert and remove row(s).
Change-Id: I4e30d7f129576bebce9216d5cc00a66b2f8af6cd
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization')
-rw-r--r-- | src/datavisualization/data/qsurface3dseries.cpp | 6 | ||||
-rw-r--r-- | src/datavisualization/data/qsurfacedataproxy.cpp | 108 | ||||
-rw-r--r-- | src/datavisualization/data/qsurfacedataproxy.h | 11 | ||||
-rw-r--r-- | src/datavisualization/data/qsurfacedataproxy_p.h | 5 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3dcontroller.cpp | 31 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3dcontroller_p.h | 3 |
6 files changed, 163 insertions, 1 deletions
diff --git a/src/datavisualization/data/qsurface3dseries.cpp b/src/datavisualization/data/qsurface3dseries.cpp index deb12f44..19462af4 100644 --- a/src/datavisualization/data/qsurface3dseries.cpp +++ b/src/datavisualization/data/qsurface3dseries.cpp @@ -330,8 +330,14 @@ void QSurface3DSeriesPrivate::connectControllerAndProxy(Abstract3DController *ne QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::arrayReset, controller, &Surface3DController::handleArrayReset); + QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::rowsAdded, controller, + &Surface3DController::handleRowsAdded); QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::rowsChanged, controller, &Surface3DController::handleRowsChanged); + QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::rowsRemoved, controller, + &Surface3DController::handleRowsRemoved); + QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::rowsInserted, controller, + &Surface3DController::handleRowsInserted); QObject::connect(surfaceDataProxy, &QSurfaceDataProxy::itemChanged, controller, &Surface3DController::handleItemChanged); } diff --git a/src/datavisualization/data/qsurfacedataproxy.cpp b/src/datavisualization/data/qsurfacedataproxy.cpp index 49553036..678ffd8d 100644 --- a/src/datavisualization/data/qsurfacedataproxy.cpp +++ b/src/datavisualization/data/qsurfacedataproxy.cpp @@ -172,6 +172,66 @@ void QSurfaceDataProxy::setItem(int rowIndex, int columnIndex, const QSurfaceDat } /*! + * Adds a new \a row to the end of array. The new \a row must have + * the same number of columns as the rows at the initial array. + * + * \return index of the added row. + */ +int QSurfaceDataProxy::addRow(QSurfaceDataRow *row) +{ + int addIndex = dptr()->addRow(row); + emit rowsAdded(addIndex, 1); + return addIndex; +} + +/*! + * Adds new \a rows to the end of array. The new rows must have the same number of columns + * as the rows at the initial array. + * + * \return index of the first added row. + */ +int QSurfaceDataProxy::addRows(const QSurfaceDataArray &rows) +{ + int addIndex = dptr()->addRows(rows); + emit rowsAdded(addIndex, rows.size()); + return addIndex; +} + +/*! + * Inserts a new \a row into \a rowIndex. + * If rowIndex is equal to array size, rows are added to end of the array. The new \a row must have + * the same number of columns as the rows at the initial array. + */ +void QSurfaceDataProxy::insertRow(int rowIndex, QSurfaceDataRow *row) +{ + dptr()->insertRow(rowIndex, row); + emit rowsInserted(rowIndex, 1); +} + +/*! + * Inserts new \a rows into \a rowIndex. + * If rowIndex is equal to array size, rows are added to end of the array. The new \a rows must have + * the same number of columns as the rows at the initial array. + */ +void QSurfaceDataProxy::insertRows(int rowIndex, const QSurfaceDataArray &rows) +{ + dptr()->insertRows(rowIndex, rows); + emit rowsInserted(rowIndex, rows.size()); +} + +/*! + * Removes \a removeCount rows staring at \a rowIndex. Attempting to remove rows past the end of the + * array does nothing. + */ +void QSurfaceDataProxy::removeRows(int rowIndex, int removeCount) +{ + if (rowIndex < rowCount() && removeCount >= 1) { + dptr()->removeRows(rowIndex, removeCount); + emit rowsRemoved(rowIndex, removeCount); + } +} + +/*! * \return pointer to the data array. */ const QSurfaceDataArray *QSurfaceDataProxy::array() const @@ -276,9 +336,9 @@ void QSurfaceDataProxyPrivate::setRows(int rowIndex, const QSurfaceDataArray &ro { 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++) { + Q_ASSERT(m_dataArray->at(rowIndex)->size() == rows.at(i)->size()); if (rows.at(i) != dataArray.at(rowIndex)) { clearRow(rowIndex); dataArray[rowIndex] = rows.at(i); @@ -295,6 +355,52 @@ void QSurfaceDataProxyPrivate::setItem(int rowIndex, int columnIndex, const QSur row[columnIndex] = item; } +int QSurfaceDataProxyPrivate::addRow(QSurfaceDataRow *row) +{ + Q_ASSERT(m_dataArray->at(0)->size() == row->size()); + int currentSize = m_dataArray->size(); + m_dataArray->append(row); + return currentSize; +} + +int QSurfaceDataProxyPrivate::addRows(const QSurfaceDataArray &rows) +{ + int currentSize = m_dataArray->size(); + for (int i = 0; i < rows.size(); i++) { + Q_ASSERT(m_dataArray->at(0)->size() == rows.at(i)->size()); + m_dataArray->append(rows.at(i)); + } + return currentSize; +} + +void QSurfaceDataProxyPrivate::insertRow(int rowIndex, QSurfaceDataRow *row) +{ + Q_ASSERT(rowIndex >= 0 && rowIndex <= m_dataArray->size()); + Q_ASSERT(m_dataArray->at(0)->size() == row->size()); + m_dataArray->insert(rowIndex, row); +} + +void QSurfaceDataProxyPrivate::insertRows(int rowIndex, const QSurfaceDataArray &rows) +{ + Q_ASSERT(rowIndex >= 0 && rowIndex <= m_dataArray->size()); + + for (int i = 0; i < rows.size(); i++) { + Q_ASSERT(m_dataArray->at(0)->size() == rows.at(i)->size()); + m_dataArray->insert(rowIndex++, rows.at(i)); + } +} + +void QSurfaceDataProxyPrivate::removeRows(int rowIndex, int removeCount) +{ + Q_ASSERT(rowIndex >= 0); + int maxRemoveCount = m_dataArray->size() - rowIndex; + removeCount = qMin(removeCount, maxRemoveCount); + for (int i = 0; i < removeCount; i++) { + clearRow(rowIndex); + m_dataArray->removeAt(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 4533f4c5..c2a0fef2 100644 --- a/src/datavisualization/data/qsurfacedataproxy.h +++ b/src/datavisualization/data/qsurfacedataproxy.h @@ -55,9 +55,20 @@ public: void setItem(int rowIndex, int columnIndex, const QSurfaceDataItem &item); + int addRow(QSurfaceDataRow *row); + int addRows(const QSurfaceDataArray &rows); + + void insertRow(int rowIndex, QSurfaceDataRow *row); + void insertRows(int rowIndex, const QSurfaceDataArray &rows); + + void removeRows(int rowIndex, int removeCount); + signals: void arrayReset(); + void rowsAdded(int startIndex, int count); void rowsChanged(int startIndex, int count); + void rowsRemoved(int startIndex, int count); + void rowsInserted(int startIndex, int count); void itemChanged(int rowIndex, int columnIndex); void seriesChanged(QSurface3DSeries *series); diff --git a/src/datavisualization/data/qsurfacedataproxy_p.h b/src/datavisualization/data/qsurfacedataproxy_p.h index 3125a40a..1fda354c 100644 --- a/src/datavisualization/data/qsurfacedataproxy_p.h +++ b/src/datavisualization/data/qsurfacedataproxy_p.h @@ -47,6 +47,11 @@ public: void setRow(int rowIndex, QSurfaceDataRow *row); void setRows(int rowIndex, const QSurfaceDataArray &rows); void setItem(int rowIndex, int columnIndex, const QSurfaceDataItem &item); + int addRow(QSurfaceDataRow *row); + int addRows(const QSurfaceDataArray &rows); + void insertRow(int rowIndex, QSurfaceDataRow *row); + void insertRows(int rowIndex, const QSurfaceDataArray &rows); + void removeRows(int rowIndex, int removeCount); void limitValues(QVector3D &minValues, QVector3D &maxValues) const; virtual void setSeries(QAbstract3DSeries *series); diff --git a/src/datavisualization/engine/surface3dcontroller.cpp b/src/datavisualization/engine/surface3dcontroller.cpp index a9c5f508..0a1bdc4e 100644 --- a/src/datavisualization/engine/surface3dcontroller.cpp +++ b/src/datavisualization/engine/surface3dcontroller.cpp @@ -379,6 +379,37 @@ void Surface3DController::handleItemChanged(int rowIndex, int columnIndex) } } +void Surface3DController::handleRowsAdded(int startIndex, int count) +{ + Q_UNUSED(startIndex) + Q_UNUSED(count) + adjustValueAxisRange(); + m_isDataDirty = true; + emitNeedRender(); +} + +void Surface3DController::handleRowsInserted(int startIndex, int count) +{ + Q_UNUSED(startIndex) + Q_UNUSED(count) + adjustValueAxisRange(); + m_isDataDirty = true; + emitNeedRender(); +} + +void Surface3DController::handleRowsRemoved(int startIndex, int count) +{ + Q_UNUSED(startIndex) + Q_UNUSED(count) + adjustValueAxisRange(); + m_isDataDirty = true; + + // Clear selection unless still valid + setSelectedPoint(m_selectedPoint, m_selectedSeries); + + emitNeedRender(); +} + void Surface3DController::adjustValueAxisRange() { if (m_seriesList.size()) { diff --git a/src/datavisualization/engine/surface3dcontroller_p.h b/src/datavisualization/engine/surface3dcontroller_p.h index c7496c18..1dfd9dc2 100644 --- a/src/datavisualization/engine/surface3dcontroller_p.h +++ b/src/datavisualization/engine/surface3dcontroller_p.h @@ -101,7 +101,10 @@ public: public slots: void handleArrayReset(); + void handleRowsAdded(int startIndex, int count); void handleRowsChanged(int startIndex, int count); + void handleRowsRemoved(int startIndex, int count); + void handleRowsInserted(int startIndex, int count); void handleItemChanged(int rowIndex, int columnIndex); // Renderer callback handlers |