magpie/models/currencies.h

71 lines
1.5 KiB
C
Raw Permalink Normal View History

2024-01-24 21:00:15 +00:00
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <deque>
#include <list>
#include <map>
#include <QString>
#include <QColor>
#include <QAbstractListModel>
#include <qqmlregistration.h>
namespace Models {
struct Currency {
using ID = uint32_t;
ID id;
QString code;
QString title;
unsigned int type;
double value;
QString description;
QString icon;
};
class Currencies : public QAbstractListModel {
Q_OBJECT
QML_ELEMENT
public:
Currencies (QObject* parent = nullptr);
enum Roles {
Id = Qt::UserRole + 1,
Code,
Title,
Type,
Value,
Description,
Icon
};
void clear ();
void add (const Currency& currency);
void add (const std::deque<Currency>& currencies);
void remove (Currency::ID id);
QString getCode(Currency::ID id);
2024-01-24 21:00:15 +00:00
//Basic functionality:
int rowCount (const QModelIndex& parent = QModelIndex()) const override;
QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const override;
static bool deserialize(const QVariantList& from, std::deque<Currency>& out);
static const QHash<int, QByteArray> roles;
private:
using Order = std::list<Currency>;
using Index = std::deque<Order::iterator>;
using Map = std::map<Currency::ID, Order::iterator>;
Order order;
Index index;
Map map;
};
}