summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-28 09:41:00 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-28 09:41:00 (GMT)
commit55865ff0bffb9a9218f6ce2d7516d8736437cfa3 (patch)
treef1bfcb92a69d976e6b77f16198007bb934384c39 /tests/auto
parentc065a7e1d26dc434cfe33177332473797db74152 (diff)
parente88a947cd8ac7bd78922a5468cd8b631b8ccf479 (diff)
downloadQt-55865ff0bffb9a9218f6ce2d7516d8736437cfa3.zip
Qt-55865ff0bffb9a9218f6ce2d7516d8736437cfa3.tar.gz
Qt-55865ff0bffb9a9218f6ce2d7516d8736437cfa3.tar.bz2
Merge branch '4.6' of git:qt/qt into 4.6
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qabstractitemmodel/dynamictreemodel.cpp118
-rw-r--r--tests/auto/qabstractitemmodel/dynamictreemodel.h39
-rw-r--r--tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp106
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp42
4 files changed, 276 insertions, 29 deletions
diff --git a/tests/auto/qabstractitemmodel/dynamictreemodel.cpp b/tests/auto/qabstractitemmodel/dynamictreemodel.cpp
index 6c3e0cb..374b7db 100644
--- a/tests/auto/qabstractitemmodel/dynamictreemodel.cpp
+++ b/tests/auto/qabstractitemmodel/dynamictreemodel.cpp
@@ -204,42 +204,106 @@ ModelMoveCommand::ModelMoveCommand(DynamicTreeModel *model, QObject *parent)
{
}
+bool ModelMoveCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow)
+{
+ return m_model->beginMoveRows(srcParent, srcStart, srcEnd, destParent, destRow);
+}
void ModelMoveCommand::doCommand()
{
- QModelIndex srcParent = findIndex(m_rowNumbers);
- QModelIndex destParent = findIndex(m_destRowNumbers);
-
- if (!m_model->beginMoveRows(srcParent, m_startRow, m_endRow, destParent, m_destRow))
- {
- return;
- }
-
- for (int column = 0; column < m_numCols; ++column)
- {
- QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1 );
+ QModelIndex srcParent = findIndex(m_rowNumbers);
+ QModelIndex destParent = findIndex(m_destRowNumbers);
- for (int i = m_startRow; i <= m_endRow ; i++)
+ if (!emitPreSignal(srcParent, m_startRow, m_endRow, destParent, m_destRow))
{
- m_model->m_childItems[srcParent.internalId()][column].removeAt(m_startRow);
- }
- int d;
- if (m_destRow < m_startRow)
- d = m_destRow;
- else
- {
- if (srcParent == destParent)
- d = m_destRow - (m_endRow - m_startRow + 1);
- else
- d = m_destRow - (m_endRow - m_startRow) + 1;
+ return;
}
- foreach(const qint64 id, l)
+ for (int column = 0; column < m_numCols; ++column)
{
- m_model->m_childItems[destParent.internalId()][column].insert(d++, id);
+ QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1 );
+
+ for (int i = m_startRow; i <= m_endRow ; i++)
+ {
+ m_model->m_childItems[srcParent.internalId()][column].removeAt(m_startRow);
+ }
+ int d;
+ if (m_destRow < m_startRow)
+ d = m_destRow;
+ else
+ {
+ if (srcParent == destParent)
+ d = m_destRow - (m_endRow - m_startRow + 1);
+ else
+ d = m_destRow - (m_endRow - m_startRow) + 1;
+ }
+
+ foreach(const qint64 id, l)
+ {
+ m_model->m_childItems[destParent.internalId()][column].insert(d++, id);
+ }
}
- }
- m_model->endMoveRows();
+ emitPostSignal();
+}
+
+void ModelMoveCommand::emitPostSignal()
+{
+ m_model->endMoveRows();
+}
+
+ModelResetCommand::ModelResetCommand(DynamicTreeModel* model, QObject* parent)
+ : ModelMoveCommand(model, parent)
+{
+
+}
+
+ModelResetCommand::~ModelResetCommand()
+{
+
+}
+
+bool ModelResetCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow)
+{
+ Q_UNUSED(srcParent);
+ Q_UNUSED(srcStart);
+ Q_UNUSED(srcEnd);
+ Q_UNUSED(destParent);
+ Q_UNUSED(destRow);
+
+ return true;
+}
+
+void ModelResetCommand::emitPostSignal()
+{
+ m_model->reset();
+}
+
+ModelResetCommandFixed::ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent)
+ : ModelMoveCommand(model, parent)
+{
+
+}
+
+ModelResetCommandFixed::~ModelResetCommandFixed()
+{
+
+}
+
+bool ModelResetCommandFixed::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow)
+{
+ Q_UNUSED(srcParent);
+ Q_UNUSED(srcStart);
+ Q_UNUSED(srcEnd);
+ Q_UNUSED(destParent);
+ Q_UNUSED(destRow);
+
+ m_model->beginResetModel();
+ return true;
+}
+
+void ModelResetCommandFixed::emitPostSignal()
+{
+ m_model->endResetModel();
}
diff --git a/tests/auto/qabstractitemmodel/dynamictreemodel.h b/tests/auto/qabstractitemmodel/dynamictreemodel.h
index 88e293c..c19ed9d 100644
--- a/tests/auto/qabstractitemmodel/dynamictreemodel.h
+++ b/tests/auto/qabstractitemmodel/dynamictreemodel.h
@@ -70,6 +70,8 @@ private:
friend class ModelInsertCommand;
friend class ModelMoveCommand;
+ friend class ModelResetCommand;
+ friend class ModelResetCommandFixed;
};
@@ -118,6 +120,7 @@ public:
virtual void doCommand();
};
+
class ModelMoveCommand : public ModelChangeCommand
{
Q_OBJECT
@@ -126,8 +129,12 @@ public:
virtual ~ModelMoveCommand() {}
+ virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
+
virtual void doCommand();
+ virtual void emitPostSignal();
+
void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; }
void setDestRow(int row) { m_destRow = row; }
@@ -137,5 +144,37 @@ protected:
int m_destRow;
};
+/**
+ A command which does a move and emits a reset signal.
+*/
+class ModelResetCommand : public ModelMoveCommand
+{
+ Q_OBJECT
+public:
+ ModelResetCommand(DynamicTreeModel* model, QObject* parent = 0);
+
+ virtual ~ModelResetCommand();
+
+ virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
+ virtual void emitPostSignal();
+
+};
+
+/**
+ A command which does a move and emits a beginResetModel and endResetModel signals.
+*/
+class ModelResetCommandFixed : public ModelMoveCommand
+{
+ Q_OBJECT
+public:
+ ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent = 0);
+
+ virtual ~ModelResetCommandFixed();
+
+ virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
+ virtual void emitPostSignal();
+
+};
+
#endif
diff --git a/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 9c83474..61eeae7 100644
--- a/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -43,6 +43,8 @@
#include <QtTest/QtTest>
#include <QtCore/QtCore>
+#include <QSortFilterProxyModel>
+
//TESTED_CLASS=QAbstractListModel QAbstractTableModel
//TESTED_FILES=
@@ -110,6 +112,8 @@ private slots:
void testMoveWithinOwnRange_data();
void testMoveWithinOwnRange();
+ void testReset();
+
private:
DynamicTreeModel *m_model;
@@ -814,7 +818,7 @@ void tst_QAbstractItemModel::complexChangesWithPersistent()
//remove a bunch of columns
model.removeColumns(2, 4);
-
+
QVERIFY(a == model.index(1, 1, QModelIndex()));
QVERIFY(b == model.index(9, 3, QModelIndex()));
QVERIFY(c == model.index(5, 2, QModelIndex()));
@@ -825,7 +829,7 @@ void tst_QAbstractItemModel::complexChangesWithPersistent()
QVERIFY(!e[i].isValid());
for (int i=6; i <10 ; i++)
QVERIFY(e[i] == model.index(2, i-4 , QModelIndex()));
-
+
//move some indexes around
model.setPersistent(model.index(1, 1 , QModelIndex()), model.index(9, 3 , QModelIndex()));
model.setPersistent(model.index(9, 3 , QModelIndex()), model.index(8, 4 , QModelIndex()));
@@ -1652,6 +1656,104 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange()
}
+class ListenerObject : public QObject
+{
+ Q_OBJECT
+public:
+ ListenerObject(QAbstractProxyModel *parent);
+
+protected:
+ void fillIndexStores(const QModelIndex &parent);
+
+public slots:
+ void slotAboutToBeReset();
+ void slotReset();
+
+private:
+ QAbstractProxyModel *m_model;
+ QList<QPersistentModelIndex> m_persistentIndexes;
+ QModelIndexList m_nonPersistentIndexes;
+};
+
+
+ListenerObject::ListenerObject(QAbstractProxyModel *parent)
+ : QObject(parent), m_model(parent)
+{
+ connect(m_model, SIGNAL(modelAboutToBeReset()), SLOT(slotAboutToBeReset()));
+ connect(m_model, SIGNAL(modelReset()), SLOT(slotReset()));
+
+ fillIndexStores(QModelIndex());
+}
+
+void ListenerObject::fillIndexStores(const QModelIndex &parent)
+{
+ const int column = 0;
+ int row = 0;
+ QModelIndex idx = m_model->index(row, column, parent);
+ 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)
+ {
+ 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)
+ {
+ QVERIFY(!idx.isValid());
+ }
+}
+
+
+void tst_QAbstractItemModel::testReset()
+{
+ QSignalSpy beforeResetSpy(m_model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy afterResetSpy(m_model, SIGNAL(modelReset()));
+
+
+ QSortFilterProxyModel *nullProxy = new QSortFilterProxyModel(this);
+ nullProxy->setSourceModel(m_model);
+
+ // Makes sure the model and proxy are in a consistent state. before and after reset.
+ new ListenerObject(nullProxy);
+
+ ModelResetCommandFixed *resetCommand = new ModelResetCommandFixed(m_model, this);
+
+ resetCommand->setNumCols(4);
+ resetCommand->setStartRow(0);
+ resetCommand->setEndRow(0);
+ resetCommand->setDestRow(0);
+ resetCommand->setDestAncestors(QList<int>() << 5);
+ resetCommand->doCommand();
+
+ // Verify that the correct signals were emitted
+ QVERIFY(beforeResetSpy.size() == 1);
+ QVERIFY(afterResetSpy.size() == 1);
+
+ // Verify that the move actually happened.
+ QVERIFY(m_model->rowCount() == 9);
+ QModelIndex destIndex = m_model->index(4, 0);
+ QVERIFY(m_model->rowCount(destIndex) == 11);
+
+}
QTEST_MAIN(tst_QAbstractItemModel)
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 20e69ce..643daa2 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -93,10 +93,13 @@ Q_OBJECT
{ emit signalWithIntArg(arg); }
void emitSignalWithStringArg(const QString &arg)
{ emit signalWithStringArg(arg); }
+ void emitSignalWithDefaultArg()
+ { emit signalWithDefaultArg(); }
Q_SIGNALS:
void signalWithNoArg();
void signalWithIntArg(int);
void signalWithStringArg(const QString &);
+ void signalWithDefaultArg(int i = 42);
};
class tst_QStateMachine : public QObject
@@ -193,6 +196,8 @@ private slots:
void nestedStateMachines();
void goToState();
+
+ void task260403_clonedSignals();
};
tst_QStateMachine::tst_QStateMachine()
@@ -3937,5 +3942,42 @@ void tst_QStateMachine::goToState()
QVERIFY(machine.configuration().contains(s2_1));
}
+class CloneSignalTransition : public QSignalTransition
+{
+public:
+ CloneSignalTransition(QObject *sender, const char *signal, QAbstractState *target)
+ : QSignalTransition(sender, signal)
+ {
+ setTargetState(target);
+ }
+
+ void onTransition(QEvent *e)
+ {
+ QSignalTransition::onTransition(e);
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ eventSignalIndex = se->signalIndex();
+ }
+
+ int eventSignalIndex;
+};
+
+void tst_QStateMachine::task260403_clonedSignals()
+{
+ SignalEmitter emitter;
+ QStateMachine machine;
+ QState *s1 = new QState(&machine);
+ QState *s2 = new QState(&machine);
+ CloneSignalTransition *t1 = new CloneSignalTransition(&emitter, SIGNAL(signalWithDefaultArg()), s2);
+ s1->addTransition(t1);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QTest::qWait(1);
+
+ emitter.emitSignalWithDefaultArg();
+ QTest::qWait(1);
+ QCOMPARE(t1->eventSignalIndex, emitter.metaObject()->indexOfSignal("signalWithDefaultArg()"));
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"