diff options
| author | Arno <am@disconnect.de> | 2014-07-08 11:26:39 +0200 | 
|---|---|---|
| committer | Arno <am@disconnect.de> | 2014-07-08 11:26:39 +0200 | 
| commit | d73a297c2daed1b70625d19a70cee48db192956f (patch) | |
| tree | 744b1909eb7561830aed637c3d26543ac7fde049 /mappingtreemodel.cpp | |
| parent | a115bc6bf4ddd96bee92c5c7cd2c2858a86e97e6 (diff) | |
| download | SheMov-d73a297c2daed1b70625d19a70cee48db192956f.tar.gz SheMov-d73a297c2daed1b70625d19a70cee48db192956f.tar.bz2 SheMov-d73a297c2daed1b70625d19a70cee48db192956f.zip | |
Fix MappingTreeResultModel for good
removeRows and insertRows is buggy. Unfortunately I can't figure out
how... So make it easy and reset the model on inserts and removals.
Diffstat (limited to 'mappingtreemodel.cpp')
| -rw-r--r-- | mappingtreemodel.cpp | 27 | 
1 files changed, 19 insertions, 8 deletions
| diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index cb981d0..64de32f 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -426,6 +426,7 @@ void MappingTreeResultModel::addItem(const MappingData &data){      MappingTreeModel *mapModel = qobject_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree"));      QModelIndex curIdx = QModelIndex();      int curId = -1; +    beginResetModel();      while(!pPath.isEmpty()){          curId = pPath.last();          curPath << curId; @@ -450,16 +451,26 @@ void MappingTreeResultModel::addItem(const MappingData &data){                      row = i;                  }              } -            insertRows(row, 1, lastIdx); -            QModelIndex newIdx = index(row, 0, lastIdx); -            setData(newIdx, curName, NameRole); -            setData(newIdx, sourceIdx.data(MappingTreeModel::MappingIdRole), MappingIdRole); -            setData(newIdx, sourceIdx.data(MappingTreeModel::DescIdRole), DescIdRole); -            setData(newIdx, sourceIdx.data(MappingTreeModel::MappingParentIdRole), ParentIdRole); -            setData(newIdx, sourceIdx.data(MappingTreeModel::DescIdRole), DescIdRole); -            curIdx = newIdx; +            QVariantList data; +            data << curName << sourceIdx.data(MappingTreeModel::MappingIdRole) << sourceIdx.data(MappingTreeModel::MappingParentIdRole) << sourceIdx.data(MappingTreeModel::DescIdRole); +            SmTreeItem *newItem = new SmTreeItem(data, pItem); +            pItem->insertChild(row, newItem); +            curIdx = createIndex(row, 0, newItem);          }      } +    endResetModel(); +} + +void MappingTreeResultModel::removeItem(const QModelIndex &idx){ +    if(!idx.isValid()){ +        return; +    } +    beginResetModel(); +    SmTreeItem *curItem = static_cast<SmTreeItem*>(idx.internalPointer()); +    int row = curItem->row(); +    SmTreeItem *parent = curItem->parent(); +    parent->removeChild(row); +    endResetModel();  }  QList<QVariant> MappingTreeResultModel::columnValues(int column) const { | 
