Skip to content

Commit 4b8b71e

Browse files
author
MarcoFalke
committed
Merge bitcoin-core#173: Follow Qt docs when implementing rowCount and columnCount
195fcb5 qt: Follow Qt docs when implementing rowCount and columnCount (Hennadii Stepanov) Pull request description: [`QAbstractItemModel::rowCount`](https://doc.qt.io/qt-5/qabstractitemmodel.html#rowCount): > **Note:** When implementing a table based model, `rowCount()` should return 0 when the parent is valid. [`QAbstractItemModel::columnCount`](https://doc.qt.io/qt-5/qabstractitemmodel.html#columnCount): > **Note:** When implementing a table based model, `columnCount()` should return 0 when the parent is valid. ACKs for top commit: jarolrod: Tested ACK 195fcb5. Compiled and ran on macOS (Big Sur 11.1 and Catalina 10.15.7), Arch Linux, and FreeBSD. visually verified no weird effects with the `Address`, `Ban`, `Peer`, and `Transaction` tables. As already stated, the code change brings us inline with what the QT Docs recommend. Tree-SHA512: 179a3430e68e77b22cdf642964cd96c023a2286ee256bbeb25b43df3d2eef6f59978c8d92173c6be5071d127fdcd6aa338142f6eaf003ff08e4abd65172d20ca
2 parents 42675e7 + 195fcb5 commit 4b8b71e

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,17 @@ AddressTableModel::~AddressTableModel()
177177

178178
int AddressTableModel::rowCount(const QModelIndex &parent) const
179179
{
180-
Q_UNUSED(parent);
180+
if (parent.isValid()) {
181+
return 0;
182+
}
181183
return priv->size();
182184
}
183185

184186
int AddressTableModel::columnCount(const QModelIndex &parent) const
185187
{
186-
Q_UNUSED(parent);
188+
if (parent.isValid()) {
189+
return 0;
190+
}
187191
return columns.length();
188192
}
189193

src/qt/bantablemodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ BanTableModel::~BanTableModel()
9898

9999
int BanTableModel::rowCount(const QModelIndex &parent) const
100100
{
101-
Q_UNUSED(parent);
101+
if (parent.isValid()) {
102+
return 0;
103+
}
102104
return priv->size();
103105
}
104106

105107
int BanTableModel::columnCount(const QModelIndex &parent) const
106108
{
107-
Q_UNUSED(parent);
109+
if (parent.isValid()) {
110+
return 0;
111+
}
108112
return columns.length();
109113
}
110114

src/qt/peertablemodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,17 @@ void PeerTableModel::stopAutoRefresh()
134134

135135
int PeerTableModel::rowCount(const QModelIndex &parent) const
136136
{
137-
Q_UNUSED(parent);
137+
if (parent.isValid()) {
138+
return 0;
139+
}
138140
return priv->size();
139141
}
140142

141143
int PeerTableModel::columnCount(const QModelIndex &parent) const
142144
{
143-
Q_UNUSED(parent);
145+
if (parent.isValid()) {
146+
return 0;
147+
}
144148
return columns.length();
145149
}
146150

src/qt/recentrequeststablemodel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ RecentRequestsTableModel::~RecentRequestsTableModel()
3636

3737
int RecentRequestsTableModel::rowCount(const QModelIndex &parent) const
3838
{
39-
Q_UNUSED(parent);
40-
39+
if (parent.isValid()) {
40+
return 0;
41+
}
4142
return list.length();
4243
}
4344

4445
int RecentRequestsTableModel::columnCount(const QModelIndex &parent) const
4546
{
46-
Q_UNUSED(parent);
47-
47+
if (parent.isValid()) {
48+
return 0;
49+
}
4850
return columns.length();
4951
}
5052

src/qt/transactiontablemodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,17 @@ void TransactionTableModel::updateConfirmations()
289289

290290
int TransactionTableModel::rowCount(const QModelIndex &parent) const
291291
{
292-
Q_UNUSED(parent);
292+
if (parent.isValid()) {
293+
return 0;
294+
}
293295
return priv->size();
294296
}
295297

296298
int TransactionTableModel::columnCount(const QModelIndex &parent) const
297299
{
298-
Q_UNUSED(parent);
300+
if (parent.isValid()) {
301+
return 0;
302+
}
299303
return columns.length();
300304
}
301305

0 commit comments

Comments
 (0)