r15036 by jghali - #9073 (second round) : fix load/save of bookmark hierarchy and pdf export of bookmarks

scribus-commit scribus-commit at lists.scribus.net
Sun May 2 21:10:47 CEST 2010


Revision: 15036
Author: jghali
Date: 2010-05-02T19:06:24.990520Z
Commit message: #9073 (second round) : fix load/save of bookmark hierarchy and pdf export of bookmarks

Changeset: 
M  /branches/Version135/Scribus/scribus/pdflib_core.cpp
M  /branches/Version135/Scribus/scribus/bookmwin.cpp

Diffs:
Index: scribus/pdflib_core.cpp
===================================================================
--- scribus/pdflib_core.cpp	(revision 15035)
+++ scribus/pdflib_core.cpp	(revision 15036)
@@ -7299,48 +7299,26 @@
 bool PDFLibCore::PDF_End_Doc(const QString& PrintPr, const QString& Name, int Components)
 {
 	QString tmp;
-	uint StX;
-	int Basis;
 	int ResO;
 	BookMItem* ip;
 	QTreeWidgetItem* pp;
 	QString Inhal = "";
 	QMap<int,QString> Inha;
-	Inha.clear();
-	int Bmc = 0;
 	//if ((Bvie->childCount() != 0) && (Options.Bookmarks) && (BookMinUse))
 	if ((Bvie->topLevelItemCount() != 0) && (Options.Bookmarks) && (BookMinUse))
 	{
-		Basis = ObjCounter; // - 1;
+		int Basis = ObjCounter - 1;
 		Outlines.Count = Bvie->topLevelItemCount();
 		ip = (BookMItem*)Bvie->topLevelItem(0);
 		pp = Bvie->topLevelItem(0);
 		Outlines.First = ip->ItemNr+Basis;
-		while (pp)
-		{
-// 			if (!pp->nextSibling())
-			if (!Bvie->itemBelow(pp))
-			{
-				ip = (BookMItem*)pp;
-				Outlines.Last = ip->ItemNr+Basis;
-				break;
-			}
-// 			pp = pp->nextSibling();
-			pp = Bvie->itemBelow(pp);
-		}
+		Outlines.Last  = ((BookMItem*) Bvie->topLevelItem(Outlines.Count - 1))->ItemNr+Basis;
 		QTreeWidgetItemIterator it(Bvie);
-// 		for ( ; it.current(); ++it)
 		while (*it)
 		{
 			ip = (BookMItem*)(*it);
-			Inhal = "";
-			Bmc++;
-			Inhal += QString::number(ip->ItemNr+Basis)+ " 0 obj\n";
-			QString encText = "";
-			for (int telen = 0; telen < ip->Titel.length(); telen++)
-			{
-				encText += ip->Titel.at(telen);
-			}
+			QString encText = ip->Titel;
+			Inhal  = QString::number(ip->ItemNr+Basis)+ " 0 obj\n";
 			Inhal += "<<\n/Title "+EncStringUTF16("("+encText+")", ip->ItemNr+Basis)+"\n";
 			if (ip->Pare == 0)
 				Inhal += "/Parent 3 0 R\n";
@@ -7354,7 +7332,6 @@
 				Inhal += "/First "+QString::number(ip->First+Basis)+" 0 R\n";
 			if (ip->Last != 0)
 				Inhal += "/Last "+QString::number(ip->Last+Basis)+" 0 R\n";
-// 			if (ip->firstChild())
 			if (ip->childCount())
 				Inhal += "/Count -"+QString::number(ip->childCount())+"\n";
 			if ((ip->PageObject->OwnPage != -1) && PageTree.Kids.contains(ip->PageObject->OwnPage))
@@ -7363,10 +7340,11 @@
 			Inha[ip->ItemNr] = Inhal;
 			++it;
 		}
-		for (int b = 0; b < Bmc; ++b)
+		QMap<int,QString> ::ConstIterator contentIt;
+		for (contentIt = Inha.begin(); contentIt != Inha.end(); ++contentIt)
 		{
 			XRef.append(bytesWritten());
-			PutDoc(Inha[b]);
+			PutDoc(contentIt.value());
 			ObjCounter++;
 		}
 	}
@@ -7696,7 +7674,7 @@
 		PutDoc("/OutputCondition ("+PDFEncode(Name)+")\n");
 		PutDoc(">>\nendobj\n");
 	}
-	StX = bytesWritten();
+	uint StX = bytesWritten();
 	PutDoc("xref\n");
 	PutDoc("0 "+QString::number(ObjCounter)+"\n");
 	PutDoc("0000000000 65535 f \n");
Index: scribus/bookmwin.cpp
===================================================================
--- scribus/bookmwin.cpp	(revision 15035)
+++ scribus/bookmwin.cpp	(revision 15036)
@@ -171,60 +171,64 @@
 // #include <QtDebug>
 void BookMView::rebuildTree()
 {
-	QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::All);
-	// level - parent : children
-	QMap<int,QMap<int,QList<BookMItem*> > > levels;
-	QMap<int,BookMItem*> items;
-
 	Last = 0;
 
-	while (*it)
+	// Reassign item ids first, some 1.3.4-1.3.7svn docs
+	// have broken items IDs
+	QTreeWidgetItemIterator it1(this, QTreeWidgetItemIterator::All);
+	while (*it1)
 	{
-		BookMItem * currItem = (BookMItem*)(*it);
+		BookMItem * currItem = (BookMItem*)(*it1);
+		currItem->ItemNr = ++Last;
+		++it1;
+	}
+
+	int topLevelCount = this->topLevelItemCount();
+	QTreeWidgetItemIterator it2(this, QTreeWidgetItemIterator::All);
+	while (*it2)
+	{
+		BookMItem * currItem = (BookMItem*)(*it2);
 		// handle parents
 		BookMItem * parent = (BookMItem*)currItem->parent();
 		currItem->Pare = parent ? parent->ItemNr : 0;
+		if (currItem->Pare == 0) // top level item
+		{
+			BookMItem *prev   = NULL, *next = NULL;
+			int topLevelIndex = this->indexOfTopLevelItem(currItem);
+			if (topLevelIndex >= 0)
+			{
+				prev = (topLevelIndex > 0) ? (BookMItem *) this->topLevelItem(topLevelIndex - 1) : NULL;
+				next = (topLevelIndex < (topLevelCount - 1)) ? (BookMItem *) this->topLevelItem(topLevelIndex + 1) : NULL;
+			}
+			currItem->Prev = prev ? prev->ItemNr : 0;
+			currItem->Next = next ? next->ItemNr : 0;
+		}
 
-		levels[currItem->level()][currItem->Pare].append(currItem);
-		items[Last] = currItem;
-		
-		currItem->ItemNr = Last;
-		++Last;
-		++it;
-	}
-
-	NrItems = Last;
-
-	foreach (int level, levels.keys())
-	{
-// 		qDebug() << "LEVEL: " << level;
-		QMapIterator<int,QList<BookMItem*> > parent(levels[level]);
-		while (parent.hasNext())
+		// handle children
+		currItem->First = 0;
+		currItem->Last  = 0;
+		int childCount  = currItem->childCount();
+		if (childCount > 0)
 		{
-			parent.next();
-// 			qDebug() << "PARENT: " << parent.key();
-			int cnt = parent.value().count();
-			items[parent.key()]->First = cnt > 0 ? parent.value().at(0)->ItemNr : 0;
-			items[parent.key()]->Last = cnt > 0 ? parent.value().at(cnt-1)->ItemNr : 0;
-			int prev = parent.key();
-			int ix = 0;
-			foreach (BookMItem* item, parent.value())
+			BookMItem * child = NULL, *prev = NULL, *next = NULL;
+			BookMItem * firstChild = (BookMItem*) currItem->child(0);
+			BookMItem * lastChild  = (BookMItem*) currItem->child(childCount - 1);
+			currItem->First = firstChild->ItemNr;
+			currItem->Last  = lastChild->ItemNr;
+			for (int i = 0; i < childCount; ++i)
 			{
-// 				qDebug() << "CHILD: " << item->ItemNr;
-				item->Prev = prev;
-				prev = item->ItemNr;
-				if (ix < (cnt - 1))
-					item->Next = parent.value()[ix+1]->ItemNr;
-				++ix;
+				child = (BookMItem*) currItem->child(i);
+				next  = (i < (childCount - 1)) ? (BookMItem*) currItem->child(i + 1) : NULL;
+				child->Prev = prev ? prev->ItemNr : 0;
+				child->Next = next ? next->ItemNr : 0;
+				prev = child;
 			}
 		}
+		++it2;
 	}
-/*
-	foreach (BookMItem* i, items.values())
-	{
-		qDebug() << i->ItemNr << " " << i->text(0).left(10) << " " << i->Prev << " " << i->Next << " " << i->Pare << " " << i->First << " " << i->Last;
-	}*/
 
+	NrItems = Last;
+
 	emit MarkMoved();
 	emit changed();
 }




More information about the scribus-commit mailing list