//SPDX-FileCopyrightText: 2023 Yury Gubich //SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include #include #include #include #include namespace Models { struct Asset { unsigned int id; QString title; QString icon; QColor color; double balance; bool archived; unsigned int currency; }; class Assets : public QAbstractListModel { Q_OBJECT QML_ELEMENT public: explicit Assets (QObject* parent = nullptr); enum Roles { Title = Qt::UserRole + 1, Icon, Balance, Archived, Color, Id }; void clear (); void add (const Asset& asset); void add (const std::deque& assets); void remove (unsigned int id); //Basic functionality: int rowCount (const QModelIndex& parent = QModelIndex()) const override; QHash roleNames () const override; //Fetch data dynamically: bool canFetchMore (const QModelIndex& parent) const override; void fetchMore (const QModelIndex& parent) override; QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const override; static bool deserialize (const QVariantList& from, std::deque& out); static const QHash roles; signals: void requestAssets (); public slots: void receivedAssets (const std::deque& assets); private: QModelIndex getIndex (unsigned int id) const; private: enum class State { initial, requesting, syncronized }; State state; std::deque records; }; }