Skip to content

Commit 199830f

Browse files
committed
qt, refactor: No need to implement index for non-hierarchical models
1 parent ae8f797 commit 199830f

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
@@ -192,7 +192,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
192192
if(!index.isValid())
193193
return QVariant();
194194

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

197197
if(role == Qt::DisplayRole || role == Qt::EditRole)
198198
{
@@ -238,7 +238,8 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
238238
{
239239
if(!index.isValid())
240240
return false;
241-
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
241+
242+
const AddressTableEntry* rec{priv->index(index.row())};
242243
std::string strPurpose = (rec->type == AddressTableEntry::Sending ? "send" : "receive");
243244
editStatus = OK;
244245

@@ -306,7 +307,7 @@ Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
306307
{
307308
if (!index.isValid()) return Qt::NoItemFlags;
308309

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

311312
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
312313
// Can edit address and label for sending addresses,
@@ -319,20 +320,6 @@ Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
319320
return retval;
320321
}
321322

322-
QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const
323-
{
324-
Q_UNUSED(parent);
325-
AddressTableEntry *data = priv->index(row);
326-
if(data)
327-
{
328-
return createIndex(row, column, priv->index(row));
329-
}
330-
else
331-
{
332-
return QModelIndex();
333-
}
334-
}
335-
336323
void AddressTableModel::updateEntry(const QString &address,
337324
const QString &label, bool isMine, const QString &purpose, int status)
338325
{

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
@@ -113,7 +113,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
113113
if(!index.isValid())
114114
return QVariant();
115115

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

118118
if (role == Qt::DisplayRole) {
119119
switch(index.column())
@@ -150,16 +150,6 @@ Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
150150
return retval;
151151
}
152152

153-
QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent) const
154-
{
155-
Q_UNUSED(parent);
156-
CCombinedBan *data = priv->index(row);
157-
158-
if (data)
159-
return createIndex(row, column, data);
160-
return QModelIndex();
161-
}
162-
163153
void BanTableModel::refresh()
164154
{
165155
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
@@ -149,7 +149,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
149149
if(!index.isValid())
150150
return QVariant();
151151

152-
CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
152+
const CNodeCombinedStats* rec{priv->index(index.row())};
153153

154154
if (role == Qt::DisplayRole) {
155155
switch(index.column())
@@ -206,16 +206,6 @@ Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
206206
return retval;
207207
}
208208

209-
QModelIndex PeerTableModel::index(int row, int column, const QModelIndex &parent) const
210-
{
211-
Q_UNUSED(parent);
212-
CNodeCombinedStats *data = priv->index(row);
213-
214-
if (data)
215-
return createIndex(row, column, data);
216-
return QModelIndex();
217-
}
218-
219209
const CNodeCombinedStats *PeerTableModel::getNodeStats(int idx)
220210
{
221211
return priv->index(idx);

src/qt/peertablemodel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class PeerTableModel : public QAbstractTableModel
7373
int columnCount(const QModelIndex &parent) const override;
7474
QVariant data(const QModelIndex &index, int role) const override;
7575
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
76-
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
7776
Qt::ItemFlags flags(const QModelIndex &index) const override;
7877
void sort(int column, Qt::SortOrder order) override;
7978
/*@}*/

src/qt/recentrequeststablemodel.cpp

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

128-
QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const
129-
{
130-
Q_UNUSED(parent);
131-
132-
return createIndex(row, column);
133-
}
134-
135128
bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex &parent)
136129
{
137130
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
@@ -519,7 +519,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
519519
{
520520
if(!index.isValid())
521521
return QVariant();
522-
TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
522+
523+
TransactionRecord* rec{priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), index.row())};
523524

524525
switch(role)
525526
{
@@ -686,17 +687,6 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
686687
return QVariant();
687688
}
688689

689-
QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const
690-
{
691-
Q_UNUSED(parent);
692-
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), row);
693-
if(data)
694-
{
695-
return createIndex(row, column, data);
696-
}
697-
return QModelIndex();
698-
}
699-
700690
void TransactionTableModel::updateDisplayUnit()
701691
{
702692
// 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)