summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp1371
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp411
2 files changed, 842 insertions, 940 deletions
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 35c0c6c606..09990ab70a 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -26,19 +26,24 @@
**
****************************************************************************/
-
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
+#include <QIdentityProxyModel>
+#include <QLabel>
+#include <QLineEdit>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QTableView>
+#include <QTest>
+#include <private/qapplication_p.h>
#include <private/qtablewidget_p.h>
-#include <QtTest/QtTest>
-#include "private/qapplication_p.h"
+#include <private/qtesthelpers_p.h>
#if QT_CONFIG(textmarkdownwriter)
-#include "private/qtextmarkdownwriter_p.h"
+#include <private/qtextmarkdownwriter_p.h>
#endif
-#include <algorithm>
-
-#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
@@ -49,14 +54,241 @@ using namespace QTestPrivate;
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false
#endif
-typedef QList<int> IntList;
+Q_DECLARE_METATYPE(Qt::Key);
+Q_DECLARE_METATYPE(Qt::KeyboardModifier);
+Q_DECLARE_METATYPE(QItemSelectionModel::SelectionFlag);
+using BoolList = QVector<bool>;
+using IntList = QVector<int>;
+using KeyList = QVector<Qt::Key>;
+using SpanList = QVector<QRect>;
+
+class QtTestTableModel: public QAbstractTableModel
+{
+ Q_OBJECT
+
+signals:
+ void invalidIndexEncountered() const;
+
+public slots:
+ bool submit() override { ++submit_count; return QAbstractTableModel::submit(); }
+
+public:
+ QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = nullptr)
+ : QAbstractTableModel(parent), row_count(rows), column_count(columns)
+ {}
+
+ int rowCount(const QModelIndex& = QModelIndex()) const override
+ {
+ return row_count;
+ }
+
+ int columnCount(const QModelIndex& = QModelIndex()) const override
+ {
+ return column_count;
+ }
+
+ bool isEditable(const QModelIndex &) const { return true; }
+
+ Qt::ItemFlags flags(const QModelIndex &index) const override
+ {
+ Qt::ItemFlags index_flags = QAbstractTableModel::flags(index);
+ if (disabled_rows.contains(index.row())
+ || disabled_columns.contains(index.column()))
+ index_flags &= ~Qt::ItemIsEnabled;
+ return index_flags;
+ }
+
+ void disableRow(int row)
+ {
+ disabled_rows.insert(row);
+ }
+
+ void enableRow(int row)
+ {
+ disabled_rows.remove(row);
+ }
+
+ void disableColumn(int column)
+ {
+ disabled_columns.insert(column);
+ }
+
+ void enableColumn(int column)
+ {
+ disabled_columns.remove(column);
+ }
+
+ QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override
+ {
+ if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
+ qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
+ emit invalidIndexEncountered();
+ return QVariant();
+ }
+
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
+ + QString::number(idx.column()) + QLatin1String(",0]");
+ }
+
+ return QVariant();
+ }
+
+ bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start > row_count)
+ return false;
+
+ beginInsertRows(parent, start, start + count - 1);
+ row_count += count;
+ endInsertRows();
+ return true;
+ }
+
+ bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start >= row_count || row_count < count)
+ return false;
+
+ beginRemoveRows(parent, start, start + count - 1);
+ row_count -= count;
+ endRemoveRows();
+ return true;
+ }
+
+ void removeLastRow()
+ {
+ beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
+ --row_count;
+ endRemoveRows();
+ }
+
+ void removeAllRows()
+ {
+ beginRemoveRows(QModelIndex(), 0, row_count - 1);
+ row_count = 0;
+ endRemoveRows();
+ }
+
+ bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start > column_count)
+ return false;
+
+ beginInsertColumns(parent, start, start + count - 1);
+ column_count += count;
+ endInsertColumns();
+ return true;
+ }
+
+ bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start >= column_count || column_count < count)
+ return false;
+
+ beginRemoveColumns(parent, start, start + count - 1);
+ column_count -= count;
+ endRemoveColumns();
+ return true;
+ }
+
+ void removeLastColumn()
+ {
+ beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
+ --column_count;
+ endRemoveColumns();
+ }
+
+ void removeAllColumns()
+ {
+ beginRemoveColumns(QModelIndex(), 0, column_count - 1);
+ column_count = 0;
+ endRemoveColumns();
+ }
+
+ bool canFetchMore(const QModelIndex &) const override
+ {
+ return can_fetch_more;
+ }
+
+ void fetchMore(const QModelIndex &) override
+ {
+ ++fetch_more_count;
+ }
-typedef QList<bool> BoolList;
+ QSet<int> disabled_rows;
+ QSet<int> disabled_columns;
+ int row_count;
+ int column_count;
+ int submit_count = 0;
+ int fetch_more_count = 0;
+ bool can_fetch_more = false;
+};
+
+class QtTestTableView : public QTableView
+{
+ Q_OBJECT
+public:
+ using QTableView::QTableView;
+
+ void setModel(QAbstractItemModel *model) override
+ {
+ QTableView::setModel(model);
+ connect(selectionModel(), &QItemSelectionModel::currentChanged,
+ this, &QtTestTableView::slotCurrentChanged);
+ connect(selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &QtTestTableView::itemSelectionChanged);
+ // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes.
+ horizontalHeader()->setMinimumSectionSize(0);
+ verticalHeader()->setMinimumSectionSize(0);
+ }
+
+ using QTableView::moveCursor;
+ using QTableView::isIndexHidden;
+ using QTableView::setSelection;
+ using QTableView::selectedIndexes;
+ using QTableView::sizeHintForRow;
+ using QTableView::viewOptions;
+
+ bool checkSignalOrder = false;
+public slots:
+ void slotCurrentChanged(QModelIndex, QModelIndex) {
+ hasCurrentChanged++;
+ if (checkSignalOrder)
+ QVERIFY(hasCurrentChanged > hasSelectionChanged);
+ }
+
+ void itemSelectionChanged(QItemSelection , QItemSelection ) {
+ hasSelectionChanged++;
+ if (checkSignalOrder)
+ QVERIFY(hasCurrentChanged >= hasSelectionChanged);
+ }
+private:
+ int hasCurrentChanged = 0;
+ int hasSelectionChanged = 0;
+
+ friend class tst_QTableView;
+ friend struct QMetaTypeId<QtTestTableView::CursorAction>;
+};
+Q_DECLARE_METATYPE(QtTestTableView::CursorAction);
+
+class QtTestItemDelegate : public QStyledItemDelegate
+{
+public:
+ QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override
+ {
+ return hint;
+ }
+
+ QSize hint;
+};
class tst_QTableView : public QObject
{
Q_OBJECT
+private:
+ using CursorActionList = QVector<QtTestTableView::CursorAction>;
private slots:
void getSetCheck();
@@ -236,14 +468,14 @@ void tst_QTableView::getSetCheck()
QHeaderView *var1 = new QHeaderView(Qt::Horizontal);
obj1.setHorizontalHeader(var1);
QCOMPARE(var1, obj1.horizontalHeader());
- obj1.setHorizontalHeader((QHeaderView *)0);
+ obj1.setHorizontalHeader(nullptr);
QCOMPARE(var1, obj1.horizontalHeader());
delete var1;
QHeaderView *var2 = new QHeaderView(Qt::Vertical);
obj1.setVerticalHeader(var2);
QCOMPARE(var2, obj1.verticalHeader());
- obj1.setVerticalHeader((QHeaderView *)0);
+ obj1.setVerticalHeader(nullptr);
QCOMPARE(var2, obj1.verticalHeader());
delete var2;
@@ -251,283 +483,12 @@ void tst_QTableView::getSetCheck()
obj1.setCornerButtonEnabled(false);
QCOMPARE(obj1.isCornerButtonEnabled(), false);
}
-
-class QtTestTableModel: public QAbstractTableModel
-{
- Q_OBJECT
-
-signals:
- void invalidIndexEncountered() const;
-
-public slots:
- bool submit() { ++submit_count; return QAbstractTableModel::submit(); }
-
-public:
- QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
- : QAbstractTableModel(parent),
- row_count(rows),
- column_count(columns),
- submit_count(0),
- can_fetch_more(false),
- fetch_more_count(0),
- disabled_rows(),
- disabled_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; }
-
- Qt::ItemFlags flags(const QModelIndex &index) const
- {
- Qt::ItemFlags index_flags = QAbstractTableModel::flags(index);
- if (disabled_rows.contains(index.row())
- || disabled_columns.contains(index.column()))
- index_flags &= ~Qt::ItemIsEnabled;
- return index_flags;
- }
-
- void disableRow(int row)
- {
- disabled_rows.insert(row);
- }
-
- void enableRow(int row)
- {
- disabled_rows.remove(row);
- }
-
- void disableColumn(int column)
- {
- disabled_columns.insert(column);
- }
-
- void enableColumn(int column)
- {
- disabled_columns.remove(column);
- }
-
- QVariant data(const QModelIndex &idx, int role) const
- {
- if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
- qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
- emit invalidIndexEncountered();
- return QVariant();
- }
-
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
- return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
- + QString::number(idx.column()) + QLatin1String(",0]");
- }
-
- return QVariant();
- }
-
- bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start > row_count)
- return false;
-
- beginInsertRows(parent, start, start + count - 1);
- row_count += count;
- endInsertRows();
- return true;
- }
-
- bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start >= row_count || row_count < count)
- return false;
-
- beginRemoveRows(parent, start, start + count - 1);
- row_count -= count;
- endRemoveRows();
- return true;
- }
-
- void removeLastRow()
- {
- beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
- --row_count;
- endRemoveRows();
- }
-
- void removeAllRows()
- {
- beginRemoveRows(QModelIndex(), 0, row_count - 1);
- row_count = 0;
- endRemoveRows();
- }
-
- bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start > column_count)
- return false;
-
- beginInsertColumns(parent, start, start + count - 1);
- column_count += count;
- endInsertColumns();
- return true;
- }
-
- bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start >= column_count || column_count < count)
- return false;
-
- beginRemoveColumns(parent, start, start + count - 1);
- column_count -= count;
- endRemoveColumns();
- return true;
- }
-
- void removeLastColumn()
- {
- beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
- --column_count;
- endRemoveColumns();
- }
-
- void removeAllColumns()
- {
- beginRemoveColumns(QModelIndex(), 0, column_count - 1);
- column_count = 0;
- endRemoveColumns();
- }
-
- bool canFetchMore(const QModelIndex &) const
- {
- return can_fetch_more;
- }
-
- void fetchMore(const QModelIndex &)
- {
- ++fetch_more_count;
- }
-
- void reset()
- {
- beginResetModel();
- endResetModel();
- }
-
- int row_count;
- int column_count;
- int submit_count;
- bool can_fetch_more;
- int fetch_more_count;
- QSet<int> disabled_rows;
- QSet<int> disabled_columns;
-};
-
-class QtTestTableView : public QTableView
-{
-Q_OBJECT
-
-public:
- QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {}
-
- void setModel(QAbstractItemModel *model)
- {
- QTableView::setModel(model);
- connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex)));
- connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection)));
- // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes.
- horizontalHeader()->setMinimumSectionSize(0);
- verticalHeader()->setMinimumSectionSize(0);
- }
-
- // enum CursorAction and moveCursor() are protected in QTableView.
- enum CursorAction {
- MoveUp = QAbstractItemView::MoveUp,
- MoveDown = QAbstractItemView::MoveDown,
- MoveLeft = QAbstractItemView::MoveLeft,
- MoveRight = QAbstractItemView::MoveRight,
- MoveHome = QAbstractItemView::MoveHome,
- MoveEnd = QAbstractItemView::MoveEnd,
- MovePageUp = QAbstractItemView::MovePageUp,
- MovePageDown = QAbstractItemView::MovePageDown,
- MoveNext = QAbstractItemView::MoveNext,
- MovePrevious = QAbstractItemView::MovePrevious
- };
-
- QModelIndex doMoveCursor(QtTestTableView::CursorAction cursorAction,
- Qt::KeyboardModifiers modifiers)
- {
- return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers);
- }
-
- int columnWidthHint(int column) const
- {
- return sizeHintForColumn(column);
- }
-
- int rowHeightHint(int row) const
- {
- return sizeHintForRow(row);
- }
-
- bool isIndexHidden(const QModelIndex &index) const
- {
- return QTableView::isIndexHidden(index);
- }
-
- void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
- {
- QTableView::setSelection(rect, command);
- }
-
- QModelIndexList selectedIndexes() const
- {
- return QTableView::selectedIndexes();
- }
-
- int sizeHintForRow(int row) const
- {
- return QTableView::sizeHintForRow(row);
- }
-
- QStyleOptionViewItem viewOptions() const {
- return QTableView::viewOptions();
- }
-
- bool checkSignalOrder;
-public slots:
- void slotCurrentChanged(QModelIndex, QModelIndex) {
- hasCurrentChanged++;
- if (checkSignalOrder)
- QVERIFY(hasCurrentChanged > hasSelectionChanged);
- }
-
- void itemSelectionChanged(QItemSelection , QItemSelection ) {
- hasSelectionChanged++;
- if (checkSignalOrder)
- QVERIFY(hasCurrentChanged >= hasSelectionChanged);
- }
-private:
- int hasCurrentChanged;
- int hasSelectionChanged;
-
-};
-
-class QtTestItemDelegate : public QItemDelegate
-{
-public:
- QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
- {
- return hint;
- }
-
- QSize hint;
-};
-
void tst_QTableView::noDelegate()
{
QtTestTableModel model(3, 3);
QTableView view;
view.setModel(&model);
- view.setItemDelegate(0);
+ view.setItemDelegate(nullptr);
view.show();
}
@@ -541,7 +502,7 @@ void tst_QTableView::emptyModel()
{
QtTestTableModel model;
QTableView view;
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
view.setModel(&model);
view.show();
QCOMPARE(spy.count(), 0);
@@ -562,7 +523,7 @@ void tst_QTableView::removeRows()
QFETCH(int, columnCount);
QtTestTableModel model(rowCount, columnCount);
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
QTableView view;
view.setModel(&model);
@@ -590,7 +551,7 @@ void tst_QTableView::removeColumns()
QFETCH(int, columnCount);
QtTestTableModel model(rowCount, columnCount);
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
QTableView view;
view.setModel(&model);
@@ -608,58 +569,18 @@ void tst_QTableView::keyboardNavigation_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<bool>("tabKeyNavigation");
- QTest::addColumn<IntList>("keyPresses");
-
- QTest::newRow("16x16 model") << 16 << 16 << true
- << (IntList()
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Right
- << Qt::Key_Right
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Down
- << Qt::Key_Tab
- << Qt::Key_Backtab);
-
-
- QTest::newRow("no tab") << 8 << 8 << false
- << (IntList()
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Right
- << Qt::Key_Right
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Down
- << Qt::Key_Tab
- << Qt::Key_Backtab);
+ QTest::addColumn<KeyList>("keyPresses");
+
+ const KeyList keyList {
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Right, Qt::Key_Right,
+ Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, Qt::Key_Up,
+ Qt::Key_Down, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Left,
+ Qt::Key_Left, Qt::Key_Up, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Tab, Qt::Key_Backtab};
+
+ QTest::newRow("16x16 model") << 16 << 16 << true << keyList;
+ QTest::newRow("no tab") << 8 << 8 << false << keyList;
}
void tst_QTableView::keyboardNavigation()
@@ -667,7 +588,7 @@ void tst_QTableView::keyboardNavigation()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(bool, tabKeyNavigation);
- QFETCH(IntList, keyPresses);
+ QFETCH(const KeyList, keyPresses);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
@@ -678,14 +599,12 @@ void tst_QTableView::keyboardNavigation()
view.setCurrentIndex(index);
view.show();
- qApp->setActiveWindow(&view);
+ QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
int row = rowCount - 1;
int column = columnCount - 1;
- for (int i = 0; i < keyPresses.count(); ++i) {
-
- Qt::Key key = (Qt::Key)keyPresses.at(i);
+ for (Qt::Key key : keyPresses) {
switch (key) {
case Qt::Key_Up:
@@ -785,8 +704,8 @@ void tst_QTableView::moveCursor_data()
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("startColumn");
- QTest::addColumn<int>("cursorMoveAction");
- QTest::addColumn<int>("modifier");
+ QTest::addColumn<QtTestTableView::CursorAction>("cursorMoveAction");
+ QTest::addColumn<Qt::KeyboardModifier>("modifier");
QTest::addColumn<int>("expectedRow");
QTest::addColumn<int>("expectedColumn");
@@ -797,346 +716,346 @@ void tst_QTableView::moveCursor_data()
QTest::newRow("MoveRight (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight (3,0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 3 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); // ###
QTest::newRow("MoveRight, hidden column 1 (0,0)")
<< 4 << 4 << -1 << 1
<< 0 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); // ###
// MoveNext should in addition wrap
QTest::newRow("MoveNext (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext (0,2)")
<< 4 << 4 << -1 << -1
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, hidden column 1 (0,0)")
<< 4 << 4 << -1 << 1
<< 0 << 0
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)")
<< 4 << 4 << -1 << 3
<< 3 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)")
<< 4 << 4 << 3 << 3
<< 2 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)")
<< 4 << 4 << -1 << 2
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 3 << IntPair(0,0) << IntPair(3,0);
// MoveLeft
QTest::newRow("MoveLeft (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft (1,0)")
<< 4 << 4 << -1 << -1
<< 1 << 0
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft, hidden column 0 (0,2)")
<< 4 << 4 << -1 << 1
<< 0 << 2
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft, hidden column 0 (0,1)")
<< 4 << 4 << -1 << 0
<< 0 << 1
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
// MovePrevious should in addition wrap
QTest::newRow("MovePrevious (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious (0,1)")
<< 4 << 4 << -1 << -1
<< 0 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap (1,0)")
<< 4 << 4 << -1 << -1
<< 1 << 0
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, hidden column 1 (0,2)")
<< 4 << 4 << -1 << 1
<< 0 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)")
<< 4 << 4 << -1 << 0
<< 0 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)")
<< 4 << 4 << 0 << 0
<< 1 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)")
<< 4 << 4 << -1 << 1
<< 1 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,3);
// MoveDown
QTest::newRow("MoveDown (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown (3,0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 3 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 1 (0,0)")
<< 4 << 4 << 1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 3 (2,0)")
<< 4 << 4 << 3 << -1
<< 2 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)")
<< 4 << 4 << 0 << 0
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 1 << 1 << IntPair(0,0) << IntPair(0,0);
// MoveUp
QTest::newRow("MoveUp (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp (3, 0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp (0,1)")
<< 4 << 4 << -1 << -1
<< 0 << 1
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp, hidden row 1 (2,0)")
<< 4 << 4 << 1 << -1
<< 2 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp, hidden row (1,0)")
<< 4 << 4 << 0 << -1
<< 1 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
// MoveHome
QTest::newRow("MoveHome (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 3 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome, hidden column 0 (3,3)")
<< 4 << 4 << -1 << 0
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 3 << 1 << IntPair(0,0) << IntPair(0,0);
// Use Ctrl modifier
QTest::newRow("MoveHome + Ctrl (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome + Ctrl (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)")
<< 4 << 4 << 0 << 0
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 1 << 1 << IntPair(0,0) << IntPair(0,0);
// MoveEnd
QTest::newRow("MoveEnd (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd, hidden column (0,0)")
<< 4 << 4 << -1 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 0<< 2 << IntPair(0,0) << IntPair(0,0);
// Use Ctrl modifier
QTest::newRow("MoveEnd + Ctrl (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)")
<< 4 << 4 << -1 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)")
<< 4 << 4 << 3 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 2 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageUp (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MovePageUp) << 0
+ << QtTestTableView::MovePageUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageUp (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MovePageUp) << 0
+ << QtTestTableView::MovePageUp << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageDown (3, 3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MovePageDown) << 0
+ << QtTestTableView::MovePageDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageDown (0, 3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MovePageDown) << 0
+ << QtTestTableView::MovePageDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
}
@@ -1148,8 +1067,8 @@ void tst_QTableView::moveCursor()
QFETCH(int, hideColumn);
QFETCH(int, startRow);
QFETCH(int, startColumn);
- QFETCH(int, cursorMoveAction);
- QFETCH(int, modifier);
+ QFETCH(QtTestTableView::CursorAction, cursorMoveAction);
+ QFETCH(Qt::KeyboardModifier, modifier);
QFETCH(int, expectedRow);
QFETCH(int, expectedColumn);
QFETCH(IntPair, moveRow);
@@ -1174,8 +1093,7 @@ void tst_QTableView::moveCursor()
QModelIndex index = model.index(startRow, startColumn);
view.setCurrentIndex(index);
- QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction,
- (Qt::KeyboardModifiers)modifier);
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, modifier);
// expected fails, task 119433
if(newIndex.row() == -1)
return;
@@ -1193,7 +1111,7 @@ void tst_QTableView::moveCursorStrikesBack_data()
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("startColumn");
- QTest::addColumn<IntList>("cursorMoveActions");
+ QTest::addColumn<CursorActionList>("cursorMoveActions");
QTest::addColumn<int>("expectedRow");
QTest::addColumn<int>("expectedColumn");
@@ -1201,70 +1119,84 @@ void tst_QTableView::moveCursorStrikesBack_data()
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext))
+ << 0 << 5
+ << CursorActionList{QtTestTableView::MoveNext}
<< 1 << 0;
QTest::newRow("Last column disabled 2. Task QTBUG-3878") << -1 << -1
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MovePrevious}
<< 0 << 5;
QTest::newRow("Span, anchor column hidden") << -1 << 1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< 2 << 1;
QTest::newRow("Span, anchor column disabled") << -1 << -1
<< IntList()
<< (IntList() << 1)
<< QRect(1, 2, 2, 3)
- << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< 2 << 1;
QTest::newRow("Span, anchor row hidden") << 2 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown}
<< 2 << 1;
QTest::newRow("Span, anchor row disabled") << -1 << -1
<< (IntList() << 2)
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown}
<< 2 << 1;
QTest::newRow("Move through span right") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight))
+ << 3 << 0
+ << CursorActionList{QtTestTableView::MoveRight,
+ QtTestTableView::MoveRight}
<< 3 << 3;
QTest::newRow("Move through span left") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft))
+ << 3 << 3
+ << CursorActionList{QtTestTableView::MoveLeft,
+ QtTestTableView::MoveLeft}
<< 3 << 0;
QTest::newRow("Move through span down") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown,
+ QtTestTableView::MoveDown}
<< 5 << 2;
QTest::newRow("Move through span up") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp))
+ << 5 << 2
+ << CursorActionList{QtTestTableView::MoveUp,
+ QtTestTableView::MoveUp}
<< 1 << 2;
IntList fullList;
@@ -1275,42 +1207,48 @@ void tst_QTableView::moveCursorStrikesBack_data()
<< fullList
<< fullList
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< -1 << -1;
QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1
<< fullList
<< fullList
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MovePrevious}
<< -1 << -1;
QTest::newRow("Last column disabled, MoveEnd. QTBUG-72400") << -1 << -1
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 0 << 0 << (IntList() << int(QtTestTableView::MoveEnd))
+ << 0 << 0
+ << CursorActionList{QtTestTableView::MoveEnd}
<< 0 << 5;
QTest::newRow("First column disabled, MoveHome. QTBUG-72400") << -1 << -1
<< IntList()
<< (IntList() << 0)
<< QRect()
- << 0 << 6 << (IntList() << int(QtTestTableView::MoveHome))
+ << 0 << 6
+ << CursorActionList{QtTestTableView::MoveHome}
<< 0 << 1;
QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1
<< (IntList() << 0)
<< IntList()
<< QRect()
- << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MovePageUp}
<< 1 << 0;
QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1
<< (IntList() << 6)
<< IntList()
<< QRect()
- << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown))
+ << 4 << 0
+ << CursorActionList{QtTestTableView::MovePageDown}
<< 5 << 0;
}
@@ -1318,13 +1256,13 @@ void tst_QTableView::moveCursorStrikesBack()
{
QFETCH(int, hideRow);
QFETCH(int, hideColumn);
- QFETCH(IntList, disableRows);
- QFETCH(IntList, disableColumns);
+ QFETCH(const IntList, disableRows);
+ QFETCH(const IntList, disableColumns);
QFETCH(QRect, span);
QFETCH(int, startRow);
QFETCH(int, startColumn);
- QFETCH(IntList, cursorMoveActions);
+ QFETCH(const CursorActionList, cursorMoveActions);
QFETCH(int, expectedRow);
QFETCH(int, expectedColumn);
@@ -1344,15 +1282,15 @@ void tst_QTableView::moveCursorStrikesBack()
QModelIndex index = model.index(startRow, startColumn);
view.setCurrentIndex(index);
- foreach (int row, disableRows)
+ for (int row : disableRows)
model.disableRow(row);
- foreach (int column, disableColumns)
+ for (int column : disableColumns)
model.disableColumn(column);
int newRow = -1;
int newColumn = -1;
- foreach (int cursorMoveAction, cursorMoveActions) {
- QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0);
+ for (auto cursorMoveAction : cursorMoveActions) {
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, nullptr);
view.setCurrentIndex(newIndex);
newRow = newIndex.row();
newColumn = newIndex.column();
@@ -1523,7 +1461,7 @@ void tst_QTableView::selection_data()
QTest::addColumn<int>("y");
QTest::addColumn<int>("width");
QTest::addColumn<int>("height");
- QTest::addColumn<int>("command");
+ QTest::addColumn<QItemSelectionModel::SelectionFlag>("command");
QTest::addColumn<int>("selectedCount"); // ### make this more detailed
QTest::newRow("no span, no hidden, no moved, 3x3 select")
@@ -1535,7 +1473,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("row span, no hidden, no moved, 3x3 select")
@@ -1547,7 +1485,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 8; // selected count
QTest::newRow("col span, no hidden, no moved, 3x3 select")
@@ -1559,7 +1497,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 8; // selected count
QTest::newRow("no span, row hidden, no moved, 3x3 select")
@@ -1571,7 +1509,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, col hidden, no moved, 3x3 select")
@@ -1583,7 +1521,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, no hidden, row moved, 3x3 select")
@@ -1595,7 +1533,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, no hidden, col moved, 3x3 select")
@@ -1607,7 +1545,7 @@ void tst_QTableView::selection_data()
<< 1 << 3 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
}
@@ -1631,7 +1569,7 @@ void tst_QTableView::selection()
QFETCH(int, y);
QFETCH(int, width);
QFETCH(int, height);
- QFETCH(int, command);
+ QFETCH(QItemSelectionModel::SelectionFlag, command);
QFETCH(int, selectedCount);
QtTestTableModel model(rowCount, columnCount);
@@ -1653,8 +1591,7 @@ void tst_QTableView::selection()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- view.setSelection(QRect(x, y, width, height),
- QItemSelectionModel::SelectionFlags(command));
+ view.setSelection(QRect(x, y, width, height), command);
QCOMPARE(view.selectedIndexes().count(), selectedCount);
}
@@ -1664,92 +1601,92 @@ void tst_QTableView::selectRow_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("row");
- QTest::addColumn<int>("mode");
- QTest::addColumn<int>("behavior");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("mode");
+ QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior");
QTest::addColumn<int>("selectedItems");
QTest::newRow("SingleSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectItems
<< 0;
QTest::newRow("SingleSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("SingleSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("MultiSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("MultiSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("MultiSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("ExtendedSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ExtendedSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("ExtendedSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("ContiguousSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ContiguousSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("ContiguousSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectColumns
<< 0;
}
@@ -1758,16 +1695,16 @@ void tst_QTableView::selectRow()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, row);
- QFETCH(int, mode);
- QFETCH(int, behavior);
+ QFETCH(QAbstractItemView::SelectionMode, mode);
+ QFETCH(QAbstractItemView::SelectionBehavior, behavior);
QFETCH(int, selectedItems);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
view.setModel(&model);
- view.setSelectionMode((QAbstractItemView::SelectionMode)mode);
- view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior);
+ view.setSelectionMode(mode);
+ view.setSelectionBehavior(behavior);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
@@ -1785,92 +1722,92 @@ void tst_QTableView::selectColumn_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("column");
- QTest::addColumn<int>("mode");
- QTest::addColumn<int>("behavior");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("mode");
+ QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior");
QTest::addColumn<int>("selectedItems");
QTest::newRow("SingleSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectItems
<< 0;
QTest::newRow("SingleSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("SingleSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("MultiSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("MultiSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("MultiSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("ExtendedSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ExtendedSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("ExtendedSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("ContiguousSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ContiguousSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("ContiguousSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectColumns
<< 10;
}
@@ -1879,16 +1816,16 @@ void tst_QTableView::selectColumn()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, column);
- QFETCH(int, mode);
- QFETCH(int, behavior);
+ QFETCH(QAbstractItemView::SelectionMode, mode);
+ QFETCH(QAbstractItemView::SelectionBehavior, behavior);
QFETCH(int, selectedItems);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
view.setModel(&model);
- view.setSelectionMode((QAbstractItemView::SelectionMode)mode);
- view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior);
+ view.setSelectionMode(mode);
+ view.setSelectionBehavior(behavior);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
@@ -1988,9 +1925,9 @@ void tst_QTableView::selectall_data()
<< 100; // selected count
}
-void QTest__keySequence(QWidget* widget, QKeySequence ks)
+void QTest__keySequence(QWidget* widget, const QKeySequence &ks)
{
- for (int i=0; i<ks.count(); ++i)
+ for (int i = 0; i < ks.count(); ++i)
{
Qt::Key key = Qt::Key(ks[i] & ~Qt::KeyboardModifierMask);
Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(ks[i] & Qt::KeyboardModifierMask);
@@ -2228,7 +2165,7 @@ void tst_QTableView::resizeRowsToContents()
QFETCH(int, cellHeight);
QFETCH(int, rowHeight);
QFETCH(int, columnWidth);
- Q_UNUSED(columnWidth);
+ Q_UNUSED(columnWidth)
QtTestTableModel model(rowCount, columnCount);
QtTestTableView view;
@@ -2240,13 +2177,12 @@ void tst_QTableView::resizeRowsToContents()
delegate.hint = QSize(cellWidth, cellHeight);
- QSignalSpy resizedSpy(view.verticalHeader(), SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy resizedSpy(view.verticalHeader(), &QHeaderView::sectionResized);
view.resizeRowsToContents();
QCOMPARE(resizedSpy.count(), model.rowCount());
- for (int r = 0; r < model.rowCount(); ++r) {
+ for (int r = 0; r < model.rowCount(); ++r)
QCOMPARE(view.rowHeight(r), rowHeight);
- }
}
void tst_QTableView::resizeColumnsToContents_data()
@@ -2275,7 +2211,7 @@ void tst_QTableView::resizeColumnsToContents()
QFETCH(int, cellHeight);
QFETCH(int, rowHeight);
QFETCH(int, columnWidth);
- Q_UNUSED(rowHeight);
+ Q_UNUSED(rowHeight)
QtTestTableModel model(rowCount, columnCount);
QtTestTableView view;
@@ -2287,7 +2223,7 @@ void tst_QTableView::resizeColumnsToContents()
delegate.hint = QSize(cellWidth, cellHeight);
- QSignalSpy resizedSpy(view.horizontalHeader(), SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy resizedSpy(view.horizontalHeader(), &QHeaderView::sectionResized);
view.resizeColumnsToContents();
QCOMPARE(resizedSpy.count(), model.columnCount());
@@ -2300,51 +2236,51 @@ void tst_QTableView::rowViewportPosition_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("rowHeight");
QTest::addColumn<int>("row");
- QTest::addColumn<int>("verticalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
QTest::addColumn<int>("verticalScrollValue");
QTest::addColumn<int>("rowViewportPosition");
QTest::newRow("row 0, scroll per item 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0;
QTest::newRow("row 1, scroll per item, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40;
QTest::newRow("row 1, scroll per item, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0;
QTest::newRow("row 5, scroll per item, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40;
QTest::newRow("row 5, scroll per item, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0;
QTest::newRow("row 9, scroll per item, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40;
QTest::newRow("row 9, scroll per item, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40;
QTest::newRow("row 0, scroll per pixel 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0;
QTest::newRow("row 1, scroll per pixel, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40;
QTest::newRow("row 1, scroll per pixel, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0;
QTest::newRow("row 5, scroll per pixel, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40;
QTest::newRow("row 5, scroll per pixel, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0;
QTest::newRow("row 9, scroll per pixel, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40;
QTest::newRow("row 9, scroll per pixel, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40;
}
void tst_QTableView::rowViewportPosition()
@@ -2352,7 +2288,7 @@ void tst_QTableView::rowViewportPosition()
QFETCH(int, rowCount);
QFETCH(int, rowHeight);
QFETCH(int, row);
- QFETCH(int, verticalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(int, verticalScrollValue);
QFETCH(int, rowViewportPosition);
@@ -2366,7 +2302,7 @@ void tst_QTableView::rowViewportPosition()
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode);
+ view.setVerticalScrollMode(verticalScrollMode);
view.verticalScrollBar()->setValue(verticalScrollValue);
#ifdef Q_OS_WINRT
@@ -2471,51 +2407,51 @@ void tst_QTableView::columnViewportPosition_data()
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("columnWidth");
QTest::addColumn<int>("column");
- QTest::addColumn<int>("horizontalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<int>("horizontalScrollValue");
QTest::addColumn<int>("columnViewportPosition");
QTest::newRow("column 0, scroll per item 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0;
QTest::newRow("column 1, scroll per item, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40;
QTest::newRow("column 1, scroll per item, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0;
QTest::newRow("column 5, scroll per item, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40;
QTest::newRow("column 5, scroll per item, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0;
QTest::newRow("column 9, scroll per item, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40;
QTest::newRow("column 9, scroll per item, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40;
QTest::newRow("column 0, scroll per pixel 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0;
QTest::newRow("column 1, scroll per pixel 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40;
QTest::newRow("column 1, scroll per pixel 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0;
QTest::newRow("column 5, scroll per pixel 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40;
QTest::newRow("column 5, scroll per pixel 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0;
QTest::newRow("column 9, scroll per pixel 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40;
QTest::newRow("column 9, scroll per pixel 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40;
}
void tst_QTableView::columnViewportPosition()
@@ -2523,7 +2459,7 @@ void tst_QTableView::columnViewportPosition()
QFETCH(int, columnCount);
QFETCH(int, columnWidth);
QFETCH(int, column);
- QFETCH(int, horizontalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode);
QFETCH(int, horizontalScrollValue);
QFETCH(int, columnViewportPosition);
@@ -2537,7 +2473,7 @@ void tst_QTableView::columnViewportPosition()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode);
+ view.setHorizontalScrollMode(horizontalScrollMode);
view.horizontalScrollBar()->setValue(horizontalScrollValue);
#ifdef Q_OS_WINRT
@@ -2737,8 +2673,8 @@ void tst_QTableView::sortingEnabled()
void tst_QTableView::scrollTo_data()
{
- QTest::addColumn<int>("verticalScrollMode");
- QTest::addColumn<int>("horizontalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("rowHeight");
@@ -2751,51 +2687,51 @@ void tst_QTableView::scrollTo_data()
QTest::addColumn<int>("columnSpan");
QTest::addColumn<int>("horizontalScroll");
QTest::addColumn<int>("verticalScroll");
- QTest::addColumn<int>("scrollHint");
+ QTest::addColumn<QAbstractItemView::ScrollHint>("scrollHint");
QTest::addColumn<int>("expectedHorizontalScroll");
QTest::addColumn<int>("expectedVerticalScroll");
QTest::newRow("no hidden, no span, no scroll, per item")
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
<< 10 << 10 // table
<< 80 << 80 // size
<< -1 << -1 // hide
<< 0 << 0 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 0 << 0; // expected
QTest::newRow("no hidden, no span, no scroll, per pixel")
- << (int)QAbstractItemView::ScrollPerPixel
- << (int)QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
<< 10 << 10 // table
<< 80 << 80 // size
<< -1 << -1 // hide
<< 0 << 0 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 0 << 0; // expected
QTest::newRow("hidden, no span, no scroll, per item")
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
<< 10 << 10 // table
<< 80 << 80 // size
<< 3 << 3 // hide
<< 5 << 5 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 4 << 4; // expected
}
void tst_QTableView::scrollTo()
{
- QFETCH(int, horizontalScrollMode);
- QFETCH(int, verticalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, rowHeight);
@@ -2808,7 +2744,7 @@ void tst_QTableView::scrollTo()
QFETCH(int, columnSpan);
QFETCH(int, horizontalScroll);
QFETCH(int, verticalScroll);
- QFETCH(int, scrollHint);
+ QFETCH(QAbstractItemView::ScrollHint, scrollHint);
QFETCH(int, expectedHorizontalScroll);
QFETCH(int, expectedVerticalScroll);
@@ -2828,8 +2764,8 @@ void tst_QTableView::scrollTo()
view.setSpan(row, column, rowSpan, columnSpan);
view.hideRow(hiddenRow);
view.hideColumn(hiddenColumn);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode);
+ view.setHorizontalScrollMode(horizontalScrollMode);
+ view.setVerticalScrollMode(verticalScrollMode);
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
@@ -2841,7 +2777,7 @@ void tst_QTableView::scrollTo()
QModelIndex index = model.index(row, column);
QVERIFY(index.isValid());
- view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint);
+ view.scrollTo(index, scrollHint);
QTRY_COMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll);
QTRY_COMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll);
}
@@ -3146,8 +3082,6 @@ void tst_QTableView::span()
VERIFY_SPANS_CONSISTENCY(&view);
}
-typedef QVector<QRect> SpanList;
-
void tst_QTableView::spans_data()
{
QTest::addColumn<int>("rows");
@@ -3275,7 +3209,7 @@ void tst_QTableView::spans()
{
QFETCH(int, rows);
QFETCH(int, columns);
- QFETCH(SpanList, spans);
+ QFETCH(const SpanList, spans);
QFETCH(bool, hideRowLastRowOfFirstSpan);
QFETCH(QPoint, pos);
QFETCH(int, expectedRowSpan);
@@ -3287,10 +3221,8 @@ void tst_QTableView::spans()
view.setModel(&model);
view.show();
- for (int i = 0; i < spans.count(); ++i) {
- QRect sp = spans.at(i);
+ for (const auto &sp : spans)
view.setSpan(sp.x(), sp.y(), sp.width(), sp.height());
- }
if (hideRowLastRowOfFirstSpan) {
view.setRowHidden(spans.at(0).bottom(), true);
@@ -3384,32 +3316,34 @@ void tst_QTableView::spansAfterRowRemoval()
QtTestTableView view;
view.setModel(&model);
- QList<QRect> spans;
- spans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 2)
- << QRect(2, 2, 1, 5)
- << QRect(2, 8, 1, 2)
- << QRect(3, 4, 1, 2)
- << QRect(4, 4, 1, 4)
- << QRect(5, 6, 1, 3)
- << QRect(6, 7, 1, 3);
- foreach (QRect span, spans)
+ static const QRect spans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 2},
+ {2, 2, 1, 5},
+ {2, 8, 1, 2},
+ {3, 4, 1, 2},
+ {4, 4, 1, 4},
+ {5, 6, 1, 3},
+ {6, 7, 1, 3}
+ };
+ for (const QRect &span : spans)
view.setSpan(span.top(), span.left(), span.height(), span.width());
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
view.model()->removeRows(3, 3);
- QList<QRect> expectedSpans;
- expectedSpans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 1)
- << QRect(2, 2, 1, 2)
- << QRect(2, 5, 1, 2)
- << QRect(3, 4, 1, 1)
- << QRect(4, 3, 1, 2)
- << QRect(5, 3, 1, 3)
- << QRect(6, 4, 1, 3);
- foreach (QRect span, expectedSpans) {
+ static const QRect expectedSpans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 1},
+ {2, 2, 1, 2},
+ {2, 5, 1, 2},
+ {3, 4, 1, 1},
+ {4, 3, 1, 2},
+ {5, 3, 1, 3},
+ {6, 4, 1, 3}
+ };
+ for (const QRect &span : expectedSpans) {
QCOMPARE(view.columnSpan(span.top(), span.left()), span.width());
QCOMPARE(view.rowSpan(span.top(), span.left()), span.height());
}
@@ -3424,32 +3358,34 @@ void tst_QTableView::spansAfterColumnRemoval()
view.setModel(&model);
// Same set as above just swapping columns and rows.
- QList<QRect> spans;
- spans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 2)
- << QRect(2, 2, 1, 5)
- << QRect(2, 8, 1, 2)
- << QRect(3, 4, 1, 2)
- << QRect(4, 4, 1, 4)
- << QRect(5, 6, 1, 3)
- << QRect(6, 7, 1, 3);
- foreach (QRect span, spans)
- view.setSpan(span.left(), span.top(), span.width(), span.height());
+ static const QRect spans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 2},
+ {2, 2, 1, 5},
+ {2, 8, 1, 2},
+ {3, 4, 1, 2},
+ {4, 4, 1, 4},
+ {5, 6, 1, 3},
+ {6, 7, 1, 3}
+ };
+ for (const QRect &span : spans)
+ view.setSpan(span.left(), span.top(), span.width(), span.height());
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
view.model()->removeColumns(3, 3);
- QList<QRect> expectedSpans;
- expectedSpans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 1)
- << QRect(2, 2, 1, 2)
- << QRect(2, 5, 1, 2)
- << QRect(3, 4, 1, 1)
- << QRect(4, 3, 1, 2)
- << QRect(5, 3, 1, 3)
- << QRect(6, 4, 1, 3);
- foreach (QRect span, expectedSpans) {
+ static const QRect expectedSpans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 1},
+ {2, 2, 1, 2},
+ {2, 5, 1, 2},
+ {3, 4, 1, 1},
+ {4, 3, 1, 2},
+ {5, 3, 1, 3},
+ {6, 4, 1, 3}
+ };
+ for (const QRect &span : expectedSpans) {
QCOMPARE(view.columnSpan(span.left(), span.top()), span.height());
QCOMPARE(view.rowSpan(span.left(), span.top()), span.width());
}
@@ -3457,12 +3393,10 @@ void tst_QTableView::spansAfterColumnRemoval()
VERIFY_SPANS_CONSISTENCY(&view);
}
-Q_DECLARE_METATYPE(Qt::Key)
-
void tst_QTableView::editSpanFromDirections_data()
{
- QTest::addColumn<QList<Qt::Key> >("keyPresses");
- QTest::addColumn<QSharedPointer<QStandardItemModel> >("model");
+ QTest::addColumn<KeyList>("keyPresses");
+ QTest::addColumn<QSharedPointer<QStandardItemModel>>("model");
QTest::addColumn<int>("row");
QTest::addColumn<int>("column");
QTest::addColumn<int>("rowSpan");
@@ -3481,8 +3415,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+
| | ^ |
+---+---+ */
- QList<Qt::Key> keyPresses;
- keyPresses << Qt::Key_Right << Qt::Key_PageDown << Qt::Key_Up;
+ KeyList keyPresses {Qt::Key_Right, Qt::Key_PageDown, Qt::Key_Up};
QSharedPointer<QStandardItemModel> model(new QStandardItemModel(4, 2));
QTest::newRow("row span, bottom up")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@@ -3496,8 +3429,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+
| | |
+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_Right << Qt::Key_Down;
+ keyPresses = {Qt::Key_Right, Qt::Key_Down};
model = QSharedPointer<QStandardItemModel>::create(4, 2);
QTest::newRow("row span, top down")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@@ -3509,8 +3441,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+ +---+
| | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left;
+ keyPresses = {Qt::Key_End, Qt::Key_Down, Qt::Key_Left};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, right to left")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@@ -3522,8 +3453,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+ +---+
| > | c | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Right;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Right};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, left to right")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@@ -3535,8 +3465,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| ^ | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Up;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Up};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0);
@@ -3548,8 +3477,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| | ^ | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Right, Qt::Key_Up};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up #2")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0);
@@ -3561,8 +3489,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_End << Qt::Key_Down;
+ keyPresses = {Qt::Key_End, Qt::Key_Down};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, top down")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0);
@@ -3571,12 +3498,10 @@ void tst_QTableView::editSpanFromDirections_data()
class TableViewWithCursorExposed : public QTableView
{
public:
- TableViewWithCursorExposed() :
- QTableView() {
- }
+ using QTableView::QTableView;
-public:
- QModelIndex visualCursorIndex() {
+ QModelIndex visualCursorIndex()
+ {
QTableViewPrivate *d = static_cast<QTableViewPrivate*>(qt_widget_private(this));
return d->model->index(d->visualCursor.y(), d->visualCursor.x());
}
@@ -3584,7 +3509,7 @@ public:
void tst_QTableView::editSpanFromDirections()
{
- QFETCH(QList<Qt::Key>, keyPresses);
+ QFETCH(const KeyList, keyPresses);
QFETCH(QSharedPointer<QStandardItemModel>, model);
QFETCH(int, row);
QFETCH(int, column);
@@ -3602,9 +3527,8 @@ void tst_QTableView::editSpanFromDirections()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- foreach (Qt::Key key, keyPresses) {
+ for (Qt::Key key : keyPresses)
QTest::keyClick(&view, key);
- }
QCOMPARE(view.visualCursorIndex(), expectedVisualCursorIndex);
QCOMPARE(view.selectionModel()->currentIndex(), expectedEditedIndex);
@@ -3613,21 +3537,21 @@ void tst_QTableView::editSpanFromDirections()
QTRY_COMPARE(view.model()->data(expectedEditedIndex).toString(), QLatin1String("x"));
}
-class Model : public QAbstractTableModel {
-
-Q_OBJECT
-
+class Model : public QAbstractTableModel
+{
+ Q_OBJECT
public:
- Model(QObject * parent = 0) : QAbstractTableModel(parent) {
- }
+ using QAbstractTableModel::QAbstractTableModel;
- int rowCount(const QModelIndex &) const {
+ int rowCount(const QModelIndex &) const override
+ {
return rows;
}
- int columnCount(const QModelIndex &) const {
+ int columnCount(const QModelIndex &) const override
+ {
return columns;
}
- QVariant data(const QModelIndex &, int) const
+ QVariant data(const QModelIndex &, int) const override
{
return QVariant();
}
@@ -3637,8 +3561,8 @@ public:
endResetModel();
}
- int rows;
- int columns;
+ int rows = 0;
+ int columns = 0;
};
void tst_QTableView::checkHeaderReset()
@@ -3662,7 +3586,7 @@ void tst_QTableView::checkHeaderMinSize()
//viewport.
QTableView view;
QStringListModel m;
- m.setStringList( QStringList() << QLatin1String("one cell is enough"));
+ m.setStringList({QLatin1String("one cell is enough")});
view.setModel(&m);
//setting the minimum height on the horizontal header
@@ -3693,31 +3617,29 @@ void tst_QTableView::resizeToContents()
table2.verticalHeader()->setVisible(false);
- for(int i = 0;i<table.columnCount();i++) {
+ for (int i = 0; i < table.columnCount(); i++)
table.resizeColumnToContents(i);
- }
- for(int i = 0;i<table.rowCount();i++) {
+ for (int i = 0; i < table.rowCount(); i++)
table.resizeRowToContents(i);
- }
table2.resizeColumnsToContents();
table2.resizeRowsToContents();
table3.resizeColumnsToContents();
table3.resizeRowsToContents();
//now let's check the row/col sizes
- for(int i = 0;i<table.columnCount();i++) {
- QCOMPARE( table.columnWidth(i), table2.columnWidth(i));
- QCOMPARE( table2.columnWidth(i), table3.columnWidth(i));
+ for (int i = 0; i < table.columnCount(); i++) {
+ QCOMPARE(table.columnWidth(i), table2.columnWidth(i));
+ QCOMPARE(table2.columnWidth(i), table3.columnWidth(i));
}
- for(int i = 0;i<table.rowCount();i++) {
- QCOMPARE( table.rowHeight(i), table2.rowHeight(i));
- QCOMPARE( table2.rowHeight(i), table3.rowHeight(i));
+ for (int i = 0; i < table.rowCount(); i++) {
+ QCOMPARE(table.rowHeight(i), table2.rowHeight(i));
+ QCOMPARE(table2.rowHeight(i), table3.rowHeight(i));
}
}
QT_BEGIN_NAMESPACE
-extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // qapplication.cpp
+extern bool Q_WIDGETS_EXPORT qt_tab_all_widgets(); // qapplication.cpp
QT_END_NAMESPACE
void tst_QTableView::tabFocus()
@@ -3747,57 +3669,57 @@ void tst_QTableView::tabFocus()
for (int i = 0; i < 2; ++i) {
// tab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(!window.hasFocus());
QVERIFY(view->hasFocus());
QVERIFY(!edit->hasFocus());
// tab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
}
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- QStandardItemModel *model = new QStandardItemModel;
- view->setModel(model);
+ QStandardItemModel model;
+ view->setModel(&model);
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- model->insertRow(0, new QStandardItem("Hei"));
- model->insertRow(0, new QStandardItem("Hei"));
- model->insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit doesn't work
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QVERIFY(!window.hasFocus());
QVERIFY(view->hasFocus());
QVERIFY(!edit->hasFocus());
@@ -3805,41 +3727,38 @@ void tst_QTableView::tabFocus()
view->setTabKeyNavigation(false);
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(view->hasFocus());
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(edit->hasFocus());
-
- delete model;
}
class BigModel : public QAbstractTableModel
{
Q_OBJECT
public:
- virtual QVariant data(const QModelIndex &index,
- int role = Qt::DisplayRole) const
+ QVariant data(const QModelIndex &index,
+ int role = Qt::DisplayRole) const override
{
if (role == Qt::DisplayRole)
return QString::number(index.column()) + QLatin1String(" - ") + QString::number(index.row());
return QVariant();
}
-
- int rowCount(const QModelIndex & parent = QModelIndex()) const
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
- Q_UNUSED(parent);
+ Q_UNUSED(parent)
return 10000000;
}
- int columnCount(const QModelIndex & parent = QModelIndex()) const
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
- Q_UNUSED(parent);
+ Q_UNUSED(parent)
return 20000000;
}
};
@@ -3868,7 +3787,7 @@ void tst_QTableView::selectionSignal()
view.resize(200, 200);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center());
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(model.index(2, 0)).center());
}
void tst_QTableView::setCurrentIndex()
@@ -3894,14 +3813,14 @@ void tst_QTableView::setCurrentIndex()
class task173773_EventFilter : public QObject
{
- int paintEventCount_;
+ int paintEventCount_ = 0;
public:
- task173773_EventFilter() : paintEventCount_(0) {}
+ using QObject::QObject;
int paintEventCount() const { return paintEventCount_; }
private:
- bool eventFilter(QObject *obj, QEvent *e)
+ bool eventFilter(QObject *obj, QEvent *e) override
{
- Q_UNUSED(obj);
+ Q_UNUSED(obj)
if (e->type() == QEvent::Paint)
++paintEventCount_;
return false;
@@ -4030,25 +3949,25 @@ void tst_QTableView::task248688_autoScrollNavigation()
#if QT_CONFIG(wheelevent)
void tst_QTableView::mouseWheel_data()
{
- QTest::addColumn<int>("scrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("scrollMode");
QTest::addColumn<int>("delta");
QTest::addColumn<int>("horizontalPositon");
QTest::addColumn<int>("verticalPosition");
QTest::newRow("scroll up per item")
- << int(QAbstractItemView::ScrollPerItem) << 120
- << 10 - qApp->wheelScrollLines() << 10 - qApp->wheelScrollLines();
+ << QAbstractItemView::ScrollPerItem << 120
+ << 10 - QApplication::wheelScrollLines() << 10 - QApplication::wheelScrollLines();
QTest::newRow("scroll down per item")
- << int(QAbstractItemView::ScrollPerItem) << -120
- << 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines();
+ << QAbstractItemView::ScrollPerItem << -120
+ << 10 + QApplication::wheelScrollLines() << 10 + QApplication::wheelScrollLines();
QTest::newRow("scroll down per pixel")
- << int(QAbstractItemView::ScrollPerPixel) << -120
- << 10 + qApp->wheelScrollLines() * 91 << 10 + qApp->wheelScrollLines() * 46;
+ << QAbstractItemView::ScrollPerPixel << -120
+ << 10 + QApplication::wheelScrollLines() * 91 << 10 + QApplication::wheelScrollLines() * 46;
}
void tst_QTableView::mouseWheel()
{
- QFETCH(int, scrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, scrollMode);
QFETCH(int, delta);
QFETCH(int, horizontalPositon);
QFETCH(int, verticalPosition);
@@ -4068,8 +3987,8 @@ void tst_QTableView::mouseWheel()
for (int c = 0; c < 100; ++c)
view.setColumnWidth(c, 100);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode);
+ view.setHorizontalScrollMode(scrollMode);
+ view.setVerticalScrollMode(scrollMode);
view.horizontalScrollBar()->setValue(10);
view.verticalScrollBar()->setValue(10);
@@ -4168,15 +4087,15 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *vHeaderVp = vHeader->viewport();
QPoint rowPos(cellRect.center());
QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &rowPressEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &rowPressEvent);
for (int i = 0; i < 4; ++i) {
rowPos.setY(rowPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &moveEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &moveEvent);
}
QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &rowReleaseEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &rowReleaseEvent);
for (int i = 0; i < 4; ++i) {
QModelIndex index = model.index(3 + i, 0, table.rootIndex());
@@ -4190,15 +4109,15 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *hHeaderVp = hHeader->viewport();
QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5);
QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &colPressEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &colPressEvent);
for (int i = 0; i < 4; ++i) {
colPos.setX(colPos.x() + cellRect.width());
QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &moveEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &moveEvent);
}
QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &colReleaseEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &colReleaseEvent);
for (int i = 0; i < 4; ++i) {
QModelIndex index = model.index(0, 3 + i, table.rootIndex());
@@ -4211,22 +4130,23 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *tableVp = table.viewport();
QPoint cellPos = cellRect.center();
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellPressEvent);
+ QCoreApplication::sendEvent(tableVp, &cellPressEvent);
for (int i = 0; i < 6; ++i) {
cellPos.setX(cellPos.x() + cellRect.width());
cellPos.setY(cellPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &moveEvent);
+ QCoreApplication::sendEvent(tableVp, &moveEvent);
}
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellReleaseEvent);
+ QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
- for (int i = 0; i < 6; ++i)
+ for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
QModelIndex index = model.index(2 + i, 2 + j, table.rootIndex());
QVERIFY(table.selectionModel()->isSelected(index));
}
+ }
}
{
@@ -4234,23 +4154,24 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *tableVp = table.viewport();
QPoint cellPos = cellRect.center();
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellPressEvent);
+ QCoreApplication::sendEvent(tableVp, &cellPressEvent);
for (int i = 0; i < 6; ++i) {
cellPos.setX(cellPos.x() + cellRect.width());
cellPos.setY(cellPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &moveEvent);
+ QCoreApplication::sendEvent(tableVp, &moveEvent);
}
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellReleaseEvent);
+ QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
QTest::qWait(200);
- for (int i = 0; i < 6; ++i)
+ for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
QModelIndex index = model.index(3 + i, 3 + j, table.rootIndex());
QVERIFY(!table.selectionModel()->isSelected(index));
}
+ }
}
}
@@ -4328,8 +4249,6 @@ void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel()
QTest::mouseClick(&label, Qt::LeftButton);
QCOMPARE(view.currentIndex(), model.index(1,1));
-
-
}
@@ -4371,14 +4290,14 @@ void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader()
}
#endif
-class TestTableView : public QTableView {
-Q_OBJECT
+class TestTableView : public QTableView
+{
+ Q_OBJECT
public:
- TestTableView(QWidget *parent = 0) : QTableView(parent)
+ TestTableView(QWidget *parent = nullptr) : QTableView(parent)
{
- connect(this, SIGNAL(entered(QModelIndex)), this, SLOT(openEditor(QModelIndex)));
+ connect(this, &QTableView::entered, this, &TestTableView::openPersistentEditor);
}
- ~TestTableView(){}
public slots:
void onDataChanged()
{
@@ -4386,9 +4305,6 @@ public slots:
setRowHidden(i, model()->data(model()->index(i, 0)).toBool());
}
}
-
- void openEditor(const QModelIndex& index)
- { openPersistentEditor(index); }
};
@@ -4396,15 +4312,13 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
{
QStandardItemModel model;
model.insertColumn(0, QModelIndex());
- for(int i = 0; i < 20; i++)
- {
+ for (int i = 0; i < 20; i++)
model.insertRow(i);
- }
TestTableView w;
w.setMouseTracking(true);
w.setModel(&model);
- connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged()));
+ connect(&model, &QStandardItemModel::dataChanged, &w, &TestTableView::onDataChanged);
w.show();
QVERIFY(QTest::qWaitForWindowExposed(&w));
for (int i = 0; i < 10; i++)
@@ -4418,10 +4332,7 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
class TableView7774 : public QTableView
{
public:
- QRegion visualRegionForSelection(const QItemSelection &selection) const
- {
- return QTableView::visualRegionForSelection(selection);
- }
+ using QTableView::visualRegionForSelection;
};
void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection()
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index 6184962d93..f640996690 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -26,15 +26,12 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <qeventloop.h>
-#include <qlist.h>
-#include <qpair.h>
-#include <qheaderview.h>
-#include <qlineedit.h>
-
-#include <qtablewidget.h>
+#include <QHeaderView>
+#include <QLineEdit>
+#include <QMimeData>
+#include <QSignalSpy>
+#include <QTableWidget>
+#include <QTest>
class QObjectTableItem : public QObject, public QTableWidgetItem
{
@@ -46,11 +43,10 @@ class tst_QTableWidget : public QObject
Q_OBJECT
public:
- tst_QTableWidget();
+ using QObject::QObject;
private slots:
void initTestCase();
- void cleanupTestCase();
void init();
void getSetCheck();
void clear();
@@ -97,12 +93,12 @@ private slots:
#endif
private:
- QTableWidget *testWidget;
+ std::unique_ptr<QTableWidget> testWidget;
};
-typedef QPair<int, int> IntPair;
-typedef QList<int> IntList;
-typedef QList<IntPair> IntIntList;
+using IntPair = QPair<int, int>;
+using IntList = QVector<int>;
+using IntIntList = QVector<IntPair>;
Q_DECLARE_METATYPE(QTableWidgetSelectionRange)
@@ -143,45 +139,36 @@ void tst_QTableWidget::getSetCheck()
obj1.setItem(3, 3, new QTableWidgetItem("3,3"));
obj1.setCurrentItem(var3);
QCOMPARE(var3, obj1.currentItem());
- obj1.setCurrentItem((QTableWidgetItem *)0);
- QCOMPARE((QTableWidgetItem *)0, obj1.currentItem());
- obj1.setItem(0, 0, 0);
- QCOMPARE((QTableWidgetItem *)0, obj1.item(0, 0));
+ obj1.setCurrentItem(nullptr);
+ QCOMPARE(obj1.currentItem(), nullptr);
+ obj1.setItem(0, 0, nullptr);
+ QCOMPARE(obj1.item(0, 0), nullptr);
// const QTableWidgetItem * QTableWidget::itemPrototype()
// void QTableWidget::setItemPrototype(const QTableWidgetItem *)
const QTableWidgetItem *var4 = new QTableWidgetItem;
obj1.setItemPrototype(var4);
QCOMPARE(var4, obj1.itemPrototype());
- obj1.setItemPrototype((QTableWidgetItem *)0);
- QCOMPARE((const QTableWidgetItem *)0, obj1.itemPrototype());
-}
-
-tst_QTableWidget::tst_QTableWidget(): testWidget(0)
-{
+ obj1.setItemPrototype(nullptr);
+ QCOMPARE(obj1.itemPrototype(), nullptr);
}
void tst_QTableWidget::initTestCase()
{
- testWidget = new QTableWidget();
+ testWidget.reset(new QTableWidget);
testWidget->show();
QApplication::setKeyboardInputInterval(100);
}
-void tst_QTableWidget::cleanupTestCase()
-{
- delete testWidget;
-}
-
void tst_QTableWidget::init()
{
testWidget->clear();
testWidget->setRowCount(5);
testWidget->setColumnCount(5);
- for (int row=0; row < testWidget->rowCount(); ++row)
+ for (int row = 0; row < testWidget->rowCount(); ++row)
testWidget->showRow(row);
- for (int column=0; column < testWidget->columnCount(); ++column)
+ for (int column = 0; column < testWidget->columnCount(); ++column)
testWidget->showColumn(column);
}
@@ -319,13 +306,15 @@ void tst_QTableWidget::item()
QCOMPARE(testWidget->rowCount(), rowCount);
QCOMPARE(testWidget->columnCount(), columnCount);
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
+ }
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
+ }
QTableWidgetItem *item = testWidget->item(row, column);
QCOMPARE(!!item, expectItem);
@@ -361,15 +350,17 @@ void tst_QTableWidget::takeItem()
QCOMPARE(testWidget->rowCount(), rowCount);
QCOMPARE(testWidget->columnCount(), columnCount);
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
+ }
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
+ }
- QSignalSpy spy(testWidget, &QTableWidget::cellChanged);
+ QSignalSpy spy(testWidget.get(), &QTableWidget::cellChanged);
QTableWidgetItem *item = testWidget->takeItem(row, column);
QCOMPARE(!!item, expectItem);
if (expectItem) {
@@ -516,11 +507,11 @@ void tst_QTableWidget::selectedItems()
{
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(IntIntList, createItems);
- QFETCH(IntList, hiddenRows);
- QFETCH(IntList, hiddenColumns);
- QFETCH(QTableWidgetSelectionRange, selectionRange);
- QFETCH(IntIntList, expectedItems);
+ QFETCH(const IntIntList, createItems);
+ QFETCH(const IntList, hiddenRows);
+ QFETCH(const IntList, hiddenColumns);
+ QFETCH(const QTableWidgetSelectionRange, selectionRange);
+ QFETCH(const IntIntList, expectedItems);
// set dimensions and test they are ok
testWidget->setRowCount(rowCount);
@@ -529,15 +520,15 @@ void tst_QTableWidget::selectedItems()
QCOMPARE(testWidget->columnCount(), columnCount);
// create and set items
- foreach (IntPair intPair, createItems) {
+ for (const auto &intPair : createItems) {
testWidget->setItem(intPair.first, intPair.second,
new QTableWidgetItem(QString("Item %1 %2")
.arg(intPair.first).arg(intPair.second)));
}
// hide rows/columns
- foreach (int row, hiddenRows)
+ for (int row : hiddenRows)
testWidget->setRowHidden(row, true);
- foreach (int column, hiddenColumns)
+ for (int column : hiddenColumns)
testWidget->setColumnHidden(column, true);
// make sure we don't have any previous selections hanging around
@@ -557,31 +548,18 @@ void tst_QTableWidget::selectedItems()
}
// check that the correct number of items and the expected items are there
- QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
+ const QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
QCOMPARE(selectedItems.count(), expectedItems.count());
- foreach (IntPair intPair, expectedItems)
+ for (const auto &intPair : expectedItems)
QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second)));
// check that setItemSelected agrees with selectedItems
- for (int row = 0; row<testWidget->rowCount(); ++row) {
- bool hidden = false;
- foreach (int hiddenRow, hiddenRows){
- if(hiddenRow == row){
- hidden = true;
- break;
- }
- }
- if (hidden)
+ for (int row = 0; row < testWidget->rowCount(); ++row) {
+ if (hiddenRows.contains(row))
continue;
- for (int column = 0; column<testWidget->columnCount(); ++column) {
- foreach (int hiddenColumn, hiddenColumns){
- if(hiddenColumn == column){
- hidden = true;
- break;
- }
- }
- if (hidden)
+ for (int column = 0; column < testWidget->columnCount(); ++column) {
+ if (hiddenColumns.contains(column))
continue;
QTableWidgetItem *item = testWidget->item(row, column);
@@ -621,11 +599,13 @@ void tst_QTableWidget::removeRow()
QCOMPARE(testWidget->columnCount(), columnCount);
// fill table with items
- for (int r = 0; r < rowCount; ++r)
- for (int c = 0; c < columnCount; ++c)
+ for (int r = 0; r < rowCount; ++r) {
+ const QString rRow = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < columnCount; ++c) {
testWidget->setItem(r, c,
- new QTableWidgetItem(
- QString::number(r) + ":" + QString::number(c)));
+ new QTableWidgetItem(rRow + QString::number(c)));
+ }
+ }
// remove and compare the results
testWidget->removeRow(row);
@@ -633,14 +613,18 @@ void tst_QTableWidget::removeRow()
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
// check if the correct items were removed
- for (int r = 0; r < expectedRowCount; ++r)
- for (int c = 0; c < expectedColumnCount; ++c)
+ for (int r = 0; r < expectedRowCount; ++r) {
+ const QString rRow = QString::number(r < row ? r : r + 1) +
+ QLatin1Char(':');
+ for (int c = 0; c < expectedColumnCount; ++c) {
if (r < row)
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c));
+ rRow + QString::number(c));
else
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r + 1) + ":" + QString::number(c));
+ rRow + QString::number(c));
+ }
+ }
}
void tst_QTableWidget::removeColumn_data()
@@ -673,11 +657,14 @@ void tst_QTableWidget::removeColumn()
QCOMPARE(testWidget->columnCount(), columnCount);
// fill table with items
- for (int r = 0; r < rowCount; ++r)
- for (int c = 0; c < columnCount; ++c)
+ for (int r = 0; r < rowCount; ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < columnCount; ++c) {
testWidget->setItem(r, c,
new QTableWidgetItem(
- QString::number(r) + ":" + QString::number(c)));
+ rStr + QString::number(c)));
+ }
+ }
// remove and compare the results
testWidget->removeColumn(column);
@@ -686,14 +673,17 @@ void tst_QTableWidget::removeColumn()
// check if the correct items were removed
- for (int r = 0; r < expectedRowCount; ++r)
- for (int c = 0; c < expectedColumnCount; ++c)
+ for (int r = 0; r < expectedRowCount; ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < expectedColumnCount; ++c) {
if (c < column)
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c));
+ rStr + QString::number(c));
else
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c + 1));
+ rStr + QString::number(c + 1));
+ }
+ }
}
void tst_QTableWidget::insertRow_data()
@@ -819,7 +809,7 @@ void tst_QTableWidget::itemOwnership()
item = new QObjectTableItem();
testWidget->setItem(0, 0, item);
delete item;
- QCOMPARE(testWidget->item(0, 0), (QTableWidgetItem *)0);
+ QCOMPARE(testWidget->item(0, 0), nullptr);
//delete vertical headeritem from outside
headerItem = new QObjectTableItem();
@@ -887,7 +877,7 @@ void tst_QTableWidget::sortItems_data()
{
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<int>("sortColumn");
QTest::addColumn<QStringList>("initial");
QTest::addColumn<QStringList>("expected");
@@ -897,7 +887,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("ascending")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -915,7 +905,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("descending")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -933,154 +923,151 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("empty table")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< IntList()
<< IntList()
<< IntList();
-
QTest::newRow("half-empty table")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (IntList() << 0 << 2 << 1)
<< IntList()
<< IntList();
QTest::newRow("empty column, should not sort.")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 3
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< IntList()
<< IntList()
<< IntList();
QTest::newRow("descending with null cell, the null cell should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << "0" << "a" << "o" << "8" << "k"
- << 0 << "b" << "7" << "3" << "u")
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << "0" << "a" << "o" << "8" << "k"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 2 << 0 << 1)
<< IntList()
<< IntList();
QTest::newRow("ascending with null cell, the null cell should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "2" << "c" << "9" << "y" << "8"
- << "3" << "d" << "k" << "o" << "6"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "2" << "c" << "9" << "y" << "8"
+ << "3" << "d" << "k" << "o" << "6"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 0 << 2 << 1)
<< IntList()
<< IntList();
QTest::newRow("ascending with null cells, the null cells should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "3" << "d" << "k" << "o" << "6"
- << "0" << "a" << "o" << "8" << "k"
- << 0 << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "3" << "d" << "k" << "o" << "6"
+ << "0" << "a" << "o" << "8" << "k"
+ << QString() << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << 0 << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << QString() << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 1 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending... Check a bug in PersistentIndexes")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "3" << "c" << "9" << "y" << "8"
<< "2" << "b" << "7" << "3" << "u"
<< "4" << "d" << "k" << "o" << "6"
- << "1" << "a" << "o" << "8" << "k"
- )
+ << "1" << "a" << "o" << "8" << "k")
<< (QStringList()
<< "1" << "a" << "o" << "8" << "k"
<< "2" << "b" << "7" << "3" << "u"
<< "3" << "c" << "9" << "y" << "8"
- << "4" << "d" << "k" << "o" << "6"
- )
+ << "4" << "d" << "k" << "o" << "6")
<< (IntList() << 2 << 1 << 3 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending with some null cells inbetween")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << 0 << "a" << "o" << "8" << "k"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "d" << "k" << "o" << "6"
- << "1" << "b" << "7" << "3" << "u")
+ << QString() << "a" << "o" << "8" << "k"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "d" << "k" << "o" << "6"
+ << "1" << "b" << "7" << "3" << "u")
<< (QStringList()
- << "1" << "b" << "7" << "3" << "u"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "a" << "o" << "8" << "k"
- << 0 << "d" << "k" << "o" << "6")
+ << "1" << "b" << "7" << "3" << "u"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "a" << "o" << "8" << "k"
+ << QString() << "d" << "k" << "o" << "6")
<< (IntList() << 1 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending hidden")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -1098,7 +1085,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("descending hidden")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -1119,7 +1106,7 @@ void tst_QTableWidget::sortItems()
{
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(int, sortColumn);
QFETCH(QStringList, initial);
QFETCH(QStringList, expected);
@@ -1131,13 +1118,13 @@ void tst_QTableWidget::sortItems()
testWidget->setColumnCount(columnCount);
QAbstractItemModel *model = testWidget->model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
int ti = 0;
for (int r = 0; r < rowCount; ++r) {
for (int c = 0; c < columnCount; ++c) {
- QString str = initial.at(ti++);
- if (!str.isNull()) {
+ QString str = initial.at(ti++);
+ if (!str.isEmpty()) {
testWidget->setItem(r, c, new QTableWidgetItem(str));
}
}
@@ -1150,7 +1137,7 @@ void tst_QTableWidget::sortItems()
QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count());
- testWidget->sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
+ testWidget->sortItems(sortColumn, sortOrder);
int te = 0;
for (int i = 0; i < rows.count(); ++i) {
@@ -1175,7 +1162,7 @@ void tst_QTableWidget::setItemWithSorting_data()
{
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<int>("sortColumn");
QTest::addColumn<QStringList>("initialValues");
QTest::addColumn<int>("row");
@@ -1187,7 +1174,7 @@ void tst_QTableWidget::setItemWithSorting_data()
QTest::newRow("2x1 no change (ascending)")
<< 2 << 1
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList() << "0" << "1")
<< 1 << 0 << "2"
<< (QStringList() << "0" << "2")
@@ -1195,7 +1182,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x1 no change (descending)")
<< 2 << 1
- << static_cast<int>(Qt::DescendingOrder) << 0
+ << Qt::DescendingOrder << 0
<< (QStringList() << "1" << "0")
<< 0 << 0 << "2"
<< (QStringList() << "2" << "0")
@@ -1203,7 +1190,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x1 reorder (ascending)")
<< 2 << 1
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList() << "0" << "1")
<< 0 << 0 << "2"
<< (QStringList() << "1" << "2")
@@ -1211,7 +1198,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x1 reorder (descending)")
<< 2 << 1
- << static_cast<int>(Qt::DescendingOrder) << 0
+ << Qt::DescendingOrder << 0
<< (QStringList() << "1" << "0")
<< 1 << 0 << "2"
<< (QStringList() << "2" << "1")
@@ -1219,7 +1206,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 no change (ascending)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList()
<< "0" << "00"
<< "1" << "11")
@@ -1231,7 +1218,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x2 reorder (ascending)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList()
<< "0" << "00"
<< "1" << "11")
@@ -1243,7 +1230,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 reorder (ascending, sortColumn = 1)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 1
+ << Qt::AscendingOrder << 1
<< (QStringList()
<< "00" << "0"
<< "11" << "1")
@@ -1255,7 +1242,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 no change (column != sortColumn)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 1
+ << Qt::AscendingOrder << 1
<< (QStringList()
<< "00" << "0"
<< "11" << "1")
@@ -1267,7 +1254,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("8x4 reorder (ascending, sortColumn = 3)")
<< 8 << 4
- << static_cast<int>(Qt::AscendingOrder) << 3
+ << Qt::AscendingOrder << 3
<< (QStringList()
<< "q" << "v" << "u" << "0"
<< "e" << "j" << "i" << "10"
@@ -1293,9 +1280,13 @@ void tst_QTableWidget::setItemWithSorting_data()
void tst_QTableWidget::setItemWithSorting()
{
+ static int dummy1 = qRegisterMetaType<QList<QPersistentModelIndex>>();
+ static int dummy2 = qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
+ Q_UNUSED(dummy1);
+ Q_UNUSED(dummy2);
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(int, sortColumn);
QFETCH(QStringList, initialValues);
QFETCH(int, row);
@@ -1309,7 +1300,7 @@ void tst_QTableWidget::setItemWithSorting()
QTableWidget w(rowCount, columnCount);
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
int ti = 0;
for (int r = 0; r < rowCount; ++r) {
@@ -1320,11 +1311,11 @@ void tst_QTableWidget::setItemWithSorting()
persistent << model->index(r, sortColumn);
}
- w.sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
+ w.sortItems(sortColumn, sortOrder);
w.setSortingEnabled(true);
- QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
- QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
+ QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged);
+ QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged);
if (i == 0) {
// set a new item
@@ -1376,7 +1367,7 @@ public:
void tst_QTableWidget::itemData()
{
QTableWidgetDataChanged widget(2, 2);
- widget.setItem(0, 0, new QTableWidgetItem());
+ widget.setItem(0, 0, new QTableWidgetItem);
QTableWidgetItem *item = widget.item(0, 0);
QVERIFY(item);
item->setFlags(item->flags() | Qt::ItemIsEditable);
@@ -1399,7 +1390,7 @@ void tst_QTableWidget::setItemData()
{
QTableWidgetDataChanged table(10, 10);
table.setSortingEnabled(false);
- QSignalSpy dataChangedSpy(table.model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ QSignalSpy dataChangedSpy(table.model(), &QAbstractItemModel::dataChanged);
QTableWidgetItem *item = new QTableWidgetItem;
table.setItem(0, 0, item);
@@ -1432,11 +1423,11 @@ void tst_QTableWidget::cellWidget()
QTableWidget table(10, 10);
QWidget widget;
- QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
+ QCOMPARE(table.cellWidget(5, 5), nullptr);
table.setCellWidget(5, 5, &widget);
QCOMPARE(table.cellWidget(5, 5), &widget);
table.removeCellWidget(5, 5);
- QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
+ QCOMPARE(table.cellWidget(5, 5), nullptr);
}
void tst_QTableWidget::cellWidgetGeometry()
@@ -1463,27 +1454,29 @@ void tst_QTableWidget::cellWidgetGeometry()
void tst_QTableWidget::sizeHint_data()
{
- QTest::addColumn<int>("scrollBarPolicy");
+ QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy");
QTest::addColumn<QSize>("viewSize");
- QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize();
- QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize();
+ QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize();
+ QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize();
// make sure the scrollbars are shown by resizing the view to 40x40
- QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40);
- QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000);
+ QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40);
+ QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000);
}
void tst_QTableWidget::sizeHint()
{
- QFETCH(int, scrollBarPolicy);
+ QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy);
QFETCH(QSize, viewSize);
QTableWidget view(2, 2);
view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
- view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- for (int r = 0 ; r < view.rowCount(); ++r)
+ view.setVerticalScrollBarPolicy(scrollBarPolicy);
+ view.setHorizontalScrollBarPolicy(scrollBarPolicy);
+ for (int r = 0 ; r < view.rowCount(); ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char('/');
for (int c = 0 ; c < view.columnCount(); ++c)
- view.setItem(r, c, new QTableWidgetItem(QString("%1/%2").arg(r).arg(c)));
+ view.setItem(r, c, new QTableWidgetItem(rStr + QString::number(c)));
+ }
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -1520,7 +1513,7 @@ void tst_QTableWidget::task231094()
if (y == 1)
twi->setFlags(Qt::ItemIsEnabled);
else
- twi->setFlags(0);
+ twi->setFlags({});
tw.setItem(y, x, twi);
}
}
@@ -1558,15 +1551,15 @@ void tst_QTableWidget::task262056_sortDuplicate()
testWidget->setColumnCount(2);
testWidget->setRowCount(8);
testWidget->setSortingEnabled(true);
- QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\
- << "EEE" << "FFF" << "GGG");
- for (int i = 0; i<8; i++ ) {
+ const QStringList items({"AAA", "BBB", "CCC", "CCC", "DDD",
+ "EEE", "FFF", "GGG"});
+ for (int i = 0; i < 8; i++ ) {
QTableWidgetItem *twi = new QTableWidgetItem(items.at(i));
- testWidget->setItem(i,0,twi);
- testWidget->setItem(i,1,new QTableWidgetItem(QLatin1String("item ") + QString::number(i)));
+ testWidget->setItem(i, 0, twi);
+ testWidget->setItem(i, 1, new QTableWidgetItem(QLatin1String("item ") + QString::number(i)));
}
testWidget->sortItems(0, Qt::AscendingOrder);
- QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged()));
+ QSignalSpy layoutChangedSpy(testWidget->model(), &QAbstractItemModel::layoutChanged);
testWidget->item(3,0)->setBackground(Qt::red);
QCOMPARE(layoutChangedSpy.count(),0);
@@ -1586,18 +1579,14 @@ void tst_QTableWidget::itemWithHeaderItems()
QTableWidgetItem *item1_0 = new QTableWidgetItem(QTableWidgetItem::UserType);
table.setItem(1, 0, item1_0);
- QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0));
+ QCOMPARE(table.item(0, 1), nullptr);
}
class TestTableWidget : public QTableWidget
{
Q_OBJECT
public:
- TestTableWidget(int rows, int columns, QWidget *parent = 0)
- : QTableWidget(rows, columns, parent)
- {
- }
-
+ using QTableWidget::QTableWidget;
using QTableWidget::mimeData;
using QTableWidget::indexFromItem;
using QTableWidget::keyPressEvent;
@@ -1661,18 +1650,19 @@ void tst_QTableWidget::selectedRowAfterSorting()
{
TestTableWidget table(3,3);
table.setSelectionBehavior(QAbstractItemView::SelectRows);
- for (int r = 0; r < 3; r++)
+ for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
- table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0")));
+ }
QHeaderView *localHorizontalHeader = table.horizontalHeader();
localHorizontalHeader->setSortIndicator(1,Qt::DescendingOrder);
table.setProperty("sortingEnabled",true);
table.selectRow(1);
table.item(1,1)->setText("9");
QCOMPARE(table.selectedItems().count(),3);
- foreach (QTableWidgetItem *item, table.selectedItems()) {
- QCOMPARE(item->row(),0);
- }
+ const auto selectedItems = table.selectedItems();
+ for (QTableWidgetItem *item : selectedItems)
+ QCOMPARE(item->row(), 0);
}
void tst_QTableWidget::search()
@@ -1717,10 +1707,11 @@ void tst_QTableWidget::search()
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void tst_QTableWidget::clearItemData()
{
- QTableWidget table(3,3);
- for (int r = 0; r < 3; r++)
+ QTableWidget table(3, 3);
+ for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
- table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0")));
+ }
QSignalSpy dataChangeSpy(table.model(), &QAbstractItemModel::dataChanged);
QVERIFY(dataChangeSpy.isValid());
QVERIFY(!table.model()->clearItemData(QModelIndex()));