diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-10-11 22:48:29 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-10-12 09:07:54 +0200 |
commit | 9a772306854bf0ca2f0c16699744136530656f43 (patch) | |
tree | 579fddf949e8371a6a546c08161c6b62f05d5840 | |
parent | 9684764bda49b7dee07ff6cd1d919ccee5631153 (diff) | |
download | qtbase-9a772306854bf0ca2f0c16699744136530656f43.tar.gz |
QTableWidgetSelectionRange: Make it possible to compare for equality
Add operators as hidden friends, add test case to make sure that
basic value-type operations are possible with this type.
Task-number: QTBUG-255
Change-Id: I7fbf453aa16084c0b2a0079487cacb4e092ff664
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/widgets/itemviews/qtablewidget.cpp | 14 | ||||
-rw-r--r-- | src/widgets/itemviews/qtablewidget.h | 8 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp | 14 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index 5072cc9240..5c3d3385da 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -919,6 +919,20 @@ Qt::DropActions QTableModel::supportedDropActions() const */ /*! + \fn bool QTableWidgetSelectionRange::operator==(const QTableWidgetSelectionRange &lhs, const QTableWidgetSelectionRange &rhs) + \since 6.3 + + Returns true if \a lhs and \a rhs are equal, otherwise returns false. +*/ + +/*! + \fn bool QTableWidgetSelectionRange::operator!=(const QTableWidgetSelectionRange &lhs, const QTableWidgetSelectionRange &rhs) + \since 6.3 + + Returns true if \a lhs and \a rhs are not equal, otherwise returns false. +*/ + +/*! \fn int QTableWidgetSelectionRange::topRow() const Returns the top row of the range. diff --git a/src/widgets/itemviews/qtablewidget.h b/src/widgets/itemviews/qtablewidget.h index 8f3a36daf1..3978bc23d6 100644 --- a/src/widgets/itemviews/qtablewidget.h +++ b/src/widgets/itemviews/qtablewidget.h @@ -57,6 +57,14 @@ public: : m_top(top), m_left(left), m_bottom(bottom), m_right(right) {} + friend inline bool operator==(const QTableWidgetSelectionRange &lhs, + const QTableWidgetSelectionRange &rhs) + { return lhs.m_top == rhs.m_top && lhs.m_left == rhs.m_left + && lhs.m_bottom == rhs.m_bottom && lhs.m_right == rhs.m_right; }; + friend inline bool operator!=(const QTableWidgetSelectionRange &lhs, + const QTableWidgetSelectionRange &rhs) + { return !(lhs == rhs); } + inline int topRow() const { return m_top; } inline int bottomRow() const { return m_bottom; } inline int leftColumn() const { return m_left; } diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index b827d87910..23e69b2190 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -49,6 +49,7 @@ private slots: void initTestCase(); void init(); void getSetCheck(); + void selectionRange(); void clear(); void clearContents(); void rowCount(); @@ -155,6 +156,19 @@ void tst_QTableWidget::getSetCheck() QCOMPARE(obj1.itemPrototype(), nullptr); } +void tst_QTableWidget::selectionRange() +{ + QTableWidgetSelectionRange defaultSelection; + QTableWidgetSelectionRange selection(1, 2, 3, 4); + + QTableWidgetSelectionRange copy(selection); + QCOMPARE(copy, selection); + QVERIFY(copy != defaultSelection); + + defaultSelection = copy; + QCOMPARE(defaultSelection, copy); +} + void tst_QTableWidget::initTestCase() { testWidget.reset(new QTableWidget); |