summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-06-08 17:54:14 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-06-08 17:54:14 +0200
commit40ffc262c31fcce2544a5b9f869f5a767f731b87 (patch)
treeef1ac9520db52f671676ef8f81445a33adbff491
parentf4e2efceac39fc5e2f4a1c66079a3e207e0a04cf (diff)
Update the visible items in QtGraphicsTableView if items are inserted, removed or moved in the model.
-rw-r--r--src/qgraphicstableview.cpp19
-rw-r--r--src/qgraphicstableview_p.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/src/qgraphicstableview.cpp b/src/qgraphicstableview.cpp
index 4c0557c..8933156 100644
--- a/src/qgraphicstableview.cpp
+++ b/src/qgraphicstableview.cpp
@@ -276,6 +276,7 @@ void QtGraphicsTableViewPrivate::_q_rowsInserted(int row, int count)
if (verticalHeader)
verticalHeader->setSectionCount(model ? model->rowCount() : 0);
checkCache(row, -1, -1, -1);
+ checkItems(row, -1, -1, -1);
}
void QtGraphicsTableViewPrivate::_q_rowsRemoved(int row, int count)
@@ -290,6 +291,7 @@ void QtGraphicsTableViewPrivate::_q_rowsMoved(int from, int to, int count)
{
// ### update
checkCache(qMin(from ,to), -1, qMax(from, to) + count, -1);
+ checkItems(qMin(from ,to), -1, qMax(from, to) + count, -1);
}
void QtGraphicsTableViewPrivate::_q_columnsInserted(int column, int count)
@@ -298,6 +300,7 @@ void QtGraphicsTableViewPrivate::_q_columnsInserted(int column, int count)
if (horizontalHeader)
horizontalHeader->setSectionCount(model ? model->columnCount() : 0);
checkCache(-1, column, -1, -1);
+ checkItems(-1, column, -1, -1);
}
void QtGraphicsTableViewPrivate::_q_columnsRemoved(int column, int count)
@@ -306,12 +309,14 @@ void QtGraphicsTableViewPrivate::_q_columnsRemoved(int column, int count)
if (horizontalHeader)
horizontalHeader->setSectionCount(model ? model->rowCount() : 0);
checkCache(-1, column, -1, -1);
+ checkItems(-1, column, -1, -1);
}
void QtGraphicsTableViewPrivate::_q_columnsMoved(int from, int to, int count)
{
// ### update
checkCache(-1, qMin(from ,to), -1, qMax(from, to) + count);
+ checkItems(-1, qMin(from ,to), -1, qMax(from, to) + count);
}
bool QtGraphicsTableViewPrivate::isSelected(int row, int column) const
@@ -328,6 +333,20 @@ bool QtGraphicsTableViewPrivate::isCurrent(int row, int column) const
return false;
}
+void QtGraphicsTableViewPrivate::checkItems(int firstRow, int firstColumn, int rowCount, int columnCount)
+{
+ Q_UNUSED(firstRow);
+ Q_UNUSED(firstColumn);
+ Q_UNUSED(rowCount);
+ Q_UNUSED(columnCount);
+ QHash<int, QtGraphicsTableViewItem*>::iterator it = items.begin();
+ while (it != items.end()) {
+ creator->recycle(it.value());
+ ++it;
+ }
+ items.clear();
+}
+
void QtGraphicsTableViewPrivate::checkCache(int firstRow, int firstColumn, int rowCount, int columnCount)
{
Q_UNUSED(firstRow);
diff --git a/src/qgraphicstableview_p.h b/src/qgraphicstableview_p.h
index 800f2c7..63a45bd 100644
--- a/src/qgraphicstableview_p.h
+++ b/src/qgraphicstableview_p.h
@@ -89,6 +89,7 @@ public:
bool isSelected(int row, int column) const;
bool isCurrent(int row, int column) const;
+ void checkItems(int firstRow, int firstColumn, int rowCount, int columnCount);
void checkCache(int firstRow, int firstColumn, int rowCount, int columnCount);
QVariant cachedData(int row, int column, int role) const;