Skip to content

Commit 7d1185c

Browse files
committed
[Model] * AddressTableModel supporting delegator and delegable addresses.
* AddressFilterProxy, method to change the type and invalidate the filter created.
1 parent c7753d4 commit 7d1185c

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

77
#include "addresstablemodel.h"
8+
#include "addressbook.h"
89

910
#include "guiutil.h"
1011
#include "walletmodel.h"
@@ -19,12 +20,14 @@
1920
const QString AddressTableModel::Send = "S";
2021
const QString AddressTableModel::Receive = "R";
2122
const QString AddressTableModel::Zerocoin = "X";
23+
const QString AddressTableModel::Delegators = "D";
2224

2325
struct AddressTableEntry {
2426
enum Type {
2527
Sending,
2628
Receiving,
2729
Zerocoin,
30+
Delegators,
2831
Hidden /* QSortFilterProxyModel will filter these out */
2932
};
3033

@@ -63,6 +66,9 @@ static AddressTableEntry::Type translateTransactionType(const QString& strPurpos
6366
addressType = AddressTableEntry::Sending;
6467
else if (strPurpose == "receive")
6568
addressType = AddressTableEntry::Receiving;
69+
else if (strPurpose == QString::fromStdString(CAddressBookData::AddressBookPurpose::DELEGATOR)
70+
|| strPurpose == QString::fromStdString(CAddressBookData::AddressBookPurpose::DELEGABLE))
71+
addressType = AddressTableEntry::Delegators;
6672
else if (strPurpose == "unknown" || strPurpose == "") // if purpose not set, guess
6773
addressType = (isMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending);
6874
return addressType;
@@ -76,6 +82,7 @@ class AddressTablePriv
7682
QList<AddressTableEntry> cachedAddressTable;
7783
int sendNum = 0;
7884
int recvNum = 0;
85+
int dellNum = 0;
7986
AddressTableModel* parent;
8087

8188
AddressTablePriv(CWallet* wallet, AddressTableModel* parent) : wallet(wallet), parent(parent) {}
@@ -96,8 +103,11 @@ class AddressTablePriv
96103
if(item.second.purpose == "receive"){
97104
creationTime = static_cast<uint>(wallet->GetKeyCreationTime(address));
98105
recvNum++;
99-
}else if(item.second.purpose == "send"){
106+
} else if(item.second.purpose == "send"){
100107
sendNum++;
108+
} else if (item.second.purpose == CAddressBookData::AddressBookPurpose::DELEGABLE
109+
|| item.second.purpose == CAddressBookData::AddressBookPurpose::DELEGATOR) {
110+
dellNum++;
101111
}
102112

103113
cachedAddressTable.append(
@@ -223,6 +233,10 @@ class AddressTablePriv
223233
return recvNum;
224234
}
225235

236+
int sizeDell(){
237+
return dellNum;
238+
}
239+
226240
AddressTableEntry* index(int idx)
227241
{
228242
if (idx >= 0 && idx < cachedAddressTable.size()) {
@@ -264,6 +278,10 @@ int AddressTableModel::sizeRecv() const{
264278
return priv->sizeRecv();
265279
}
266280

281+
int AddressTableModel::sizeDell() const {
282+
return priv->sizeDell();
283+
}
284+
267285
QVariant AddressTableModel::data(const QModelIndex& index, int role) const
268286
{
269287
if (!index.isValid())
@@ -292,12 +310,14 @@ QVariant AddressTableModel::data(const QModelIndex& index, int role) const
292310
return font;
293311
} else if (role == TypeRole) {
294312
switch (rec->type) {
295-
case AddressTableEntry::Sending:
296-
return Send;
297-
case AddressTableEntry::Receiving:
298-
return Receive;
299-
default:
300-
break;
313+
case AddressTableEntry::Sending:
314+
return Send;
315+
case AddressTableEntry::Receiving:
316+
return Receive;
317+
case AddressTableEntry::Delegators:
318+
return Delegators;
319+
default:
320+
break;
301321
}
302322
}
303323
return QVariant();

src/qt/addresstablemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ class AddressTableModel : public QAbstractTableModel
4848
static const QString Send; /**< Specifies send address */
4949
static const QString Receive; /**< Specifies receive address */
5050
static const QString Zerocoin; /**< Specifies stealth address */
51+
static const QString Delegators;
5152

5253
/** @name Methods overridden from QAbstractTableModel
5354
@{*/
5455
int rowCount(const QModelIndex& parent) const;
5556
int columnCount(const QModelIndex& parent) const;
5657
int sizeSend() const;
5758
int sizeRecv() const;
59+
int sizeDell() const;
5860
QVariant data(const QModelIndex& index, int role) const;
5961
bool setData(const QModelIndex& index, const QVariant& value, int role);
6062
QVariant headerData(int section, Qt::Orientation orientation, int role) const;

src/qt/pivx/addressfilterproxymodel.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "qt/pivx/addressfilterproxymodel.h"
6+
#include <iostream>
67

78
bool AddressFilterProxyModel::filterAcceptsRow(int row, const QModelIndex& parent) const
89
{
910
auto model = sourceModel();
1011
auto label = model->index(row, AddressTableModel::Label, parent);
1112

12-
if (model->data(label, AddressTableModel::TypeRole).toString() != m_type) {
13+
auto type = model->data(label, AddressTableModel::TypeRole).toString();
14+
if (type != m_type) {
15+
std::cout << "Type:" << type.toStdString() << "=" << m_type.toStdString() << std::endl;
1316
return false;
1417
}
1518

@@ -23,6 +26,12 @@ bool AddressFilterProxyModel::filterAcceptsRow(int row, const QModelIndex& paren
2326
return true;
2427
}
2528

29+
void AddressFilterProxyModel::setType(const QString& type)
30+
{
31+
this->m_type = type;
32+
invalidateFilter();
33+
}
34+
2635
int AddressFilterProxyModel::rowCount(const QModelIndex& parent) const
2736
{
2837
return QSortFilterProxyModel::rowCount(parent);

src/qt/pivx/addressfilterproxymodel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
class AddressFilterProxyModel final : public QSortFilterProxyModel
1313
{
14-
const QString m_type;
1514

1615
public:
1716
AddressFilterProxyModel(const QString& type, QObject* parent)
@@ -24,8 +23,13 @@ class AddressFilterProxyModel final : public QSortFilterProxyModel
2423

2524
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
2625

26+
void setType(const QString& type);
27+
2728
protected:
2829
bool filterAcceptsRow(int row, const QModelIndex& parent) const override;
30+
31+
private:
32+
QString m_type;
2933
};
3034

3135

0 commit comments

Comments
 (0)