r16396 by fschmid - Write out correctly sorted paragraph and char styles, so that there are no forward references in the xml.

scribus-commit scribus-commit at lists.scribus.net
Mon Feb 21 23:18:06 CET 2011


Author: fschmid
Date: Mon Feb 21 22:18:06 2011
New Revision: 16396

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16396
Log:
Write out correctly sorted paragraph and char styles, so that there are no forward references in the xml.

Modified:
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16396&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp Mon Feb 21 22:18:06 2011
@@ -66,17 +66,33 @@
 	}
 	QList<QString>::Iterator it;
 	QList<QString> names = lists.styleNames();
-	for (it = names.begin(); it != names.end(); ++it)
-	{
-		putPStyle(writer, m_Doc->paragraphStyles().get(*it), "STYLE");
-	}
+	QList<int> styleList = m_Doc->getSortedStyleList();
+	for (int a = 0; a < styleList.count(); ++a)
+	{
+		if (names.contains(m_Doc->paragraphStyles()[styleList[a]].name()))
+			putPStyle(writer, m_Doc->paragraphStyles()[styleList[a]], "STYLE");
+	}
+//	for (it = names.begin(); it != names.end(); ++it)
+//	{
+//		putPStyle(writer, m_Doc->paragraphStyles().get(*it), "STYLE");
+//	}
 	names = lists.charStyleNames();
-	for (it = names.begin(); it != names.end(); ++it)
-	{
-		writer.writeStartElement("CHARSTYLE");
-		putNamedCStyle(writer, m_Doc->charStyles().get(*it));
-		writer.writeEndElement();
-	}
+	styleList = m_Doc->getSortedCharStyleList();
+	for (int a = 0; a < styleList.count(); ++a)
+	{
+		if (names.contains(m_Doc->charStyles()[styleList[a]].name()))
+		{
+			writer.writeStartElement("CHARSTYLE");
+			putNamedCStyle(writer, m_Doc->charStyles()[styleList[a]]);
+			writer.writeEndElement();
+		}
+	}
+//	for (it = names.begin(); it != names.end(); ++it)
+//	{
+//		writer.writeStartElement("CHARSTYLE");
+//		putNamedCStyle(writer, m_Doc->charStyles().get(*it));
+//		writer.writeEndElement();
+//	}
 /*	names = lists.lineStyleNames();
 	for (it = names.begin(); it != names.end(); ++it)
 	{
@@ -548,11 +564,16 @@
 
 void Scribus150Format::writePStyles(ScXmlStreamWriter & docu) 
 {
+	QList<int> styleList = m_Doc->getSortedStyleList();
+	for (int a = 0; a < styleList.count(); ++a)
+	{
+		putPStyle(docu, m_Doc->paragraphStyles()[styleList[a]], "STYLE");
+	}
 	//	if (m_Doc->docParagraphStyles.count() > 5)
-	{
-		for (int ff = 0; ff < m_Doc->paragraphStyles().count(); ++ff)
-			putPStyle(docu, m_Doc->paragraphStyles()[ff], "STYLE");
-	}
+//	{
+//		for (int ff = 0; ff < m_Doc->paragraphStyles().count(); ++ff)
+//			putPStyle(docu, m_Doc->paragraphStyles()[ff], "STYLE");
+//	}
 }
 
 void Scribus150Format::putPStyle(ScXmlStreamWriter & docu, const ParagraphStyle & style, const QString &nodeName)
@@ -628,12 +649,19 @@
 
 void Scribus150Format::writeCStyles(ScXmlStreamWriter & docu) 
 {
-	for (int ff = 0; ff < m_Doc->charStyles().count(); ++ff)
+	QList<int> styleList = m_Doc->getSortedCharStyleList();
+	for (int a = 0; a < styleList.count(); ++a)
 	{
 		docu.writeStartElement("CHARSTYLE");
-		putNamedCStyle(docu, m_Doc->charStyles()[ff]);
+		putNamedCStyle(docu, m_Doc->charStyles()[styleList[a]]);
 		docu.writeEndElement();
 	}
+//	for (int ff = 0; ff < m_Doc->charStyles().count(); ++ff)
+//	{
+//		docu.writeStartElement("CHARSTYLE");
+//		putNamedCStyle(docu, m_Doc->charStyles()[ff]);
+//		docu.writeEndElement();
+//	}
 }
 
 void Scribus150Format::putCStylePT(ScXmlStreamWriter & docu, const CharStyle & style)

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16396&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Mon Feb 21 22:18:06 2011
@@ -996,6 +996,79 @@
 	return false;
 }
 
+QList<int> ScribusDoc::getSortedStyleList()
+{
+	QList<int> retList;
+	for (int ff = 0; ff < paragraphStyles().count(); ++ff)
+	{
+		if (paragraphStyles()[ff].parent().isEmpty())
+		{
+			if (!retList.contains(ff))
+				retList.append(ff);
+		}
+		else
+		{
+			QList<int> retList2;
+			QString par = paragraphStyles()[ff].parent();
+			retList2.prepend(ff);
+			while (!par.isEmpty())
+			{
+				for (int pp = 0; pp < paragraphStyles().count(); ++pp)
+				{
+					if (paragraphStyles()[pp].name() == par)
+					{
+						if (!retList2.contains(pp))
+							retList2.prepend(pp);
+						par = paragraphStyles()[pp].parent();
+					}
+				}
+			}
+			for (int r = 0; r < retList2.count(); ++r)
+			{
+				if (!retList.contains(retList2[r]))
+					retList.append(retList2[r]);
+			}
+		}
+	}
+	return retList;
+}
+
+QList<int> ScribusDoc::getSortedCharStyleList()
+{
+	QList<int> retList;
+	for (int ff = 0; ff < docCharStyles.count(); ++ff)
+	{
+		if (docCharStyles[ff].parent().isEmpty())
+		{
+			if (!retList.contains(ff))
+				retList.append(ff);
+		}
+		else
+		{
+			QList<int> retList2;
+			QString par = docCharStyles[ff].parent();
+			retList2.prepend(ff);
+			while (!par.isEmpty())
+			{
+				for (int pp = 0; pp < docCharStyles.count(); ++pp)
+				{
+					if (docCharStyles[pp].name() == par)
+					{
+						if (!retList2.contains(pp))
+							retList2.prepend(pp);
+						par = docCharStyles[pp].parent();
+					}
+				}
+			}
+			for (int r = 0; r < retList2.count(); ++r)
+			{
+				if (!retList.contains(retList2[r]))
+					retList.append(retList2[r]);
+			}
+		}
+	}
+	return retList;
+}
 
 void ScribusDoc::replaceStyles(const QMap<QString,QString>& newNameForOld)
 {

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16396&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Mon Feb 21 22:18:06 2011
@@ -519,6 +519,8 @@
 	void getNamedResources(ResourceCollection& lists) const;
 	void replaceNamedResources(ResourceCollection& newNames);
 	bool styleExists(QString styleName);
+	QList<int> getSortedStyleList();
+	QList<int> getSortedCharStyleList();
 	
 	void redefineStyles(const StyleSet<ParagraphStyle>& newStyles, bool removeUnused=false);
 	/**




More information about the scribus-commit mailing list