|
mkRPG
|
00001 #ifndef ITEMMODELS_H 00002 #define ITEMMODELS_H 00003 00004 00005 #include <QAbstractItemModel> 00006 #include "../game.h" 00007 00019 class ObjectsTreeModel : public QAbstractItemModel 00020 { 00021 public: 00022 explicit ObjectsTreeModel(QObject *parent = nullptr); 00023 explicit ObjectsTreeModel(GameObject *o, QObject *parent = nullptr); 00024 void setGameObject(GameObject *o); 00025 int columnCount(const QModelIndex &) const; 00026 int rowCount(const QModelIndex &parent) const; 00027 QVariant data(const QModelIndex &index, int role) const; 00028 QModelIndex index(int row, int column, const QModelIndex &parent) const; 00029 QModelIndex parent(const QModelIndex &child) const; 00030 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 00031 Qt::ItemFlags flags(const QModelIndex &index) const; 00032 bool setData(const QModelIndex &index, const QVariant &value, int role); 00033 void setEditable(bool e); 00034 QModelIndex find(int id, const QModelIndex &root = QModelIndex()); 00035 00036 private: 00037 GameObject *obj; 00038 bool aEditable; 00039 }; 00040 00041 00046 class FilteredObjectsTreeModel : public QSortFilterProxyModel 00047 { 00048 public: 00049 explicit FilteredObjectsTreeModel(QObject *parent = nullptr); 00050 void setMode(bool eq); 00051 void setDisplayedItem(int nb); 00052 int displayedItem() const; 00053 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; 00054 // virtual int rowCount(const QModelIndex &parent) const; 00055 00056 private: 00057 int aDisplayedItem; 00058 bool eqTest; 00059 }; 00060 00061 00062 00063 00068 class ActionsListModel : public QAbstractListModel 00069 { 00070 public: 00071 explicit ActionsListModel(QObject *parent = nullptr); 00072 explicit ActionsListModel(Game *g, QObject *parent = nullptr); 00073 00074 void setGame(Game *g); 00075 00076 int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE; 00077 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; 00078 QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; 00079 bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE; 00080 00081 void addAction(const QString &action); 00082 00083 00084 private: 00085 void sortActions(); 00086 00087 Game *game; 00088 QList<QString> actions; 00089 }; 00090 00091 00092 00097 class ReceiverListModel : public QAbstractListModel 00098 { 00099 Q_OBJECT 00100 00101 public: 00102 explicit ReceiverListModel(QObject *parent = nullptr); 00103 00104 void setAction(Action *action); 00105 int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE; 00106 QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; 00107 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; 00108 bool removeRows(int row, int count, const QModelIndex &parent) Q_DECL_OVERRIDE; 00109 void addReceiver(GameObject *rcv, const QString &order); 00110 QPair<GameObject*, QString> receiver(int row); 00111 private: 00112 void sortActions(); 00113 00114 Action* aAction; 00115 QList<QPair<GameObject*, QString>> aReceivers; 00116 }; 00117 00118 00119 00120 00125 class ImageListModel : public QAbstractListModel 00126 { 00127 Q_OBJECT 00128 00129 public: 00130 explicit ImageListModel(QObject *parent = nullptr); 00131 00132 void setGame(Game *game); 00133 int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE; 00134 QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; 00135 00136 int getIndex(Image *im) const; 00137 Image *getImage(int i); 00138 00139 private: 00140 QList<Image*> images; 00141 }; 00142 00143 00144 #endif // ITEMMODELS_H
1.7.6.1