diff options
author | Arno <am@disconnect.de> | 2012-09-30 04:34:22 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-09-30 04:34:22 +0200 |
commit | 887c2cd696c54af0cd6fdd54950d006626afeacc (patch) | |
tree | 2ad296208a7d8e44ac249612dfcd09919e7ba07d /mappingtreewidget.cpp | |
parent | 5addc8a8ec89c1e354949bcf5c3152fea4fe44b9 (diff) | |
download | SheMov-887c2cd696c54af0cd6fdd54950d006626afeacc.tar.gz SheMov-887c2cd696c54af0cd6fdd54950d006626afeacc.tar.bz2 SheMov-887c2cd696c54af0cd6fdd54950d006626afeacc.zip |
Foremost a fix for SmTreeModel
Not working again, but I eventually have to commit the changes. Fixes to
SmTreeModel:
* Fix SmTreeModel::index(). The previous comment was quite valid. I'm
surprised that it worked at all. I have no clue why to return an invalid
QModelIndex if the column isn't 0. Now an index with any valid column
number can be created.
* Fix SmTreeModel::parent(). Again, why shouldn't we create a parent
index with a column other than 0? No idea...
* Fix SmTreeModel::headerData(). Add some sanity checks.
* Fix SmTreeModel::findRecursive(). Well, what is there to say. It never
worked for models with a depth > 1, but obviously it didn't really
matter until now. To make it work I had to change SmTreeItem as well.
SmTreeItem::next() returns the next valid parent/sibling, or 0 if there
isn't one.
There may be some fallout from these changes, but they're yet to be
seen.
Changes to PictureView:
* fix selecting an item according to the new datasbase layout
* same goes for editing items. If an update actually works has to be
checked.
Overall, it's an intermediate commit that should have been a sane series
of commits. Can't be changed now...
Diffstat (limited to 'mappingtreewidget.cpp')
-rw-r--r-- | mappingtreewidget.cpp | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index e4e9e76..82a1490 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -92,28 +92,13 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){ } MappingData MappingTreeWidget::selectedItem() const { - MappingData retval; + MappingData retval = { -1, QString(), QStringList() }; QModelIndex sel = selected(); if(!sel.isValid()){ - retval.id = -1; - }else{ - QModelIndex real = mProxy->mapToSource(sel); - if(mModel->childCount(real)){ - retval.id = -1; - }else{ - retval.id = sel.data(MappingTreeModel::IdRole).toInt(); - } - retval.name = sel.data(MappingTreeModel::NameRole).toString(); - QStringList p; - QModelIndex parent = sel; - while(parent.isValid()){ - p << parent.data().toString(); - parent = parent.parent(); - } - std::reverse(p.begin(), p.end()); - retval.path = p; + return retval; } - return retval; + QModelIndex real = mProxy->mapToSource(sel); + return mModel->mappingDataFromIndex(real); } void MappingTreeWidget::addChild(){ @@ -308,17 +293,18 @@ void MappingEditWidget::removeMapping(){ mResultModel->removeRows(firstIdx.row(), 1, firstIdx.parent()); } -void MappingEditWidget::setMappings(const QList<int> &mappings){ +void MappingEditWidget::setMappings(const QList<MappingData> &mappings){ if(mappings.isEmpty()){ return; } - MappingTreeModel *mModel = static_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree")); + //MappingTreeModel *mModel = static_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree")); mResultModel->clearData(); - foreach(int i, mappings){ - MappingData curData = mModel->mappingDataFromId(i); + foreach(MappingData d, mappings){ + mResultModel->addItem(d); + /*MappingData curData = mModel->mappingDataFromId(i); if(curData.id != -1){ mResultModel->addItem(curData); - } + }*/ } mMappingResult->expandAll(); } |