r16694 by jghali - #10064: table of contents with identical attributes for a single frame

scribus-commit scribus-commit at lists.scribus.net
Sun Jun 26 10:46:51 UTC 2011


Author: jghali
Date: Sun Jun 26 10:46:51 2011
New Revision: 16694

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16694
Log:
#10064: table of contents with identical attributes for a single frame

Modified:
    branches/Version135/Scribus/scribus/pageitem.cpp
    branches/Version135/Scribus/scribus/pageitem.h
    branches/Version135/Scribus/scribus/tocgenerator.cpp

Modified: branches/Version135/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16694&path=/branches/Version135/Scribus/scribus/pageitem.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem.cpp Sun Jun 26 10:46:51 2011
@@ -4103,23 +4103,36 @@
 	return &pageItemAttributes;
 }
 
+QList<ObjectAttribute> PageItem::getObjectAttributes(QString attributeName) const
+{
+	QList<ObjectAttribute> attributes;
+	for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin() ; objAttrIt != pageItemAttributes.end(); ++objAttrIt )
+	{
+		if (objAttrIt->name == attributeName)
+		{
+			attributes.append(*objAttrIt);
+		}
+	}
+	return attributes;
+}
+
 ObjectAttribute PageItem::getObjectAttribute(QString attributeName) const
 {
-	int countFound=0;
+	int countFound = 0;
 	ObjAttrVector::const_iterator foundIt = pageItemAttributes.begin();
-	for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin() ; objAttrIt != pageItemAttributes.end(); ++objAttrIt )
-	{
-		if ((*objAttrIt).name==attributeName)
+	for(ObjAttrVector::const_iterator objAttrIt = pageItemAttributes.begin(); objAttrIt != pageItemAttributes.end(); ++objAttrIt )
+	{
+		if (objAttrIt->name == attributeName)
 		{
 			++countFound;
-			foundIt=objAttrIt;
+			foundIt = objAttrIt;
 		}
 	}
 	ObjectAttribute returnAttribute;
-	if(countFound==1)
-		returnAttribute=(*foundIt);
+	if(countFound == 1)
+		returnAttribute = (*foundIt);
 	else
-		returnAttribute.name=QString::null;
+		returnAttribute.name = QString::null;
 	return returnAttribute;
 }
 

Modified: branches/Version135/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16694&path=/branches/Version135/Scribus/scribus/pageitem.h
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.h (original)
+++ branches/Version135/Scribus/scribus/pageitem.h Sun Jun 26 10:46:51 2011
@@ -263,10 +263,15 @@
 	void moveImageInFrame(double newX, double newY);
 
 	ObjAttrVector* getObjectAttributes();
+
 	/*!
-	 * brief Returns a complete ObjectAttribute struct if 1 is found, or ObjectAttribute.name will be QString::null if 0 or >1 are found
-	 */
-	ObjectAttribute getObjectAttribute(QString) const;
+	 * brief Returns a list of attributes with specified name
+	 */
+	QList<ObjectAttribute> getObjectAttributes(QString attributeName) const;
+	/*!
+	 * brief Returns a complete ObjectAttribute struct if 1 is found. ObjectAttribute.name will be QString::null if 0 or > 1 are found
+	 */
+	ObjectAttribute getObjectAttribute(QString attributeName) const;
 	void setObjectAttributes(ObjAttrVector*);
 	
 	virtual bool createInfoGroup(QFrame *, QGridLayout *) {return false;}

Modified: branches/Version135/Scribus/scribus/tocgenerator.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16694&path=/branches/Version135/Scribus/scribus/tocgenerator.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/tocgenerator.cpp (original)
+++ branches/Version135/Scribus/scribus/tocgenerator.cpp Sun Jun 26 10:46:51 2011
@@ -23,13 +23,13 @@
 #include <QMap>
 #include <QString>
 
-#include "scribusdoc.h"
-#include "pagestructs.h"
-#include "pageitem.h"
+#include "gtframestyle.h"
 #include "gtparagraphstyle.h"
-#include "gtframestyle.h"
 #include "gtwriter.h"
 #include "page.h"
+#include "pageitem.h"
+#include "pagestructs.h"
+#include "scribusdoc.h"
 
 TOCGenerator::TOCGenerator(QObject *parent, ScribusDoc *doc) : QObject(parent)
 {
@@ -71,80 +71,88 @@
 	if (currDoc==NULL)
 		return;
 	Q_ASSERT(!currDoc->masterPageMode());
-	for(ToCSetupVector::Iterator tocSetupIt = currDoc->docToCSetups.begin() ; tocSetupIt != currDoc->docToCSetups.end(); ++tocSetupIt )
+	for(ToCSetupVector::Iterator tocSetupIt = currDoc->docToCSetups.begin(); tocSetupIt != currDoc->docToCSetups.end(); ++tocSetupIt )
 	{
-		PageItem* tocFrame=findTargetFrame((*tocSetupIt).frameName);
-		if (tocFrame!=NULL)
+		PageItem* tocFrame = findTargetFrame(tocSetupIt->frameName);
+		if (tocFrame == NULL)
+			continue;
+
+		PageItem *currentDocItem;
+		QMap<QString, QString> tocMap;
+
+		uint *pageCounter = new uint[currDoc->DocPages.count()];
+		if (pageCounter == NULL)
+			return;
+		uint pageNumberWidth = QString("%1").arg(currDoc->DocPages.count()).length();
+		for (int i = 0;i < currDoc->DocPages.count();++i)
+			pageCounter[i] = 0;
+
+		for (int d = 0; d < currDoc->DocItems.count(); ++d)
 		{
-			PageItem *currentDocItem;
-			QMap<QString, QString> tocMap;
-			tocMap.clear();
-			uint *pageCounter = new uint[currDoc->DocPages.count()];
-			if (pageCounter==NULL)
-				return;
-			uint pageNumberWidth=QString("%1").arg(currDoc->DocPages.count()).length();
-			for (int i=0;i<currDoc->DocPages.count();++i)
-				pageCounter[i]=0;
-			int maxDataWidth=0;
-			for (int d = 0; d < currDoc->DocItems.count(); ++d)
+			currentDocItem = currDoc->DocItems.at(d);
+			if (currentDocItem == NULL)
+				continue;
+			//Item not on a page, continue
+			if (currentDocItem->OwnPage == -1)
+				continue;
+			//If we dont want to list non printing frames and this one is set to not print, continue
+			if (!tocSetupIt->listNonPrintingFrames && !currentDocItem->printEnabled())
+				continue;
+
+			ObjectAttribute objAttr;
+			QList<ObjectAttribute> objAttrs = currentDocItem->getObjectAttributes(tocSetupIt->itemAttrName);
+			if (objAttrs.count() <= 0)
+				continue;
+
+			QString pageID = QString("%1").arg(currentDocItem->OwnPage + currDoc->FirstPnum, pageNumberWidth);
+			QString sectionID = currDoc->getSectionPageNumberForPageIndex(currentDocItem->OwnPage);
+
+			for (int i = 0; i < objAttrs.count(); ++i)
 			{
-				currentDocItem = currDoc->DocItems.at(d);
-				if (currentDocItem!=NULL)
-				{
-					//Item not on a page, continue
-					if (currentDocItem->OwnPage==-1)
-						continue;
-					//If we dont want to list non printing frames and this one is set to not print, continue
-					if (!(*tocSetupIt).listNonPrintingFrames && !currentDocItem->printEnabled())
-						continue;
-					ObjectAttribute objattr=currentDocItem->getObjectAttribute((*tocSetupIt).itemAttrName);
-					if (!objattr.name.isNull())
-					{
-						//The key is generated to produce a sequence of numbers for the page numbers
-						//First is the page of the item
-						//Second is an incremented counter for the item so multiple per page works
-						//Third is the section based page number which is actually used in the TOC.
-						QString key=QString("%1,%2,%3").arg(currentDocItem->OwnPage + currDoc->FirstPnum, pageNumberWidth).arg(pageCounter[currentDocItem->OwnPage]++).arg(currDoc->getSectionPageNumberForPageIndex(currentDocItem->OwnPage));
-						tocMap.insert(key, objattr.value);
-						if (objattr.value.length()>maxDataWidth)
-							maxDataWidth=objattr.value.length();
-					}
-				}
+				objAttr = objAttrs.at(i);
+				if (objAttr.name.isNull())
+					continue;
+
+				//The key is generated to produce a sequence of numbers for the page numbers
+				//First is the page of the item
+				//Second is an incremented counter for the item so multiple per page works
+				//Third is the section based page number which is actually used in the TOC.
+				QString tocID = QString("%1").arg(pageCounter[currentDocItem->OwnPage]++, 2 , 10, QChar('0'));
+				QString key   = QString("%1,%2,%3").arg(pageID).arg(tocID).arg(sectionID);
+				tocMap.insert(key, objAttr.value);
 			}
-			//Set up the gtWriter instance with the selected paragraph style
-			gtWriter* writer = new gtWriter(false, tocFrame);
-			if (writer!=NULL)
-			{
-				writer->setUpdateParagraphStyles(false);
-				writer->setOverridePStyleFont(false);
-				gtFrameStyle* fstyle = writer->getDefaultStyle();
-				gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle);
-				pstyle->setName((*tocSetupIt).textStyle);
-				writer->setParagraphStyle(pstyle);
-				
-				QString oldTocPage=QString::null;
-				for (QMap<QString, QString>::Iterator tocIt=tocMap.begin();tocIt!=tocMap.end();++tocIt)
-				{
-					QString tocPage(tocIt.key().section( ',', 2, 2 ).trimmed());
-					QString tocLine;
-					//Start with text or numbers
-					if ((*tocSetupIt).pageLocation==End || (*tocSetupIt).pageLocation==NotShown)
-						tocLine = tocIt.value();
-					if ((*tocSetupIt).pageLocation==Beginning && oldTocPage!=tocPage)
-						tocLine = tocPage;
-					//Add in the tab for the leaders
-					tocLine+="\t";
-					//End with text or numbers
-					if ((*tocSetupIt).pageLocation==Beginning)
-						tocLine += tocIt.value();
-					if ((*tocSetupIt).pageLocation==End && oldTocPage!=tocPage)
-						tocLine += tocPage;
-					tocLine += "\n";
-					writer->append(tocLine);
-				}
-				delete writer;
-			}
-			delete[] pageCounter;
 		}
+
+		//Set up the gtWriter instance with the selected paragraph style
+		gtWriter writer(false, tocFrame);
+		writer.setUpdateParagraphStyles(false);
+		writer.setOverridePStyleFont(false);
+		gtFrameStyle* fstyle = writer.getDefaultStyle();
+		gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle);
+		pstyle->setName(tocSetupIt->textStyle);
+		writer.setParagraphStyle(pstyle);
+		
+		QString oldTocPage=QString::null;
+		for (QMap<QString, QString>::Iterator tocIt = tocMap.begin(); tocIt != tocMap.end();++tocIt)
+		{
+			QString tocPage(tocIt.key().section( ',', 2, 2 ).trimmed());
+			QString tocLine;
+			//Start with text or numbers
+			if (tocSetupIt->pageLocation == End || tocSetupIt->pageLocation == NotShown)
+				tocLine = tocIt.value();
+			if (tocSetupIt->pageLocation == Beginning && oldTocPage != tocPage)
+				tocLine = tocPage;
+			//Add in the tab for the leaders
+			tocLine += "\t";
+			//End with text or numbers
+			if (tocSetupIt->pageLocation == Beginning)
+				tocLine += tocIt.value();
+			if (tocSetupIt->pageLocation == End && oldTocPage != tocPage)
+				tocLine += tocPage;
+			tocLine += "\n";
+			writer.append(tocLine);
+		}
+
+		delete[] pageCounter;
 	}
 }




More information about the scribus-commit mailing list