r23811 by jghali - Add begin() overload to PageItemIterator for iterating across items of a whole document

scribus-commit scribus-commit at lists.scribus.net
Sat May 16 15:10:30 UTC 2020


Author: jghali
Date: Sat May 16 15:10:30 2020
New Revision: 23811

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23811
Log:
Add begin() overload to PageItemIterator for iterating across items of a whole document

Modified:
    trunk/Scribus/scribus/pageitemiterator.cpp
    trunk/Scribus/scribus/pageitemiterator.h

Modified: trunk/Scribus/scribus/pageitemiterator.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23811&path=/trunk/Scribus/scribus/pageitemiterator.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.cpp	(original)
+++ trunk/Scribus/scribus/pageitemiterator.cpp	Sat May 16 15:10:30 2020
@@ -70,6 +70,53 @@
 
 	if (m_stateStack.count() > 0)
 		m_current = next();
+}
+
+PageItem* PageItemIterator::begin(ScribusDoc* doc)
+{
+	m_current = nullptr;
+	m_stateStack.resize(0); // Not clear in order to keep the already allocated memory available
+
+	int stackItemCount = doc->docPatterns.count() + 3;
+	if (m_stateStack.capacity() < stackItemCount)
+		m_stateStack.reserve(stackItemCount);
+
+	if (doc->docPatterns.count() > 0)
+	{
+		auto docPatternEnd = doc->docPatterns.constEnd();
+		for (auto it = doc->docPatterns.constBegin(); it != docPatternEnd; ++it)
+		{
+			const ScPattern& pattern = it.value();
+			if (pattern.items.count() > 0)
+			{
+				State state = { pattern.items, 0 };
+				m_stateStack.push(state);
+			}
+		}
+	}
+
+	if (doc->FrameItems.count() > 0)
+	{
+		QList<PageItem*> frameItems = doc->FrameItems.values();
+		State state = { frameItems, 0 };
+		m_stateStack.push(state);
+	}
+
+	if (doc->MasterItems.count() > 0)
+	{
+		State state = { doc->MasterItems, 0 };
+		m_stateStack.push(state);
+	}
+
+	if (doc->DocItems.count() > 0)
+	{
+		State state = { doc->DocItems, 0 };
+		m_stateStack.push(state);
+	}
+
+	if (m_stateStack.count() > 0)
+		m_current = next();
+	return m_current;
 }
 
 PageItem* PageItemIterator::begin(const QList<PageItem*>& itemList)

Modified: trunk/Scribus/scribus/pageitemiterator.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23811&path=/trunk/Scribus/scribus/pageitemiterator.h
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.h	(original)
+++ trunk/Scribus/scribus/pageitemiterator.h	Sat May 16 15:10:30 2020
@@ -31,6 +31,7 @@
 	bool isNull() const { return (m_current == nullptr); }
 	PageItem* current() const { return m_current; }
 	
+	PageItem* begin(ScribusDoc* doc);
 	PageItem* begin(const QList<PageItem*>& itemList);
 	PageItem* next();
 




More information about the scribus-commit mailing list