r23812 by jghali - Fix cases of non optimal iteration across document patterns

scribus-commit scribus-commit at lists.scribus.net
Sat May 16 16:25:36 UTC 2020


Author: jghali
Date: Sat May 16 16:25:36 2020
New Revision: 23812

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23812
Log:
Fix cases of non optimal iteration across document patterns

Modified:
    trunk/Scribus/scribus/scribusdoc.cpp

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23812&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Sat May 16 16:25:36 2020
@@ -529,10 +529,10 @@
 		}
 		allItems.clear();
 	}
-	QStringList patterns = docPatterns.keys();
-	for (int i = 0; i < patterns.count(); ++i)
-	{
-		ScPattern pa = docPatterns[patterns[i]];
+	auto patternEnd = docPatterns.end();
+	for (auto it = docPatterns.begin(); it != patternEnd; ++it)
+	{
+		ScPattern& pa = it.value();
 		for (int j = 0; j < pa.items.count(); j++)
 		{
 			PageItem *currItem = pa.items.at(j);
@@ -3688,10 +3688,10 @@
 		}
 		allItems.clear();
 	}
-	QStringList patterns = docPatterns.keys();
-	for (int c = 0; c < patterns.count(); ++c)
-	{
-		ScPattern pa = docPatterns[patterns[c]];
+	auto patternEnd = docPatterns.end();
+	for (auto it = docPatterns.begin(); it != patternEnd; ++it)
+	{
+		ScPattern& pa = it.value();
 		for (int o = 0; o < pa.items.count(); o++)
 		{
 			PageItem *currItem = pa.items.at(o);
@@ -3843,11 +3843,12 @@
 		}
 		allItems.clear();
 	}
-	for (QHash<QString, ScPattern>::const_iterator it = docPatterns.begin(); it != docPatterns.end(); ++it)
-	{
-		for (int i = 0; i < it.value().items.count(); ++i)
-		{
-			PageItem* currItem = it.value().items.at(i);
+	for (auto it = docPatterns.constBegin(); it != docPatterns.constEnd(); ++it)
+	{
+		const ScPattern& pattern = it.value();
+		for (int i = 0; i < pattern.items.count(); ++i)
+		{
+			PageItem* currItem = pattern.items.at(i);
 			if (currItem->isGroup())
 				allItems = currItem->getAllChildren();
 			else
@@ -4075,9 +4076,10 @@
 	}
 	for (auto it = docPatterns.cbegin(); it != docPatterns.cend(); ++it)
 	{
-		for (int i = 0; i < it.value().items.count(); ++i)
-		{
-			PageItem* currItem = it.value().items.at(i);
+		const ScPattern& pattern = it.value();
+		for (int i = 0; i < pattern.items.count(); ++i)
+		{
+			PageItem* currItem = pattern.items.at(i);
 			if (currItem->isGroup())
 				allItems = currItem->getAllChildren();
 			else
@@ -4201,8 +4203,8 @@
 		}
 	}
 
-	QHash<QString, ScPattern>::const_iterator patIter;
-	for (patIter = docPatterns.begin(); patIter != docPatterns.end(); ++patIter)
+	auto patternEnd = docPatterns.cend();
+	for (auto patIter = docPatterns.cbegin(); patIter != patternEnd; ++patIter)
 	{
 		const ScPattern& pat = patIter.value();
 		allItems = pat.items;
@@ -4644,10 +4646,10 @@
 		}
 	}
 
-	QStringList patterns = docPatterns.keys();
-	for (int i = 0; i < patterns.count(); ++i)
-	{
-		ScPattern pa = docPatterns[patterns[i]];
+	auto patternEnd = docPatterns.constEnd();
+	for (auto patIter = docPatterns.constBegin(); patIter != patternEnd; ++patIter)
+	{
+		const ScPattern& pa = patIter.value();
 		for (it.begin(pa.items); *it; ++it)
 		{
 			PageItem *currItem = *it;
@@ -4680,10 +4682,10 @@
 		}
 	}
 
-	QStringList patterns = docPatterns.keys();
-	for (int i = 0; i < patterns.count(); ++i)
-	{
-		ScPattern pa = docPatterns[patterns[i]];
+	auto patternEnd = docPatterns.constEnd();
+	for (auto patIter = docPatterns.constBegin(); patIter != patternEnd; ++patIter)
+	{
+		const ScPattern& pa = patIter.value();
 		for (it.begin(pa.items); *it; ++it)
 		{
 			PageItem *currItem = *it;
@@ -4709,12 +4711,10 @@
 	return m_docPrefsData.docSetupPrefs.docUnitIndex;
 }
 
-
 double ScribusDoc::unitRatio() const
 {
 	return m_docUnitRatio;
 }
-
 
 bool ScribusDoc::applyMasterPage(const QString& pageName, int pageNumber)
 {
@@ -5113,10 +5113,10 @@
 		}
 		allItems.clear();
 	}
-	QStringList patterns = docPatterns.keys();
-	for (int c = 0; c < patterns.count(); ++c)
-	{
-		ScPattern pa = docPatterns[patterns[c]];
+	auto patternEnd = docPatterns.end();
+	for (auto patIter = docPatterns.begin(); patIter != patternEnd; ++patIter)
+	{
+		ScPattern& pa = patIter.value();
 		if (pa.items.count() <= 0)
 			continue;
 		for (int o = 0; o < pa.items.count(); o++)
@@ -5176,7 +5176,7 @@
 		miny = qMin(miny, y1);
 		maxx = qMax(maxx, x2);
 		maxy = qMax(maxy, y2);
-		docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
+		pa.pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
 	}
 
 	m_undoManager->setUndoEnabled(true);
@@ -6060,8 +6060,7 @@
 
 	// #11274: Scribus crash when opening .sla document
 	// OwnPage is not meaningful for pattern items
-	QHash<QString, ScPattern>::iterator patternIt;
-	for (patternIt = docPatterns.begin(); patternIt != docPatterns.end(); ++patternIt)
+	for (auto patternIt = docPatterns.begin(); patternIt != docPatterns.end(); ++patternIt)
 	{
 		QList<PageItem*> patternItems = patternIt->items;
 		while (patternItems.count() > 0)
@@ -9890,7 +9889,7 @@
 //CB Same as RecalcPicturesRes apart from the name checking, which should be able to be removed
 void ScribusDoc::updatePict(const QString& name)
 {
-	bool updated=false;
+	bool updated = false;
 	QList<PageItem*> allItems;
 	for (int i = 0; i < DocItems.count(); ++i)
 	{
@@ -9967,10 +9966,10 @@
 		}
 		allItems.clear();
 	}
-	QStringList patterns = docPatterns.keys();
-	for (int i = 0; i < patterns.count(); ++i)
-	{
-		ScPattern pa = docPatterns[patterns[i]];
+	auto patternEnd = docPatterns.end();
+	for (auto it = docPatterns.begin(); it != patternEnd; ++it)
+	{
+		ScPattern& pa = it.value();
 		if (pa.items.count() <= 0)
 			continue;
 		for (int j = 0; j < pa.items.count(); j++)
@@ -10009,7 +10008,7 @@
 		miny = qMin(miny, y1);
 		maxx = qMax(maxx, x2);
 		maxy = qMax(maxy, y2);
-		docPatterns[patterns[i]].pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
+		pa.pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
 	}
 	if (updated)
 	{
@@ -10109,10 +10108,10 @@
 		}
 		allItems.clear();
 	}
-	QStringList patterns = docPatterns.keys();
-	for (int c = 0; c < patterns.count(); ++c)
-	{
-		ScPattern pa = docPatterns[patterns[c]];
+	auto patternEnd = docPatterns.end();
+	for (auto it = docPatterns.begin(); it != patternEnd; ++it)
+	{
+		ScPattern& pa = it.value();
 		if (pa.items.count() <= 0)
 			continue;
 		for (int o = 0; o < pa.items.count(); o++)
@@ -10155,7 +10154,7 @@
 		miny = qMin(miny, y1);
 		maxx = qMax(maxx, x2);
 		maxy = qMax(maxy, y2);
-		docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
+		pa.pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
 	}
 	if (updated)
 	{
@@ -10172,7 +10171,6 @@
 	PageItemIterator itemIt;
 	ScGuardedPtr<ScribusDoc> docPtr = guardedPtr();
 	QList<PageItem*> frameItemList = FrameItems.values();
-	QStringList patterns = docPatterns.keys();
 
 	for (itemIt.begin(DocItems); *itemIt; ++itemIt)
 	{
@@ -10192,9 +10190,10 @@
 		if (currItem->imageIsAvailable)
 			imageCount++;
 	}
-	for (int c = 0; c < patterns.count(); ++c)
-	{
-		ScPattern pa = docPatterns[patterns[c]];
+	auto patternConstEnd = docPatterns.constEnd();
+	for (auto patIt = docPatterns.constBegin(); patIt != patternConstEnd; ++patIt)
+	{
+		const ScPattern& pa = patIt.value();
 		for (itemIt.begin(pa.items); *itemIt; ++itemIt)
 		{
 			PageItem *currItem = *itemIt;
@@ -10317,9 +10316,10 @@
 		if (!docPtr) return;
 	}
 
-	for (int i = 0; i < patterns.count(); ++i)
-	{
-		ScPattern pa = docPatterns[patterns[i]];
+	auto patternEnd = docPatterns.end();
+	for (auto patIt = docPatterns.begin(); patIt != patternEnd; ++patIt)
+	{
+		ScPattern& pa = patIt.value();
 		if (pa.items.count() <= 0)
 			continue;
 		for (itemIt.begin(pa.items); *itemIt; ++itemIt)
@@ -10368,7 +10368,7 @@
 		miny = qMin(miny, y1);
 		maxx = qMax(maxx, x2);
 		maxy = qMax(maxy, y2);
-		docPatterns[patterns[i]].pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
+		pa.pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
 	}
 	regionsChanged()->update(QRectF());
 	changed();
@@ -10383,7 +10383,7 @@
 
 void ScribusDoc::removePict(const QString& name)
 {
-	bool updated=false;
+	bool updated = false;
 	QList<PageItem*> allItems;
 	for (int a = 0; a < DocItems.count(); ++a)
 	{
@@ -10399,7 +10399,7 @@
 			{
 				currItem->imageIsAvailable = false;
 				currItem->pixm = ScImage();
-				updated=true;
+				updated = true;
 			}
 		}
 		allItems.clear();
@@ -10418,7 +10418,7 @@
 			{
 				currItem->imageIsAvailable = false;
 				currItem->pixm = ScImage();
-				updated=true;
+				updated = true;
 			}
 		}
 		allItems.clear();
@@ -10437,15 +10437,15 @@
 			{
 				currItem->imageIsAvailable = false;
 				currItem->pixm = ScImage();
-				updated=true;
+				updated = true;
 			}
 		}
 		allItems.clear();
 	}
-	QStringList patterns = docPatterns.keys();
-	for (int c = 0; c < patterns.count(); ++c)
-	{
-		ScPattern pa = docPatterns[patterns[c]];
+	auto patternEnd = docPatterns.end();
+	for (auto it = docPatterns.begin(); it != patternEnd; ++it)
+	{
+		ScPattern& pa = it.value();
 		if (pa.items.count() <= 0)
 			continue;
 		for (int o = 0; o < pa.items.count(); o++)
@@ -10462,7 +10462,7 @@
 				{
 					currItem->imageIsAvailable = false;
 					currItem->pixm = ScImage();
-					updated=true;
+					updated = true;
 				}
 			}
 			allItems.clear();
@@ -10478,7 +10478,7 @@
 		miny = qMin(miny, y1);
 		maxx = qMax(maxx, x2);
 		maxy = qMax(maxy, y2);
-		docPatterns[patterns[c]].pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
+		pa.pattern = ite->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
 	}
 	if (updated)
 	{
@@ -10496,7 +10496,7 @@
 	if (docSelectionCount <= 0)
 		return;
 
-	bool toUpdate=false;
+	bool toUpdate = false;
 	for (uint i = 0; i < docSelectionCount; ++i)
 	{
 		PageItem* currItem = m_Selection->itemAt(i);




More information about the scribus-commit mailing list