r22116 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Wed Jul 19 17:36:10 UTC 2017


Author: jghali
Date: Wed Jul 19 17:36:10 2017
New Revision: 22116

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22116
Log:
some refactoring for ODT importer: code style fixes, exit early when possible...

Modified:
    trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp

Modified: trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22116&path=/trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp	(original)
+++ trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp	Wed Jul 19 17:36:10 2017
@@ -162,11 +162,11 @@
 bool ODTIm::parseRawDocReferenceXML(QDomDocument &designMapDom)
 {
 	QDomElement docElem = designMapDom.documentElement();
-	for(QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
+	for (QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
 	{
 		if (drawPag.tagName() == "office:body")
 		{
-			for(QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement() )
+			for (QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement() )
 			{
 				if (sp.tagName() == "office:text")
 				{
@@ -180,40 +180,40 @@
 
 void ODTIm::parseRawTextSpan(QDomElement &elem, PageItem* item, ParagraphStyle &tmpStyle, CharStyle &tmpCStyle, int &posC)
 {
-	if (elem.hasChildNodes())
-	{
-		for(QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
-		{
-			QString txt = "";
-			QDomElement spEl = spn.toElement();
-			if (spn.nodeName() == "#text")
-				txt = spn.nodeValue();
-			else if (spn.nodeName() == "text:span")
-				parseRawTextSpan(spEl, item, tmpStyle, tmpCStyle, posC);
-			else if (spn.nodeName() == "text:s")
-			{
-				if (spEl.hasAttribute("text:c"))
-				{
-					int n = spEl.attribute("text:c").toInt();
-					for (int nn = 0; nn < n; nn++)
-					{
-						txt += " ";
-					}
-				}
-				else
-					txt = " ";
-			}
-			else if (spn.nodeName() == "text:tab")
-				txt = SpecialChars::TAB;
-			else if (spn.nodeName() == "text:line-break")
-				txt = SpecialChars::LINEBREAK;
-			if (!txt.isEmpty())
-			{
-				txt.replace(QChar(0xAD), SpecialChars::SHYPHEN);
-				txt.replace(QChar(0x2011), SpecialChars::NBHYPHEN);
-				txt.replace(QChar(0xA0), SpecialChars::NBSPACE);
-				insertChars(item, txt, tmpStyle, tmpCStyle, posC);
-			}
+	if (!elem.hasChildNodes())
+		return;
+
+	for (QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+	{
+		QString txt = "";
+		QDomElement spEl = spn.toElement();
+		if (spn.nodeName() == "#text")
+			txt = spn.nodeValue();
+		else if (spn.nodeName() == "text:span")
+			parseRawTextSpan(spEl, item, tmpStyle, tmpCStyle, posC);
+		else if (spn.nodeName() == "text:s")
+		{
+			if (spEl.hasAttribute("text:c"))
+			{
+				int n = spEl.attribute("text:c").toInt();
+				for (int nn = 0; nn < n; nn++)
+				{
+					txt += " ";
+				}
+			}
+			else
+				txt = " ";
+		}
+		else if (spn.nodeName() == "text:tab")
+			txt = SpecialChars::TAB;
+		else if (spn.nodeName() == "text:line-break")
+			txt = SpecialChars::LINEBREAK;
+		if (!txt.isEmpty())
+		{
+			txt.replace(QChar(0xAD), SpecialChars::SHYPHEN);
+			txt.replace(QChar(0x2011), SpecialChars::NBHYPHEN);
+			txt.replace(QChar(0xA0), SpecialChars::NBSPACE);
+			insertChars(item, txt, tmpStyle, tmpCStyle, posC);
 		}
 	}
 }
@@ -223,7 +223,7 @@
 	CharStyle tmpCStyle = newStyle.charStyle();
 	if (elem.hasChildNodes())
 	{
-		for(QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+		for (QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
 		{
 			QString txt = "";
 			QDomElement spEl = spn.toElement();
@@ -274,27 +274,25 @@
 		item->itemText.setDefaultStyle(newStyle);
 	}
 	int posC = item->itemText.length();
-	for(QDomNode para = elem.firstChild(); !para.isNull(); para = para.nextSibling())
+	for (QDomNode para = elem.firstChild(); !para.isNull(); para = para.nextSibling())
 	{
 		if ((para.nodeName() == "text:p") || (para.nodeName() == "text:h"))
 			parseRawTextParagraph(para, item, newStyle, posC);
 		else if (para.nodeName() == "text:list")
 		{
-			if (para.hasChildNodes())
-			{
-				for(QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
-				{
-					if (spn.nodeName() == "text:list-item")
+			if (!para.hasChildNodes())
+				continue;
+			for (QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+			{
+				if (spn.nodeName() == "text:list-item")
+				{
+					if (!spn.hasChildNodes())
+						continue;
+					for(QDomNode spp = spn.firstChild(); !spp.isNull(); spp = spp.nextSibling())
 					{
-						if (spn.hasChildNodes())
+						if (spp.nodeName() == "text:p")
 						{
-							for(QDomNode spp = spn.firstChild(); !spp.isNull(); spp = spp.nextSibling())
-							{
-								if (spp.nodeName() == "text:p")
-								{
-									parseRawTextParagraph(spp, item, newStyle, posC);
-								}
-							}
+							parseRawTextParagraph(spp, item, newStyle, posC);
 						}
 					}
 				}
@@ -302,14 +300,13 @@
 		}
 		else if (para.nodeName() == "text:section")
 		{
-			if (para.hasChildNodes())
-			{
-				for(QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
-				{
-					if (spn.nodeName() == "text:p")
-					{
-						parseRawTextParagraph(spn, item, newStyle, posC);
-					}
+			if (!para.hasChildNodes())
+				continue;
+			for (QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+			{
+				if (spn.nodeName() == "text:p")
+				{
+					parseRawTextParagraph(spn, item, newStyle, posC);
 				}
 			}
 		}
@@ -342,11 +339,11 @@
 bool ODTIm::parseStyleSheetsXML(QDomDocument &designMapDom)
 {
 	QDomElement docElem = designMapDom.documentElement();
-	for(QDomElement sp = docElem.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement() )
+	for (QDomElement sp = docElem.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement() )
 	{
 		if (sp.tagName() == "office:font-face-decls")
 		{
-			for(QDomElement spf = sp.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement() )
+			for (QDomElement spf = sp.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement() )
 			{
 				if (spf.tagName() == "style:font-face")
 				{
@@ -372,13 +369,13 @@
 
 void ODTIm::parseStyles(QDomElement &sp, QString type)
 {
-	for(QDomElement spd = sp.firstChildElement(); !spd.isNull(); spd = spd.nextSiblingElement() )
+	for (QDomElement spd = sp.firstChildElement(); !spd.isNull(); spd = spd.nextSiblingElement() )
 	{
 		if (spd.tagName() == "style:default-style")
 		{
 			DrawStyle currStyle;
 			currStyle.styleOrigin = AttributeValue(type);
-			for(QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement() )
+			for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement() )
 			{
 				if (spe.tagName() == "style:paragraph-properties")
 				{
@@ -394,13 +391,13 @@
 					currStyle.breakBefore = AttributeValue(spe.attribute("fo:break-before", ""));
 					if (spe.hasChildNodes())
 					{
-						for(QDomElement spt = spe.firstChildElement(); !spt.isNull(); spt = spt.nextSiblingElement() )
+						for (QDomElement spt = spe.firstChildElement(); !spt.isNull(); spt = spt.nextSiblingElement() )
 						{
 							if (spt.tagName() == "style:tab-stops")
 							{
 								QString tabDists = "";
 								QString tabTypes = "";
-								for(QDomElement spte = spt.firstChildElement(); !spte.isNull(); spte = spte.nextSiblingElement() )
+								for (QDomElement spte = spt.firstChildElement(); !spte.isNull(); spte = spte.nextSiblingElement() )
 								{
 									if (spte.tagName() == "style:tab-stop")
 									{
@@ -458,7 +455,7 @@
 			}
 			currStyle.styleType = AttributeValue(spd.attribute("style:family", ""));
 			currStyle.styleOrigin = AttributeValue(type);
-			for(QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement() )
+			for (QDomElement spe = spd.firstChildElement(); !spe.isNull(); spe = spe.nextSiblingElement() )
 			{
 				if (spe.tagName() == "style:paragraph-properties")
 				{
@@ -474,13 +471,13 @@
 					currStyle.breakBefore = AttributeValue(spe.attribute("fo:break-before", ""));
 					if (spe.hasChildNodes())
 					{
-						for(QDomElement spt = spe.firstChildElement(); !spt.isNull(); spt = spt.nextSiblingElement() )
+						for (QDomElement spt = spe.firstChildElement(); !spt.isNull(); spt = spt.nextSiblingElement() )
 						{
 							if (spt.tagName() == "style:tab-stops")
 							{
 								QString tabDists = "";
 								QString tabTypes = "";
-								for(QDomElement spte = spt.firstChildElement(); !spte.isNull(); spte = spte.nextSiblingElement() )
+								for (QDomElement spte = spt.firstChildElement(); !spte.isNull(); spte = spte.nextSiblingElement() )
 								{
 									if (spte.tagName() == "style:tab-stop")
 									{
@@ -606,11 +603,11 @@
 bool ODTIm::parseDocReferenceXML(QDomDocument &designMapDom)
 {
 	QDomElement docElem = designMapDom.documentElement();
-	for(QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
+	for (QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
 	{
 		if (drawPag.tagName() == "office:font-face-decls")
 		{
-			for(QDomElement spf = drawPag.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement() )
+			for (QDomElement spf = drawPag.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement() )
 			{
 				if (spf.tagName() == "style:font-face")
 				{
@@ -632,7 +629,7 @@
 			parseStyles(drawPag, "auto");
 		else if (drawPag.tagName() == "office:body")
 		{
-			for(QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement() )
+			for (QDomElement sp = drawPag.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement() )
 			{
 				if (sp.tagName() == "office:text")
 				{
@@ -652,40 +649,40 @@
 	if (elem.hasAttribute("text:style-name"))
 		resovleStyle(cStyle, elem.attribute("text:style-name"));
 	applyCharacterStyle(tmpCStyle, cStyle);
-	if (elem.hasChildNodes())
-	{
-		for(QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
-		{
-			QString txt = "";
-			QDomElement spEl = spn.toElement();
-			if (spn.nodeName() == "#text")
-				txt = spn.nodeValue();
-			else if (spn.nodeName() == "text:span")
-				parseTextSpan(spEl, item, tmpStyle, tmpCStyle, cStyle, posC);
-			else if (spn.nodeName() == "text:s")
-			{
-				if (spEl.hasAttribute("text:c"))
-				{
-					int n = spEl.attribute("text:c").toInt();
-					for (int nn = 0; nn < n; nn++)
-					{
-						txt += " ";
-					}
-				}
-				else
-					txt = " ";
-			}
-			else if (spn.nodeName() == "text:tab")
-				txt = SpecialChars::TAB;
-			else if (spn.nodeName() == "text:line-break")
-				txt = SpecialChars::LINEBREAK;
-			if (!txt.isEmpty())
-			{
-				txt.replace(QChar(0xAD), SpecialChars::SHYPHEN);
-				txt.replace(QChar(0x2011), SpecialChars::NBHYPHEN);
-				txt.replace(QChar(0xA0), SpecialChars::NBSPACE);
-				insertChars(item, txt, tmpStyle, tmpCStyle, posC);
-			}
+	if (!elem.hasChildNodes())
+		return;
+
+	for (QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+	{
+		QString txt = "";
+		QDomElement spEl = spn.toElement();
+		if (spn.nodeName() == "#text")
+			txt = spn.nodeValue();
+		else if (spn.nodeName() == "text:span")
+			parseTextSpan(spEl, item, tmpStyle, tmpCStyle, cStyle, posC);
+		else if (spn.nodeName() == "text:s")
+		{
+			if (spEl.hasAttribute("text:c"))
+			{
+				int n = spEl.attribute("text:c").toInt();
+				for (int nn = 0; nn < n; nn++)
+				{
+					txt += " ";
+				}
+			}
+			else
+				txt = " ";
+		}
+		else if (spn.nodeName() == "text:tab")
+			txt = SpecialChars::TAB;
+		else if (spn.nodeName() == "text:line-break")
+			txt = SpecialChars::LINEBREAK;
+		if (!txt.isEmpty())
+		{
+			txt.replace(QChar(0xAD), SpecialChars::SHYPHEN);
+			txt.replace(QChar(0x2011), SpecialChars::NBHYPHEN);
+			txt.replace(QChar(0xA0), SpecialChars::NBSPACE);
+			insertChars(item, txt, tmpStyle, tmpCStyle, posC);
 		}
 	}
 }
@@ -733,7 +730,7 @@
 	applyParagraphStyle(tmpStyle, pStyle);
 	if (elem.hasChildNodes())
 	{
-		for(QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+		for (QDomNode spn = elem.firstChild(); !spn.isNull(); spn = spn.nextSibling())
 		{
 			if (!parStyleName.isEmpty())
 			{
@@ -824,27 +821,25 @@
 		item->setFirstLineOffset(FLOPFontAscent);
 	}
 	int posC = item->itemText.length();
-	for(QDomNode para = elem.firstChild(); !para.isNull(); para = para.nextSibling())
+	for (QDomNode para = elem.firstChild(); !para.isNull(); para = para.nextSibling())
 	{
 		if ((para.nodeName() == "text:p") || (para.nodeName() == "text:h"))
 			parseTextParagraph(para, item, newStyle, tmpOStyle, posC);
 		else if (para.nodeName() == "text:list")
 		{
-			if (para.hasChildNodes())
-			{
-				for(QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
-				{
-					if (spn.nodeName() == "text:list-item")
+			if (!para.hasChildNodes())
+				continue;
+			for (QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+			{
+				if (spn.nodeName() == "text:list-item")
+				{
+					if (!spn.hasChildNodes())
+						continue;
+					for(QDomNode spp = spn.firstChild(); !spp.isNull(); spp = spp.nextSibling())
 					{
-						if (spn.hasChildNodes())
+						if (spp.nodeName() == "text:p")
 						{
-							for(QDomNode spp = spn.firstChild(); !spp.isNull(); spp = spp.nextSibling())
-							{
-								if (spp.nodeName() == "text:p")
-								{
-									parseTextParagraph(spp, item, newStyle, tmpOStyle, posC);
-								}
-							}
+							parseTextParagraph(spp, item, newStyle, tmpOStyle, posC);
 						}
 					}
 				}
@@ -852,14 +847,13 @@
 		}
 		else if (para.nodeName() == "text:section")
 		{
-			if (para.hasChildNodes())
-			{
-				for(QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
-				{
-					if (spn.nodeName() == "text:p")
-					{
-						parseTextParagraph(spn, item, newStyle, tmpOStyle, posC);
-					}
+			if (!para.hasChildNodes())
+				continue;
+			for (QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
+			{
+				if (spn.nodeName() == "text:p")
+				{
+					parseTextParagraph(spn, item, newStyle, tmpOStyle, posC);
 				}
 			}
 		}




More information about the scribus-commit mailing list