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/data/qsurfacedataproxy.cpp | |
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/data/qsurfacedataproxy.cpp')
-rw-r--r-- | src/datavisualization/data/qsurfacedataproxy.cpp | 108 |
1 files changed, 107 insertions, 1 deletions
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); |