Commit 06be88a0 by Alisa Jung

still compiling (not tested)

parent 1098166a
#include "myitemmodel.h" #include "myitemmodel.h"
MyItemModel::MyItemModel() MyItemModel::MyItemModel(QObject* parent) : QAbstractItemModel(parent)
{ {
root = new TreeItem();
}
MyItemModel::~MyItemModel(){
delete root;
}
int MyItemModel::rowCount(const QModelIndex& parent) const {
TreeItem* parentItem = getItem(parent);
return parentItem->getChildrenCount();
} }
int MyItemModel::columnCount(const QModelIndex &parent) const{
return root->columnCount();
}
//Helferfunktion
TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
if (index.isValid()){
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
if (item) {
return item;
}
}
return root;
}
...@@ -2,11 +2,22 @@ ...@@ -2,11 +2,22 @@
#define MYITEMMODEL_H #define MYITEMMODEL_H
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <treeitem.h>
class MyItemModel : public QAbstractItemModel class MyItemModel : public QAbstractItemModel
{ {
Q_OBJECT;
public: public:
MyItemModel(); MyItemModel(QObject *parent = 0);
~MyItemModel();
int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
private:
TreeItem* root;
TreeItem* getItem(const QModelIndex &index) const;
}; };
#endif // MYITEMMODEL_H #endif // MYITEMMODEL_H
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
TreeItem::TreeItem() TreeItem::TreeItem()
{ {
children = QList<TreeItem*>(); children = QList<TreeItem*>();
name = "root";
} }
TreeItem::~TreeItem(){ TreeItem::~TreeItem(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment