receive: add option to show change addresses

This commit is contained in:
tobtoht 2023-06-27 15:21:46 +02:00
parent fa33172760
commit 906bd164e4
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
5 changed files with 30 additions and 7 deletions

View file

@ -44,6 +44,8 @@ ReceiveWidget::ReceiveWidget(Wallet *wallet, QWidget *parent)
m_headerMenu = new QMenu(this); m_headerMenu = new QMenu(this);
m_showFullAddressesAction = m_headerMenu->addAction("Show full addresses", this, &ReceiveWidget::setShowFullAddresses); m_showFullAddressesAction = m_headerMenu->addAction("Show full addresses", this, &ReceiveWidget::setShowFullAddresses);
m_showFullAddressesAction->setCheckable(true); m_showFullAddressesAction->setCheckable(true);
m_showChangeAddressesAction = m_headerMenu->addAction("Show change addresses", this, &ReceiveWidget::setShowChangeAddresses);
m_showChangeAddressesAction->setCheckable(true);
connect(ui->addresses->header(), &QHeaderView::customContextMenuRequested, this, &ReceiveWidget::showHeaderMenu); connect(ui->addresses->header(), &QHeaderView::customContextMenuRequested, this, &ReceiveWidget::showHeaderMenu);
// context menu // context menu
@ -141,6 +143,11 @@ void ReceiveWidget::onShowTransactions() {
emit showTransactions(address); emit showTransactions(address);
} }
void ReceiveWidget::setShowChangeAddresses(bool show) {
if (!m_proxyModel) return;
m_proxyModel->setShowChangeAddresses(show);
}
void ReceiveWidget::setShowFullAddresses(bool show) { void ReceiveWidget::setShowFullAddresses(bool show) {
if (!m_model) return; if (!m_model) return;
m_model->setShowFullAddresses(show); m_model->setShowFullAddresses(show);

View file

@ -35,6 +35,7 @@ public slots:
void editLabel(); void editLabel();
void showContextMenu(const QPoint& point); void showContextMenu(const QPoint& point);
void setShowFullAddresses(bool show); void setShowFullAddresses(bool show);
void setShowChangeAddresses(bool show);
void setShowUsedAddresses(bool show); void setShowUsedAddresses(bool show);
void setShowHiddenAddresses(bool show); void setShowHiddenAddresses(bool show);
void setSearchFilter(const QString &filter); void setSearchFilter(const QString &filter);
@ -57,6 +58,7 @@ private:
QMenu *m_headerMenu; QMenu *m_headerMenu;
QAction *m_showFullAddressesAction; QAction *m_showFullAddressesAction;
QAction *m_showTransactionsAction; QAction *m_showTransactionsAction;
QAction *m_showChangeAddressesAction;
SubaddressModel *m_model; SubaddressModel *m_model;
SubaddressProxyModel *m_proxyModel; SubaddressProxyModel *m_proxyModel;

View file

@ -110,7 +110,15 @@ QVariant SubaddressModel::parseSubaddressRow(const Monero::SubaddressRow &subadd
return address; return address;
} }
case Label: case Label:
return index.row() == 0 ? tr("Primary address") : QString::fromStdString(subaddress.getLabel()); {
if (m_currentSubaddressAccount == 0 && index.row() == 0) {
return "Primary address";
}
else if (index.row() == 0) {
return "Change";
}
return QString::fromStdString(subaddress.getLabel());
}
case isUsed: case isUsed:
return subaddress.isUsed(); return subaddress.isUsed();
default: default:

View file

@ -3,12 +3,12 @@
#include "SubaddressProxyModel.h" #include "SubaddressProxyModel.h"
SubaddressProxyModel::SubaddressProxyModel(QObject *parent, Subaddress *subaddress, bool hidePrimary) SubaddressProxyModel::SubaddressProxyModel(QObject *parent, Subaddress *subaddress, bool showChange)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
, m_subaddress(subaddress) , m_subaddress(subaddress)
, m_searchRegExp("") , m_searchRegExp("")
, m_searchCaseSensitiveRegExp("") , m_searchCaseSensitiveRegExp("")
, m_hidePrimary(hidePrimary) , m_showChange(showChange)
{ {
m_searchRegExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption); m_searchRegExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
} }
@ -23,9 +23,10 @@ bool SubaddressProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so
label = QString::fromStdString(subaddress.getLabel()); label = QString::fromStdString(subaddress.getLabel());
}); });
// Hide primary address // Hide primary/change addresses
if (sourceRow == 0 && m_hidePrimary) if (!m_showChange && sourceRow == 0) {
return false; return false;
}
if (!m_showHidden && m_hiddenAddresses.contains(address)) { if (!m_showHidden && m_hiddenAddresses.contains(address)) {
return false; return false;

View file

@ -12,7 +12,7 @@ class SubaddressProxyModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SubaddressProxyModel(QObject* parent, Subaddress *subaddress, bool hidePrimary = true); explicit SubaddressProxyModel(QObject* parent, Subaddress *subaddress, bool hidePrimary = false);
bool filterAcceptsRow(int sourceRow, bool filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const; const QModelIndex &sourceParent) const;
@ -38,6 +38,11 @@ public slots:
invalidateFilter(); invalidateFilter();
} }
void setShowChangeAddresses(const bool showChange) {
m_showChange = showChange;
invalidateFilter();
}
private: private:
Subaddress *m_subaddress; Subaddress *m_subaddress;
@ -46,7 +51,7 @@ private:
QRegularExpression m_searchCaseSensitiveRegExp; QRegularExpression m_searchCaseSensitiveRegExp;
bool m_showUsed = false; bool m_showUsed = false;
bool m_showHidden = false; bool m_showHidden = false;
bool m_hidePrimary; bool m_showChange = false;
}; };
#endif //FEATHER_SUBADDRESSPROXYMODEL_H #endif //FEATHER_SUBADDRESSPROXYMODEL_H