File indexing completed on 2024-05-19 05:40:20

0001 /***************************************************************************
0002  *   Copyright (C) 2009 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef CHARACTERSHEET_H
0022 #define CHARACTERSHEET_H
0023 #include <QMap>
0024 #include <QString>
0025 #include <QVariant>
0026 
0027 #include <charactersheet/charactersheet_global.h>
0028 #include <charactersheet/charactersheetitem.h>
0029 
0030 class Section;
0031 class CSItem;
0032 /**
0033  * @brief the characterSheet stores Section as many as necessary
0034  */
0035 class CHARACTERSHEET_EXPORT CharacterSheet : public QObject
0036 {
0037     Q_OBJECT
0038     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
0039     Q_PROPERTY(QString uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
0040 public:
0041     /**
0042      * Constructor
0043      */
0044     CharacterSheet(QObject* parent= nullptr);
0045     virtual ~CharacterSheet();
0046     const QString getkey(int index);
0047     virtual void save(QJsonObject& json) const;
0048     virtual void load(const QJsonObject& json);
0049     const QString getTitle();
0050     int getFieldCount();
0051     CSItem* getFieldAt(int i) const;
0052 
0053     CSItem* getFieldFromKey(QString key) const;
0054     QHash<QString, QString> getVariableDictionnary();
0055 
0056     void insertCharacterItem(CSItem* item);
0057 
0058     QString uuid() const;
0059     void setUuid(const QString& uuid);
0060     QString name() const;
0061     void setName(const QString& name);
0062 
0063     virtual void setFieldData(const QJsonObject& obj, const QString& parent);
0064     void setOrigin(Section*);
0065 
0066     QList<QString> getAllDependancy(QString key);
0067     CSItem* getFieldFromIndex(const std::vector<int>& row) const;
0068 
0069     const QVariant getValueByIndex(const std::vector<int>& row, QString key,
0070                                    Qt::ItemDataRole role= Qt::DisplayRole) const;
0071     const QVariant getValue(QString path, int role= Qt::DisplayRole) const;
0072 
0073     bool removeField(const QString& path);
0074 public slots:
0075     CSItem* setValue(QString key, QString value, QString formula);
0076 
0077 signals:
0078     void updateField(CharacterSheet*, CSItem*, const QString& path);
0079     void addLineToTableField(CharacterSheet*, CSItem*);
0080     void uuidChanged();
0081     void nameChanged();
0082 
0083 protected:
0084     void insertField(QString key, CSItem* itemSheet);
0085 
0086 private:
0087     QStringList explosePath(QString);
0088 
0089 private:
0090     QMap<QString, CSItem*> m_valuesMap;
0091     QString m_name;
0092     static int m_count;
0093     QString m_uuid;
0094 };
0095 
0096 #endif // CHARACTERSHEET_H