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 | |
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.
-rw-r--r-- | mappingtreemodel.cpp | 27 | ||||
-rw-r--r-- | mappingtreemodel.h | 1 | ||||
-rw-r--r-- | mappingtreewidget.cpp | 5 |
3 files changed, 22 insertions, 11 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 { diff --git a/mappingtreemodel.h b/mappingtreemodel.h index a730aaa..1b5f3ea 100644 --- a/mappingtreemodel.h +++ b/mappingtreemodel.h @@ -90,6 +90,7 @@ class MappingTreeResultModel : public SmTreeModel { public slots: void addItem(const MappingData &data); + void removeItem(const QModelIndex &idx); private: int hasChild(SmTreeItem *item, const QVariant &name, int column = 0) const; diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index b56dd48..6497cbd 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -331,10 +331,9 @@ void MappingEditWidget::removeMapping(){ } QModelIndex firstIdx = sel.first(); if(firstIdx.isValid()){ - int row = firstIdx.row(); - QModelIndex p = firstIdx.parent(); - mResultModel->removeRows(row, 1, p); + mResultModel->removeItem(firstIdx); } + mMappingResult->expandAll(); } void MappingEditWidget::setMappings(const QList<MappingData> &mappings){ |