Author: jghali
Date: Tue Dec 22 00:06:47 2020
New Revision: 24341

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

Modified:
    trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp
    trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.h

Modified: trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24341&path=/trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp       
(original)
+++ trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.cpp       Tue Dec 
22 00:06:47 2020
@@ -57,20 +57,14 @@
        tName = "";
 }
 
-bool ContentReader::startElement(const QString&, const QString&, const QString 
&name, const QXmlAttributes &attrs) 
+bool ContentReader::startElement(const QString &name, const SXWAttributesMap 
&attrs) 
 {
        if ((name == "text:p") || (name == "text:h"))
        {
                ++append;
-               QString name = "";
-               for (int i = 0; i < attrs.count(); ++i)
-               {
-                       if (attrs.localName(i) == "text:style-name")
-                       {
-                               name = attrs.value(i);
-                               styleNames.push_back(attrs.value(i));
-                       }
-               }
+               QString name = attrs.value("text:style-name");
+               if (!name.isEmpty())
+                       styleNames.push_back(name);
                if (!inList)
                {
                        pstyle = sreader->getStyle(name);
@@ -88,15 +82,11 @@
        else if (name == "text:span")
        {
                inSpan = true;
-               QString styleName = "";
-               for (int i = 0; i < attrs.count(); ++i)
-               {
-                       if (attrs.localName(i) == "text:style-name")
-                       {
-                               currentStyle = 
sreader->getStyle(attrs.value(i));
-                               styleName = attrs.value(i);
-                               styleNames.push_back(styleName);
-                       }
+               QString styleName = attrs.value("text:style-name");
+               if (!styleName.isEmpty())
+               {
+                       currentStyle = sreader->getStyle(styleName);
+                       styleNames.push_back(styleName);
                }
                gtStyle *tmp = sreader->getStyle(getName());
                if ((tmp->getName()).indexOf("default-style") != -1)
@@ -110,11 +100,9 @@
                ++listLevel;
                if (static_cast<int>(listIndex2.size()) < listLevel)
                        listIndex2.push_back(0);
-               for (int i = 0; i < attrs.count(); ++i)
-               {
-                       if (attrs.localName(i) == "text:style-name")
-                               currentList = attrs.value(i);
-               }
+               QString styleName = attrs.value("text:style-name");
+               if (!styleName.isEmpty())
+                       currentList = styleName;
                currentStyle = sreader->getStyle(QString(currentList + 
"_%1").arg(listLevel));
                styleNames.clear();
                styleNames.push_back(QString(currentList + 
"_%1").arg(listLevel));
@@ -149,11 +137,12 @@
        {
                QString sname = "";
                bool isTextStyle = false;
-               for (int i = 0; i < attrs.count(); ++i)
-               {
-                       if (attrs.localName(i) == "style:name")
-                               sname = attrs.value(i);
-                       else if ((attrs.localName(i) == "style:family") && 
(attrs.value(i) == "text"))
+               for (auto attr = attrs.cbegin(); attr != attrs.cend(); ++attr)
+               {
+                       QString attrName = attr.key();
+                       if (attrName == "style:name")
+                               sname = attr.value();
+                       else if ((attrName == "style:family") && (attr.value() 
== "text"))
                                isTextStyle = true;
                }
                if (isTextStyle)
@@ -165,9 +154,9 @@
        else if ((name == "style:properties") && (inT))
        {
                Properties p;
-               for (int i = 0; i < attrs.count(); ++i)
-               {
-                       std::pair<QString, QString> pair(attrs.localName(i), 
attrs.value(i));
+               for (auto attr = attrs.cbegin(); attr != attrs.cend(); ++attr)
+               {
+                       std::pair<QString, QString> pair(attr.key(), 
attr.value());
                        p.push_back(pair);
                }
                tmap[tName] = p;
@@ -175,15 +164,13 @@
        else if (name == "text:s")
        {
                int count = 1;
-               for (int i = 0; i < attrs.count(); ++i)
-               {
-                       if (attrs.localName(i) == "text:c")
-                       {
-                               bool ok = false;
-                               int tmpcount = (attrs.value(i)).toInt(&ok);
-                               if (ok)
-                                       count = tmpcount;
-                       }
+               QString textC = attrs.value("text:c");
+               if (!textC.isEmpty())
+               {
+                       bool ok = false;
+                       int tmpcount = textC.toInt(&ok);
+                       if (ok)
+                               count = tmpcount;
                }
                for (int i = 0; i < count; ++i)
                        write(" ");
@@ -203,7 +190,7 @@
        return true;
 }
 
-bool ContentReader::endElement(const QString&, const QString&, const QString 
&name)
+bool ContentReader::endElement(const QString &name)
 {
        if ((name == "text:p") || (name == "text:h"))
        {
@@ -325,13 +312,14 @@
 void ContentReader::startElement(void*, const xmlChar *fullname, const xmlChar 
** atts)
 {
        QString name(QString((const char*) fullname).toLower());
-       QXmlAttributes 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)));
-       }
-       creader->startElement(nullptr, nullptr, name, attrs);
+       SXWAttributesMap attrs;
+       for (const xmlChar** cur = atts; cur && *cur; cur += 2)
+       {
+               QString attrName((char*)*cur);
+               QString attrValue((char*)*(cur + 1));
+               attrs[attrName] = attrValue;
+       }
+       creader->startElement(name, attrs);
 }
 
 void ContentReader::characters(void*, const xmlChar *ch, int len)
@@ -343,7 +331,7 @@
 void ContentReader::endElement(void*, const xmlChar *name)
 {
        QString nname(QString((const char*) name).toLower());
-       creader->endElement(nullptr, nullptr, nname);
+       creader->endElement(nname);
 }
 
 QString ContentReader::getName()

Modified: trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24341&path=/trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.h (original)
+++ trunk/Scribus/scribus/plugins/gettext/sxwim/contentreader.h Tue Dec 22 
00:06:47 2020
@@ -38,19 +38,35 @@
 #else
  #include <libxml/SAX.h>
 #endif
-#include <QXmlAttributes>
+
 #include <QMap>
+
 #include <gtstyle.h>
 #include <gtwriter.h>
 #include "stylereader.h"
 
 typedef std::vector<std::pair<QString, QString> > Properties;
+typedef QMap<QString, QString> SXWAttributesMap;
 typedef QMap<QString, Properties > TMap;
 
 class ContentReader
 {
+public:
+       ContentReader(const QString& documentName, StyleReader* s, gtWriter *w, 
bool textOnly);
+       ~ContentReader();
+       
+       void parse(const QString& fileName);
+
+       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 &name, const SXWAttributesMap &attrs);
+       bool endElement(const QString &name);
+       bool characters(const QString &ch);
+
 private:
        static ContentReader *creader;
+
        TMap tmap;
        QString docname;
        StyleReader* sreader;
@@ -76,16 +92,6 @@
        void write(const QString& text);
        QString getName();
        void getStyle();
-public:
-       ContentReader(const QString& documentName, StyleReader* s, gtWriter *w, 
bool textOnly);
-       ~ContentReader();
-       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 characters(const QString &ch);
-       void parse(const QString& fileName);
 };
 
 #endif // HAVE_XML


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to