mkRPG
src/editor/Game/ItemModels/attrtreeitemmodel.h
Go to the documentation of this file.
00001 #ifndef ATTRTREEITEMMODEL_H
00002 #define ATTRTREEITEMMODEL_H
00003 
00004 
00005 #include <QAbstractItemModel>
00006 #include "../game.h"
00007 #include <algorithm>
00008 
00025 enum ItemType{
00026     ParamItem,  
00027     FlagItem,   
00028     EventItem, 
00029     OrderItem    
00030 };
00031 
00041 template<ItemType type>
00042 class GameTreeItem{
00043     enum State{Type, Object, Attribute, Value};
00044 public:
00045     explicit GameTreeItem(GameObject &obj);
00046     explicit GameTreeItem(InheritableObject &typ);
00047     ~GameTreeItem();
00048 
00049     Qt::ItemFlags flags(int col, bool readOnly = false) const;
00050     QVariant data(int col, int role) const;
00051     GameTreeItem *parent() const ;
00052     GameTreeItem *child(int row) const ;
00053     int rowCount() const;
00054     int row() const;
00055     bool setData(int col, QVariant value, int role);
00056     void addAttr(const QString &attr);
00057     void sort();
00058     void setAttributeRowNb(int r);
00059     bool isAttr(const QString &a) const;
00060 
00061 private:
00062     explicit GameTreeItem(int rowNb, GameObject *obj, InheritableObject* typ, State state, GameTreeItem *parent);
00063     int rowNb;
00064     GameTreeItem<type> *parentItem;
00065     QList<GameTreeItem<type>*> children;
00066 
00067     void genealogy(InheritableObject *t);
00068 
00069     QVariant typeData(int col, int role) const;
00070     QVariant objectData(int col, int role) const;
00071     QVariant attrData(int col, int role) const;
00072     QVariant valueData(int col, int role) const;
00073     //bool setTypeData(int col, QVariant value, int role);
00074     //bool setObjectData(int col, QVariant value, int role);
00075     bool setAttrData(int col, QVariant value, int role);
00076     bool setValueData(int col, QVariant value, int role);
00077 
00078     Qt::ItemFlags typeFlags(int, bool) const;
00079     Qt::ItemFlags objectFlags(int, bool) const;
00080     Qt::ItemFlags attrFlags(int col, bool readOnly) const;
00081     Qt::ItemFlags valueFlags(int col, bool readOnly) const;
00082 
00083     GameObject *obj;
00084     InheritableObject *typ;
00085 
00086     InheritableObject *anc;
00087     QList<InheritableObject*> ancestors;
00088     QString attr;
00089     QList<QString> attrs;
00090 
00091     State state;
00092     QColor bgColor;
00093 };
00094 
00095 
00096 
00103 class ParamTreeItemModel : public QAbstractItemModel
00104 {
00105     Q_OBJECT
00106 public:
00107     explicit ParamTreeItemModel(QObject *parent = 0);
00108     void setObject(GameObject *o);
00109     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00110     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00111     Qt::ItemFlags flags(const QModelIndex &index) const;
00112     QVariant data(const QModelIndex &index, int role) const;
00113     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00114     QModelIndex parent(const QModelIndex &child) const;
00115     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00116     bool setData(const QModelIndex &index, const QVariant &value, int role);
00117     void addParam(const QString &name);
00118     void sortAttr(const QModelIndex &par);
00119 
00120 private:
00121     Game *game;
00122     GameObject *obj;
00123     InheritableObject *type;
00124 
00125     GameTreeItem<ParamItem> *item;
00126 };
00127 
00128 
00135 class FlagTreeItemModel : public QAbstractItemModel
00136 {
00137     Q_OBJECT
00138 public:
00139     explicit FlagTreeItemModel(QObject *parent = 0);
00140     void setObject(GameObject *o);
00141     int columnCount(const QModelIndex &parent) const;
00142     int rowCount(const QModelIndex &parent) const;
00143     Qt::ItemFlags flags(const QModelIndex &index) const;
00144     QVariant data(const QModelIndex &index, int role) const;
00145     QModelIndex index(int row, int column, const QModelIndex &parent) const;
00146     QModelIndex parent(const QModelIndex &child) const;
00147     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00148     bool setData(const QModelIndex &index, const QVariant &value, int role);
00149     void addFlag(const QString &name);
00150     void sortAttr(const QModelIndex &par);
00151 
00152 private:
00153     Game *game;
00154     GameObject *obj;
00155     InheritableObject *type;
00156 
00157     GameTreeItem<FlagItem> *item;
00158 };
00159 
00160 
00167 class EventTreeItemModel : public QAbstractItemModel
00168 {
00169     Q_OBJECT
00170 public:
00171     explicit EventTreeItemModel(QObject *parent = 0, bool readOnly = false);
00172     void setObject(GameObject *o);
00173     int columnCount(const QModelIndex &parent) const;
00174     int rowCount(const QModelIndex &parent) const;
00175     Qt::ItemFlags flags(const QModelIndex &index) const;
00176     QVariant data(const QModelIndex &index, int role) const;
00177     QModelIndex index(int row, int column, const QModelIndex &parent) const;
00178     QModelIndex parent(const QModelIndex &child) const;
00179     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00180     bool setData(const QModelIndex &index, const QVariant &value, int role);
00181     void addEvent(const QString &name);
00182     void sortAttr(const QModelIndex &par);
00183 
00184 private:
00185     Game *game;
00186     GameObject *obj;
00187     InheritableObject *type;
00188 
00189     GameTreeItem<EventItem> *item;
00190     bool readOnly;
00191 };
00192 
00193 
00194 
00201 class OrderTreeItemModel : public QAbstractItemModel
00202 {
00203     Q_OBJECT
00204 public:
00205     explicit OrderTreeItemModel(QObject *parent = 0, bool readOnly = false);
00206     void setObject(GameObject *o);
00207     int columnCount(const QModelIndex &parent) const;
00208     int rowCount(const QModelIndex &parent) const;
00209     Qt::ItemFlags flags(const QModelIndex &index) const;
00210     QVariant data(const QModelIndex &index, int role) const;
00211     QModelIndex index(int row, int column, const QModelIndex &parent) const;
00212     QModelIndex parent(const QModelIndex &child) const;
00213     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00214     bool setData(const QModelIndex &index, const QVariant &value, int role);
00215     void addOrder(const QString &name);
00216     void sortAttr(const QModelIndex &par);
00217 
00218     QModelIndex findOrder(const QString &order, const QModelIndex &root = QModelIndex());
00219 
00220 private:
00221     Game *game;
00222     GameObject *obj;
00223     InheritableObject *type;
00224 
00225     GameTreeItem<OrderItem> *item;
00226     bool readOnly;
00227 };
00228 #endif // ATTRTREEITEMMODEL_H
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines