r23625 by jghali - Some refactoring related to mark code

scribus-commit scribus-commit at lists.scribus.net
Mon Apr 20 02:33:23 UTC 2020


Author: jghali
Date: Mon Apr 20 02:33:23 2020
New Revision: 23625

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23625
Log:
Some refactoring related to mark code

Modified:
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/text/storytext.cpp
    trunk/Scribus/scribus/text/storytext.h

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23625&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Mon Apr 20 02:33:23 2020
@@ -17156,31 +17156,21 @@
 	{
 		for (PageItem* item : DocItems)
 		{
-			if (item->isTextFrame() && (item->prevInChain() == nullptr))
-			{
-				for (int pos = 0; pos < item->itemText.length(); ++pos)
-				{
-					if (item->itemText.hasMark(pos, mrk))
-					{
-						currItem = item;
-						return pos;
-					}
-				}
+			if (!item->isTextFrame() || (item->prevInChain() != nullptr))
+				continue;
+			int pos = item->itemText.findMark(mrk);
+			if (pos >= 0)
+			{
+				currItem = item;
+				return pos;
 			}
 		}
 		return -1;
 	}
 	Q_ASSERT(currItem->isTextFrame());
 
-	if (start < currItem->firstInFrame())
-		start = currItem->firstInFrame();
-
-	for (int i = start; i < currItem->itemText.length(); ++i)
-	{
-		if (currItem->itemText.hasMark(i, mrk))
-			return i;
-	}
-	return -1;
+	int markPos = currItem->itemText.findMark(mrk, start);
+	return markPos;
 }
 
 bool ScribusDoc::isMarkUsed(const Mark* mrk, bool visible) const
@@ -17239,30 +17229,30 @@
 	{
 		if (item != nullptr)
 		{
-			int MPos = findMarkCPos(mrk, item);
-			while (MPos > -1)
-			{
-				if (mrk->isType(MARKNoteFrameType) && MPos > 1 && item->itemText.text(MPos -1) == SpecialChars::PARSEP)
-					item->itemText.removeChars(MPos-1,2);
+			int markPos = findMarkCPos(mrk, item);
+			while (markPos > -1)
+			{
+				if (mrk->isType(MARKNoteFrameType) && markPos > 1 && item->itemText.text(markPos -1) == SpecialChars::PARSEP)
+					item->itemText.removeChars(markPos - 1,2);
 				else
-					item->itemText.removeChars(MPos, 1);
+					item->itemText.removeChars(markPos, 1);
 				found = true;
-				MPos = findMarkCPos(mrk, item);
+				markPos = findMarkCPos(mrk, item);
 			}
 		}
 		else
 		{
 			//find and delete all mark`s apperences in text
-			int MPos = -1;
+			int markPos = -1;
 			int itemIndex = -1;
 			item = findMarkItem(mrk, itemIndex);
 			while (item != nullptr)
 			{
-				MPos = findMarkCPos(mrk, item);
-				while (MPos > -1)
+				markPos = findMarkCPos(mrk, item);
+				while (markPos > -1)
 				{
-					item->itemText.removeChars(MPos, 1);
-					MPos = findMarkCPos(mrk, item);
+					item->itemText.removeChars(markPos, 1);
+					markPos = findMarkCPos(mrk, item);
 				}
 				found = true;
 				item->asTextFrame()->invalidateLayout(false);
@@ -17326,19 +17316,19 @@
 		else
 		{
 			ims->set("MARK", QString("delNonUnique"));
-			int MPos = -1;
+			int markPos = -1;
 			int itemIndex = -1;
 			//find all mark insertions
 			PageItem* item = findMarkItem(mrk, itemIndex);
 			while (item != nullptr)
 			{
 				int num = 0; //shift of insertion position for undo
-				MPos = findMarkCPos(mrk, item);
-				while (MPos > -1)
+				markPos = findMarkCPos(mrk, item);
+				while (markPos > -1)
 				{
-					ims->insertItemPos.append(QPair<void*, int>((void*) item, MPos - num)); //-num as while undo text will be shorter (without marks)
+					ims->insertItemPos.append(QPair<void*, int>((void*) item, markPos - num)); //-num as while undo text will be shorter (without marks)
 					//++num;
-					MPos = findMarkCPos(mrk, item, MPos+1);
+					markPos = findMarkCPos(mrk, item, markPos + 1);
 				}
 				item = findMarkItem(mrk, itemIndex);
 			}

Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23625&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp	(original)
+++ trunk/Scribus/scribus/text/storytext.cpp	Mon Apr 20 02:33:23 2020
@@ -1104,6 +1104,22 @@
 	return that->d->at(pos)->getItem(m_doc);
 }
 
+int StoryText::findMark(const Mark* mrk, int startPos) const
+{
+	assert(startPos >= 0);
+	assert(startPos < length());
+
+	int len = d->len;
+	for (int i = startPos; i < len; ++i)
+	{
+		if (d->at(i)->ch != SpecialChars::OBJECT)
+			continue;
+		if (d->at(i)->hasMark(mrk))
+			return i;
+	}
+
+	return -1;
+}
 
 bool StoryText::hasMark(int pos, const Mark* mrk) const
 {
@@ -1928,7 +1944,7 @@
 	if (on) {
 		// extend if possible
 		if (selected(pos - 1))
-			m_selLast = qMax(m_selLast, pos + static_cast<int>(len) - 1);
+			m_selLast = qMax(m_selLast, pos + len - 1);
 		else if (selected(pos + len))
 			m_selFirst = qMin(m_selFirst, pos);
 		else {

Modified: trunk/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23625&path=/trunk/Scribus/scribus/text/storytext.h
==============================================================================
--- trunk/Scribus/scribus/text/storytext.h	(original)
+++ trunk/Scribus/scribus/text/storytext.h	Mon Apr 20 02:33:23 2020
@@ -171,6 +171,7 @@
 
 	bool hasObject(int pos) const;
 	PageItem* getItem(int pos) const; // deprecated
+	int  findMark(const Mark* mrk, int startPos = 0) const;
 	bool hasMark(int pos, const Mark* mrk = nullptr) const;
 	Mark *mark(int pos) const;
 	void replaceMark(int pos, Mark* mrk);




More information about the scribus-commit mailing list