r24315 by jghali - Get rid of deprecated QXmlAttributes in HTML and SXW importers

scribus-commit scribus-commit at lists.scribus.net
Wed Dec 9 04:14:36 UTC 2020


Author: jghali
Date: Wed Dec  9 04:14:36 2020
New Revision: 24315

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24315
Log:
Get rid of deprecated QXmlAttributes in HTML and SXW importers

Modified:
    trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.cpp
    trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.h
    trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.cpp
    trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.h

Modified: trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24315&path=/trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.cpp	(original)
+++ trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.cpp	Wed Dec  9 04:14:36 2020
@@ -111,16 +111,20 @@
 	elemJustStarted = true;
 	elemJustFinished = false;
 	QString name(QString((const char*) fullname).toLower());
-	QXmlAttributes attrs;
+	HTMLAttributesMap attrs;
 	if (atts)
 	{
 		for (const xmlChar** cur = atts; cur && *cur; cur += 2)
-			attrs.append(QString((char*)*cur), nullptr, QString((char*)*cur), QString((char*)*(cur + 1)));
-	}
-	hreader->startElement(nullptr, nullptr, name, attrs);
-}
-
-bool HTMLReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs) 
+		{
+			QString attrName((char*)*cur);
+			QString attrValue((char*)*(cur + 1));
+			attrs[attrName] = attrValue;
+		}
+	}
+	hreader->startElement(name, attrs);
+}
+
+bool HTMLReader::startElement(const QString &name, const HTMLAttributesMap &attrs) 
 {
 	if (name == "p")
 		inP = true;
@@ -132,14 +136,10 @@
 	{
 		toggleEffect(UNDERLINE);
 		setBlueFont();
-		for (int i = 0; i < attrs.count(); i++)
-		{
-			if (attrs.localName(i) == "href")
-			{
-				href = attrs.value(i);
-			}
-			inA = true;
-		}
+		QString hRefVal = attrs.value("href");
+		if (!hRefVal.isEmpty())
+			href = hRefVal;
+		inA = true;
 	} 
 	else if (name == "ul")
 	{
@@ -192,26 +192,22 @@
 	else if (name == "img")
 	{
 		QString imgline("(img,");
-		for (int i = 0; i < attrs.count(); i++)
-		{
-			if (attrs.localName(i) == "src")
+		QString srcValue = attrs.value("src");
+		if (!srcValue.isEmpty())
+		{
+			QString attrValue = srcValue;
+			if (attrValue.indexOf("data:image") < 0)
+				imgline +=  " src: " + attrValue;
+			else
 			{
-				QString attrValue = attrs.value(i);
-				if (attrValue.indexOf("data:image") < 0)
-					imgline +=  " src: " + attrValue;
-				else
-				{
-					// TODO: correctly embed the image (just putting the source in the
-					// text frame crashes scribus for big images; ale/20120808)
-					imgline +=  " src: embedded image";
-				}
+				// TODO: correctly embed the image (just putting the source in the
+				// text frame crashes scribus for big images; ale/20120808)
+				imgline +=  " src: embedded image";
 			}
-			if (attrs.localName(i) == "alt")
-			{
-				if (!attrs.value(i).isEmpty())
-					imgline += ", alt: " + attrs.value(i);
-			}
-		}
+		}
+		QString altValue = attrs.value("alt");
+		if (!altValue.isEmpty())
+			imgline += ", alt: " + altValue;
 		imgline += ")\n\n";
 		writer->append(imgline, pstyle);
 	}
@@ -317,10 +313,10 @@
 	elemJustStarted = false;
 	elemJustFinished = true;
 	QString nname(QString((const char*) name).toLower());
-	hreader->endElement(nullptr, nullptr, nname);
-}
-
-bool HTMLReader::endElement(const QString&, const QString&, const QString &name)
+	hreader->endElement(nname);
+}
+
+bool HTMLReader::endElement(const QString &name)
 {
 	if (name == "center")
 	{

Modified: trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24315&path=/trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.h	(original)
+++ trunk/Scribus/scribus/plugins/gettext/htmlim/htmlreader.h	Wed Dec  9 04:14:36 2020
@@ -31,11 +31,13 @@
 #include <vector>
 #include <libxml/HTMLparser.h>
 
+#include <QMap>
 #include <QString>
-#include <QXmlAttributes>
 
 #include <gtparagraphstyle.h>
 #include <gtwriter.h>
+
+typedef QMap<QString, QString> HTMLAttributesMap;
 
 /*! \brief Parse and import a HTML file.
 Supported tags: P, CENTER, BR, A, UL, OL, LI, H1, H2, H3, H4,
@@ -52,8 +54,8 @@
 	static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
 	static void endElement(void *user_data, const xmlChar * name);
 	static void characters(void *user_data, const xmlChar * ch, int len);
-	bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
-	bool endElement(const QString&, const QString&, const QString &name);
+	bool startElement(const QString &name, const HTMLAttributesMap &attrs);
+	bool endElement(const QString &name);
 	bool characters(const QString &ch);
 
 private:

Modified: trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24315&path=/trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.cpp	(original)
+++ trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.cpp	Wed Dec  9 04:14:36 2020
@@ -26,12 +26,13 @@
 
 #include "stylereader.h"
 
+#include <QByteArray>
+
 #include <scribusstructs.h>
 #include <gtmeasure.h>
 #include <gtparagraphstyle.h>
 #include <gtframestyle.h>
 #include <gtfont.h>
-#include <QByteArray>
 
 StyleReader* StyleReader::sreader = nullptr;
 
@@ -47,7 +48,34 @@
 	packStyles   = combineStyles;
 }
 
-bool StyleReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs)
+StyleReader::~StyleReader()
+{
+	sreader = nullptr;
+	StyleMap::Iterator it;
+	for (it = styles.begin(); it != styles.end(); ++it)
+	{
+		if (it.value())
+		{
+			delete it.value();
+			it.value() = nullptr;
+		}
+	}
+}
+
+void StyleReader::startElement(void*, const xmlChar * fullname, const xmlChar ** atts)
+{
+	QString name = QString((const char*) fullname).toLower();
+	SXWAttributesMap attrs;
+	for (const xmlChar** cur = atts; cur && *cur; cur += 2)
+	{
+		QString attrName((char*)*cur);
+		QString attrValue((char*)*(cur + 1));
+		attrs[attrName] = attrValue;
+	}
+	sreader->startElement(name, attrs);
+}
+
+bool StyleReader::startElement(const QString &name, const SXWAttributesMap &attrs)
 {
 	if (name == "style:default-style")
 		defaultStyle(attrs);
@@ -69,89 +97,84 @@
 		tabStop(attrs);
 	else if (name == "text:list-style")
 	{
-		for (int i = 0; i < attrs.count(); ++i)
-			if (attrs.localName(i) == "style:name")
-				currentList = attrs.value(i);
+		currentList = attrs.value("style:name");
 		inList = true;
 	}
 	else if (((name == "text:list-level-style-bullet") ||
 			  (name == "text:list-level-style-number") ||
 			  (name == "text:list-level-style-image")) && (inList))
 	{
-		for (int i = 0; i < attrs.count(); ++i)
-		{
-			if (attrs.localName(i) == "text:level")
-			{
-				gtStyle *plist;
-				if (attrs.value(i) == "1")
+		QString textLevel = attrs.value("text:level");
+		if (!textLevel.isEmpty())
+		{
+			gtStyle *plist;
+			if (textLevel == "1")
+			{
+				plist = listParents[currentList];
+			}
+			else
+			{
+				int level = textLevel.toInt();
+				--level;
+				plist = styles[QString(currentList + "_%1").arg(level)];
+			}
+			gtParagraphStyle *pstyle;
+			if (plist == nullptr)
+				plist = new gtStyle(*(styles["default-style"]));
+
+			if (plist->target() == "paragraph")
+			{
+				pstyle = dynamic_cast<gtParagraphStyle*>(plist);
+				assert(pstyle != nullptr);
+				gtParagraphStyle* tmp = new gtParagraphStyle(*pstyle);
+				currentStyle = tmp;
+			}
+			else
+			{
+				gtParagraphStyle* tmp = new gtParagraphStyle(*plist);
+				currentStyle = tmp;
+			}
+			currentStyle->setName(currentList + "_" + textLevel);
+		}
+		readProperties = true;
+	}
+	else if ((name == "style:drop-cap") && (readProperties))
+	{
+		if (currentStyle->target() == "paragraph")
+		{
+			QString styleLines = attrs.value( "style:lines");
+			if (!styleLines.isEmpty())
+			{
+				bool ok = false;
+				QString sd = styleLines;
+				int dh = sd.toInt(&ok);
+				if (ok)
 				{
-					plist = listParents[currentList];
+					gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
+					assert(s != nullptr);
+					s->setDropCapHeight(dh);
+					s->setDropCap(true);
 				}
-				else
-				{
-					int level = (attrs.value(i)).toInt();
-					--level;
-					plist = styles[QString(currentList + "_%1").arg(level)];
-				}
-				gtParagraphStyle *pstyle;
-				if (plist == nullptr)
-					plist = new gtStyle(*(styles["default-style"]));
-
-				if (plist->target() == "paragraph")
-				{
-					pstyle = dynamic_cast<gtParagraphStyle*>(plist);
-					assert(pstyle != nullptr);
-					gtParagraphStyle* tmp = new gtParagraphStyle(*pstyle);
-					currentStyle = tmp;
-				}
-				else
-				{
-					gtParagraphStyle* tmp = new gtParagraphStyle(*plist);
-					currentStyle = tmp;
-				}
-				currentStyle->setName(currentList + "_" + attrs.value(i));
-			}
-		}
-		readProperties = true;
-	}
-	else if ((name == "style:drop-cap") && (readProperties))
-	{
-		if (currentStyle->target() == "paragraph")
-		{
-			for (int i = 0; i < attrs.count(); ++i)
-			{
-				if (attrs.localName(i) == "style:lines")
-				{
-					bool ok = false;
-					QString sd = attrs.value(i);
-					int dh = sd.toInt(&ok);
-					if (ok)
-					{
-						gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
-						assert(s != nullptr);
-						s->setDropCapHeight(dh);
-						s->setDropCap(true);
-					}
-				}
 			}
 		}
 	}
 	else if (name == "style:font-decl")
 	{
-		QString key = "";
-		QString family = "";
-		QString style = "";
-		for (int i = 0; i < attrs.count(); ++i)
-		{
-			if (attrs.localName(i) == "style:name")
-				key = attrs.value(i);
-			else if (attrs.localName(i) == "fo:font-family")
-			{
-				family = attrs.value(i);
+		QString key;
+		QString family;
+		QString style;
+		for (auto& attr = attrs.cbegin(); attr != attrs.cend(); ++attr)
+		{
+			QString attrName = attr.key();
+			if (attrName == "style:name")
+				key = attr.value();
+			else if (attrName == "fo:font-family")
+			{
+				family = attr.value();
 				family = family.remove("'");
 			}
-			else if (attrs.localName(i) == "style:font-style-name")
-				style += attrs.value(i) + " ";
+			else if (attrName == "style:font-style-name")
+				style += attr.value() + " ";
 		}
 		QString name = family + " " + style;
 		name = name.simplified();
@@ -160,40 +183,42 @@
 	return true;
 }
 
-void StyleReader::defaultStyle(const QXmlAttributes& attrs)
+void StyleReader::defaultStyle(const SXWAttributesMap& attrs)
 {
 	currentStyle = nullptr;
-	for (int i = 0; i < attrs.count(); ++i)
-	{
-		if (attrs.localName(i) == "style:family" && attrs.value(i) == "paragraph")
-		{
-			gtParagraphStyle* pstyle = new gtParagraphStyle(writer->getDefaultStyle()->asGtParagraphStyle());
-			pstyle->setDefaultStyle(true);
-			currentStyle = dynamic_cast<gtStyle*>(pstyle);
-			currentStyle->setName("default-style");
-			readProperties = true;
-			defaultStyleCreated = true;
-		}
-	}
-}
-
-void StyleReader::styleProperties(const QXmlAttributes& attrs)
+	QString styleFamily = attrs.value("style:family");
+	if (styleFamily == "paragraph")
+	{
+		gtParagraphStyle* pstyle = new gtParagraphStyle(writer->getDefaultStyle()->asGtParagraphStyle());
+		pstyle->setDefaultStyle(true);
+		currentStyle = dynamic_cast<gtStyle*>(pstyle);
+		currentStyle->setName("default-style");
+		readProperties = true;
+		defaultStyleCreated = true;
+	}
+}
+
+void StyleReader::styleProperties(const SXWAttributesMap& attrs)
 {
 	if ((currentStyle == nullptr) || (!readProperties))
 		return;
+
 	gtParagraphStyle* pstyle = nullptr;
 	if (currentStyle->target() == "paragraph")
 		pstyle = dynamic_cast<gtParagraphStyle*>(currentStyle);
 	else
 		pstyle = nullptr;
+
 	QString align;
 	QString force;
 	bool hasColorTag = false;
-	for (int i = 0; i < attrs.count(); ++i)
-	{
-		if ((attrs.localName(i) == "style:font-name") && (!inList))
-			currentStyle->getFont()->setName(getFont(attrs.value(i)));
-		else if (attrs.localName(i) == "fo:font-size")
+	for (auto attr = attrs.begin(); attr != attrs.end(); ++attr)
+	{
+		QString attrName = attr.key();
+		QString attrValue = attr.value();
+		if ((attrName == "style:font-name") && (!inList))
+			currentStyle->getFont()->setName(getFont(attrValue));
+		else if (attrName == "fo:font-size")
 		{
 			double size = 0.0;
 			double psize = 0.0;
@@ -203,84 +228,84 @@
 				psize = static_cast<double>(styles["default-style"]->getFont()->getSize());
 
 			psize = psize / 10;
-			size = getSize(attrs.value(i), psize);
+			size = getSize(attrValue, psize);
 			int nsize = static_cast<int>(size * 10);
 			currentStyle->getFont()->setSize(nsize);
 			if (pstyle)
 				pstyle->setLineSpacing(writer->getPreferredLineSpacing(nsize));
 		}
-		else if ((attrs.localName(i) == "fo:line-height") && (parentStyle != nullptr))
+		else if ((attrName == "fo:line-height") && (parentStyle != nullptr))
 		{
 			gtParagraphStyle* ppstyle;
 			if (parentStyle->target() == "paragraph")
 			{
 				ppstyle = dynamic_cast<gtParagraphStyle*>(parentStyle);
 				assert(ppstyle != nullptr);
-				ppstyle->setLineSpacing(getSize(attrs.value(i), writer->getPreferredLineSpacing(currentStyle->getFont()->getSize())));
-			}
-		}
-		else if (attrs.localName(i) == "fo:color")
-		{
-			currentStyle->getFont()->setColor(attrs.value(i));
+				ppstyle->setLineSpacing(getSize(attrValue, writer->getPreferredLineSpacing(currentStyle->getFont()->getSize())));
+			}
+		}
+		else if (attrName == "fo:color")
+		{
+			currentStyle->getFont()->setColor(attrValue);
 			hasColorTag = true;
 		}
-		else if ((attrs.localName(i) == "style:use-window-font-color") && (attrs.value(i) == "true"))
+		else if ((attrName == "style:use-window-font-color") && (attrValue == "true"))
 		{
 			currentStyle->getFont()->setColor("Black");
 			hasColorTag = true;
 		}
-		else if ((attrs.localName(i) == "fo:font-weight") && (attrs.value(i) == "bold"))
+		else if ((attrName == "fo:font-weight") && (attrValue == "bold"))
 			currentStyle->getFont()->setWeight(BOLD);
-		else if ((attrs.localName(i) == "fo:font-style") && (attrs.value(i) == "italic"))
+		else if ((attrName == "fo:font-style") && (attrValue == "italic"))
 			currentStyle->getFont()->setSlant(ITALIC);
-		else if ((attrs.localName(i) == "style:text-underline") && (attrs.value(i) != "none"))
+		else if ((attrName == "style:text-underline") && (attrValue != "none"))
 			currentStyle->getFont()->toggleEffect(UNDERLINE);
-		else if ((attrs.localName(i) == "style:text-crossing-out") && (attrs.value(i) != "none"))
+		else if ((attrName == "style:text-crossing-out") && (attrValue != "none"))
 			currentStyle->getFont()->toggleEffect(STRIKETHROUGH);
-		else if ((attrs.localName(i) == "fo:font-variant") && (attrs.value(i) == "small-caps"))
+		else if ((attrName == "fo:font-variant") && (attrValue == "small-caps"))
 			currentStyle->getFont()->toggleEffect(SMALL_CAPS);
-		else if ((attrs.localName(i) == "style:text-outline") && (attrs.value(i) == "true"))
+		else if ((attrName == "style:text-outline") && (attrValue == "true"))
 		{
 			currentStyle->getFont()->toggleEffect(OUTLINE);
 			currentStyle->getFont()->setStrokeColor("Black");
 			currentStyle->getFont()->setColor("White");
 		}
-		else if (attrs.localName(i) == "fo:letter-spacing")
-			currentStyle->getFont()->setKerning(static_cast<int>(getSize(attrs.value(i), -1.0)));
-		else if (attrs.localName(i) == "style:text-scale")
-			currentStyle->getFont()->setHscale(static_cast<int>(getSize(attrs.value(i), -1.0)));
-		else if ((attrs.localName(i) == "style:text-position") &&
-				 (((attrs.value(i)).indexOf("sub") != -1) ||
-				  (((attrs.value(i)).at(0) == "-") && ((attrs.value(i)).at(0) != "0"))))
+		else if (attrName == "fo:letter-spacing")
+			currentStyle->getFont()->setKerning(static_cast<int>(getSize(attrValue, -1.0)));
+		else if (attrName == "style:text-scale")
+			currentStyle->getFont()->setHscale(static_cast<int>(getSize(attrValue, -1.0)));
+		else if ((attrName == "style:text-position") &&
+				 (((attrValue).indexOf("sub") != -1) ||
+				  (((attrValue).at(0) == "-") && ((attrValue).at(0) != "0"))))
 			currentStyle->getFont()->toggleEffect(SUBSCRIPT);
-		else if ((attrs.localName(i) == "style:text-position") &&
-				 (((attrs.value(i)).indexOf("super") != -1) ||
-				  (((attrs.value(i)).at(0) != "-") && ((attrs.value(i)).at(0) != "0"))))
+		else if ((attrName == "style:text-position") &&
+				 (((attrValue).indexOf("super") != -1) ||
+				  (((attrValue).at(0) != "-") && ((attrValue).at(0) != "0"))))
 			currentStyle->getFont()->toggleEffect(SUPERSCRIPT);
-		else if ((attrs.localName(i) == "fo:margin-top") && (pstyle != nullptr))
-			pstyle->setSpaceAbove(getSize(attrs.value(i)));
-		else if ((attrs.localName(i) == "fo:margin-bottom") && (pstyle != nullptr))
-			pstyle->setSpaceBelow(getSize(attrs.value(i)));
-		else if ((attrs.localName(i) == "fo:margin-left") && (pstyle != nullptr))
+		else if ((attrName == "fo:margin-top") && (pstyle != nullptr))
+			pstyle->setSpaceAbove(getSize(attrValue));
+		else if ((attrName == "fo:margin-bottom") && (pstyle != nullptr))
+			pstyle->setSpaceBelow(getSize(attrValue));
+		else if ((attrName == "fo:margin-left") && (pstyle != nullptr))
 		{
 			if (inList)
-				pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
-			else
-				pstyle->setIndent(getSize(attrs.value(i)));
-		}
-		else if ((attrs.localName(i) == "text:space-before") && (pstyle != nullptr))
+				pstyle->setIndent(pstyle->getIndent() + getSize(attrValue));
+			else
+				pstyle->setIndent(getSize(attrValue));
+		}
+		else if ((attrName == "text:space-before") && (pstyle != nullptr))
 		{
 			if (inList)
-				pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
-			else
-				pstyle->setIndent(getSize(attrs.value(i)));
-		}
-		else if ((attrs.localName(i) == "fo:text-indent") && (pstyle != nullptr))
-			pstyle->setFirstLineIndent(getSize(attrs.value(i)));
-		else if ((attrs.localName(i) == "fo:text-align") && (pstyle != nullptr))
-			align = attrs.value(i);
-		else if ((attrs.localName(i) == "style:justify-single-word") && (pstyle != nullptr))
-			force = attrs.value(i);
+				pstyle->setIndent(pstyle->getIndent() + getSize(attrValue));
+			else
+				pstyle->setIndent(getSize(attrValue));
+		}
+		else if ((attrName == "fo:text-indent") && (pstyle != nullptr))
+			pstyle->setFirstLineIndent(getSize(attrValue));
+		else if ((attrName == "fo:text-align") && (pstyle != nullptr))
+			align = attrValue;
+		else if ((attrName == "style:justify-single-word") && (pstyle != nullptr))
+			force = attrValue;
 	}
 	if (!align.isEmpty() && (pstyle != nullptr))
 	{
@@ -300,7 +325,7 @@
 		currentStyle->getFont()->setColor("Black");
 }
 
-void StyleReader::styleStyle(const QXmlAttributes& attrs)
+void StyleReader::styleStyle(const SXWAttributesMap& attrs)
 {
 	QString name;
 	QString listName;
@@ -319,16 +344,18 @@
 		parentStyle  = currentStyle;
 	}
 
-	for (int i = 0; i < attrs.count(); ++i)
-	{
-		if (attrs.localName(i) == "style:family")
-		{
-			if (attrs.value(i) == "paragraph")
+	for (auto attr = attrs.begin(); attr != attrs.end(); ++attr)
+	{
+		QString attrName = attr.key();
+		QString attrValue = attr.value();
+		if (attrName == "style:family")
+		{
+			if (attrValue == "paragraph")
 			{
 				isParaStyle = true;
 				readProperties = true;
 			}
-			else if (attrs.value(i) == "text")
+			else if (attrValue == "text")
 			{
 				isParaStyle = false;
 				readProperties = true;
@@ -339,17 +366,17 @@
 				return;
 			}
 		}
-		else if (attrs.localName(i) == "style:name")
-			name = attrs.value(i);
-		else if (attrs.localName(i) == "style:parent-style-name")
-		{
-			if (styles.contains(attrs.value(i)))
-				parentStyle = styles[attrs.value(i)];
+		else if (attrName == "style:name")
+			name = attrValue;
+		else if (attrName == "style:parent-style-name")
+		{
+			if (styles.contains(attrValue))
+				parentStyle = styles[attrValue];
 			else
 				parentStyle = nullptr;
 		}
-		else if (attrs.localName(i) == "style:list-style-name")
-			listName = attrs.value(i);
+		else if (attrName == "style:list-style-name")
+			listName = attrValue;
 	}
 	if ((parentStyle == nullptr) && (styles.contains("default-style")))
 		parentStyle = styles["default-style"];
@@ -397,22 +424,14 @@
 		currentStyle = nullptr;
 }
 
-void StyleReader::tabStop(const QXmlAttributes& attrs)
+void StyleReader::tabStop(const SXWAttributesMap& attrs)
 {
 	if (currentStyle->target() == "paragraph")
 	{
 		gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(currentStyle);
 		assert(pstyle != nullptr);
-		QString pos;
-		QString type;
-		for (int i = 0; i < attrs.count(); ++i)
-		{
-			if (attrs.localName(i) == "style:position")
-				pos = attrs.value(i);
-			else if (attrs.localName(i) == "style:type")
-				type = attrs.value(i);
-
-		}
+		QString pos = attrs.value("style:position");
+		QString type = attrs.value("style:type");
 		if (!pos.isEmpty())
 		{
 			if (!type.isEmpty())
@@ -430,7 +449,13 @@
 	}
 }
 
-bool StyleReader::endElement(const QString&, const QString&, const QString &name)
+void StyleReader::endElement(void*, const xmlChar * name)
+{
+	QString nname = QString((const char*) name).toLower();
+	sreader->endElement(nname);
+}
+
+bool StyleReader::endElement(const QString &name)
 {
 	if ((name == "style:default-style") && (currentStyle != nullptr) && (readProperties))
 	{
@@ -741,20 +766,6 @@
 			ret = factor;
 	}
 	return ret;
-}
-
-StyleReader::~StyleReader()
-{
-	sreader = nullptr;
-	StyleMap::Iterator it;
-	for (it = styles.begin(); it != styles.end(); ++it)
-	{
-		if (it.value())
-		{
-			delete it.value();
-			it.value() = nullptr;
-		}
-	}
 }
 
 xmlSAXHandler sSAXHandlerStruct = {
@@ -797,18 +808,3 @@
 
 xmlSAXHandlerPtr sSAXHandler = &sSAXHandlerStruct;
 
-void StyleReader::startElement(void*, const xmlChar * fullname, const xmlChar ** atts)
-{
-	QString name = QString((const char*) fullname).toLower();
-	QXmlAttributes attrs;
-	for (const xmlChar** cur = atts; cur && *cur; cur += 2)
-		attrs.append(QString((char*)*cur), nullptr, QString((char*)*cur), QString((char*)*(cur + 1)));
-	sreader->startElement(nullptr, nullptr, name, attrs);
-}
-
-void StyleReader::endElement(void*, const xmlChar * name)
-{
-	QString nname = QString((const char*) name).toLower();
-	sreader->endElement(nullptr, nullptr, nname);
-}
-

Modified: trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24315&path=/trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.h	(original)
+++ trunk/Scribus/scribus/plugins/gettext/sxwim/stylereader.h	Wed Dec  9 04:14:36 2020
@@ -35,12 +35,13 @@
  #include <libxml/SAX.h>
 #endif
 #include <QMap>
-#include <QXmlAttributes>
+
 #include <gtstyle.h>
 #include <gtwriter.h>
 
 typedef QMap<QString, gtStyle*> StyleMap;
 typedef QMap<QString, QString> FontMap;
+typedef QMap<QString, QString> SXWAttributesMap;
 typedef QMap<QString, int> CounterMap;
 
 class StyleReader
@@ -48,17 +49,20 @@
 public:
 	StyleReader(const QString& documentName, gtWriter *wr, bool textOnly, bool prefix, bool combineStyles = true);
 	~StyleReader();
+	
+	void parse(const QString& fileName);
 
-	bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
 	static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
 	static void endElement(void *user_data, const xmlChar * name);
-	bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
-	bool endElement(const QString&, const QString&, const QString &name);
-	void parse(const QString& fileName);
+	bool startElement(const QString &name, const SXWAttributesMap &attrs);
+	bool endElement(const QString &name);
+
 	gtStyle* getDefaultStyle();
 	gtStyle* getStyle(const QString& name);
 	void setStyle(const QString& name, gtStyle* style);
 	QString getFont(const QString& key);
+
+	bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
 
 private:
 	static StyleReader *sreader;
@@ -81,10 +85,10 @@
 	bool defaultStyleCreated { false };
 
 	double getSize(const QString& s, double parentSize = -1);
-	void styleProperties(const QXmlAttributes& attrs);
-	void defaultStyle(const QXmlAttributes& attrs);
-	void styleStyle(const QXmlAttributes& attrs);
-	void tabStop(const QXmlAttributes& attrs);
+	void styleProperties(const SXWAttributesMap& attrs);
+	void defaultStyle(const SXWAttributesMap& attrs);
+	void styleStyle(const SXWAttributesMap& attrs);
+	void tabStop(const SXWAttributesMap& attrs);
 	void setupFrameStyle();
 };
 




More information about the scribus-commit mailing list