Files
pay/src/PortfolioDataProvider.h
T

115 lines
3.9 KiB
C++
Raw Permalink Normal View History

2020-05-24 13:20:03 +02:00
/*
* This file is part of the Flowee project
2026-03-07 23:55:20 +01:00
* Copyright (C) 2020-2026 Tom Zander <tom@flowee.org>
2020-05-24 13:20:03 +02:00
*
* 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 PORTFOLIODATAPROVIDER_H
#define PORTFOLIODATAPROVIDER_H
#include <QObject>
2020-10-14 15:12:33 +02:00
#include "AccountInfo.h"
2020-06-08 14:37:29 +02:00
2020-10-14 15:12:33 +02:00
class Wallet;
class BitcoinValue;
2020-10-23 22:34:34 +02:00
class Payment;
2020-06-08 14:37:29 +02:00
2020-05-24 13:20:03 +02:00
class PortfolioDataProvider : public QObject
{
Q_OBJECT
2023-05-18 17:06:33 +02:00
/**
* List all active and visible accounts.
*/
2021-11-29 20:57:41 +01:00
Q_PROPERTY(QList<QObject*> accounts READ accounts NOTIFY accountsChanged)
2023-05-18 17:06:33 +02:00
/**
* List only archived accounts.
*/
2021-12-04 11:25:27 +01:00
Q_PROPERTY(QList<QObject*> archivedAccounts READ archivedAccounts NOTIFY accountsChanged)
2023-05-18 17:06:33 +02:00
/**
* List all accounts, active, inactive (aka private) and archived.
*/
Q_PROPERTY(QList<QObject*> rawAccounts READ rawAccounts NOTIFY accountsChanged)
2020-05-24 13:20:03 +02:00
Q_PROPERTY(AccountInfo* current READ current WRITE setCurrent NOTIFY currentChanged)
2021-04-29 12:26:02 +02:00
Q_PROPERTY(double totalBalance READ totalBalance NOTIFY totalBalanceChanged)
/**
* This returns true when the UI can avoid showing elements that allows the user to
* select between different wallets.
*
2024-06-30 23:33:55 +02:00
* Notice that when the limitedArchiveView is set to true (default), we are a single-account-setup
* simply by having exactly one non-archived wallet.
* In the case of the limitedArchiveView being set to false, implying the UI has full
* view of the archived wallets, the only way to have a single-account setup is by having
* exactly one wallet.
*/
Q_PROPERTY(bool singleAccountSetup READ isSingleAccount NOTIFY singleAccountChanged)
/**
* If true, the UI hides archived wallets in the general screens.
* This should be set by the UI.
*
* A user interface that allows direct interaction with archived wallets will have a different idea of what
* makes a 'singleAccountSetup'.
*/
Q_PROPERTY(bool limitedArchiveView READ limitedArchiveView WRITE setLimitedArchiveView NOTIFY limitedArchiveViewChanged FINAL)
2020-05-24 13:20:03 +02:00
public:
explicit PortfolioDataProvider(QObject *parent = nullptr);
2021-11-29 20:57:41 +01:00
QList<QObject*> accounts() const;
2023-05-18 17:06:33 +02:00
QList<QObject*> rawAccounts() const;
2021-12-04 11:25:27 +01:00
QList<QObject*> archivedAccounts() const;
2020-05-24 13:20:03 +02:00
AccountInfo *current() const;
void setCurrent(AccountInfo *item);
2021-11-16 11:47:33 +01:00
/// find the highest priority wallet and make it the selected one
void selectDefaultWallet();
2021-04-29 12:26:02 +02:00
double totalBalance() const;
bool isSingleAccount() const;
bool limitedArchiveView() const;
void setLimitedArchiveView(bool newLimitedArchiveView);
2025-10-28 23:02:16 +01:00
// returns a AccountInfo matching a segmentId, or null
Q_INVOKABLE QObject* account(int id) const;
2026-03-07 23:55:20 +01:00
std::shared_ptr<Wallet> walletById(uint16_t segmentId) const;
2020-05-24 13:20:03 +02:00
public slots:
2025-10-08 15:35:34 +02:00
void addWalletAccount(const std::shared_ptr<Wallet> &wallet);
2020-05-24 13:20:03 +02:00
signals:
void accountsChanged();
void currentChanged(uint16_t segmentId);
2021-04-29 12:26:02 +02:00
void totalBalanceChanged();
void singleAccountChanged();
void limitedArchiveViewChanged();
2020-05-24 13:20:03 +02:00
2020-10-19 16:50:36 +02:00
private slots:
void walletChangedPriority();
void updateIsSingleAccount();
2020-10-19 16:50:36 +02:00
2020-05-24 13:20:03 +02:00
private:
2021-11-16 11:47:33 +01:00
Payment* createPaymentObject(const QString &address, double value) const;
2020-10-23 22:34:34 +02:00
2026-03-07 23:55:20 +01:00
std::map<uint16_t, std::shared_ptr<Wallet>> m_accounts;
2020-05-24 13:20:03 +02:00
QList<AccountInfo*> m_accountInfos;
2026-03-07 23:55:20 +01:00
uint16_t m_currentAccount = 0;
bool m_isSingleAccount = true;
bool m_limitedArchiveView = false;
2020-05-24 13:20:03 +02:00
};
#endif