#ifndef QCD_MODEL_H #define QCD_MODEL_H #include #include #include #include "pistring.h" namespace CDUtils { class CDType; class CDSection; class Interface; } namespace QAD { struct Enum; } class CDItemModel; class CDItem { friend class CDItemModel; public: enum CDItemType{ItemCDType, ItemCDSection}; CDItem(CDUtils::Interface * interface, int index, CDItemType type, CDItem * parent); ~CDItem(); QVariant data(int column, int role) const; QVariant value(CDUtils::CDType t, int role) const; bool setData(int column, const QVariant & value); private: PIDeque buildPath() const; QString stringType(const PIString & t) const; CDUtils::Interface * interface; CDItem * parent_; int index_; CDItemType type_; QList childs; }; class CDDelegate : public QStyledItemDelegate { Q_OBJECT public: CDDelegate(QObject *parent = 0); QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; }; class CDItemModel : public QAbstractItemModel { Q_OBJECT public: explicit CDItemModel(int type_, QObject *parent = 0); ~CDItemModel(); QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; Qt::ItemFlags flags(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); void buildItem(CDItem * it, CDUtils::CDSection &r); public slots: void rebuildModel(); void updateModel(); private: void internalRebuild(); CDItem * getItem(const QModelIndex & index) const; CDUtils::Interface * interface; CDItem * root; signals: }; #endif // QCD_MODEL_H