Commit 18280c79 by Alisa Jung

still compiling

parent 06be88a0
......@@ -20,6 +20,64 @@ int MyItemModel::columnCount(const QModelIndex &parent) const{
return root->columnCount();
}
QVariant MyItemModel::data(const QModelIndex &index, int role) const{
if (!index.isValid()){
return QVariant();
}
if (role != Qt::DisplayRole){
return QVariant();
}
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
return item->data(index.column());
}
QVariant MyItemModel::headerData(int section, Qt::Orientation orientation, int role) const{
//Im tutorial stand mehr. erstmal ignorieren.
return root->data(section);
}
QModelIndex MyItemModel::index(int row, int column, const QModelIndex& parent) const{
if (!hasIndex(row, column, parent)){
return QModelIndex();
}
TreeItem* parentItem;
if (!parent.isValid()){
parentItem = root;
} else{
parentItem = static_cast<TreeItem*>(parent.internalPointer());
}
TreeItem* childItem = parentItem->getChild(row);
if (childItem){
return createIndex(row, column, childItem);
}else{
return QModelIndex();
}
}
QModelIndex MyItemModel::parent(const QModelIndex &index) const{
if (!index.isValid()){
return QModelIndex();
}
TreeItem* childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem* parentItem = childItem->getParent();
if (parentItem == root){
return QModelIndex();
}else{
return createIndex(parentItem->childNumber(), 0, parentItem);
}
}
//enable editing and selection.
Qt::ItemFlags MyItemModel::flags(const QModelIndex &index) const{
if (!index.isValid()){
return 0;
}else{
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
}
}
//Helferfunktion
TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
......
......@@ -14,6 +14,14 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
private:
TreeItem* root;
......
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