}
}
-
void tst_QAbstractItemModel::changePersistentIndex()
{
QtTestModel model(3, 3);
QVERIFY(!e[i].isValid());
for (int i=6; i <10 ; i++)
QVERIFY(e[i] == model.index(2, i-2 , QModelIndex()));
-
}
void tst_QAbstractItemModel::testMoveSameParentDown_data()
void tst_QAbstractItemModel::testMoveSameParentDown()
{
- QFETCH( int, startRow);
- QFETCH( int, endRow);
- QFETCH( int, destRow);
- QFETCH( bool, topLevel);
+ QFETCH(int, startRow);
+ QFETCH(int, endRow);
+ QFETCH(int, destRow);
+ QFETCH(bool, topLevel);
QModelIndex moveParent = topLevel ? QModelIndex() : m_model->index(5, 0);
QList<QPersistentModelIndex> persistentList;
QModelIndexList indexList;
- for (int column = 0; column < m_model->columnCount(); ++column)
- {
- for (int row= 0; row < m_model->rowCount(); ++row)
- {
+ for (int column = 0; column < m_model->columnCount(); ++column) {
+ for (int row = 0; row < m_model->rowCount(); ++row) {
QModelIndex idx = m_model->index(row, column);
QVERIFY(idx.isValid());
indexList << idx;
}
QModelIndex parent = m_model->index(5, 0);
- for (int column = 0; column < m_model->columnCount(); ++column)
- {
- for (int row= 0; row < m_model->rowCount(parent); ++row)
- {
+ for (int column = 0; column < m_model->columnCount(); ++column) {
+ for (int row = 0; row < m_model->rowCount(parent); ++row) {
QModelIndex idx = m_model->index(row, column, parent);
QVERIFY(idx.isValid());
indexList << idx;
QCOMPARE(afterSignal.at(3).value<QModelIndex>(), moveParent);
QCOMPARE(afterSignal.at(4).toInt(), destRow);
- for (int i = 0; i < indexList.size(); i++)
- {
+ for (int i = 0; i < indexList.size(); i++) {
QModelIndex idx = indexList.at(i);
QModelIndex persistentIndex = persistentList.at(i);
- if (idx.parent() == moveParent)
- {
+ if (idx.parent() == moveParent) {
int row = idx.row();
- if ( row >= startRow)
- {
- if (row <= endRow)
- {
- QCOMPARE(row + destRow - endRow - 1, persistentIndex.row() );
+ if ( row >= startRow) {
+ if (row <= endRow) {
+ QCOMPARE(row + destRow - endRow - 1, persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(idx.parent(), persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
- } else if ( row < destRow)
- {
- QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() );
+ } else if (row < destRow) {
+ QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(idx.parent(), persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
- } else
- {
- QCOMPARE(idx, persistentIndex);
+ } else {
+ QCOMPARE(idx, persistentIndex);
}
- } else
- {
+ } else {
QCOMPARE(idx, persistentIndex);
}
- } else
- {
+ } else {
QCOMPARE(idx, persistentIndex);
}
}
void tst_QAbstractItemModel::testMoveSameParentUp()
{
-
- QFETCH( int, startRow);
- QFETCH( int, endRow);
- QFETCH( int, destRow);
- QFETCH( bool, topLevel);
+ QFETCH(int, startRow);
+ QFETCH(int, endRow);
+ QFETCH(int, destRow);
+ QFETCH(bool, topLevel);
QModelIndex moveParent = topLevel ? QModelIndex() : m_model->index(5, 0);
QList<QPersistentModelIndex> persistentList;
QModelIndexList indexList;
- for (int column = 0; column < m_model->columnCount(); ++column)
- {
- for (int row= 0; row < m_model->rowCount(); ++row)
- {
+ for (int column = 0; column < m_model->columnCount(); ++column) {
+ for (int row = 0; row < m_model->rowCount(); ++row) {
QModelIndex idx = m_model->index(row, column);
QVERIFY(idx.isValid());
indexList << idx;
}
QModelIndex parent = m_model->index(2, 0);
- for (int column = 0; column < m_model->columnCount(); ++column)
- {
- for (int row= 0; row < m_model->rowCount(parent); ++row)
- {
+ for (int column = 0; column < m_model->columnCount(); ++column) {
+ for (int row = 0; row < m_model->rowCount(parent); ++row) {
QModelIndex idx = m_model->index(row, column, parent);
QVERIFY(idx.isValid());
indexList << idx;
QCOMPARE(afterSignal.at(3).value<QModelIndex>(), moveParent);
QCOMPARE(afterSignal.at(4).toInt(), destRow);
-
- for (int i = 0; i < indexList.size(); i++)
- {
+ for (int i = 0; i < indexList.size(); i++) {
QModelIndex idx = indexList.at(i);
QModelIndex persistentIndex = persistentList.at(i);
- if (idx.parent() == moveParent)
- {
+ if (idx.parent() == moveParent) {
int row = idx.row();
- if ( row >= destRow)
- {
- if (row < startRow)
- {
- QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() );
+ if ( row >= destRow) {
+ if (row < startRow) {
+ QCOMPARE(row + endRow - startRow + 1, persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(idx.parent(), persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
- } else if ( row <= endRow)
- {
- QCOMPARE(row + destRow - startRow, persistentIndex.row() );
+ } else if (row <= endRow) {
+ QCOMPARE(row + destRow - startRow, persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(idx.parent(), persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
- } else
- {
+ } else {
QCOMPARE(idx, persistentIndex);
}
- } else
- {
+ } else {
QCOMPARE(idx, persistentIndex);
}
- } else
- {
+ } else {
QCOMPARE(idx, persistentIndex);
}
}
void tst_QAbstractItemModel::testMoveToGrandParent()
{
-
- QFETCH( int, startRow);
- QFETCH( int, endRow);
- QFETCH( int, destRow);
+ QFETCH(int, startRow);
+ QFETCH(int, endRow);
+ QFETCH(int, destRow);
QList<QPersistentModelIndex> persistentList;
QModelIndexList indexList;
QModelIndexList parentsList;
- for (int column = 0; column < m_model->columnCount(); ++column)
- {
- for (int row= 0; row < m_model->rowCount(); ++row)
- {
+ for (int column = 0; column < m_model->columnCount(); ++column) {
+ for (int row = 0; row < m_model->rowCount(); ++row) {
QModelIndex idx = m_model->index(row, column);
QVERIFY(idx.isValid());
indexList << idx;
}
QModelIndex sourceIndex = m_model->index(5, 0);
- for (int column = 0; column < m_model->columnCount(); ++column)
- {
- for (int row= 0; row < m_model->rowCount(sourceIndex); ++row)
- {
+ for (int column = 0; column < m_model->columnCount(); ++column) {
+ for (int row = 0; row < m_model->rowCount(sourceIndex); ++row) {
QModelIndex idx = m_model->index(row, column, sourceIndex);
QVERIFY(idx.isValid());
indexList << idx;
QCOMPARE(afterSignal.at(3).value<QModelIndex>(), QModelIndex());
QCOMPARE(afterSignal.at(4).toInt(), destRow);
- for (int i = 0; i < indexList.size(); i++)
- {
+ for (int i = 0; i < indexList.size(); i++) {
QModelIndex idx = indexList.at(i);
QModelIndex idxParent = parentsList.at(i);
QModelIndex persistentIndex = persistentList.at(i);
int row = idx.row();
- if (idxParent == QModelIndex())
- {
- if ( row >= destRow)
- {
- QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() );
- QCOMPARE(idx.column(), persistentIndex.column());
- QCOMPARE(idxParent, persistentIndex.parent());
- QCOMPARE(idx.model(), persistentIndex.model());
- } else
- {
+ if (idxParent == QModelIndex()) {
+ if (row >= destRow) {
+ QCOMPARE(row + endRow - startRow + 1, persistentIndex.row());
+ QCOMPARE(idx.column(), persistentIndex.column());
+ QCOMPARE(idxParent, persistentIndex.parent());
+ QCOMPARE(idx.model(), persistentIndex.model());
+ } else {
QCOMPARE(idx, persistentIndex);
}
- } else
- {
- if (row < startRow)
- {
+ } else {
+ if (row < startRow) {
QCOMPARE(idx, persistentIndex);
- } else if (row <= endRow)
- {
- QCOMPARE(row + destRow - startRow, persistentIndex.row() );
+ } else if (row <= endRow) {
+ QCOMPARE(row + destRow - startRow, persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(QModelIndex(), persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
} else {
- QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() );
+ QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
- if (idxParent.row() >= destRow)
- {
+ if (idxParent.row() >= destRow) {
QModelIndex adjustedParent;
- adjustedParent = idxParent.sibling( idxParent.row() + endRow - startRow + 1, idxParent.column());
+ adjustedParent = idxParent.sibling(idxParent.row() + endRow - startRow + 1, idxParent.column());
QCOMPARE(adjustedParent, persistentIndex.parent());
- } else
- {
+ } else {
QCOMPARE(idxParent, persistentIndex.parent());
}
QCOMPARE(idx.model(), persistentIndex.model());
void tst_QAbstractItemModel::testMoveToSibling()
{
-
- QFETCH( int, startRow);
- QFETCH( int, endRow);
- QFETCH( int, destRow);
+ QFETCH(int, startRow);
+ QFETCH(int, endRow);
+ QFETCH(int, destRow);
QList<QPersistentModelIndex> persistentList;
QModelIndexList indexList;
const int column = 0;
- for (int i= 0; i < m_model->rowCount(); ++i)
- {
+ for (int i = 0; i < m_model->rowCount(); ++i) {
QModelIndex idx = m_model->index(i, column);
QVERIFY(idx.isValid());
indexList << idx;
QModelIndex destIndex = m_model->index(5, 0);
QModelIndex sourceIndex;
- for (int i= 0; i < m_model->rowCount(destIndex); ++i)
- {
+ for (int i = 0; i < m_model->rowCount(destIndex); ++i) {
QModelIndex idx = m_model->index(i, column, destIndex);
QVERIFY(idx.isValid());
indexList << idx;
QCOMPARE(afterSignal.at(3).value<QModelIndex>(), static_cast<QModelIndex>(persistentDest));
QCOMPARE(afterSignal.at(4).toInt(), destRow);
- for (int i = 0; i < indexList.size(); i++)
- {
+ for (int i = 0; i < indexList.size(); i++) {
QModelIndex idx = indexList.at(i);
QModelIndex idxParent = parentsList.at(i);
QModelIndex persistentIndex = persistentList.at(i);
QModelIndex adjustedDestination = destIndex.sibling(destIndex.row() - (endRow - startRow + 1), destIndex.column());
int row = idx.row();
- if (idxParent == destIndex)
- {
- if ( row >= destRow)
- {
- QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() );
- QCOMPARE(idx.column(), persistentIndex.column());
- if (idxParent.row() > startRow)
- {
- QCOMPARE(adjustedDestination, persistentIndex.parent());
- } else {
- QCOMPARE(destIndex, persistentIndex.parent());
- }
- QCOMPARE(idx.model(), persistentIndex.model());
- } else
- {
+ if (idxParent == destIndex) {
+ if (row >= destRow) {
+ QCOMPARE(row + endRow - startRow + 1, persistentIndex.row());
+ QCOMPARE(idx.column(), persistentIndex.column());
+ if (idxParent.row() > startRow) {
+ QCOMPARE(adjustedDestination, persistentIndex.parent());
+ } else {
+ QCOMPARE(destIndex, persistentIndex.parent());
+ }
+ QCOMPARE(idx.model(), persistentIndex.model());
+ } else {
QCOMPARE(idx, persistentIndex);
}
- } else
- {
- if (row < startRow)
- {
+ } else {
+ if (row < startRow) {
QCOMPARE(idx, persistentIndex);
- } else if (row <= endRow)
- {
- QCOMPARE(row + destRow - startRow, persistentIndex.row() );
+ } else if (row <= endRow) {
+ QCOMPARE(row + destRow - startRow, persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
- if (destIndex.row() > startRow)
- {
+ if (destIndex.row() > startRow) {
QCOMPARE(adjustedDestination, persistentIndex.parent());
} else {
QCOMPARE(destIndex, persistentIndex.parent());
}
QCOMPARE(idx.model(), persistentIndex.model());
-
} else {
- QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() );
+ QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(idxParent, persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
void tst_QAbstractItemModel::testMoveToUncle_data()
{
-
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("endRow");
QTest::addColumn<int>("destRow");
insertCommand->setEndRow(9);
insertCommand->doCommand();
- QFETCH( int, startRow);
- QFETCH( int, endRow);
- QFETCH( int, destRow);
+ QFETCH(int, startRow);
+ QFETCH(int, endRow);
+ QFETCH(int, destRow);
QList<QPersistentModelIndex> persistentList;
QModelIndexList indexList;
const int column = 0;
QModelIndex sourceIndex = m_model->index(9, 0);
- for (int i= 0; i < m_model->rowCount(sourceIndex); ++i)
- {
+ for (int i = 0; i < m_model->rowCount(sourceIndex); ++i) {
QModelIndex idx = m_model->index(i, column, sourceIndex);
QVERIFY(idx.isValid());
indexList << idx;
}
QModelIndex destIndex = m_model->index(5, 0);
- for (int i= 0; i < m_model->rowCount(destIndex); ++i)
- {
+ for (int i = 0; i < m_model->rowCount(destIndex); ++i) {
QModelIndex idx = m_model->index(i, column, destIndex);
QVERIFY(idx.isValid());
indexList << idx;
QCOMPARE(afterSignal.at(3).value<QModelIndex>(), destIndex);
QCOMPARE(afterSignal.at(4).toInt(), destRow);
- for (int i = 0; i < indexList.size(); i++)
- {
+ for (int i = 0; i < indexList.size(); i++) {
QModelIndex idx = indexList.at(i);
QModelIndex idxParent = parentsList.at(i);
QModelIndex persistentIndex = persistentList.at(i);
int row = idx.row();
- if (idxParent == destIndex)
- {
- if ( row >= destRow)
- {
- QCOMPARE(row + endRow - startRow + 1, persistentIndex.row() );
- QCOMPARE(idx.column(), persistentIndex.column());
- QCOMPARE(destIndex, persistentIndex.parent());
- QCOMPARE(idx.model(), persistentIndex.model());
- } else
- {
+ if (idxParent == destIndex) {
+ if (row >= destRow) {
+ QCOMPARE(row + endRow - startRow + 1, persistentIndex.row());
+ QCOMPARE(idx.column(), persistentIndex.column());
+ QCOMPARE(destIndex, persistentIndex.parent());
+ QCOMPARE(idx.model(), persistentIndex.model());
+ } else {
QCOMPARE(idx, persistentIndex);
}
- } else
- {
- if (row < startRow)
- {
+ } else {
+ if (row < startRow) {
QCOMPARE(idx, persistentIndex);
- } else if (row <= endRow)
- {
- QCOMPARE(row + destRow - startRow, persistentIndex.row() );
+ } else if (row <= endRow) {
+ QCOMPARE(row + destRow - startRow, persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(destIndex, persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
-
} else {
- QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row() );
+ QCOMPARE(row - (endRow - startRow + 1), persistentIndex.row());
QCOMPARE(idx.column(), persistentIndex.column());
QCOMPARE(idxParent, persistentIndex.parent());
QCOMPARE(idx.model(), persistentIndex.model());
// Need to have some extra rows available in a tree.
QList<int> rows;
ModelInsertCommand *insertCommand;
- for (int i = 0; i < depth; i++)
- {
+ for (int i = 0; i < depth; i++) {
insertCommand = new ModelInsertCommand(m_model, this);
insertCommand->setAncestorRowNumbers(rows);
insertCommand->setNumCols(4);
const int column = 0;
QModelIndex sourceIndex = m_model->index(9, 0);
- for (int i= 0; i < m_model->rowCount(sourceIndex); ++i)
- {
+ for (int i = 0; i < m_model->rowCount(sourceIndex); ++i) {
QModelIndex idx = m_model->index(i, column, sourceIndex);
QVERIFY(idx.isValid());
indexList << idx;
}
QModelIndex destIndex = m_model->index(5, 0);
- for (int i= 0; i < m_model->rowCount(destIndex); ++i)
- {
+ for (int i = 0; i < m_model->rowCount(destIndex); ++i) {
QModelIndex idx = m_model->index(i, column, destIndex);
QVERIFY(idx.isValid());
indexList << idx;
ModelMoveCommand *moveCommand;
QList<int> ancestors;
- while (ancestors.size() < depth)
- {
+ while (ancestors.size() < depth) {
ancestors << 9;
- for (int row = 0; row <= 9; row++)
- {
+ for (int row = 0; row <= 9; row++) {
moveCommand = new ModelMoveCommand(m_model, this);
moveCommand->setNumCols(4);
moveCommand->setStartRow(9);
QTest::newRow("move20") << 8 << 9 << 10;
QTest::newRow("move21") << 9 << 9 << 9;
QTest::newRow("move22") << 0 << 9 << 10;
-
}
void tst_QAbstractItemModel::testMoveWithinOwnRange()
{
-
- QFETCH( int, startRow);
- QFETCH( int, endRow);
- QFETCH( int, destRow);
-
+ QFETCH(int, startRow);
+ QFETCH(int, endRow);
+ QFETCH(int, destRow);
QSignalSpy beforeSpy(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
QSignalSpy afterSpy(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
QVERIFY(beforeSpy.size() == 0);
QVERIFY(afterSpy.size() == 0);
-
-
}
class ListenerObject : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
ListenerObject(QAbstractProxyModel *parent);
const int column = 0;
int row = 0;
QModelIndex idx = m_model->index(row, column, parent);
- while (idx.isValid())
- {
+ while (idx.isValid()) {
m_persistentIndexes << QPersistentModelIndex(idx);
m_nonPersistentIndexes << idx;
if (m_model->hasChildren(idx))
- {
fillIndexStores(idx);
- }
++row;
idx = m_model->index(row, column, parent);
}
void ListenerObject::slotAboutToBeReset()
{
// Nothing has been changed yet. All indexes should be the same.
- for (int i = 0; i < m_persistentIndexes.size(); ++i)
- {
+ for (int i = 0; i < m_persistentIndexes.size(); ++i) {
QModelIndex idx = m_persistentIndexes.at(i);
QVERIFY(idx == m_nonPersistentIndexes.at(i));
QVERIFY(m_model->mapToSource(idx).isValid());
void ListenerObject::slotReset()
{
- foreach(const QModelIndex &idx, m_persistentIndexes)
- {
+ foreach (const QModelIndex &idx, m_persistentIndexes) {
QVERIFY(!idx.isValid());
}
}
-
void tst_QAbstractItemModel::testReset()
{
QSignalSpy beforeResetSpy(m_model, SIGNAL(modelAboutToBeReset()));
QVERIFY(m_model->rowCount() == 9);
QModelIndex destIndex = m_model->index(4, 0);
QVERIFY(m_model->rowCount(destIndex) == 11);
-
}
class CustomRoleModel : public QStringListModel
CustomRoleModel(QObject *parent = 0)
: QStringListModel(QStringList() << "a" << "b" << "c", parent)
{
-
}
void emitSignals()
QVERIFY(p1LastPersistent.row() == 0);
QVERIFY(p2FirstPersistent.row() == 9);
QVERIFY(p2LastPersistent.row() == 8);
-
}
insertCommand = new ModelInsertCommand(&model, this);
**
****************************************************************************/
-
#include <QtTest/QtTest>
#include <qabstractproxymodel.h>
#include <QItemSelection>
class AnotherStandardItemModelWithCustomRoleNames : public QStandardItemModel
{
- public:
- enum CustomRole {
- AnotherCustomRole1 = Qt::UserRole + 10, // Different to StandardItemModelWithCustomRoleNames::CustomRole1
- AnotherCustomRole2
- };
-
- AnotherStandardItemModelWithCustomRoleNames() {
- QHash<int, QByteArray> _roleNames = roleNames();
- _roleNames.insert(AnotherCustomRole1, "another_custom1");
- _roleNames.insert(AnotherCustomRole2, "another_custom2");
- setRoleNames(_roleNames);
- }
+public:
+ enum CustomRole {
+ AnotherCustomRole1 = Qt::UserRole + 10, // Different to StandardItemModelWithCustomRoleNames::CustomRole1
+ AnotherCustomRole2
+ };
+
+ AnotherStandardItemModelWithCustomRoleNames() {
+ QHash<int, QByteArray> _roleNames = roleNames();
+ _roleNames.insert(AnotherCustomRole1, "another_custom1");
+ _roleNames.insert(AnotherCustomRole2, "another_custom2");
+ setRoleNames(_roleNames);
+ }
};
/**
QVERIFY( proxy2RoleNames.contains(StandardItemModelWithCustomRoleNames::CustomRole2));
QVERIFY( proxy2RoleNames.value(StandardItemModelWithCustomRoleNames::CustomRole1) == "custom1" );
QVERIFY( proxy2RoleNames.value(StandardItemModelWithCustomRoleNames::CustomRole2) == "custom2" );
-
}
QTEST_MAIN(tst_QAbstractProxyModel)
**
****************************************************************************/
-
#include <QtTest/QtTest>
#include <QtCore>
#include <QtGui>
tst_QIdentityProxyModel::tst_QIdentityProxyModel()
: m_model(0), m_proxy(0)
{
-
}
void tst_QIdentityProxyModel::initTestCase()
QVERIFY(modelAfterSpy.first().at(2) == proxyAfterSpy.first().at(2));
verifyIdentity(m_model);
-
}
void tst_QIdentityProxyModel::removeRows()
TARGET = tst_qitemselectionmodel
QT += widgets testlib
SOURCES += tst_qitemselectionmodel.cpp
-
-
**
****************************************************************************/
-
#include <QtTest/QtTest>
#include <QtGui/QtGui>
typedef QPair<int, int> IntPair;
typedef QList<IntPair> PairList;
-
Q_DECLARE_METATYPE(PairList)
Q_DECLARE_METATYPE(QModelIndex)
Q_DECLARE_METATYPE(QModelIndexList)
return s;
}
-tst_QItemSelectionModel::tst_QItemSelectionModel() : model(0), selection(0)
+tst_QItemSelectionModel::tst_QItemSelectionModel()
+ : model(0), selection(0)
{
}
// populate selectionmodel
selection->select(model->index(1, 1, QModelIndex()), QItemSelectionModel::Select);
QCOMPARE(selection->selectedIndexes().count(), 1);
- QVERIFY(selection->hasSelection());
+ QVERIFY(selection->hasSelection());
// ClearAndSelect with empty selection
QItemSelection emptySelection;
// verify the selectionmodel is empty
QVERIFY(selection->selectedIndexes().isEmpty());
- QVERIFY(selection->hasSelection()==false);
+ QVERIFY(selection->hasSelection()==false);
}
void tst_QItemSelectionModel::toggleSelection()
{
- //test the toggle selection and checks whether selectedIndex
- //and hasSelection returns the correct value
+ //test the toggle selection and checks whether selectedIndex
+ //and hasSelection returns the correct value
- selection->clearSelection();
+ selection->clearSelection();
QCOMPARE(selection->selectedIndexes().count(), 0);
- QVERIFY(selection->hasSelection()==false);
+ QVERIFY(selection->hasSelection()==false);
- QModelIndex index=model->index(1, 1, QModelIndex());
+ QModelIndex index=model->index(1, 1, QModelIndex());
// populate selectionmodel
selection->select(index, QItemSelectionModel::Toggle);
QCOMPARE(selection->selectedIndexes().count(), 1);
- QVERIFY(selection->hasSelection()==true);
+ QVERIFY(selection->hasSelection()==true);
selection->select(index, QItemSelectionModel::Toggle);
QCOMPARE(selection->selectedIndexes().count(), 0);
- QVERIFY(selection->hasSelection()==false);
+ QVERIFY(selection->hasSelection()==false);
// populate selectionmodel with rows
selection->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
QCOMPARE(selection->selectedIndexes().count(), model->columnCount());
- QVERIFY(selection->hasSelection()==true);
+ QVERIFY(selection->hasSelection()==true);
selection->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
QCOMPARE(selection->selectedIndexes().count(), 0);
- QVERIFY(selection->hasSelection()==false);
-
+ QVERIFY(selection->hasSelection()==false);
}
-
void tst_QItemSelectionModel::select_data()
{
QTest::addColumn<QModelIndexList>("indexList");
}
{
QModelIndexList indexes;
- IntList commands;
- QModelIndexList expected;
-
- indexes << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // press 0
- << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // release 0
- << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // press 1
- << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // release 1
- << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2
- << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // release 2
- << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // press 3
- << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // release 3
- << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 again
- << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex());// move 2
-
- commands << (QItemSelectionModel::NoUpdate) // press 0
- << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 0
- << (QItemSelectionModel::NoUpdate) // press 1
- << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 1
- << (QItemSelectionModel::NoUpdate) // press 2
- << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 2
- << (QItemSelectionModel::NoUpdate) // press 3
- << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 3
- << (QItemSelectionModel::NoUpdate) // press 2 again
- << (QItemSelectionModel::Toggle/*Current*/|QItemSelectionModel::Rows);// move 2
-
- expected << model->index(0, 0, QModelIndex())
- << model->index(0, 1, QModelIndex())
- << model->index(0, 2, QModelIndex())
- << model->index(0, 3, QModelIndex())
- << model->index(0, 4, QModelIndex())
-
- << model->index(1, 0, QModelIndex())
- << model->index(1, 1, QModelIndex())
- << model->index(1, 2, QModelIndex())
- << model->index(1, 3, QModelIndex())
- << model->index(1, 4, QModelIndex())
- /*
- << model->index(2, 0, QModelIndex())
- << model->index(2, 1, QModelIndex())
- << model->index(2, 2, QModelIndex())
- << model->index(2, 3, QModelIndex())
- << model->index(2, 4, QModelIndex())
- */
- << model->index(3, 0, QModelIndex())
- << model->index(3, 1, QModelIndex())
- << model->index(3, 2, QModelIndex())
- << model->index(3, 3, QModelIndex())
- << model->index(3, 4, QModelIndex());
+ IntList commands;
+ QModelIndexList expected;
+
+ indexes << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // press 0
+ << model->index(0, 0, QModelIndex()) << model->index(0, 0, QModelIndex()) // release 0
+ << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // press 1
+ << model->index(1, 0, QModelIndex()) << model->index(1, 0, QModelIndex()) // release 1
+ << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2
+ << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // release 2
+ << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // press 3
+ << model->index(3, 0, QModelIndex()) << model->index(3, 0, QModelIndex()) // release 3
+ << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex()) // press 2 again
+ << model->index(2, 0, QModelIndex()) << model->index(2, 0, QModelIndex());// move 2
+
+ commands << (QItemSelectionModel::NoUpdate) // press 0
+ << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 0
+ << (QItemSelectionModel::NoUpdate) // press 1
+ << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 1
+ << (QItemSelectionModel::NoUpdate) // press 2
+ << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 2
+ << (QItemSelectionModel::NoUpdate) // press 3
+ << (QItemSelectionModel::Toggle|QItemSelectionModel::Rows) // release 3
+ << (QItemSelectionModel::NoUpdate) // press 2 again
+ << (QItemSelectionModel::Toggle/*Current*/|QItemSelectionModel::Rows);// move 2
+
+ expected << model->index(0, 0, QModelIndex())
+ << model->index(0, 1, QModelIndex())
+ << model->index(0, 2, QModelIndex())
+ << model->index(0, 3, QModelIndex())
+ << model->index(0, 4, QModelIndex())
+
+ << model->index(1, 0, QModelIndex())
+ << model->index(1, 1, QModelIndex())
+ << model->index(1, 2, QModelIndex())
+ << model->index(1, 3, QModelIndex())
+ << model->index(1, 4, QModelIndex())
+ /*
+ << model->index(2, 0, QModelIndex())
+ << model->index(2, 1, QModelIndex())
+ << model->index(2, 2, QModelIndex())
+ << model->index(2, 3, QModelIndex())
+ << model->index(2, 4, QModelIndex())
+ */
+ << model->index(3, 0, QModelIndex())
+ << model->index(3, 1, QModelIndex())
+ << model->index(3, 2, QModelIndex())
+ << model->index(3, 3, QModelIndex())
+ << model->index(3, 4, QModelIndex());
QTest::newRow("simulated treeview multiselection behavior")
<< indexes
<< insertRows << insertColumns << deleteRows << deleteColumns
<< expected;
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0);
- command << QItemSelectionModel::ClearAndSelect;
- deleteRows << 0 << 1;
- QTest::newRow("ClearAndSelect (0, 0). Delete first row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(1, 0);
- command << QItemSelectionModel::ClearAndSelect;
- deleteRows << 0 << 1;
- expected << IntPair(0, 0);
- QTest::newRow("ClearAndSelect (1, 0). Delete first row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0);
- command << QItemSelectionModel::ClearAndSelect;
- insertRows << 5 << 1;
- expected << IntPair(0, 0);
- QTest::newRow("ClearAndSelect (0, 0). Append row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0);
- command << QItemSelectionModel::ClearAndSelect;
- insertRows << 0 << 1;
- expected << IntPair(1, 0);
- QTest::newRow("ClearAndSelect (0, 0). Insert before first row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0)
- << IntPair(4, 0);
- command << QItemSelectionModel::ClearAndSelect;
- insertRows << 5 << 1;
- expected << IntPair(0, 0)
- << IntPair(1, 0)
- << IntPair(2, 0)
- << IntPair(3, 0)
- << IntPair(4, 0);
- QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Append row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0)
- << IntPair(4, 0);
- command << QItemSelectionModel::ClearAndSelect;
- insertRows << 0 << 1;
- expected << IntPair(1, 0)
- << IntPair(2, 0)
- << IntPair(3, 0)
- << IntPair(4, 0)
- << IntPair(5, 0);
- QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert before first row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0)
- << IntPair(4, 0);
- command << QItemSelectionModel::ClearAndSelect;
- deleteRows << 0 << 1;
- expected << IntPair(0, 0)
- << IntPair(1, 0)
- << IntPair(2, 0)
- << IntPair(3, 0);
- QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete first row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0)
- << IntPair(4, 0);
- command << QItemSelectionModel::ClearAndSelect;
- deleteRows << 4 << 1;
- expected << IntPair(0, 0)
- << IntPair(1, 0)
- << IntPair(2, 0)
- << IntPair(3, 0);
- QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete last row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0)
- << IntPair(4, 0);
- command << QItemSelectionModel::ClearAndSelect;
- deleteRows << 1 << 3;
- expected << IntPair(0, 0)
- << IntPair(1, 0);
- QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Deleting all but first and last row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
-
- index.clear(); expected.clear(); command.clear();
- insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
- index << IntPair(0, 0)
- << IntPair(4, 0);
- command << QItemSelectionModel::ClearAndSelect;
- insertRows << 1 << 1;
- expected << IntPair(0, 0)
- // the inserted row should not be selected
- << IntPair(2, 0)
- << IntPair(3, 0)
- << IntPair(4, 0)
- << IntPair(5, 0);
- QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert after first row.")
- << index << command
- << insertRows << insertColumns << deleteRows << deleteColumns
- << expected;
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ deleteRows << 0 << 1;
+ QTest::newRow("ClearAndSelect (0, 0). Delete first row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(1, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ deleteRows << 0 << 1;
+ expected << IntPair(0, 0);
+ QTest::newRow("ClearAndSelect (1, 0). Delete first row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ insertRows << 5 << 1;
+ expected << IntPair(0, 0);
+ QTest::newRow("ClearAndSelect (0, 0). Append row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ insertRows << 0 << 1;
+ expected << IntPair(1, 0);
+ QTest::newRow("ClearAndSelect (0, 0). Insert before first row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0)
+ << IntPair(4, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ insertRows << 5 << 1;
+ expected << IntPair(0, 0)
+ << IntPair(1, 0)
+ << IntPair(2, 0)
+ << IntPair(3, 0)
+ << IntPair(4, 0);
+ QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Append row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0)
+ << IntPair(4, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ insertRows << 0 << 1;
+ expected << IntPair(1, 0)
+ << IntPair(2, 0)
+ << IntPair(3, 0)
+ << IntPair(4, 0)
+ << IntPair(5, 0);
+ QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert before first row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0)
+ << IntPair(4, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ deleteRows << 0 << 1;
+ expected << IntPair(0, 0)
+ << IntPair(1, 0)
+ << IntPair(2, 0)
+ << IntPair(3, 0);
+ QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete first row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0)
+ << IntPair(4, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ deleteRows << 4 << 1;
+ expected << IntPair(0, 0)
+ << IntPair(1, 0)
+ << IntPair(2, 0)
+ << IntPair(3, 0);
+ QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Delete last row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0)
+ << IntPair(4, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ deleteRows << 1 << 3;
+ expected << IntPair(0, 0)
+ << IntPair(1, 0);
+ QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Deleting all but first and last row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
+
+ index.clear(); expected.clear(); command.clear();
+ insertRows.clear(); insertColumns.clear(); deleteRows.clear(); deleteColumns.clear();
+ index << IntPair(0, 0)
+ << IntPair(4, 0);
+ command << QItemSelectionModel::ClearAndSelect;
+ insertRows << 1 << 1;
+ expected << IntPair(0, 0)
+ // the inserted row should not be selected
+ << IntPair(2, 0)
+ << IntPair(3, 0)
+ << IntPair(4, 0)
+ << IntPair(5, 0);
+ QTest::newRow("ClearAndSelect (0, 0) to (4, 0). Insert after first row.")
+ << index << command
+ << insertRows << insertColumns << deleteRows << deleteColumns
+ << expected;
}
void tst_QItemSelectionModel::persistentselections()
// verify that selection is as expected
QItemSelection selection = selectionModel.selection();
QCOMPARE(selection.count(), expectedSelectedRanges.count());
- QVERIFY(selectionModel.hasSelection() == !expectedSelectedRanges.isEmpty());
+ QVERIFY(selectionModel.hasSelection() == !expectedSelectedRanges.isEmpty());
for (int i = 0; i < expectedSelectedRanges.count(); ++i) {
IntPairPair expectedRange = expectedSelectedRanges.at(i);
class QtTestTableModel: public QAbstractTableModel
{
Q_OBJECT
+public:
+ QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
+ : QAbstractTableModel(parent)
+ , row_count(rows)
+ , column_count(columns)
+ {
+ }
- public:
- QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
- : QAbstractTableModel(parent),
- row_count(rows),
- column_count(columns) {}
-
- int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; }
- int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; }
- bool isEditable(const QModelIndex &) const { return true; }
+ int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; }
+ int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; }
+ bool isEditable(const QModelIndex &) const { return true; }
- QVariant data(const QModelIndex &idx, int role) const
- {
- if (role == Qt::DisplayRole || role == Qt::EditRole)
- return QString("[%1,%2]").arg(idx.row()).arg(idx.column());
- return QVariant();
- }
+ QVariant data(const QModelIndex &idx, int role) const
+ {
+ if (role == Qt::DisplayRole || role == Qt::EditRole)
+ return QString("[%1,%2]").arg(idx.row()).arg(idx.column());
+ return QVariant();
+ }
- int row_count;
- int column_count;
- friend class tst_QItemSelectionModel;
+ int row_count;
+ int column_count;
+ friend class tst_QItemSelectionModel;
};
<< r1;
}
-
void tst_QItemSelectionModel::merge()
{
QFETCH(QItemSelection, init);
}
}
-
QCOMPARE(model.rowCount(), int(cNumRows));
QCOMPARE(proxy.rowCount(), int(cNumRows/2));
}
QVERIFY(m_itemSelectionModel->selection().size() == 2);
}
-
};
void tst_QItemSelectionModel::deselectRemovedMiddleRange()
}
enum Result {
- LessThan,
- NotLessThan,
- NotEqual
+ LessThan,
+ NotLessThan,
+ NotEqual
};
Q_DECLARE_METATYPE(Result);
void tst_QItemSelectionModel::rangeOperatorLessThan()
{
- QStandardItemModel *model1 = getModel(this);
- QStandardItemModel *model2 = getModel(this);
+ QStandardItemModel *model1 = getModel(this);
+ QStandardItemModel *model2 = getModel(this);
- QFETCH(int, parent1);
- QFETCH(int, top1);
- QFETCH(int, left1);
- QFETCH(int, bottom1);
- QFETCH(int, right1);
- QFETCH(int, parent2);
- QFETCH(int, top2);
- QFETCH(int, left2);
- QFETCH(int, bottom2);
- QFETCH(int, right2);
- QFETCH(Result, result);
+ QFETCH(int, parent1);
+ QFETCH(int, top1);
+ QFETCH(int, left1);
+ QFETCH(int, bottom1);
+ QFETCH(int, right1);
+ QFETCH(int, parent2);
+ QFETCH(int, top2);
+ QFETCH(int, left2);
+ QFETCH(int, bottom2);
+ QFETCH(int, right2);
+ QFETCH(Result, result);
- QModelIndex p1 = model1->index(parent1, 0);
+ QModelIndex p1 = model1->index(parent1, 0);
- QModelIndex tl1 = model1->index(top1, left1, p1);
- QModelIndex br1 = model1->index(bottom1, right1, p1);
+ QModelIndex tl1 = model1->index(top1, left1, p1);
+ QModelIndex br1 = model1->index(bottom1, right1, p1);
- QItemSelectionRange r1(tl1, br1);
+ QItemSelectionRange r1(tl1, br1);
- QModelIndex p2 = model1->index(parent2, 0);
+ QModelIndex p2 = model1->index(parent2, 0);
- QModelIndex tl2 = model1->index(top2, left2, p2);
- QModelIndex br2 = model1->index(bottom2, right2, p2);
+ QModelIndex tl2 = model1->index(top2, left2, p2);
+ QModelIndex br2 = model1->index(bottom2, right2, p2);
- QItemSelectionRange r2(tl2, br2);
+ QItemSelectionRange r2(tl2, br2);
- if (result == LessThan)
- QVERIFY(r1 < r2);
- else if (result == NotLessThan)
- QVERIFY(!(r1 < r2));
- else if (result == NotEqual)
- if (!(r1 < r2))
- QVERIFY(r2 < r1);
+ if (result == LessThan)
+ QVERIFY(r1 < r2);
+ else if (result == NotLessThan)
+ QVERIFY(!(r1 < r2));
+ else if (result == NotEqual)
+ if (!(r1 < r2))
+ QVERIFY(r2 < r1);
- // Ranges in different models are always non-equal
+ // Ranges in different models are always non-equal
- QModelIndex p3 = model2->index(parent1, 0);
+ QModelIndex p3 = model2->index(parent1, 0);
- QModelIndex tl3 = model2->index(top1, left1, p3);
- QModelIndex br3 = model2->index(bottom1, right1, p3);
+ QModelIndex tl3 = model2->index(top1, left1, p3);
+ QModelIndex br3 = model2->index(bottom1, right1, p3);
- QItemSelectionRange r3(tl3, br3);
+ QItemSelectionRange r3(tl3, br3);
- if (!(r1 < r3))
- QVERIFY(r3 < r1);
+ if (!(r1 < r3))
+ QVERIFY(r3 < r1);
- if (!(r2 < r3))
- QVERIFY(r3 < r2);
+ if (!(r2 < r3))
+ QVERIFY(r3 < r2);
- QModelIndex p4 = model2->index(parent2, 0);
+ QModelIndex p4 = model2->index(parent2, 0);
- QModelIndex tl4 = model2->index(top2, left2, p4);
- QModelIndex br4 = model2->index(bottom2, right2, p4);
+ QModelIndex tl4 = model2->index(top2, left2, p4);
+ QModelIndex br4 = model2->index(bottom2, right2, p4);
- QItemSelectionRange r4(tl4, br4);
+ QItemSelectionRange r4(tl4, br4);
- if (!(r1 < r4))
- QVERIFY(r4 < r1);
+ if (!(r1 < r4))
+ QVERIFY(r4 < r1);
- if (!(r2 < r4))
- QVERIFY(r4 < r2);
+ if (!(r2 < r4))
+ QVERIFY(r4 < r2);
}
void tst_QItemSelectionModel::testDifferentModels()
model1.appendColumn(QList<QStandardItem*>() << &top11 << &top12 << &top13);
model2.appendColumn(QList<QStandardItem*>() << &top21 << &top22 << &top23);
-
QModelIndex topIndex1 = model1.index(0, 0);
QModelIndex bottomIndex1 = model1.index(2, 0);
QModelIndex topIndex2 = model2.index(0, 0);
class SelectionObserver : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
SelectionObserver(QAbstractItemModel *model, QObject *parent = 0)
- : QObject(parent), m_model(model), m_selectionModel(0)
+ : QObject(parent), m_model(model), m_selectionModel(0)
{
connect(model, SIGNAL(modelReset()), SLOT(modelReset()));
}
connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection)));
}
- private slots:
+private slots:
void modelReset()
{
const QModelIndex idx = m_model->index(2, 0);
class DuplicateItemSelectionModel : public QItemSelectionModel
{
- Q_OBJECT
+ Q_OBJECT
public:
- DuplicateItemSelectionModel(QItemSelectionModel *target, QAbstractItemModel *model, QObject *parent = 0)
- : QItemSelectionModel(model, parent), m_target(target)
- {
-
- }
+ DuplicateItemSelectionModel(QItemSelectionModel *target, QAbstractItemModel *model, QObject *parent = 0)
+ : QItemSelectionModel(model, parent), m_target(target)
+ {
+ }
- void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
- {
- QItemSelectionModel::select(selection, command);
- m_target->select(selection, command);
- }
+ void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
+ {
+ QItemSelectionModel::select(selection, command);
+ m_target->select(selection, command);
+ }
- using QItemSelectionModel::select;
+ using QItemSelectionModel::select;
- void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
- {
- QItemSelectionModel::setCurrentIndex(index, command);
- m_target->setCurrentIndex(index, command);
- }
+ void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
+ {
+ QItemSelectionModel::setCurrentIndex(index, command);
+ m_target->setCurrentIndex(index, command);
+ }
- void clearCurrentIndex()
- {
- QItemSelectionModel::clearCurrentIndex();
- m_target->clearCurrentIndex();
- }
+ void clearCurrentIndex()
+ {
+ QItemSelectionModel::clearCurrentIndex();
+ m_target->clearCurrentIndex();
+ }
private:
- QItemSelectionModel *m_target;
-
+ QItemSelectionModel *m_target;
};
void tst_QItemSelectionModel::testChainedSelectionClear()
**
****************************************************************************/
-
#include <QtTest/QtTest>
#include "dynamictreemodel.h"
#include "modeltest.h"
class tst_QSortFilterProxyModel : public QObject
{
Q_OBJECT
-
public:
-
tst_QSortFilterProxyModel();
public slots:
tst_QSortFilterProxyModel::tst_QSortFilterProxyModel()
: m_model(0), m_proxy(0)
{
-
}
void tst_QSortFilterProxyModel::initTestCase()
<< (QStringList()
<< "BETA" << "Gamma" << "alpha" << "delta");
-
QStringList list;
for (int i = 10000; i < 20000; ++i)
list.append(QString("Number: %1").arg(i));
QModelIndex index = m_proxy->index(row, 0, QModelIndex());
QCOMPARE(m_proxy->data(index, Qt::DisplayRole).toString(), initial.at(row));
}
-
}
void tst_QSortFilterProxyModel::sortHierarchy_data()
for (int i = 0; i < insert.count(); ++i) {
QModelIndex index = m_proxy->index(position + i, 0, QModelIndex());
m_proxy->setData(index, insert.at(i), Qt::DisplayRole);
- }
+ }
// make sure the model correct after insert
for (int row = 0; row < m_model->rowCount(QModelIndex()); ++row) {
{
//this tests that data is correctly handled by the sort filter when prepending a row
QStandardItemModel model;
- QSortFilterProxyModel proxy;
+ QSortFilterProxyModel proxy;
proxy.setSourceModel(&model);
QStandardItem item("root");
}
}
-
void tst_QSortFilterProxyModel::filterColumns_data()
{
QTest::addColumn<QString>("pattern");
}
}
-
-
class TestModel: public QAbstractTableModel
{
public:
void tst_QSortFilterProxyModel::sourceModelDeletion()
{
-
QSortFilterProxyModel proxyModel;
{
QStandardItemModel model;
QCOMPARE(proxyModel.sourceModel(), static_cast<QAbstractItemModel*>(&model));
}
QCOMPARE(proxyModel.sourceModel(), static_cast<QAbstractItemModel*>(0));
-
}
void tst_QSortFilterProxyModel::sortColumnTracking1()
void tst_QSortFilterProxyModel::sortStable()
{
QStandardItemModel* model = new QStandardItemModel(5, 2);
- for (int r=0; r<5; r++) {
- for (int c=0; c<2; c++) {
+ for (int r = 0; r < 5; r++) {
+ for (int c = 0; c < 2; c++) {
QStandardItem* item = new QStandardItem(
QString("Row:%0, Column:%1").arg(r).arg(c) );
- for( int i=0; i<3; i++ ) {
+ for (int i = 0; i < 3; i++) {
QStandardItem* child = new QStandardItem(
QString("Item %0").arg(i) );
item->appendRow( child );
}
}
model->setHorizontalHeaderItem( 0, new QStandardItem( "Name" ));
- model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ) );
-
+ model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ));
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(model);
filterModel->setSourceModel(model);
QModelIndex index = proxy.index(row, 0, QModelIndex());
QCOMPARE(proxy.data(index, Qt::DisplayRole).toString(), expected.at(row));
}
-
}
void tst_QSortFilterProxyModel::task248868_dynamicSorting()
class QtTestModel: public QAbstractItemModel
{
- public:
- QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent),
- rows(_rows), cols(_cols), wrongIndex(false) { }
+public:
+ QtTestModel(int _rows, int _cols, QObject *parent = 0)
+ : QAbstractItemModel(parent)
+ , rows(_rows)
+ , cols(_cols)
+ , wrongIndex(false)
+ {
+ }
- bool canFetchMore(const QModelIndex &idx) const {
- return !fetched.contains(idx);
- }
+ bool canFetchMore(const QModelIndex &idx) const
+ {
+ return !fetched.contains(idx);
+ }
- void fetchMore(const QModelIndex &idx) {
- if (fetched.contains(idx))
- return;
- beginInsertRows(idx, 0, rows-1);
- fetched.insert(idx);
- endInsertRows();
- }
+ void fetchMore(const QModelIndex &idx)
+ {
+ if (fetched.contains(idx))
+ return;
+ beginInsertRows(idx, 0, rows-1);
+ fetched.insert(idx);
+ endInsertRows();
+ }
- bool hasChildren(const QModelIndex & = QModelIndex()) const {
- return true;
- }
+ bool hasChildren(const QModelIndex & = QModelIndex()) const
+ {
+ return true;
+ }
- int rowCount(const QModelIndex& parent = QModelIndex()) const {
- return fetched.contains(parent) ? rows : 0;
- }
- int columnCount(const QModelIndex& parent = QModelIndex()) const {
- Q_UNUSED(parent);
- return cols;
- }
+ int rowCount(const QModelIndex& parent = QModelIndex()) const
+ {
+ return fetched.contains(parent) ? rows : 0;
+ }
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
- {
- if (row < 0 || column < 0 || column >= cols || row >= rows) {
- return QModelIndex();
- }
- QModelIndex i = createIndex(row, column, int(parent.internalId() + 1));
- parentHash[i] = parent;
- return i;
- }
+ int columnCount(const QModelIndex& parent = QModelIndex()) const
+ {
+ Q_UNUSED(parent);
+ return cols;
+ }
- QModelIndex parent(const QModelIndex &index) const
- {
- if (!parentHash.contains(index))
- return QModelIndex();
- return parentHash[index];
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
+ {
+ if (row < 0 || column < 0 || column >= cols || row >= rows) {
+ return QModelIndex();
}
+ QModelIndex i = createIndex(row, column, int(parent.internalId() + 1));
+ parentHash[i] = parent;
+ return i;
+ }
- QVariant data(const QModelIndex &idx, int role) const
- {
- if (!idx.isValid())
- return QVariant();
-
- if (role == Qt::DisplayRole) {
- if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) {
- wrongIndex = true;
- qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(),
- idx.internalPointer());
- }
- return QString("[%1,%2]").arg(idx.row()).arg(idx.column());
- }
+ QModelIndex parent(const QModelIndex &index) const
+ {
+ if (!parentHash.contains(index))
+ return QModelIndex();
+ return parentHash[index];
+ }
+
+ QVariant data(const QModelIndex &idx, int role) const
+ {
+ if (!idx.isValid())
return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) {
+ wrongIndex = true;
+ qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(),
+ idx.internalPointer());
+ }
+ return QString("[%1,%2]").arg(idx.row()).arg(idx.column());
}
+ return QVariant();
+ }
- QSet<QModelIndex> fetched;
- int rows, cols;
- mutable bool wrongIndex;
- mutable QMap<QModelIndex,QModelIndex> parentHash;
+ QSet<QModelIndex> fetched;
+ int rows, cols;
+ mutable bool wrongIndex;
+ mutable QMap<QModelIndex,QModelIndex> parentHash;
};
void tst_QSortFilterProxyModel::task250023_fetchMore()
return pItem;
}
-
void tst_QSortFilterProxyModel::task255652_removeRowsRecursive()
{
QStandardItemModel pModel;
{
class PModel : public QSortFilterProxyModel
{
- public:
- PModel() : mVisible(false) {};
- protected:
- bool filterAcceptsRow(int, const QModelIndex &) const
- {
- return mVisible;
- }
+ public:
+ PModel() : mVisible(false) {};
+ protected:
+ bool filterAcceptsRow(int, const QModelIndex &) const
+ {
+ return mVisible;
+ }
- public:
- void updateXX()
- {
- mVisible = true;
- invalidate();
- }
- private:
- bool mVisible;
+ public:
+ void updateXX()
+ {
+ mVisible = true;
+ invalidate();
+ }
+ private:
+ bool mVisible;
} proxyModel;
-
QStringListModel sourceModel;
QStringList list;
list << "b" << "a" << "c";
private:
QItemSelectionModel *selectionModel;
-
};
void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection()
// trick the proxy into emitting begin/end reset signals.
proxy.setSourceModel(0);
-
}
-static bool isValid(const QItemSelection &selection) {
- foreach(const QItemSelectionRange &range, selection)
- if (!range.isValid())
- return false;
+static bool isValid(const QItemSelection &selection)
+{
+ foreach (const QItemSelectionRange &range, selection)
+ if (!range.isValid())
+ return false;
return true;
}
class FilteredColumnProxyModel : public QSortFilterProxyModel
{
- Q_OBJECT
+ Q_OBJECT
public:
- FilteredColumnProxyModel(QObject *parent = 0)
- : QSortFilterProxyModel(parent)
- {
-
- }
+ FilteredColumnProxyModel(QObject *parent = 0)
+ : QSortFilterProxyModel(parent)
+ {
+ }
protected:
- bool filterAcceptsColumn(int column, const QModelIndex & /* source_parent */) const
- {
- return column % 2 != 0;
- }
+ bool filterAcceptsColumn(int column, const QModelIndex & /* source_parent */) const
+ {
+ return column % 2 != 0;
+ }
};
void tst_QSortFilterProxyModel::filteredColumns()
struct Proxy : QSortFilterProxyModel {
QString pattern;
- virtual bool filterAcceptsRow(int source_row, const QModelIndex&) const {
+ virtual bool filterAcceptsRow(int source_row, const QModelIndex&) const
+ {
return sourceModel()->data(sourceModel()->index(source_row, 0)).toString().contains(pattern);
}
- void notifyChange(int test) {
+ void notifyChange(int test)
+ {
switch (test) {
case 0: break;
case 1: reset(); break;
QVERIFY(beforeParents.contains(proxy2.mapToSource(idx)));
foreach (const QPersistentModelIndex &idx, proxy2AfterList)
QVERIFY(afterParents.contains(proxy2.mapToSource(idx)));
-
}
class SignalArgumentChecker : public QObject
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include <QObject>
#include <QModelIndex>
#include <qdebug.h>
-
QT_FORWARD_DECLARE_CLASS(QStringListModel)
class QModelListener : public QObject
virtual ~QModelListener() { }
void setTestData(QStringList *pAboutToStringlist, QStringList *pExpectedStringlist, QStringListModel *pModel)
- {
+ {
m_pAboutToStringlist = pAboutToStringlist;
m_pExpectedStringlist = pExpectedStringlist;
m_pModel = pModel;
public slots:
void rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end );
void rowsRemovedOrInserted(const QModelIndex & parent, int start, int end );
-
};
TARGET = tst_qstringlistmodel
QT += widgets testlib
HEADERS += qmodellistener.h
-
-SOURCES += tst_qstringlistmodel.cpp
-
-
-
+SOURCES += tst_qstringlistmodel.cpp
**
****************************************************************************/
-
#include <QtTest/QtTest>
#include <qabstractitemmodel.h>
#include <qapplication.h>
void QModelListener::rowsAboutToBeRemovedOrInserted(const QModelIndex & parent, int start, int end )
{
- int i;
- for (i = 0; start + i <= end; i++)
- {
+ for (int i = 0; start + i <= end; i++) {
QModelIndex mIndex = m_pModel->index(start + i, 0, parent);
QVariant var = m_pModel->data(mIndex, Qt::DisplayRole);
QString str = var.toString();
-
+
QCOMPARE(str, m_pAboutToStringlist->at(i));
}
}
void QModelListener::rowsRemovedOrInserted(const QModelIndex & parent, int , int)
{
- int i;
// Can the rows that *are* removed be iterated now ?
// What about rowsAboutToBeInserted - what will the indices be?
// RemoveColumn. Does that also fire the rowsRemoved-family signals?
- for (i = 0; i < m_pExpectedStringlist->size(); i++)
- {
+ for (int i = 0; i < m_pExpectedStringlist->size(); i++) {
QModelIndex mIndex = m_pModel->index(i, 0, parent);
QVariant var = m_pModel->data(mIndex, Qt::DisplayRole);
QString str = var.toString();
-
+
//qDebug() << "index: " << i << " start: " << start << "end: " << end;
QCOMPARE(str, m_pExpectedStringlist->at(i));
}
}
-
class tst_QStringListModel : public QObject
{
Q_OBJECT
QStringListModel *model = new QStringListModel(input);
QModelListener *pListener = new QModelListener(&aboutto, &res, model);
- pListener->connect(model, SIGNAL( rowsAboutToBeRemoved(const QModelIndex & , int , int )),
+ pListener->connect(model, SIGNAL( rowsAboutToBeRemoved(const QModelIndex & , int , int )),
pListener, SLOT( rowsAboutToBeRemovedOrInserted(const QModelIndex & , int , int )) );
- pListener->connect(model, SIGNAL( rowsRemoved(const QModelIndex & , int , int )),
+ pListener->connect(model, SIGNAL( rowsRemoved(const QModelIndex & , int , int )),
pListener, SLOT( rowsRemovedOrInserted(const QModelIndex & , int , int )) );
model->removeRows(row,count);
- // At this point, control goes to our connected slots inn this order:
+ // At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
delete pListener;
delete model;
-
}
void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted_data()
QStringListModel *model = new QStringListModel(input);
QModelListener *pListener = new QModelListener(&aboutto, &res, model);
- connect(model, SIGNAL( rowsAboutToBeInserted(const QModelIndex & , int , int )),
+ connect(model, SIGNAL( rowsAboutToBeInserted(const QModelIndex & , int , int )),
pListener, SLOT( rowsAboutToBeRemovedOrInserted(const QModelIndex & , int , int )) );
- connect(model, SIGNAL( rowsInserted(const QModelIndex & , int , int )),
+ connect(model, SIGNAL( rowsInserted(const QModelIndex & , int , int )),
pListener, SLOT( rowsRemovedOrInserted(const QModelIndex & , int , int )) );
model->insertRows(row,count);
- // At this point, control goes to our connected slots inn this order:
+ // At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
delete pListener;
delete model;
-
}
-
QTEST_MAIN(tst_QStringListModel)
#include "tst_qstringlistmodel.moc"
-