From 7a2c2c37d4324935ea55221b57d1c878fff4860e Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 9 Jul 2014 13:32:26 +0200 Subject: Bring back the nice MappingItem! Resurrect the indented MappingItem. There's some recursion involved, but actually it ain't so hard if you have a template :) This adventure uncovered a bug in NewPicsDialog: Right now we also record the nodes (not just the leaves) for the Mappings. This bug was introduced by commit dc7cc269a4fffe43bdac2ae2dc6548fbd1e3bb5e and will be fixed in one of the next commits. --- pictureviewer2.cpp | 87 ++++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 59 deletions(-) (limited to 'pictureviewer2.cpp') diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp index 4532030..dbb1763 100644 --- a/pictureviewer2.cpp +++ b/pictureviewer2.cpp @@ -20,9 +20,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -483,65 +480,12 @@ void PictureViewer2::constructInfoItem(const PicData &data, QSize picSize){ } void PictureViewer2::constructMappingItem(const PicData &file){ - QList mapData = mPicFilesModel->mappingDataFromFile(file.at(PicFilesModel::Id).toInt()); - QList mappings; + SmTreeItem *mapData = mPicFilesModel->mappingTreeFromFile(file.at(PicFilesModel::Id).toInt()); QTextDocument *doc = new QTextDocument; doc->setIndentWidth(2); doc->setDocumentMargin(8); - QTextCursor *cursor = new QTextCursor(doc); - if(mapData.isEmpty()){ - QString itemString = QString("%1 (none)").arg(QChar(0x2640)); - cursor->insertText(itemString); - }else{ - QMap sortedPaths; - int maxRows = 0; - foreach(MappingData d, mapData){ - QStringList pItems = d.path; - if(pItems.size() > maxRows){ - maxRows = pItems.size(); - } - QString mapKey = pItems.join("/"); - sortedPaths.insert(mapKey, pItems); - } - QTextTable *table = cursor->insertTable(sortedPaths.size(), 1); - QTextTableFormat fmt; - fmt.setBorder(0); - table->setFormat(fmt); - QMap::const_iterator it = sortedPaths.constBegin(); - int row = 0; - while(it != sortedPaths.constEnd()){ - QChar bullet(0x2640); - if(row % 2){ - bullet = QChar(0x2642); - } - QStringList pItems = it.value(); - int column = 0; - QTextTableCell curCell = table->cellAt(row, column); - curCell.firstCursorPosition().insertText(bullet); - for(int i = 0; i < pItems.size(); ++i){ - if(table->columns() - 1 < column + 1){ - table->appendColumns(1); - } - ++column; - curCell = table->cellAt(row, column); - curCell.firstCursorPosition().insertText(pItems.at(i)); - if(i + 1 < pItems.size()){ - if(table->columns() - 1 < column + 1){ - table->appendColumns(1); - } - ++column; - curCell = table->cellAt(row, column); - QTextTableCellFormat cfmt; - cfmt.setRightPadding(5); - curCell.setFormat(cfmt); - curCell.firstCursorPosition().insertText(QChar(0x2192)); - } - } - ++it; - ++row; - } - } - + QTextCursor *cur = new QTextCursor(doc); + docFromTree(mapData, cur, 0); if(mMappingItem){ mMappingPos = mMappingItem->scenePos(); mScene->removeItem(mMappingItem); @@ -550,6 +494,31 @@ void PictureViewer2::constructMappingItem(const PicData &file){ mMappingItem = new PictureViewer2Item(doc); mMappingItem->setPos(getPos(mMappingItem, mConfigMapPos, mMappingPos)); mScene->addItem(mMappingItem); + delete mapData; +} + +void PictureViewer2::docFromTree(SmTreeItem *start, QTextCursor *cur, int indent){ + if(!start){ + return; + } + QChar bullet(0x2640); + if(indent % 2){ + bullet = QChar(0x2642); + } + for(int i = 0; i < start->childCount(); ++i){ + SmTreeItem *child = start->child(i); + if(!cur->atStart()){ + cur->insertBlock(); + } + QTextBlockFormat fmt; + fmt.setIndent(4 * indent); + cur->setBlockFormat(fmt); + QString text = QString("%1 %2").arg(bullet).arg(child->data(0).toString()); + cur->insertText(text); + if(child->childCount()){ + docFromTree(child, cur, indent + 1); + } + } } void PictureViewer2::setGradient(const QPixmap &pic){ -- cgit v1.2.3-70-g09d2