Files
pay/WalletCoinsModel.h
T

76 lines
2.2 KiB
C++
Raw Permalink Normal View History

2021-11-19 11:20:01 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2021 Tom Zander <tom@flowee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WALLETCOINSMODEL_H
#define WALLETCOINSMODEL_H
#include <QAbstractListModel>
#include <functional>
2021-11-19 11:20:01 +01:00
class Wallet;
class WalletCoinsModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit WalletCoinsModel(Wallet *wallet, QObject *parent = nullptr);
2021-11-21 17:46:17 +01:00
void setWallet(Wallet *newWallet);
2021-11-19 11:20:01 +01:00
enum {
2021-11-21 17:46:17 +01:00
Value = Qt::UserRole, // in sats
Age,
2021-11-21 17:46:17 +01:00
Blockheight,
FusedCount,
Locked, // bool
2021-11-21 17:46:17 +01:00
Address,
CloakedAddress,
Selected
2021-11-19 11:20:01 +01:00
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
/**
* For a specific row return the Wallet::OutputRef that matches it.
*/
uint64_t outRefForRow(int row) const;
// lock or unlock a UTXO entry in the backing wallet.
void setOutputLocked(int row, bool lock);
void setSelectionGetter(const std::function<bool(uint64_t)> &callback);
/// Find the row for a Wallet::OutputRef and mark it dirty for refresh in the UI
void updateRow(uint64_t outRef);
/// mark row dirty for refresh in the UI
void updateRow(int row);
2021-11-19 11:20:01 +01:00
private slots:
2021-12-06 12:09:46 +01:00
void utxosChanged();
2021-11-19 11:20:01 +01:00
private:
void createMap();
Wallet *m_wallet = nullptr;
2021-11-21 17:46:17 +01:00
std::map<int, uint64_t> m_rowsToOutputRefs;
std::function<bool(uint64_t)> m_selectionGetter;
2021-11-19 11:20:01 +01:00
};
#endif