Skip to content

Commit d64b338

Browse files
committed
qt, refactor: No need to implement index for non-hierarchical models
1 parent 616eace commit d64b338

10 files changed

+8
-63
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
196196
if(!index.isValid())
197197
return QVariant();
198198

199-
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
199+
const AddressTableEntry* rec{priv->index(index.row())};
200200

201201
if(role == Qt::DisplayRole || role == Qt::EditRole)
202202
{
@@ -242,7 +242,8 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
242242
{
243243
if(!index.isValid())
244244
return false;
245-
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
245+
246+
const AddressTableEntry* rec{priv->index(index.row())};
246247
std::string strPurpose = (rec->type == AddressTableEntry::Sending ? "send" : "receive");
247248
editStatus = OK;
248249

@@ -310,7 +311,7 @@ Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
310311
{
311312
if (!index.isValid()) return Qt::NoItemFlags;
312313

313-
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
314+
const AddressTableEntry* rec{priv->index(index.row())};
314315

315316
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
316317
// Can edit address and label for sending addresses,
@@ -323,20 +324,6 @@ Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
323324
return retval;
324325
}
325326

326-
QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const
327-
{
328-
Q_UNUSED(parent);
329-
AddressTableEntry *data = priv->index(row);
330-
if(data)
331-
{
332-
return createIndex(row, column, priv->index(row));
333-
}
334-
else
335-
{
336-
return QModelIndex();
337-
}
338-
}
339-
340327
void AddressTableModel::updateEntry(const QString &address,
341328
const QString &label, bool isMine, const QString &purpose, int status)
342329
{

src/qt/addresstablemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class AddressTableModel : public QAbstractTableModel
5757
QVariant data(const QModelIndex &index, int role) const override;
5858
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
5959
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
60-
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
6160
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
6261
Qt::ItemFlags flags(const QModelIndex &index) const override;
6362
/*@}*/

src/qt/bantablemodel.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
117117
if(!index.isValid())
118118
return QVariant();
119119

120-
CCombinedBan *rec = static_cast<CCombinedBan*>(index.internalPointer());
120+
const CCombinedBan* rec{priv->index(index.row())};
121121

122122
if (role == Qt::DisplayRole) {
123123
switch(index.column())
@@ -154,16 +154,6 @@ Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
154154
return retval;
155155
}
156156

157-
QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent) const
158-
{
159-
Q_UNUSED(parent);
160-
CCombinedBan *data = priv->index(row);
161-
162-
if (data)
163-
return createIndex(row, column, data);
164-
return QModelIndex();
165-
}
166-
167157
void BanTableModel::refresh()
168158
{
169159
Q_EMIT layoutAboutToBeChanged();

src/qt/bantablemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class BanTableModel : public QAbstractTableModel
6060
int columnCount(const QModelIndex &parent) const override;
6161
QVariant data(const QModelIndex &index, int role) const override;
6262
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
63-
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
6463
Qt::ItemFlags flags(const QModelIndex &index) const override;
6564
void sort(int column, Qt::SortOrder order) override;
6665
/*@}*/

src/qt/peertablemodel.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
153153
if(!index.isValid())
154154
return QVariant();
155155

156-
CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
156+
CNodeCombinedStats* rec{priv->index(index.row())};
157157

158158
if (role == Qt::DisplayRole) {
159159
switch(index.column())
@@ -215,16 +215,6 @@ Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
215215
return retval;
216216
}
217217

218-
QModelIndex PeerTableModel::index(int row, int column, const QModelIndex &parent) const
219-
{
220-
Q_UNUSED(parent);
221-
CNodeCombinedStats *data = priv->index(row);
222-
223-
if (data)
224-
return createIndex(row, column, data);
225-
return QModelIndex();
226-
}
227-
228218
void PeerTableModel::refresh()
229219
{
230220
Q_EMIT layoutAboutToBeChanged();

src/qt/peertablemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class PeerTableModel : public QAbstractTableModel
7777
int columnCount(const QModelIndex &parent) const override;
7878
QVariant data(const QModelIndex &index, int role) const override;
7979
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
80-
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
8180
Qt::ItemFlags flags(const QModelIndex &index) const override;
8281
void sort(int column, Qt::SortOrder order) override;
8382
/*@}*/

src/qt/recentrequeststablemodel.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@ QString RecentRequestsTableModel::getAmountTitle()
127127
return (this->walletModel->getOptionsModel() != nullptr) ? tr("Requested") + " ("+BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) + ")" : "";
128128
}
129129

130-
QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const
131-
{
132-
Q_UNUSED(parent);
133-
134-
return createIndex(row, column);
135-
}
136-
137130
bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex &parent)
138131
{
139132
Q_UNUSED(parent);

src/qt/recentrequeststablemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class RecentRequestsTableModel: public QAbstractTableModel
7070
QVariant data(const QModelIndex &index, int role) const override;
7171
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
7272
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
73-
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
7473
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
7574
Qt::ItemFlags flags(const QModelIndex &index) const override;
7675
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;

src/qt/transactiontablemodel.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
523523
{
524524
if(!index.isValid())
525525
return QVariant();
526-
TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
526+
527+
TransactionRecord* rec{priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), index.row())};
527528

528529
switch(role)
529530
{
@@ -690,17 +691,6 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
690691
return QVariant();
691692
}
692693

693-
QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const
694-
{
695-
Q_UNUSED(parent);
696-
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), row);
697-
if(data)
698-
{
699-
return createIndex(row, column, data);
700-
}
701-
return QModelIndex();
702-
}
703-
704694
void TransactionTableModel::updateDisplayUnit()
705695
{
706696
// emit dataChanged to update Amount column with the current unit

src/qt/transactiontablemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class TransactionTableModel : public QAbstractTableModel
8080
int columnCount(const QModelIndex &parent) const override;
8181
QVariant data(const QModelIndex &index, int role) const override;
8282
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
83-
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
8483
bool processingQueuedTransactions() const { return fProcessingQueuedTransactions; }
8584

8685
private:

0 commit comments

Comments
 (0)