Skip to content

Commit

Permalink
qt, refactor: No need to implement index for non-hierarchical models
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jan 2, 2021
1 parent ae8f797 commit 199830f
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 63 deletions.
21 changes: 4 additions & 17 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
if(!index.isValid())
return QVariant();

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

if(role == Qt::DisplayRole || role == Qt::EditRole)
{
Expand Down Expand Up @@ -238,7 +238,8 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
{
if(!index.isValid())
return false;
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());

const AddressTableEntry* rec{priv->index(index.row())};
std::string strPurpose = (rec->type == AddressTableEntry::Sending ? "send" : "receive");
editStatus = OK;

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

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

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

QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
AddressTableEntry *data = priv->index(row);
if(data)
{
return createIndex(row, column, priv->index(row));
}
else
{
return QModelIndex();
}
}

void AddressTableModel::updateEntry(const QString &address,
const QString &label, bool isMine, const QString &purpose, int status)
{
Expand Down
1 change: 0 additions & 1 deletion src/qt/addresstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class AddressTableModel : public QAbstractTableModel
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
/*@}*/
Expand Down
12 changes: 1 addition & 11 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
if(!index.isValid())
return QVariant();

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

if (role == Qt::DisplayRole) {
switch(index.column())
Expand Down Expand Up @@ -150,16 +150,6 @@ Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const
return retval;
}

QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
CCombinedBan *data = priv->index(row);

if (data)
return createIndex(row, column, data);
return QModelIndex();
}

void BanTableModel::refresh()
{
Q_EMIT layoutAboutToBeChanged();
Expand Down
1 change: 0 additions & 1 deletion src/qt/bantablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class BanTableModel : public QAbstractTableModel
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
void sort(int column, Qt::SortOrder order) override;
/*@}*/
Expand Down
12 changes: 1 addition & 11 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
if(!index.isValid())
return QVariant();

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

if (role == Qt::DisplayRole) {
switch(index.column())
Expand Down Expand Up @@ -206,16 +206,6 @@ Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const
return retval;
}

QModelIndex PeerTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
CNodeCombinedStats *data = priv->index(row);

if (data)
return createIndex(row, column, data);
return QModelIndex();
}

const CNodeCombinedStats *PeerTableModel::getNodeStats(int idx)
{
return priv->index(idx);
Expand Down
1 change: 0 additions & 1 deletion src/qt/peertablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class PeerTableModel : public QAbstractTableModel
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
void sort(int column, Qt::SortOrder order) override;
/*@}*/
Expand Down
7 changes: 0 additions & 7 deletions src/qt/recentrequeststablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ QString RecentRequestsTableModel::getAmountTitle()
return (this->walletModel->getOptionsModel() != nullptr) ? tr("Requested") + " ("+BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) + ")" : "";
}

QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);

return createIndex(row, column);
}

bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
Q_UNUSED(parent);
Expand Down
1 change: 0 additions & 1 deletion src/qt/recentrequeststablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class RecentRequestsTableModel: public QAbstractTableModel
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
Expand Down
14 changes: 2 additions & 12 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());

TransactionRecord* rec{priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), index.row())};

switch(role)
{
Expand Down Expand Up @@ -686,17 +687,6 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
return QVariant();
}

QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), row);
if(data)
{
return createIndex(row, column, data);
}
return QModelIndex();
}

void TransactionTableModel::updateDisplayUnit()
{
// emit dataChanged to update Amount column with the current unit
Expand Down
1 change: 0 additions & 1 deletion src/qt/transactiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class TransactionTableModel : public QAbstractTableModel
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
bool processingQueuedTransactions() const { return fProcessingQueuedTransactions; }

private:
Expand Down

0 comments on commit 199830f

Please sign in to comment.