7#include <private/qobject_p.h>
8#include <private/qabstractitemmodel_p.h>
9#include <QtCore/QPointer>
10#include <QtCore/QAbstractItemModel>
11#include <QtCore/QStack>
13#include <QLoggingCategory>
19#define MODELTESTER_VERIFY(statement) \
21 if (!verify(static_cast<bool>(statement), #statement, "", __FILE__, __LINE__)) \
25#define MODELTESTER_COMPARE(actual, expected) \
27 if (!compare((actual), (expected), #actual, #expected, __FILE__, __LINE__)) \
55 const QModelIndex &destinationParent,
int destinationColumn);
64 const QModelIndex &destinationParent,
int destinationRow);
75 bool verify(
bool statement,
const char *statementStr,
const char *description,
const char *
file,
int line);
77 template<
typename T1,
typename T2>
78 bool compare(
const T1 &
t1,
const T2 &
t2,
79 const char *actual,
const char *
expected,
94 bool useFetchMore =
true;
97 enum class ChangeInFlight {
108 ChangeInFlight changeInFlight = ChangeInFlight::None;
217 auto runAllTests = [
d] {
d->runAllTests(); };
248 this, [
d]{
d->layoutAboutToBeChanged(); });
250 this, [
d]{
d->layoutChanged(); });
256 this, [
d](
const QModelIndex &sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex &destinationParent,
int destinationColumn) {
257 d->columnsAboutToBeMoved(sourceParent, sourceStart, sourceEnd, destinationParent, destinationColumn); });
272 this, [
d](
const QModelIndex &sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex &destinationParent,
int destinationRow) {
273 d->rowsAboutToBeMoved(sourceParent, sourceStart, sourceEnd, destinationParent, destinationRow); });
286 this, [
d]() {
d->modelAboutToBeReset(); });
288 this, [
d]() {
d->modelReset(); });
305 return d->model.data();
316 return d->failureReportingMode;
333bool QAbstractItemModelTester::verify(
bool statement,
const char *statementStr,
const char *description,
const char *
file,
int line)
336 return d->verify(statement, statementStr, description,
file,
line);
341 failureReportingMode(failureReportingMode),
370 fetchingMore =
false;
375 const bool hasRow = model->
hasIndex(0, 0);
401 int rows = model->
rowCount(topIndex);
407 if (rows == 0 || columns == 0)
415 rows = model->
rowCount(secondLevelIndex);
421 if (rows == 0 || columns == 0)
446 if (rows > 0 && columns > 0)
541void QAbstractItemModelTesterPrivate::checkChildren(
const QModelIndex &
parent,
int currentDepth)
552 fetchingMore =
false;
564 if (rows > 0 && columns > 0)
572 for (
int r = 0;
r < rows; ++
r) {
575 for (
int c = 0;
c < columns; ++
c) {
579 if (!
index.isValid())
580 qCWarning(lcModelTest) <<
"Got invalid index at row=" <<
r <<
"col=" <<
c <<
"parent=" <<
parent;
603 qCWarning(lcModelTest) <<
"Inconsistent parent() implementation detected:";
605 qCWarning(lcModelTest) <<
" row=" <<
r <<
"col=" <<
c <<
"depth=" << currentDepth;
617 checkChildren(
index, currentDepth + 1);
658 if (textAlignmentVariant.
isValid()) {
659 Qt::Alignment
alignment = QtPrivate::legacyFlagValueFromModelData<Qt::Alignment>(textAlignmentVariant);
665 if (checkStateVariant.
isValid()) {
666 Qt::CheckState state = QtPrivate::legacyEnumValueFromModelData<Qt::CheckState>(checkStateVariant);
682 changeInFlight = ChangeInFlight::ColumnsInserted;
684 qCDebug(lcModelTest) <<
"columnsAboutToBeInserted"
696 changeInFlight = ChangeInFlight::None;
698 qCDebug(lcModelTest) <<
"columnsInserted"
699 <<
"start=" <<
first <<
"end=" << last <<
"parent=" <<
parent
705 int sourceStart,
int sourceEnd,
707 int destinationColumn)
710 changeInFlight = ChangeInFlight::ColumnsMoved;
712 qCDebug(lcModelTest) <<
"columnsAboutToBeMoved"
713 <<
"sourceStart=" << sourceStart <<
"sourceEnd=" << sourceEnd
714 <<
"sourceParent=" << sourceParent
715 <<
"sourceParent data=" << model->
data(sourceParent).
toString()
716 <<
"destinationParent=" << destinationParent
717 <<
"destinationColumn=" << destinationColumn;
723 int destinationColumn)
726 changeInFlight = ChangeInFlight::None;
728 qCDebug(lcModelTest) <<
"columnsMoved"
729 <<
"sourceStart=" << sourceStart <<
"sourceEnd=" << sourceEnd
730 <<
"sourceParent=" << sourceParent
731 <<
"sourceParent data=" << model->
data(sourceParent).
toString()
732 <<
"destinationParent=" << destinationParent
733 <<
"destinationColumn=" << destinationColumn;
740 changeInFlight = ChangeInFlight::ColumnsRemoved;
742 qCDebug(lcModelTest) <<
"columnsAboutToBeRemoved"
743 <<
"start=" <<
first <<
"end=" << last <<
"parent=" <<
parent
753 changeInFlight = ChangeInFlight::None;
755 qCDebug(lcModelTest) <<
"columnsRemoved"
756 <<
"start=" <<
first <<
"end=" << last <<
"parent=" <<
parent
769 changeInFlight = ChangeInFlight::RowsInserted;
771 qCDebug(lcModelTest) <<
"rowsAboutToBeInserted"
793 changeInFlight = ChangeInFlight::None;
795 qCDebug(lcModelTest) <<
"rowsInserted"
801 qCDebug(lcModelTest) <<
" itemWasInserted:" <<
i
806 Changing
c = insert.
pop();
826 int sourceStart,
int sourceEnd,
831 changeInFlight = ChangeInFlight::RowsMoved;
833 qCDebug(lcModelTest) <<
"rowsAboutToBeMoved"
834 <<
"sourceStart=" << sourceStart <<
"sourceEnd=" << sourceEnd
835 <<
"sourceParent=" << sourceParent
836 <<
"sourceParent data=" << model->
data(sourceParent).
toString()
837 <<
"destinationParent=" << destinationParent
838 <<
"destinationRow=" << destinationRow;
842 int sourceEnd,
const QModelIndex &destinationParent,
846 changeInFlight = ChangeInFlight::None;
848 qCDebug(lcModelTest) <<
"rowsMoved"
849 <<
"sourceStart=" << sourceStart <<
"sourceEnd=" << sourceEnd
850 <<
"sourceParent=" << sourceParent
851 <<
"sourceParent data=" << model->
data(sourceParent).
toString()
852 <<
"destinationParent=" << destinationParent
853 <<
"destinationRow=" << destinationRow;
859 changeInFlight = ChangeInFlight::LayoutChanged;
868 changeInFlight = ChangeInFlight::None;
870 for (
int i = 0;
i < changing.
size(); ++
i) {
880 changeInFlight = ChangeInFlight::ModelReset;
886 changeInFlight = ChangeInFlight::None;
897 changeInFlight = ChangeInFlight::RowsRemoved;
899 qCDebug(lcModelTest) <<
"rowsAboutToBeRemoved"
911 c.last = model->
data(startIndex);
913 if (end < c.oldSize - 1 && model->columnCount(
parent) > 0) {
916 c.next = model->
data(endIndex);
930 changeInFlight = ChangeInFlight::None;
932 qCDebug(lcModelTest) <<
"rowsRemoved"
937 Changing
c = remove.
pop();
942 if (
end <
c.oldSize - 1)
954 int rowCount = model->
rowCount(commonParent);
955 int columnCount = model->
columnCount(commonParent);
970bool QAbstractItemModelTesterPrivate::verify(
bool statement,
971 const char *statementStr,
const char *description,
974 static const char formatString[] =
"FAIL! %s (%s) returned FALSE (%s:%d)";
976 switch (failureReportingMode) {
996template<
typename T1,
typename T2>
997bool QAbstractItemModelTesterPrivate::compare(
const T1 &
t1,
const T2 &
t2,
998 const char *actual,
const char *
expected,
1001 const bool result =
static_cast<bool>(
t1 ==
t2);
1003 static const char formatString[] =
"FAIL! Compared values are not the same:\n Actual (%s) %s\n Expected (%s) %s\n (%s:%d)";
1005 switch (failureReportingMode) {
1014 qCWarning(lcModelTest, formatString, actual, t1string ? t1string :
"(nullptr)",
1015 expected, t2string ? t2string :
"(nullptr)",
1026 qFatal(formatString, actual, t1string ? t1string :
"(nullptr)",
1027 expected, t2string ? t2string :
"(nullptr)",
1041#include "moc_qabstractitemmodeltester.cpp"
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
void rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
void rowsRemoved(const QModelIndex &parent, int start, int end)
void columnsRemoved(const QModelIndex &parent, int first, int last)
void columnsInserted(const QModelIndex &parent, int first, int last)
void rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
void columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
void modelAboutToBeReset()
void layoutAboutToBeChanged()
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void headerDataChanged(Qt::Orientation orientation, int start, int end)
void rowsInserted(const QModelIndex &parent, int start, int end)
void nonDestructiveBasicTest()
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
QAbstractItemModelTesterPrivate(QAbstractItemModel *model, QAbstractItemModelTester::FailureReportingMode failureReportingMode)
The QAbstractItemModelTester class helps testing QAbstractItemModel subclasses.
QAbstractItemModel * model() const
Returns the model that this instance is testing.
QAbstractItemModelTester(QAbstractItemModel *model, QObject *parent=nullptr)
Creates a model tester instance, with the given parent, that will test the model model.
FailureReportingMode failureReportingMode() const
Returns the mode that this instancing is using to report test failures.
void setUseFetchMore(bool value)
If value is true, enables dynamic population of the tested model, which is the default.
FailureReportingMode
This enumeration specifies how QAbstractItemModelTester should report a failure when it tests a QAbst...
virtual Qt::DropActions supportedDropActions() const
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
void modelAboutToBeReset(QPrivateSignal)
virtual Q_INVOKABLE QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Returns a list of indexes for the items in the column of the start index where data stored under the ...
void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been removed from the model.
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are inserted into the model.
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before columns are inserted into the model.
Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns {true} if the model returns a valid QModelIndex for row and column with parent,...
virtual Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
void modelReset(QPrivateSignal)
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns {true} if parent has any children; otherwise returns {false}.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
virtual Q_INVOKABLE void fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before columns are removed from the model.
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
virtual QModelIndex buddy(const QModelIndex &index) const
Returns a model index for the buddy of the item represented by index.
virtual Q_INVOKABLE bool canFetchMore(const QModelIndex &parent) const
Returns {true} if there is more data available for parent; otherwise returns {false}.
virtual Q_INVOKABLE QModelIndex sibling(int row, int column, const QModelIndex &idx) const
Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no...
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are removed from the model.
virtual QHash< int, QByteArray > roleNames() const
void rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been inserted into the model.
virtual QStringList mimeTypes() const
Returns the list of allowed MIME types.
void columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been inserted into the model.
virtual QSize span(const QModelIndex &index) const
Returns the row and column span of the item represented by index.
virtual Q_INVOKABLE QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index.
void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been removed from the model.
qsizetype size() const noexcept
void append(parameter_type t)
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
constexpr int row() const noexcept
Returns the row this model index refers to.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
constexpr int column() const noexcept
Returns the column this model index refers to.
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
T pop()
Removes the top item from the stack and returns it.
void push(const T &t)
Adds element t to the top of the stack.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool canConvert(QMetaType targetType) const
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
bool testDataGuiRoles(QAbstractItemModelTester *tester)
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description, const char *file, int line)
char * toString(const MyPoint &point)
char * formatString(const char *prefix, const char *suffix, size_t numArguments,...)
bool qCompare(QString const &t1, QLatin1StringView const &t2, const char *actual, const char *expected, const char *file, int line)
#define MODELTESTER_COMPARE(actual, expected)
#define MODELTESTER_VERIFY(statement)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
QSqlQueryModel * model
[16]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent