This repository has been archived by the owner on Jan 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
AssetModel.h
167 lines (129 loc) · 5.55 KB
/
AssetModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* 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/>.
*/
#pragma once
#include <unordered_map>
#include <optional>
#include <QAbstractItemModel>
#include <QDateTime>
#include "Character.h"
#include "Item.h"
namespace Evernus
{
class EveDataProvider;
class AssetProvider;
class AssetList;
class AssetModel
: public QAbstractItemModel
{
Q_OBJECT
public:
using LocationId = ItemData::LocationIdType::value_type;
using CustomValueType = std::optional<double>;
AssetModel(const AssetProvider &assetProvider,
const EveDataProvider &dataProvider,
bool showOwner,
QObject *parent = nullptr);
virtual ~AssetModel() = default;
virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex{}) const override;
virtual QModelIndex parent(const QModelIndex &index) const override;
virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
void setCharacter(Character::IdType id);
void setCustomStation(quint64 id);
void setCombineCharacters(bool flag);
bool isCombiningCharacters() const;
void reset();
uint getTotalAssets() const noexcept;
double getTotalVolume() const noexcept;
double getTotalSellPrice() const noexcept;
LocationId getAssetLocationId(const QModelIndex &index) const;
ItemData::TypeIdType getAssetTypeId(const QModelIndex &index) const;
Character::IdType getAssetOwnerId(const QModelIndex &index) const;
CustomValueType getAssetCustomValue(const QModelIndex &index) const;
Item::IdType getAssetId(const QModelIndex &index) const;
private slots:
void updateNames();
private:
class TreeItem final
{
public:
TreeItem() = default;
~TreeItem() = default;
void appendChild(std::unique_ptr<TreeItem> child);
void clearChildren() noexcept;
TreeItem *child(int row) const noexcept;
int childCount() const noexcept;
int columnCount() const;
QVariant data(int column) const;
QVariantList data() const;
void setData(const QVariantList &data);
void addData(const QVariant &data);
QDateTime priceTimestamp() const;
void setPriceTimestamp(const QDateTime &dt);
LocationId locationId() const noexcept;
void setLocationId(LocationId id) noexcept;
ItemData::TypeIdType typeId() const noexcept;
void setTypeId(ItemData::TypeIdType id) noexcept;
Character::IdType ownerId() const noexcept;
void setOwnerId(Character::IdType id) noexcept;
QVariant decoration() const;
void setDecoration(const QVariant &data);
CustomValueType customValue() const;
void setCustomValue(CustomValueType value);
Item::IdType id() const noexcept;
void setId(Item::IdType id) noexcept;
int row() const noexcept;
TreeItem *parent() const noexcept;
private:
std::vector<std::unique_ptr<TreeItem>> mChildItems;
QVariantList mItemData;
QDateTime mPriceTimestamp;
LocationId mLocationId = LocationId{};
ItemData::TypeIdType mTypeId = ItemData::TypeIdType{};
Character::IdType mOwnerId = Character::IdType{};
QVariant mDecoration;
CustomValueType mCustomValue;
Item::IdType mId = Item::invalidId;
TreeItem *mParentItem = nullptr;
};
enum
{
typeColumn,
quantityColumn,
unitVolumeColumn,
totalVolumeColumn,
unitPriceColumn,
customValueColumn,
totalPriceColumn,
ownerColumn,
numColumns
};
const AssetProvider &mAssetProvider;
const EveDataProvider &mDataProvider;
Character::IdType mCharacterId = Character::invalidId;
quint64 mCustomStationId = 0;
bool mCombineCharacters = false;
TreeItem mRootItem;
uint mTotalAssets = 0;
double mTotalVolume = 0.;
double mTotalSellPrice = 0.;
std::unordered_map<LocationId, TreeItem *> mLocationItems;
void buildItemMap(const Item &item, TreeItem &treeItem, LocationId locationId, Character::IdType ownerId);
std::unique_ptr<TreeItem> createTreeItemForItem(const Item &item, LocationId locationId, Character::IdType ownerId);
void fillAssets(const std::shared_ptr<AssetList> &assets);
};
}