File indexing completed on 2024-05-12 05:39:42
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 CHARACTERSHEETMODEL_H 0022 #define CHARACTERSHEETMODEL_H 0023 0024 #include <QAbstractItemModel> 0025 0026 #include <QFile> 0027 #include <QPointF> 0028 #include <QTextStream> 0029 #include <QPointer> 0030 0031 #include <charactersheet/charactersheet_global.h> 0032 0033 #include "charactersheetitem.h" 0034 0035 class CharacterSheet; 0036 class Section; 0037 class CSItem; 0038 0039 namespace Formula 0040 { 0041 class FormulaManager; 0042 } 0043 /** 0044 * @brief CharacterSheetModel is part of the MVC architecture for charactersheet viewer. it herits from 0045 * QAbstractItemModel it also provides features for adding data into stored CharacterSheet. 0046 */ 0047 class CHARACTERSHEET_EXPORT CharacterSheetModel : public QAbstractItemModel 0048 { 0049 Q_OBJECT 0050 public: 0051 enum CustomRole 0052 { 0053 FormulaRole= Qt::UserRole + 1, 0054 ValueRole, 0055 UuidRole, 0056 NameRole 0057 }; 0058 Q_ENUM(CustomRole) 0059 /** 0060 * @brief default constructor 0061 */ 0062 CharacterSheetModel(); 0063 virtual ~CharacterSheetModel(); 0064 0065 int rowCount(const QModelIndex& parent= QModelIndex()) const; 0066 QModelIndex index(int row, int column, const QModelIndex& parent= QModelIndex()) const; 0067 QModelIndex parent(const QModelIndex& index) const; 0068 int columnCount(const QModelIndex& parent= QModelIndex()) const; 0069 QVariant data(const QModelIndex& index, int role= Qt::DisplayRole) const; 0070 bool setData(const QModelIndex& index, const QVariant& value, int role= Qt::EditRole); 0071 Qt::ItemFlags flags(const QModelIndex& index) const; 0072 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 0073 bool hasChildren(const QModelIndex& parent) const; 0074 0075 void addSection(/*int index*/); 0076 void addLine(const QModelIndex& index); 0077 TreeSheetItem* indexToSection(const QModelIndex& index); 0078 QModelIndex indexToSectionIndex(const QModelIndex& index); 0079 CharacterSheet* getCharacterSheet(int id) const; 0080 0081 bool writeModel(QJsonObject& file); 0082 void readModel(const QJsonObject& file, bool readRootSection); 0083 0084 TreeSheetItem* addSection(QString title); 0085 void addLine(TreeSheetItem* parentItem, QString name, const QModelIndex& parent); 0086 0087 void setRootSection(Section* rootSection); 0088 Section* getRootSection() const; 0089 0090 void addCharacterSheet(CharacterSheet* sheet, int pos); 0091 CharacterSheet* getCharacterSheetById(const QString& id) const; 0092 int getCharacterSheetCount() const; 0093 void removeCharacterSheet(int index); 0094 void removeCharacterSheet(CharacterSheet* sheet); 0095 0096 CharacterSheet* addCharacterSheet(); 0097 public slots: 0098 void clearModel(); 0099 0100 void checkCharacter(Section* section); 0101 void addSubChildRoot(TreeSheetItem* item); 0102 void fieldHasBeenChanged(CharacterSheet* sheet, CSItem* item, const QString&); 0103 void addSubChild(CharacterSheet* sheet, CSItem *item); 0104 0105 signals: 0106 void characterSheetHasBeenAdded(CharacterSheet* sheet); 0107 void dataCharacterChange(); 0108 0109 protected: 0110 void computeFormula(QString path, CharacterSheet* sheet); 0111 0112 private: 0113 void checkTableItem(); 0114 0115 private: 0116 std::vector<std::unique_ptr<CharacterSheet>> m_characterList; 0117 QPointer<Section> m_rootSection; 0118 std::unique_ptr<Formula::FormulaManager> m_formulaManager; 0119 }; 0120 0121 #endif // CHARACTERSHEETMODEL_H