summaryrefslogtreecommitdiffstats
path: root/mappingtreemodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-09-30 04:34:22 +0200
committerArno <am@disconnect.de>2012-09-30 04:34:22 +0200
commit887c2cd696c54af0cd6fdd54950d006626afeacc (patch)
tree2ad296208a7d8e44ac249612dfcd09919e7ba07d /mappingtreemodel.cpp
parent5addc8a8ec89c1e354949bcf5c3152fea4fe44b9 (diff)
downloadSheMov-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 'mappingtreemodel.cpp')
-rw-r--r--mappingtreemodel.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp
index 9bb278d..ff7d7d3 100644
--- a/mappingtreemodel.cpp
+++ b/mappingtreemodel.cpp
@@ -11,6 +11,8 @@
#include <algorithm>
+#include <QDebug>
+
#include "mappingtreemodel.h"
#include "smtreeitem.h"
@@ -148,7 +150,7 @@ QVariant MappingTreeModel::data(const QModelIndex &index, int role) const{
}
QList<QVariant> MappingTreeModel::childList(const QVariant &value, int column) const{
- QModelIndex itemIdx = findRecursive(value, column, createIndex(0, 0, root()));
+ QModelIndex itemIdx = findRecursive(value, column, createIndex(0, column, root()));
SmTreeItem *item = static_cast<SmTreeItem*>(itemIdx.internalPointer());
if(item){
if(item->childCount()){
@@ -169,6 +171,23 @@ QList<QVariant> MappingTreeModel::mappingsForFile(const QVariant &fileId) const{
return retval;
}
+QStringList MappingTreeModel::path(QModelIndex &idx) const{
+ if(!idx.isValid()){
+ return QStringList();
+ }
+ QStringList retval;
+ SmTreeItem *item = static_cast<SmTreeItem*>(idx.internalPointer());
+ do {
+ QString d = item->data(MappingTreeModel::Name).toString();
+ if(!d.isEmpty()){
+ retval << d;
+ }
+ item = item->parent();
+ }while(item);
+ std::reverse(retval.begin(), retval.end());
+ return retval;
+}
+
QModelIndex MappingTreeModel::indexFromPath(const QString &path, int column) const{
QStringList items = path.split("/");
if(items.isEmpty() || column >= NumFields){
@@ -362,14 +381,37 @@ int MappingTreeModel::childCount(const QModelIndex &idx) const{
return item->childCount();
}
+MappingData MappingTreeModel::mappingDataFromIndex(QModelIndex &idx) const{
+ MappingData retval = { -1, QString(), QStringList() };
+ if(!idx.isValid()){
+ return retval;
+ }
+ retval.id = idx.data(MappingTreeModel::IdRole).toInt();
+ retval.name = idx.data(MappingTreeModel::NameRole).toString();
+ retval.path = path(idx);
+ return retval;
+}
+
+//continue here!
MappingData MappingTreeModel::mappingDataFromId(int mappingId) const{
MappingData retval = { -1, QString(), QStringList() };
- foreach(MappingData d, mValidMappings){
+ QModelIndex mapIdx = findRecursive(mappingId, MappingTreeModel::Id, rootIndex());
+ //REMOVE ME
+ Q_ASSERT(mapIdx.isValid());
+ retval.id = mappingId;
+ retval.name = mapIdx.data(MappingTreeModel::NameRole).toString();
+ qDebug() << "mapping" << retval.id << retval.name;
+ SmTreeItem *mapItem = static_cast<SmTreeItem*>(mapIdx.internalPointer());
+ //REMOVE ME
+ Q_ASSERT(mapItem);
+ //retval.path = path(mapItem);
+
+ /*foreach(MappingData d, mValidMappings){
if(d.id == mappingId){
retval = d;
break;
}
- }
+ }*/
return retval;
}