summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-05-11 14:01:25 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-05-11 14:01:25 +0200
commitb5d3a31467bea339875dd314687ad96f3559e68a (patch)
tree4cd53024164710311c4c61aed70d9507c0c0d859
parente5fa88b08d9ce2c0cf83c7b2f45c141465708560 (diff)
Add some more test data to the QtTableSelectionManager auto-test.
-rw-r--r--src/qtableselectionmanager.cpp13
-rw-r--r--tests/qtableselectionmanager/tst_qtableselectionmanager.cpp47
2 files changed, 57 insertions, 3 deletions
diff --git a/src/qtableselectionmanager.cpp b/src/qtableselectionmanager.cpp
index 9c3853f..be03016 100644
--- a/src/qtableselectionmanager.cpp
+++ b/src/qtableselectionmanager.cpp
@@ -529,6 +529,12 @@ void QtTableSelectionManagerPrivate::_q_columnsRemoved(int column, int count)
void QtTableSelectionManagerPrivate::_q_reset()
{
+ const int rowCount = model ? model->rowCount() : 0;
+ const int columnCount = model ? model->columnCount() : 0;
+ currentRow = rowCount ? qBound(0, currentRow, rowCount - 1) : -1;
+ currentColumn = columnCount ? qBound(0, currentColumn, columnCount - 1) : -1;
+ anchorRow = rowCount ? qBound(0, anchorRow, rowCount - 1) : -1;
+ anchorColumn = columnCount ? qBound(0, anchorColumn, columnCount - 1) : -1;
}
bool QtTableSelectionManagerPrivate::isRowIntersected(int row) const
@@ -702,6 +708,7 @@ void QtTableSelectionManager::setModel(QtTableModelInterface *model)
connect(d->model, SIGNAL(columnsInserted(int,int)), this, SLOT(_q_columnsInserted(int,int)));
connect(d->model, SIGNAL(columnsRemoved(int,int)), this, SLOT(_q_columnsRemoved(int,int)));
}
+ d->_q_reset();
clearSelections();
}
@@ -724,8 +731,8 @@ void QtTableSelectionManager::setCurrentCell(int row, int column)
Q_D(QtTableSelectionManager);
if (!d->model || !d->model->rowCount() || !d->model->columnCount())
return;
- row = qBound(0, row, d->model->rowCount() -1);
- column = qBound(0, column, d->model->columnCount() -1);
+ row = qBound(0, row, d->model->rowCount() - 1);
+ column = qBound(0, column, d->model->columnCount() - 1);
if (d->currentRow != row || d->currentColumn != column) {
const int previousRow = d->currentRow;
const int previousColumn = d->currentColumn;
@@ -767,6 +774,8 @@ void QtTableSelectionManager::setAnchorCell(int row, int column)
Q_D(QtTableSelectionManager);
if (!d->model || !d->model->rowCount() || !d->model->columnCount())
return;
+ row = qBound(0, row, d->model->rowCount() - 1);
+ column = qBound(0, column, d->model->columnCount() - 1);
if (d->anchorRow != row || d->anchorColumn != column) {
const int previousRow = d->anchorRow;
const int previousColumn = d->anchorColumn;
diff --git a/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp b/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp
index e1e3b8b..0eed4fe 100644
--- a/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp
+++ b/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp
@@ -137,7 +137,7 @@ void tst_QtTableSelectionManager::currentCell_data()
QTest::addColumn<int>("signalCount");
QTest::newRow("no model")
- << false
+ << false // use model
<< 0 << 0 // cell count
<< -1 << -1 // current cell
<< 0 << 0 // new current
@@ -150,6 +150,36 @@ void tst_QtTableSelectionManager::currentCell_data()
<< 0 << 0 << 0 // move columns
<< -1 << -1 // changed current
<< 0; // signals
+
+ QTest::newRow("no data")
+ << true
+ << 0 << 0
+ << -1 << -1
+ << 0 << 0
+ << -1 << -1
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << -1 << -1
+ << 0;
+
+ QTest::newRow("before first row")
+ << true
+ << 10 << 10
+ << 0 << 0
+ << -1 << -1
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0
+ << 0;
}
void tst_QtTableSelectionManager::currentCell()
@@ -284,6 +314,21 @@ void tst_QtTableSelectionManager::anchorCell_data()
<< 0 << 0 << 0 // move columns
<< -1 << -1 // changed anchor
<< 0; // signals
+
+ QTest::newRow("no data")
+ << true
+ << 0 << 0 // cell count
+ << -1 << -1 // anchor cell
+ << 0 << 0 // new anchor
+ << -1 << -1 // expected anchor
+ << 0 << 0 // insert rows
+ << 0 << 0 // insert columns
+ << 0 << 0 // remove rows
+ << 0 << 0 // remove columns
+ << 0 << 0 << 0 // move rows
+ << 0 << 0 << 0 // move columns
+ << -1 << -1 // changed anchor
+ << 0; // signals
}
void tst_QtTableSelectionManager::anchorCell()