r23807 by jghali - Enable PageItemIterator to iterate through table cells

scribus-commit scribus-commit at lists.scribus.net
Wed May 13 23:32:36 UTC 2020


Author: jghali
Date: Wed May 13 23:32:36 2020
New Revision: 23807

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23807
Log:
Enable PageItemIterator to iterate through table cells

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=23807&path=/trunk/Scribus/scribus/pageitemiterator.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.cpp	(original)
+++ trunk/Scribus/scribus/pageitemiterator.cpp	Wed May 13 23:32:36 2020
@@ -8,14 +8,16 @@
 #include "pageitemiterator.h"
 #include "pageitem.h"
 #include "pageitem_group.h"
+#include "pageitem_table.h"
 
-PageItemIterator::PageItemIterator(const QList<PageItem*>& itemList)
+PageItemIterator::PageItemIterator(const QList<PageItem*>& itemList, int options) :
+	m_options(options)
 {
 	m_current = nullptr;
 
 	if (itemList.count() > 0)
 	{
-		State state = { &itemList, 0 };
+		State state = { itemList, 0 };
 		m_stateStack.push(state);
 	}
 }
@@ -25,30 +27,49 @@
 	while (m_stateStack.count() > 0)
 	{
 		State& currentState = m_stateStack.top();
-		if (currentState.currentIndex >= currentState.pItemList->count())
+		if (currentState.currentIndex >= currentState.itemList.count())
 		{
 			m_stateStack.pop();
 			continue;
 		}
 
-		PageItem* item = currentState.pItemList->at(currentState.currentIndex);
+		PageItem* item = currentState.itemList.at(currentState.currentIndex);
 		if (!item)
 		{
 			currentState.currentIndex++;
 			continue;
 		}
 
-		PageItem_Group* groupItem = item->asGroupFrame();
-		if (groupItem)
+		if (m_options & IterateInGroups)
 		{
-			m_current = groupItem;
-			currentState.currentIndex++;
-			if (groupItem->groupItemList.count() > 0)
+			PageItem_Group* groupItem = item->asGroupFrame();
+			if (groupItem)
 			{
-				State groupState = { &groupItem->groupItemList, 0 };
-				m_stateStack.push(groupState);
+				m_current = groupItem;
+				currentState.currentIndex++;
+				if (groupItem->groupItemList.count() > 0)
+				{
+					State groupState = { groupItem->groupItemList, 0 };
+					m_stateStack.push(groupState);
+				}
+				break;
 			}
-			break;
+		}
+
+		if (m_options & IterateInTables)
+		{
+			PageItem_Table* tableItem = item->asTable();
+			if (tableItem)
+			{
+				m_current = tableItem;
+				currentState.currentIndex++;
+				QList<PageItem*> cellItems = tableItem->getChildren();
+				if (cellItems.count() > 0)
+				{
+					State tableState = { cellItems, 0 };
+					m_stateStack.push(tableState);
+				}
+			}
 		}
 
 		m_current = item;

Modified: trunk/Scribus/scribus/pageitemiterator.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23807&path=/trunk/Scribus/scribus/pageitemiterator.h
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.h	(original)
+++ trunk/Scribus/scribus/pageitemiterator.h	Wed May 13 23:32:36 2020
@@ -18,7 +18,12 @@
 class SCRIBUS_API PageItemIterator
 {
 public:
-	PageItemIterator(const QList<PageItem*>& itemList);
+	enum Options
+	{
+		IterateInGroups = 1,
+		IterateInTables = 2
+	};
+	PageItemIterator(const QList<PageItem*>& itemList, int options = IterateInGroups);
 
 	bool hasCurrent() const { return (m_current != 0); }
 	PageItem* current() const { return m_current; }
@@ -31,11 +36,12 @@
 protected:
 	struct State
 	{
-		const QList<PageItem*> *pItemList;
+		QList<PageItem*> itemList;
 		int   currentIndex;
 	};
 
-	PageItem* m_current;
+	int m_options { 0 };
+	PageItem* m_current { nullptr };
 	QStack<State> m_stateStack;
 };
 




More information about the scribus-commit mailing list