-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcharactersheet.h
159 lines (142 loc) · 4.93 KB
/
charactersheet.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
/***************************************************************************
* Copyright (C) 2009 by Renaud Guezennec *
* https://rolisteam.org/contact *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CHARACTERSHEET_H
#define CHARACTERSHEET_H
#include <QMap>
#include <QString>
#include <QVariant>
#include "field.h"
class Section;
#ifndef RCSE
#include "network/networkmessagereader.h"
#include "network/networkmessagewriter.h"
#endif
#include "charactersheetitem.h"
/**
* @brief the characterSheet stores Section as many as necessary
*/
class CharacterSheet : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
public:
/**
* Constructor
*/
CharacterSheet();
virtual ~CharacterSheet();
/**
* @brief allows to get the key, this function is used for displaying the meaning of fields
* @param int index : 0 refers to the title of the section, 1 refers to key of the first data of the first
* section...
*/
const QString getkey(int index);
/**
* @brief save
* @param json
*/
virtual void save(QJsonObject& json);
/**
* @brief load
* @param json
*/
virtual void load(QJsonObject& json);
#ifndef RCSE
void fill(NetworkMessageWriter& message);
void read(NetworkMessageReader& msg);
#endif
/**
* @brief getTitle
* @return
*/
const QString getTitle();
/**
* @brief getFieldCount
* @return
*/
int getFieldCount();
/**
* @brief getFieldAt
* @param i
* @return
*/
CharacterSheetItem* getFieldAt(int i) const;
/**
* @brief getFieldFromKey
* @param key
* @return
*/
CharacterSheetItem* getFieldFromKey(QString key) const;
/**
* @brief getRootSection
* @return
*/
Section* getRootSection() const;
/**
* @brief setRootSection
* @param rootSection
*/
void buildDataFromSection(Section* rootSection);
/**
* @brief getVariableDictionnary
* @return
*/
QHash<QString, QString> getVariableDictionnary();
void insertCharacterItem(CharacterSheetItem* item);
QString uuid() const;
void setUuid(const QString& uuid);
QString name() const;
void setName(const QString& name);
void setFieldData(QJsonObject& obj, const QString& parent);
void setOrigin(Section*);
QList<QString> getAllDependancy(QString key);
CharacterSheetItem* getFieldFromIndex(const std::vector<int>& row) const;
/**
* @brief global getter of data. This function has been written to make easier the MVC architecture.
* @param QString path : 0 refers to the title of the first section, 1 refers to the first data of the first
* section....
*/
const QVariant getValueByIndex(const std::vector<int>& row, QString key,
Qt::ItemDataRole role= Qt::DisplayRole) const;
const QVariant getValue(QString path, int role= Qt::DisplayRole) const;
bool removeField(const QString& path);
public slots:
CharacterSheetItem* setValue(QString key, QString value, QString formula);
signals:
void updateField(CharacterSheet*, CharacterSheetItem*, const QString& path);
void addLineToTableField(CharacterSheet*, CharacterSheetItem*);
void uuidChanged();
void nameChanged();
protected:
void insertField(QString key, CharacterSheetItem* itemSheet);
private:
QStringList explosePath(QString);
private:
QMap<QString, CharacterSheetItem*> m_valuesMap;
/**
*@brief User Id of the owner
*/
QString m_name;
static int m_count;
Section* m_rootSection;
QString m_uuid;
};
#endif // CHARACTERSHEET_H