From 184448e767ccdeae66fe4d795757cace98033b0e Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 4 Oct 2012 06:59:44 +0200 Subject: Fix Mappings in PictureViewer2 Another fix for the new MappingTreeModel database layout: Make the mappings display correctly when showing an archived picture. For performance reasons I had to make PicFilesModel global and put it into a separate file. Also clean up MappingTreeModel: remove comments and unused functions. --- pictureviewer2.cpp | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'pictureviewer2.cpp') diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp index 36701ff..ae18a0c 100644 --- a/pictureviewer2.cpp +++ b/pictureviewer2.cpp @@ -14,9 +14,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -29,6 +29,7 @@ #include #include "pictureviewer2.h" +#include "picfilesmodel.h" #include "pictureswidget.h" #include "smglobals.h" #include "mappingtreemodel.h" @@ -52,6 +53,10 @@ PictureViewer2::PictureViewer2(QWidget *parent) : QGraphicsView(parent), mCur(0) mSlideTimer = new QTimer(this); connect(mSlideTimer, SIGNAL(timeout()), this, SLOT(next())); + //models + mMappingTreeModel = static_cast(SmGlobals::instance()->model("MappingTree")); + mPicFilesModel = static_cast(SmGlobals::instance()->model("PicFiles")); + //setup gui mScene = new QGraphicsScene(this); setScene(mScene); @@ -306,15 +311,18 @@ void PictureViewer2::constructInfoItem(const PicData &data, QSize picSize){ mScene->addItem(mFnItem); } -//FIXME! void PictureViewer2::constructMappingItem(const PicData &file){ - MappingTreeModel *mappingModel = static_cast(SmGlobals::instance()->model("MappingTree")); - QList mappings = mappingModel->mappingsForFile(file.at(PicFilesModel::Id)); + QList mapData = mPicFilesModel->mappingDataFromFile(file.at(PicFilesModel::Id).toInt()); + QList mappings; + foreach(MappingData d, mapData){ + mappings << d.path; + } QStringList mappingPaths; - foreach(QVariant mId, mappings){ - mappingPaths << mappingModel->mappingDataFromId(mId.toInt()).path.join("/"); + foreach(QStringList l, mappings){ + mappingPaths << l.join("/"); } - SmTreeItem *mappingTree = mappingModel->treeFromPaths(mappingPaths); + + SmTreeItem *mappingTree = mMappingTreeModel->treeFromPaths(mappingPaths); if(mappingTree){ if(mMappingItem){ mMappingPos = mMappingItem->scenePos(); @@ -352,26 +360,29 @@ QTextDocument *PictureViewer2::treeToString(const SmTreeItem *root) const{ retval->setIndentWidth(2); retval->setDocumentMargin(8); QTextCursor *cursor = new QTextCursor(retval); - treeToStringRecursive(root, cursor, 0); + for(int i = 0; i < root->childCount(); ++i){ + treeToStringRecursive(root->child(i), cursor, 0); + QTextBlockFormat fmt; + fmt.setIndent(0); + cursor->insertBlock(fmt); + } return retval; } void PictureViewer2::treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor, int indent) const{ + QChar bullet(0x2640); + if(indent % 2){ + bullet = QChar(0x2642); + } + cursor->insertText(QString("%1 %2").arg(bullet).arg(parent->data(0).toString())); + if(parent->childCount()){ + indent++; + } for(int i = 0; i < parent->childCount(); ++i){ QTextBlockFormat fmt; fmt.setIndent(indent * 5); - //to prevent a stupid empty line with a
... - if(indent > 0){ - cursor->insertBlock(fmt); - } - QChar bullet(0x2640); - if(indent % 2){ - bullet = QChar(0x2642); - } - cursor->insertText(QString("%1 %2").arg(bullet).arg(parent->child(i)->data(0).toString())); - if(parent->child(i)->childCount()){ - treeToStringRecursive(parent->child(i), cursor, indent + 1); - } + cursor->insertBlock(fmt); + treeToStringRecursive(parent->child(i), cursor, indent); } } -- cgit v1.2.3-70-g09d2