r23968 by jghali - Fix a few mark related functions which would not work with items embedded inside groups

scribus-commit scribus-commit at lists.scribus.net
Thu Jul 30 19:44:38 UTC 2020


Author: jghali
Date: Thu Jul 30 19:44:38 2020
New Revision: 23968

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23968
Log:
Fix a few mark related functions which would not work with items embedded inside groups

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

Modified: trunk/Scribus/scribus/pageitemiterator.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23968&path=/trunk/Scribus/scribus/pageitemiterator.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.cpp	(original)
+++ trunk/Scribus/scribus/pageitemiterator.cpp	Thu Jul 30 19:44:38 2020
@@ -195,3 +195,29 @@
 		m_current = nullptr;
 	return m_current;
 }
+
+PageItem* PageItemIterator::moveTo(PageItem* item)
+{
+	if (current() == item)
+		return item;
+
+	PageItem* nextItem = next();
+	while (nextItem)
+	{
+		if (nextItem == item)
+			break;
+		nextItem = next();
+	}
+	return nextItem;
+}
+
+PageItem* PageItemIterator::movePast(PageItem* item)
+{
+	if (current() == nullptr)
+		return nullptr;
+
+	PageItem* nextItem = moveTo(item);
+	if (nextItem)
+		nextItem = next();
+	return nextItem;
+}

Modified: trunk/Scribus/scribus/pageitemiterator.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23968&path=/trunk/Scribus/scribus/pageitemiterator.h
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.h	(original)
+++ trunk/Scribus/scribus/pageitemiterator.h	Thu Jul 30 19:44:38 2020
@@ -42,6 +42,9 @@
 	PageItem* begin(const QList<PageItem*>& itemList);
 	PageItem* next();
 
+	PageItem* moveTo(PageItem* item);
+	PageItem* movePast(PageItem* item);
+
 	inline PageItem*  operator*() const { return m_current; }
 	inline PageItem*  operator->() const { return m_current; }
 	PageItemIterator& operator++() { next(); return *this; }

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23968&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Thu Jul 30 19:44:38 2020
@@ -3713,7 +3713,7 @@
 	QList<PageItem*> allItems;
 	QStringList results;
 
-	for (PageItemIterator it(this, PageItemIterator::IterateInDocNoPatterns) ; *it; ++it)
+	for (PageItemIterator it(this, PageItemIterator::IterateInDocNoPatterns); *it; ++it)
 	{
 		PageItem* currItem = *it;
 		if ((!results.contains(currItem->pattern())) && ((currItem->GrType == Gradient_Pattern) || (currItem->itemType() == PageItem::Symbol)))
@@ -5460,7 +5460,7 @@
 			break;
 	}
 
-	if (frameType==PageItem::Rectangle || itemType==PageItem::TextFrame || itemType==PageItem::ImageFrame || itemType==PageItem::LatexFrame || itemType==PageItem::OSGFrame || itemType==PageItem::Symbol || itemType==PageItem::Group || itemType==PageItem::Table || itemType==PageItem::NoteFrame)
+	if (frameType == PageItem::Rectangle || itemType == PageItem::TextFrame || itemType == PageItem::ImageFrame || itemType == PageItem::LatexFrame || itemType == PageItem::OSGFrame || itemType == PageItem::Symbol || itemType == PageItem::Group || itemType == PageItem::Table || itemType == PageItem::NoteFrame)
 	{
 		newItem->SetRectFrame();
 		//TODO one day hopefully, if (ScCore->usingGUI())
@@ -5477,7 +5477,7 @@
 	}
 
 	//ItemType Polygon
-	if (itemType==PageItem::Polygon || itemType==PageItem::PolyLine || itemType==PageItem::Spiral || itemType == PageItem::RegularPolygon || itemType == PageItem::Arc)
+	if (itemType == PageItem::Polygon || itemType == PageItem::PolyLine || itemType == PageItem::Spiral || itemType == PageItem::RegularPolygon || itemType == PageItem::Arc)
 	{
 		newItem->PLineArt = Qt::PenStyle(m_docPrefsData.itemToolPrefs.shapeLineStyle);
 		newItem->setFillShade(m_docPrefsData.itemToolPrefs.shapeFillColorShade);
@@ -5511,6 +5511,8 @@
 
 int ScribusDoc::getItemNrfromUniqueID(uint unique)
 {
+	// FIXME : don't work for items inside groups
+	// Needs to fix group/ungroup undo first
 	int ret = 0;
 	for (int i = 0; i < Items->count(); ++i)
 	{
@@ -5525,13 +5527,13 @@
 
 PageItem* ScribusDoc::getItemFromName(const QString& name) const
 {
-	PageItem* ret = nullptr;
-	for (int i = 0; i < Items->count(); ++i)
-	{
-		if (Items->at(i)->itemName() == name)
-			return Items->at(i);
-	}
-	return ret;
+	PageItemIterator it(*Items, PageItemIterator::IterateInGroups);
+	for (PageItem* currItem = *it; currItem != nullptr; currItem = it.next())
+	{
+		if (currItem->itemName() == name)
+			return currItem;
+	}
+	return nullptr;
 }
 
 void ScribusDoc::rebuildItemLists()
@@ -16708,25 +16710,29 @@
 	return newNote;
 }
 
-PageItem* ScribusDoc::findMarkItem(const Mark* mrk, int &lastItem) const
-{
-	PageItem* item = nullptr;
-	for (int i = lastItem + 1; i < DocItems.count(); ++i)
-	{
-		item = DocItems.at(i);
+PageItem* ScribusDoc::findMarkItem(const Mark* mrk, PageItem* &lastItem) const
+{
+	PageItemIterator it(DocItems, PageItemIterator::IterateInGroups);
+	if (lastItem != nullptr)
+		it.movePast(lastItem);
+
+	for (PageItem* item = *it;  item != nullptr; item = it.next())
+	{
 		if (!item || !item->isTextFrame() || (item->itemText.length() <= 0))
+			continue;
+		if (item->prevInChain() != nullptr)
 			continue;
 	//	for (int j = item->firstInFrame(); j <= item->lastInFrame(); ++j)
 		for (int j = 0; j < item->itemText.length(); ++j)
 		{
 			if (item->itemText.hasMark(j, mrk))
 			{
-				lastItem = i;
+				lastItem = item;
 				return item;
 			}
 		}
 	}
-	lastItem = 0;
+	lastItem = nullptr;
 	return nullptr;
 }
 
@@ -16736,7 +16742,8 @@
 		currItem = findFirstMarkItem(mrk);
 	if (currItem == nullptr)
 	{
-		for (PageItem* item : DocItems)
+		PageItemIterator it(DocItems, PageItemIterator::IterateInGroups);
+		for (PageItem* item = *it;  item != nullptr; item = it.next())
 		{
 			if (!item->isTextFrame() || (item->prevInChain() != nullptr))
 				continue;
@@ -16757,26 +16764,21 @@
 
 bool ScribusDoc::isMarkUsed(const Mark* mrk, bool visible) const
 {
-	for (const PageItem* currItem : qAsConst(DocItems))
-	{
-		if (currItem->isTextFrame() && (currItem->itemText.length() > 0))
-		{
-			if (!visible && currItem->prevInChain() != nullptr)
-				//check in whole itemText only for first frames in chain
-				continue;
-			int i = 0;
-			int end = currItem->itemText.length();
-			if (visible)
-			{
-				//search only in visible text
-				i = currItem->firstInFrame();
-				end = currItem->lastInFrame() +1;
-			}
-			for (; i < end; ++i)
-			{
-				if (currItem->itemText.hasMark(i, mrk))
-					return true;
-			}
+	PageItemIterator it(DocItems, PageItemIterator::IterateInGroups);
+	for (PageItem* currItem = *it;  currItem != nullptr; currItem = it.next())
+	{
+		if (!currItem->isTextFrame() || (currItem->itemText.length() <= 0))
+			continue;
+		// Check in whole itemText only for first frames in chain
+		if (!visible && currItem->prevInChain() != nullptr)
+			continue;
+
+		int i = visible ? currItem->firstInFrame() : 0;
+		int end = visible ? (currItem->lastInFrame() + 1) : currItem->itemText.length();
+		for (; i < end; ++i)
+		{
+			if (currItem->itemText.hasMark(i, mrk))
+				return true;
 		}
 	}
 	return false;
@@ -16826,8 +16828,8 @@
 		{
 			//find and delete all mark`s apperences in text
 			int markPos = -1;
-			int itemIndex = -1;
-			item = findMarkItem(mrk, itemIndex);
+			PageItem* lastItem = nullptr;
+			item = findMarkItem(mrk, lastItem);
 			while (item != nullptr)
 			{
 				markPos = findMarkCPos(mrk, item);
@@ -16838,7 +16840,7 @@
 				}
 				found = true;
 				item->asTextFrame()->invalidateLayout(false);
-				item = findMarkItem(mrk, itemIndex);
+				item = findMarkItem(mrk, lastItem);
 			}
 		}
 	}
@@ -16901,9 +16903,9 @@
 		{
 			ims->set("MARK", QString("delNonUnique"));
 			int markPos = -1;
-			int itemIndex = -1;
+			PageItem* lastItem = nullptr;
 			//find all mark insertions
-			PageItem* item = findMarkItem(mrk, itemIndex);
+			PageItem* item = findMarkItem(mrk, lastItem);
 			while (item != nullptr)
 			{
 				int num = 0; //shift of insertion position for undo
@@ -16914,7 +16916,7 @@
 					//++num;
 					markPos = findMarkCPos(mrk, item, markPos + 1);
 				}
-				item = findMarkItem(mrk, itemIndex);
+				item = findMarkItem(mrk, lastItem);
 			}
 		}
 		ims->set("ETEA", mrk->label);
@@ -16929,16 +16931,16 @@
 {
 	if (!mrk->isType(MARKVariableTextType))
 		return false;
-	int itemNo = -1;
 	bool found = false;
-	PageItem* mItem = findMarkItem(mrk, itemNo);
+	PageItem* lastItem = nullptr;
+	PageItem* mItem = findMarkItem(mrk, lastItem);
 	while (mItem != nullptr)
 	{
 		found = true;
 		mItem->asTextFrame()->invalidateLayout(false);
 		if (forceUpdate)
 			mItem->layout();
-		mItem = findMarkItem(mrk, itemNo);
+		mItem = findMarkItem(mrk, lastItem);
 	}
 	return found;
 }

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23968&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Thu Jul 30 19:44:38 2020
@@ -1819,13 +1819,13 @@
 	QList<PageItem_NoteFrame*> m_docEndNotesFramesChanged;
 
 	//finds item which holds given mark, start searching from next to lastItem index in DocItems
-	PageItem* findMarkItem(const Mark* mrk, int &lastItem) const;
+	PageItem* findMarkItem(const Mark* mrk, PageItem* &lastItem) const;
 	
 private:
 	//QMap<PageItem_NoteFrame*, QList<TextNote *> > map of notesframes and its list of notes
 	NotesInFrameMap m_docNotesInFrameMap;
 
-	PageItem* findFirstMarkItem(const Mark* mrk) const { int tmp = -1; return findMarkItem(mrk, tmp); }
+	PageItem* findFirstMarkItem(const Mark* mrk) const { PageItem* tmp = nullptr; return findMarkItem(mrk, tmp); }
 
 	//search for endnotesframe for given notes style and item holding master mark or section number
 	PageItem_NoteFrame* endNoteFrame(NotesStyle* nStyle, void* item = nullptr);




More information about the scribus-commit mailing list