r23822 by jghali - Some code simplification thanks to PageItemIterator

scribus-commit scribus-commit at lists.scribus.net
Thu May 21 17:36:59 UTC 2020


Author: jghali
Date: Thu May 21 17:36:59 2020
New Revision: 23822

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23822
Log:
Some code simplification thanks to PageItemIterator

Modified:
    trunk/Scribus/scribus/ui/prefs_pdfexport.cpp
    trunk/Scribus/scribus/ui/tabpdfoptions.cpp

Modified: trunk/Scribus/scribus/ui/prefs_pdfexport.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23822&path=/trunk/Scribus/scribus/ui/prefs_pdfexport.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_pdfexport.cpp	(original)
+++ trunk/Scribus/scribus/ui/prefs_pdfexport.cpp	Thu May 21 17:36:59 2020
@@ -9,6 +9,7 @@
 #include <QAbstractItemView>
 
 #include "iconmanager.h"
+#include "pageitemiterator.h"
 #include "prefsstructs.h"
 #include "scribuscore.h"
 #include "scribusdoc.h"
@@ -293,53 +294,13 @@
 	fontEmbeddingCombo->setEmbeddingMode(prefsData->pdfPrefs.FontEmbedding);
 	if (m_doc != nullptr && exportingPDF)
 	{
-//	Build a list of all Fonts used in Annotations;
-		PageItem *pgit;
-		QList<PageItem*> allItems;
-		for (auto it = m_doc->FrameItems.begin(); it != m_doc->FrameItems.end(); ++it)
-		{
-			PageItem *currItem = it.value();
-			if (currItem->isGroup())
-				allItems = currItem->getAllChildren();
-			else
-				allItems.append(currItem);
-			for (int ii = 0; ii < allItems.count(); ii++)
-			{
-				pgit = allItems.at(ii);
-				if (((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) && (pgit->isAnnotation()) && (pgit->itemText.length() > 0))
-					AnnotationFonts.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), "");
-			}
-			allItems.clear();
-		}
-		for (int a = 0; a < m_doc->MasterItems.count(); ++a)
-		{
-			PageItem *currItem = m_doc->MasterItems.at(a);
-			if (currItem->isGroup())
-				allItems = currItem->getAllChildren();
-			else
-				allItems.append(currItem);
-			for (int ii = 0; ii < allItems.count(); ii++)
-			{
-				pgit = allItems.at(ii);
-				if (((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) && (pgit->isAnnotation()) && (pgit->itemText.length() > 0))
-					AnnotationFonts.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), "");
-			}
-			allItems.clear();
-		}
-		for (int a = 0; a < m_doc->DocItems.count(); ++a)
-		{
-			PageItem *currItem = m_doc->DocItems.at(a);
-			if (currItem->isGroup())
-				allItems = currItem->getAllChildren();
-			else
-				allItems.append(currItem);
-			for (int ii = 0; ii < allItems.count(); ii++)
-			{
-				pgit = allItems.at(ii);
-				if (((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) && (pgit->isAnnotation()) && (pgit->itemText.length() > 0))
-					AnnotationFonts.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), "");
-			}
-			allItems.clear();
+		//	Build a list of all Fonts used in Annotations;
+		int pageItOptions = PageItemIterator::IterateInGroups | PageItemIterator::IterateInDocItems | PageItemIterator::IterateInMasterItems | PageItemIterator::IterateInFrameItems;
+		for (PageItemIterator it(m_doc, pageItOptions); *it; ++it)
+		{
+			PageItem *currItem = *it;
+			if (((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText)) && (currItem->isAnnotation()) && (currItem->itemText.length() > 0))
+				AnnotationFonts.insert(currItem->itemText.defaultStyle().charStyle().font().replacementName(), QString());
 		}
 		toSubsetButton->setEnabled(false);
 		fromSubsetButton->setEnabled(false);

Modified: trunk/Scribus/scribus/ui/tabpdfoptions.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23822&path=/trunk/Scribus/scribus/ui/tabpdfoptions.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/tabpdfoptions.cpp	(original)
+++ trunk/Scribus/scribus/ui/tabpdfoptions.cpp	Thu May 21 17:36:59 2020
@@ -34,18 +34,17 @@
 #include <QToolButton>
 #include <QVBoxLayout>
 
-
-#include "ui/createrange.h"
+#include "iconmanager.h"
+#include "pageitemiterator.h"
 #include "pdfoptions.h"
 #include "prefsmanager.h"
+#include "scconfig.h"
 #include "scribuscore.h"
 #include "scribusview.h"
-#include "scconfig.h"
+#include "ui/createrange.h"
+#include "ui/scrspinbox.h"
 #include "units.h"
 #include "usertaskstructs.h"
-#include "ui/scrspinbox.h"
-#include "iconmanager.h"
-#include "scribuscore.h"
 #include "util.h"
 
 TabPDFOptions::TabPDFOptions(QWidget* parent, PDFOptions & Optionen,
@@ -389,67 +388,17 @@
 	FromSubset->setEnabled(false); // Will be enabled when user select a font in appropriate list
 
 //	Build a list of all Fonts used in Annotations;
-	PageItem *pgit;
-	QList<PageItem*> allItems;
-	for (QHash<int, PageItem*>::iterator it = m_Doc->FrameItems.begin(); it != m_Doc->FrameItems.end(); ++it)
-	{
-		PageItem *currItem = it.value();
-		if (currItem->isGroup())
-			allItems = currItem->getAllChildren();
-		else
-			allItems.append(currItem);
-		for (int ii = 0; ii < allItems.count(); ii++)
-		{
-			pgit = allItems.at(ii);
-			if (((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) && (pgit->isAnnotation()))
-			{
-				int annotType  = pgit->annotation().Type();
-				bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox));
-				if (pgit->itemText.length() > 0 || mustEmbed)
-					m_annotationFonts.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), "");
-			}
-		}
-		allItems.clear();
-	}
-	for (int a = 0; a < m_Doc->MasterItems.count(); ++a)
-	{
-		PageItem *currItem = m_Doc->MasterItems.at(a);
-		if (currItem->isGroup())
-			allItems = currItem->getAllChildren();
-		else
-			allItems.append(currItem);
-		for (int ii = 0; ii < allItems.count(); ii++)
-		{
-			pgit = allItems.at(ii);
-			if (((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) && (pgit->isAnnotation()))
-			{
-				int annotType  = pgit->annotation().Type();
-				bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox));
-				if (pgit->itemText.length() > 0 || mustEmbed)
-					m_annotationFonts.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), "");
-			}
-		}
-		allItems.clear();
-	}
-	for (int a = 0; a < m_Doc->DocItems.count(); ++a)
-	{
-		PageItem *currItem = m_Doc->DocItems.at(a);
-		if (currItem->isGroup())
-			allItems = currItem->getAllChildren();
-		else
-			allItems.append(currItem);
-		for (int ii = 0; ii < allItems.count(); ii++)
-		{
-			pgit = allItems.at(ii);
-			if (((pgit->itemType() == PageItem::TextFrame) || (pgit->itemType() == PageItem::PathText)) && (pgit->isAnnotation()))
-			{
-				int annotType  = pgit->annotation().Type();
-				bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox));
-				if (pgit->itemText.length() > 0 || mustEmbed)
-					m_annotationFonts.insert(pgit->itemText.defaultStyle().charStyle().font().replacementName(), "");
-			}
-		}
-		allItems.clear();
+	int pageItOptions = PageItemIterator::IterateInGroups | PageItemIterator::IterateInDocItems | PageItemIterator::IterateInMasterItems | PageItemIterator::IterateInFrameItems;
+	for (PageItemIterator it(m_Doc, pageItOptions); *it; ++it)
+	{
+		PageItem *currItem = *it;
+		if (((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText)) && (currItem->isAnnotation()))
+		{
+			int annotType  = currItem->annotation().Type();
+			bool mustEmbed = ((annotType >= Annotation::Button) && (annotType <= Annotation::Listbox) && (annotType != Annotation::Checkbox));
+			if (currItem->itemText.length() > 0 || mustEmbed)
+				m_annotationFonts.insert(currItem->itemText.defaultStyle().charStyle().font().replacementName(), QString());
+		}
 	}
 	ToSubset->setEnabled(false);
 	FromSubset->setEnabled(false);




More information about the scribus-commit mailing list