File indexing completed on 2024-05-12 05:39:50
0001 /*************************************************************************** 0002 * Copyright (C) 2009 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * Rolisteam 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 #ifndef CHARACTERSTATEMODEL_H 0021 #define CHARACTERSTATEMODEL_H 0022 0023 #include <QAbstractListModel> 0024 0025 #include "data/characterstate.h" 0026 #include <core_global.h> 0027 #include <memory> 0028 #include <vector> 0029 /** 0030 * @brief The CharacterStateModel class 0031 */ 0032 class CORE_EXPORT CharacterStateModel : public QAbstractListModel //, public PreferencesListener, public NetWorkReceiver 0033 { 0034 Q_OBJECT 0035 public: 0036 /** 0037 * @brief The COLUMN_TYPE enum 0038 */ 0039 enum COLUMN_TYPE 0040 { 0041 LABEL= Qt::UserRole + 1, 0042 COLOR, 0043 PICTUREPATH, 0044 PICTURE, 0045 ID 0046 }; 0047 /** 0048 * @brief CharacterStateModel 0049 */ 0050 explicit CharacterStateModel(QObject* parent= nullptr); 0051 /** 0052 * 0053 * */ 0054 ~CharacterStateModel() override; 0055 0056 /** 0057 * @brief data 0058 * @param index 0059 * @param role 0060 * @return 0061 */ 0062 QVariant data(const QModelIndex& index, int role) const override; 0063 /** 0064 * @brief rowCount 0065 * @param parent 0066 * @return 0067 */ 0068 int rowCount(const QModelIndex& parent= QModelIndex()) const override; 0069 /** 0070 * @brief columnCount 0071 * @param parent 0072 * @return 0073 */ 0074 int columnCount(const QModelIndex& parent= QModelIndex()) const override; 0075 /** 0076 * @brief headerData 0077 * @param section 0078 * @param orientation 0079 * @param role 0080 * @return 0081 */ 0082 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0083 /** 0084 * @brief flags 0085 * @param index 0086 * @return 0087 */ 0088 Qt::ItemFlags flags(const QModelIndex& index) const override; 0089 /** 0090 * @brief setData 0091 * @param index 0092 * @param value 0093 * @param role 0094 * @return 0095 */ 0096 bool setData(const QModelIndex& idx, const QVariant& value, int role) override; 0097 0098 /// new methods 0099 const std::vector<std::unique_ptr<CharacterState>>& statesList() const; 0100 0101 void appendState(CharacterState&& state); 0102 void deleteState(const QModelIndex& index); 0103 void clear(); 0104 0105 int indexFromId(const QString& id) const; 0106 0107 void upState(const QModelIndex& index); 0108 void downState(const QModelIndex& index); 0109 void topState(const QModelIndex& index); 0110 void bottomState(const QModelIndex& index); 0111 void moveState(int from, int to); 0112 void removeStateAt(int i); 0113 0114 QString stateLabelFromId(const QString& id); 0115 0116 signals: 0117 void characterStateAdded(CharacterState* state, int i); 0118 void stateRemoved(const QString& id); 0119 void stateMoved(int from, int to); 0120 void stateChanged(); 0121 0122 private: 0123 std::vector<std::unique_ptr<CharacterState>> m_stateList; 0124 QStringList m_header; 0125 }; 0126 0127 #endif // CHARACTERSTATEMODEL_H