Skip to content

Commit 868a8ce

Browse files
committed
Merge #16674: refactor: remove obsolete qt algorithm usage
153d9dd refactor: replace qLowerBound & qUpperBound with std:: upper_bound & lower_bound (fanquake) 59373e3 refactor: replace qSort with std::sort (fanquake) fea33cb refactor: replace qStableSort with std::stable_sort (fanquake) Pull request description: `qStablesort`, `qSort`, `qLowerBound` and `qUpperBound` have been marked as obsolete since at least Qt 5.9: [Obsolete Members for QtAlgorithms](https://doc.qt.io/qt-5.9/qtalgorithms-obsolete.html). This pull request replaces their usage with the suggested `std::` replacements. This also removes some warning spam when compiling against newer Qt (5.13.0 via brew): ```bash CXX qt/libbitcoinqt_a-walletcontroller.o qt/transactiontablemodel.cpp:96:52: warning: 'qLowerBound<QList<TransactionRecord>::iterator, uint256, TxLessThan>' is deprecated: Use std::lower_bound [-Wdeprecated-declarations] QList<TransactionRecord>::iterator lower = qLowerBound( qt/transactiontablemodel.cpp:98:52: warning: 'qUpperBound<QList<TransactionRecord>::iterator, uint256, TxLessThan>' is deprecated: Use std::upper_bound [-Wdeprecated-declarations] QList<TransactionRecord>::iterator upper = qUpperBound( ``` ```bash CXX qt/libbitcoinqt_a-moc_walletcontroller.o qt/bantablemodel.cpp:64:13: warning: 'qStableSort<QList<CCombinedBan>::iterator, BannedNodeLessThan>' is deprecated: Use std::stable_sort [-Wdeprecated-declarations] qStableSort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder)); ``` ```bash CXX qt/libbitcoinqt_a-sendcoinsentry.o qt/recentrequeststablemodel.cpp:205:5: warning: 'qSort<QList<RecentRequestEntry>::iterator, RecentRequestEntryLessThan>' is deprecated: Use std::sort [-Wdeprecated-declarations] qSort(list.begin(), list.end(), RecentRequestEntryLessThan(column, order)); ``` ACKs for top commit: hebasto: ACK 153d9dd promag: ACK 153d9dd. jonasschnelli: utACK 153d9dd Tree-SHA512: 22f7290ed798ce8b0f5f313405377845d4c8e48dc8687be7464e27fff53363b451a40e9e18910a8c3b4b9d4dcc236a366c92e7d171fcb8576c48f149a1886c26
2 parents 6dfa9ef + 153d9dd commit 868a8ce

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <key_io.h>
1111
#include <wallet/wallet.h>
1212

13+
#include <algorithm>
14+
1315
#include <QFont>
1416
#include <QDebug>
1517

@@ -86,18 +88,18 @@ class AddressTablePriv
8688
QString::fromStdString(EncodeDestination(address.dest))));
8789
}
8890
}
89-
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order
91+
// std::lower_bound() and std::upper_bound() require our cachedAddressTable list to be sorted in asc order
9092
// Even though the map is already sorted this re-sorting step is needed because the originating map
9193
// is sorted by binary address, not by base58() address.
92-
qSort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
94+
std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
9395
}
9496

9597
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
9698
{
9799
// Find address / label in model
98-
QList<AddressTableEntry>::iterator lower = qLowerBound(
100+
QList<AddressTableEntry>::iterator lower = std::lower_bound(
99101
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
100-
QList<AddressTableEntry>::iterator upper = qUpperBound(
102+
QList<AddressTableEntry>::iterator upper = std::upper_bound(
101103
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
102104
int lowerIndex = (lower - cachedAddressTable.begin());
103105
int upperIndex = (upper - cachedAddressTable.begin());

src/qt/bantablemodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <sync.h>
1111
#include <util/time.h>
1212

13+
#include <algorithm>
14+
1315
#include <QDebug>
1416
#include <QList>
1517

@@ -61,7 +63,7 @@ class BanTablePriv
6163

6264
if (sortColumn >= 0)
6365
// sort cachedBanlist (use stable sort to prevent rows jumping around unnecessarily)
64-
qStableSort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder));
66+
std::stable_sort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder));
6567
}
6668

6769
int size() const

src/qt/peertablemodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <interfaces/node.h>
1212
#include <sync.h>
1313

14+
#include <algorithm>
15+
1416
#include <QDebug>
1517
#include <QList>
1618
#include <QTimer>
@@ -76,7 +78,7 @@ class PeerTablePriv
7678

7779
if (sortColumn >= 0)
7880
// sort cacheNodeStats (use stable sort to prevent rows jumping around unnecessarily)
79-
qStableSort(cachedNodeStats.begin(), cachedNodeStats.end(), NodeLessThan(sortColumn, sortOrder));
81+
std::stable_sort(cachedNodeStats.begin(), cachedNodeStats.end(), NodeLessThan(sortColumn, sortOrder));
8082

8183
// build index map
8284
mapNodeRows.clear();

src/qt/recentrequeststablemodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <clientversion.h>
1212
#include <streams.h>
1313

14+
#include <algorithm>
15+
1416

1517
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
1618
QAbstractTableModel(parent), walletModel(parent)
@@ -202,7 +204,7 @@ void RecentRequestsTableModel::addNewRequest(RecentRequestEntry &recipient)
202204

203205
void RecentRequestsTableModel::sort(int column, Qt::SortOrder order)
204206
{
205-
qSort(list.begin(), list.end(), RecentRequestEntryLessThan(column, order));
207+
std::sort(list.begin(), list.end(), RecentRequestEntryLessThan(column, order));
206208
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex()));
207209
}
208210

src/qt/transactiontablemodel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <interfaces/handler.h>
1818
#include <uint256.h>
1919

20+
#include <algorithm>
21+
2022
#include <QColor>
2123
#include <QDateTime>
2224
#include <QDebug>
@@ -93,9 +95,9 @@ class TransactionTablePriv
9395
qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status);
9496

9597
// Find bounds of this transaction in model
96-
QList<TransactionRecord>::iterator lower = qLowerBound(
98+
QList<TransactionRecord>::iterator lower = std::lower_bound(
9799
cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
98-
QList<TransactionRecord>::iterator upper = qUpperBound(
100+
QList<TransactionRecord>::iterator upper = std::upper_bound(
99101
cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
100102
int lowerIndex = (lower - cachedWallet.begin());
101103
int upperIndex = (upper - cachedWallet.begin());

0 commit comments

Comments
 (0)