diff options
Diffstat (limited to 'mappingtreemodel.cpp')
-rw-r--r-- | mappingtreemodel.cpp | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index 07e3a24..2c636e6 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -123,6 +123,9 @@ QVariant MappingTreeModel::data(const QModelIndex &index, int role) const{ if(role == MyIdRole){ return item->data(MyId); } + if(role == ParentIdRole){ + return item->data(ParentId); + } return SmTreeModel::data(index, role); } @@ -302,11 +305,13 @@ bool MappingTreeModel::deleteChild(const QModelIndex &idx){ } MappingData MappingTreeModel::mappingDataFromIndex(QModelIndex &idx) const{ - MappingData retval = { -1, QString(), QList<QStringList>() }; + MappingData retval = { -1, -1, -1, QString(), QList<QStringList>() }; if(!idx.isValid()){ return retval; } - retval.id = idx.data(MappingTreeModel::MyIdRole).toInt(); + retval.mappingId = idx.data(MappingTreeModel::MappingIdRole).toInt(); + retval.parentId = idx.data(MappingTreeModel::ParentIdRole).toInt(); + retval.myId = idx.data(MappingTreeModel::MyIdRole).toInt(); retval.name = idx.data(MappingTreeModel::NameRole).toString(); retval.path << path(idx); return retval; @@ -480,8 +485,16 @@ bool MappingTreeResultModel::setData(const QModelIndex &index, const QVariant &v item->setData(Name, value); return true; } - if(role == IdRole){ - item->setData(Id, value); + if(role == MappingIdRole){ + item->setData(MappingId, value); + return true; + } + if(role == ParentIdRole){ + item->setData(ParentId, value); + return true; + } + if(role == MyIdRole){ + item->setData(MyId, value); return true; } return SmTreeModel::setData(index, value, role); @@ -499,18 +512,22 @@ void MappingTreeResultModel::addItem(const MappingData &data){ continue; }else{ //insert child - int id = -1; + int mappingId = -1; + int parentId = -1; + int myId = -1; if(i == p.count() - 1){ - id = data.id; + mappingId = data.mappingId; + parentId = data.parentId; + myId = data.myId; } - QModelIndex curIdx = insertChild(p.at(i), id, curItem); + QModelIndex curIdx = insertChild(p.at(i), mappingId, parentId, myId, curItem); curItem = itemAt(curIdx); } } } } -QModelIndex MappingTreeResultModel::insertChild(const QVariant &data, int id, SmTreeItem *parent){ +QModelIndex MappingTreeResultModel::insertChild(const QVariant &data, int mappingId, int parentId, int myId, SmTreeItem *parent){ QModelIndex parentIdx; int row = parent->childCount(); if(parent != root()){ @@ -524,12 +541,14 @@ QModelIndex MappingTreeResultModel::insertChild(const QVariant &data, int id, Sm insertRows(row, 1, parentIdx); QModelIndex newIdx = index(row, 0, parentIdx); setData(newIdx, data, NameRole); - setData(newIdx, id, IdRole); + setData(newIdx, mappingId, MappingIdRole); + setData(newIdx, myId, MyIdRole); + setData(newIdx, parentId, ParentIdRole); return newIdx; } -QList<int> MappingTreeResultModel::mappingsIds() const { - return mappingIdsRecursive(root()); +QList<QVariant> MappingTreeResultModel::columnValues(int column) const { + return columnValuesRecursive(root(), column); } void MappingTreeResultModel::clearData(){ @@ -545,18 +564,18 @@ int MappingTreeResultModel::hasChild(SmTreeItem *item, const QVariant &name, int return -1; } -QList<int> MappingTreeResultModel::mappingIdsRecursive(SmTreeItem *parent) const { - QList<int> retval; +QList<QVariant> MappingTreeResultModel::columnValuesRecursive(SmTreeItem *parent, int column) const { + QList<QVariant> retval; if(!parent->childCount()){ return retval; } for(int i = 0; i < parent->childCount(); ++i){ SmTreeItem *child = parent->child(i); - int id = child->data(Id).toInt(); - if(id != -1){ - retval << id; + QVariant value = child->data(column); + if(value.canConvert(QVariant::Int) && (value.toInt() != -1)){ + retval << value; } - retval << mappingIdsRecursive(child); + retval << columnValuesRecursive(child, column); } return retval; } |