r22665 by jghali - remove a few more Qt foreach and replace them by C++11 range-for

scribus-commit scribus-commit at lists.scribus.net
Tue Sep 4 22:08:24 UTC 2018


Author: jghali
Date: Tue Sep  4 22:08:23 2018
New Revision: 22665

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22665
Log:
remove a few more Qt foreach and replace them by C++11 range-for

Modified:
    trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
    trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
    trunk/Scribus/scribus/pageitem_latexframe.cpp
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/ui/guidemanager.cpp
    trunk/Scribus/scribus/ui/helpbrowser.cpp
    trunk/Scribus/scribus/ui/resourcemanager.cpp
    trunk/Scribus/scribus/ui/smcellstyle.cpp
    trunk/Scribus/scribus/ui/smtablestyle.cpp

Modified: trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp	(original)
+++ trunk/Scribus/scribus/downloadmanager/scdlmgr.cpp	Tue Sep  4 22:08:23 2018
@@ -63,7 +63,7 @@
 
 void ScDLManager::addURLs(const QStringList &urlList, bool overwrite, const QString &downloadLocation, const QString& destinationLocation)
 {
-	foreach(const QString& s, urlList)
+	for(const QString& s : urlList)
 	{
 		DownloadData d;
 		d.id=m_dlID++;

Modified: trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/downloadmanager/scdlthread.cpp
==============================================================================
--- trunk/Scribus/scribus/downloadmanager/scdlthread.cpp	(original)
+++ trunk/Scribus/scribus/downloadmanager/scdlthread.cpp	Tue Sep  4 22:08:23 2018
@@ -46,7 +46,7 @@
 	QString l(QDir::cleanPath(location));
 	if (!l.endsWith("/"))
 		l += "/";
-	foreach (QString u, m_urlList)
+	for (const QString& u : m_urlList)
 	{
 		QUrl url(u);
 		if (!urlOK(u))

Modified: trunk/Scribus/scribus/pageitem_latexframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/pageitem_latexframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_latexframe.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_latexframe.cpp	Tue Sep  4 22:08:23 2018
@@ -117,9 +117,9 @@
 	Q_ASSERT(!fi.fileName().isEmpty());
 	Q_ASSERT(!fi.fileName().contains("/"));
 	Q_ASSERT(!fi.fileName().contains("\\"));
-	QStringList files;
-	files = dir.entryList(filter);
-	foreach (const QString& file, files)
+
+	const QStringList files = dir.entryList(filter);
+	for (const QString& file : files)
 	{
 		Q_ASSERT(file.startsWith("scribus_temp"));
 		dir.remove(file);
@@ -465,8 +465,8 @@
 	if (relative)
 	{
 		QFileInfo fi;
-		QStringList configs = PrefsManager::instance()->latexConfigs();
-		foreach (const QString& config, configs)
+		const QStringList configs = PrefsManager::instance()->latexConfigs();
+		for (const QString& config : configs)
 		{
 			fi.setFile(config);
 			if (newConfig == fi.fileName())

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp	(original)
+++ trunk/Scribus/scribus/prefsmanager.cpp	Tue Sep  4 22:08:23 2018
@@ -790,24 +790,24 @@
 
 	//Move plugin data files to new plugin data file directory
 	QDir oldPluginData(ScPaths::preferencesDir() + "/plugins");
-	QFileInfoList filPluginData(oldPluginData.entryInfoList());
-	foreach (const QFileInfo &fiP, filPluginData)
+	const QFileInfoList filPluginData(oldPluginData.entryInfoList());
+	for (const QFileInfo &fiP : filPluginData)
 		moveFile(fiP.absoluteFilePath(), ScPaths::pluginDataDir(true) + fiP.fileName());
 
 	//Move scrapbook files to new scrapbook directory
 	QDir oldScrapData(ScPaths::preferencesDir() + "/scrapbook");
-	QFileInfoList filScrapData(oldScrapData.entryInfoList());
-	foreach (const QFileInfo &fiS, filScrapData)
+	const QFileInfoList filScrapData(oldScrapData.entryInfoList());
+	for (const QFileInfo &fiS : filScrapData)
 		moveFile(fiS.absoluteFilePath(), ScPaths::scrapbookDir(true) + fiS.fileName());
 
 	//Move swatch files to new palette directory
 	QDir oldPaletteData(ScPaths::preferencesDir() + "/swatches");
-	QFileInfoList filPaletteData(oldPaletteData.entryInfoList());
-	foreach (const QFileInfo &fiPal, filPaletteData)
+	const QFileInfoList filPaletteData(oldPaletteData.entryInfoList());
+	for (const QFileInfo &fiPal : filPaletteData)
 		moveFile(fiPal.absoluteFilePath(), ScPaths::userPaletteFilesDir(true) + fiPal.fileName());
-	QDir oldPaletteData2=ScPaths::preferencesDir() + "/palettes";
-	QFileInfoList filPaletteData2(oldPaletteData2.entryInfoList());
-	foreach (const QFileInfo &fiPal, filPaletteData2)
+	QDir oldPaletteData2 = ScPaths::preferencesDir() + "/palettes";
+	const QFileInfoList filPaletteData2(oldPaletteData2.entryInfoList());
+	for (const QFileInfo &fiPal : filPaletteData2)
 		moveFile(fiPal.absoluteFilePath(), ScPaths::userPaletteFilesDir(true) + fiPal.fileName());
 
 	//Now make copies for 1.3 use and leave the old ones alone for <1.3.0 usage
@@ -1759,8 +1759,8 @@
 	dcExternalTools.setAttribute("LatexResolution", latexResolution());
 	dcExternalTools.setAttribute("LatexForceDpi", static_cast<int>(appPrefs.extToolPrefs.latexForceDpi));
 	dcExternalTools.setAttribute("LatexStartWithEmptyFrames", static_cast<int>(appPrefs.extToolPrefs.latexStartWithEmptyFrames));
-	QStringList configs = latexConfigs();
-	foreach (const QString& config, configs)
+	const QStringList configs = latexConfigs();
+	for (const QString& config : configs)
 	{
 		QDomElement domConfig = docu.createElement("LatexConfig");
 		domConfig.setAttribute("file", config);

Modified: trunk/Scribus/scribus/ui/guidemanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/ui/guidemanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/guidemanager.cpp	(original)
+++ trunk/Scribus/scribus/ui/guidemanager.cpp	Tue Sep  4 22:08:23 2018
@@ -276,11 +276,10 @@
 
 void GuideManager::delHorButton_clicked()
 {
-	QModelIndexList indexes = horizontalView->selectionModel()->selectedRows(0);
-	QModelIndex ix;
+	const QModelIndexList indexes = horizontalView->selectionModel()->selectedRows(0);
 	Guides v;
 
-	foreach(ix, indexes)
+	for (const QModelIndex& ix : indexes)
 		// here *must* go EditRole due truncations in DisplayRole
 		// see GuidesModel::data()
 		v.append(horizontalModel->data(ix, Qt::EditRole).toDouble());
@@ -295,11 +294,10 @@
 
 void GuideManager::delVerButton_clicked()
 {
-	QModelIndexList indexes = verticalView->selectionModel()->selectedRows(0);
-	QModelIndex ix;
+	const QModelIndexList indexes = verticalView->selectionModel()->selectedRows(0);
 	Guides v;
 
-	foreach(ix, indexes)
+	for (const QModelIndex& ix : indexes)
 		// here *must* go EditRole due truncations in DisplayRole
 		// see GuidesModel::data()
 		v.append(verticalModel->data(ix, Qt::EditRole).toDouble());
@@ -440,26 +438,24 @@
 
 Guides GuideManager::selectedHorizontals()
 {
-	QModelIndex i;
-	QModelIndexList selectedIndexes = horizontalView->selectionModel()->selectedIndexes();
+	const QModelIndexList selectedIndexes = horizontalView->selectionModel()->selectedIndexes();
 	Guides ret;
 	Guides curr = horizontalModel->values();
-	foreach (i , selectedIndexes)
-	{
-		ret.append(curr.at(i.row()));
+	for (const QModelIndex& idx : selectedIndexes)
+	{
+		ret.append(curr.at(idx.row()));
 	}
 	return ret;
 }
 
 Guides GuideManager::selectedVerticals()
 {
-	QModelIndex i;
-	QModelIndexList selectedIndexes = verticalView->selectionModel()->selectedIndexes();
+	const QModelIndexList selectedIndexes = verticalView->selectionModel()->selectedIndexes();
 	Guides ret;
 	Guides curr = verticalModel->values();
-	foreach (i , selectedIndexes)
-	{
-		ret.append(curr.at(i.row()));
+	for (const QModelIndex& idx : selectedIndexes)
+	{
+		ret.append(curr.at(idx.row()));
 	}
 	return ret;
 }

Modified: trunk/Scribus/scribus/ui/helpbrowser.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/ui/helpbrowser.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/helpbrowser.cpp	(original)
+++ trunk/Scribus/scribus/ui/helpbrowser.cpp	Tue Sep  4 22:08:23 2018
@@ -653,12 +653,11 @@
 {
 	Q_UNUSED(deselected);
 
-	QModelIndex index;
-	QModelIndexList items = selected.indexes();
-	int i=0;
-	foreach (index, items)
-	{
-		if (i==1) // skip 0, as this is always the rootitem, even if we are selecting the rootitem. hmm
+	int i = 0;
+	const QModelIndexList items = selected.indexes();
+	for (const QModelIndex& index : items)
+	{
+		if (i == 1) // skip 0, as this is always the rootitem, even if we are selecting the rootitem. hmm
 		{
 			QString filename(menuModel->data(index, Qt::DisplayRole).toString());
 			if (!filename.isEmpty())

Modified: trunk/Scribus/scribus/ui/resourcemanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/ui/resourcemanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/resourcemanager.cpp	(original)
+++ trunk/Scribus/scribus/ui/resourcemanager.cpp	Tue Sep  4 22:08:23 2018
@@ -1017,13 +1017,13 @@
 							qDebug()<<"Zip file doesn\'t open"<<fn;
 						else
 						{
-							QStringList zipFileContents(fun->files());
+							const QStringList zipFileContents(fun->files());
 							QStringList extractFiles(d.extractfiles.split(";", QString::SkipEmptyParts));
 							QString toDir(ScPaths::userFontDir(false)+fi.baseName()+"/");
 							QDir dir(ScPaths::userFontDir(false));
 							if (!dir.exists(fi.baseName()))
 								dir.mkdir(fi.baseName());
-							foreach (const QString& f2e, zipFileContents)
+							for (const QString& f2e : zipFileContents)
 							{
 								fun->extract(f2e, toDir, ScZipHandler::SkipPaths);
 							}
@@ -1055,13 +1055,13 @@
 								qDebug()<<"Zip file doesn\'t open"<<fn;
 							else
 							{
-								QStringList zipContents(fun->files());
+								const QStringList zipContents(fun->files());
 								QStringList extractFiles(d.extractfiles.split(";", QString::SkipEmptyParts));
 								QString toDir(ScPaths::userDictDir(static_cast<ScPaths::DictType>(fileType), false));
 								QDir dir(toDir);
 								if (dir.exists())
 								{
-									foreach (const QString& f2e, zipContents)
+									for (const QString& f2e : zipContents)
 									{
 										if (extractFiles.contains(f2e))
 											fun->extract(f2e, toDir, ScZipHandler::SkipPaths);
@@ -1101,13 +1101,13 @@
 								qDebug()<<"Zip file doesn\'t open"<<fn;
 							else
 							{
-								QStringList zipFileContents(fun->files());
+								const QStringList zipFileContents(fun->files());
 								QStringList extractFiles(d.extractfiles.split(";", QString::SkipEmptyParts));
 								QString toDir(ScPaths::userHelpFilesDir(false)+d.lang+"/");
 								QDir dir(ScPaths::userHelpFilesDir(false));
 								if (!dir.exists(d.lang))
 									dir.mkdir(d.lang);
-								foreach (const QString& f2e, zipFileContents)
+								for (const QString& f2e : zipFileContents)
 								{
 									//qDebug()<<"Unzipping"<<f2e<<"to"<<toDir;
 									fun->extract(f2e, toDir, ScZipHandler::ExtractPaths);
@@ -1219,8 +1219,8 @@
 				{
 					if (d.filetype=="zip")
 					{
-						QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
-						foreach (const QString& s, plainURLs)
+						const QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+						for (const QString& s : plainURLs)
 						{
 //							qDebug()<<"Requesting:"<<d.url+"/"+s;
 							ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder, d.files);
@@ -1231,8 +1231,8 @@
 					}
 					if (d.filetype=="plain")
 					{
-						QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
-						foreach (const QString& s, plainURLs)
+						const QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+						for (const QString& s : plainURLs)
 						{
 							ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder);
 							++dlCount;
@@ -1253,8 +1253,8 @@
 					if (d.filetype=="zip")
 					{
 //						qDebug()<<"zip type:"<<d.url<<d.files;
-						QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
-						foreach (const QString& s, plainURLs)
+						const QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+						for (const QString& s : plainURLs)
 						{
 							ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder);
 							++dlCount;
@@ -1265,8 +1265,8 @@
 					if (d.filetype=="plain")
 					{
 //						qDebug()<<"plain type:"<<d.url<<d.files;
-						QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
-						foreach (const QString& s, plainURLs)
+						const QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+						for (const QString& s : plainURLs)
 						{
 							ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder);
 							++dlCount;
@@ -1286,8 +1286,8 @@
 					if (d.filetype=="zip")
 					{
 //						qDebug()<<"zip type:"<<d.url<<d.files;
-						QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
-						foreach (const QString& s, plainURLs)
+						const QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+						for (const QString& s : plainURLs)
 						{
 							ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder);
 							ScQApp->dlManager()->addURL(d.url+"/"+s+".sha256", true, ScPaths::downloadDir(), destinationFolder);
@@ -1308,8 +1308,8 @@
 					if (d.filetype=="zip")
 					{
 //						qDebug()<<"zip type:"<<d.url<<d.files;
-						QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
-						foreach (const QString& s, plainURLs)
+						const QStringList plainURLs(d.files.split(";", QString::SkipEmptyParts));
+						for (const QString& s : plainURLs)
 						{
 							ScQApp->dlManager()->addURL(d.url+"/"+s, true, ScPaths::downloadDir(), destinationFolder);
 							ScQApp->dlManager()->addURL(d.url+"/"+s+".sha256", true, ScPaths::downloadDir(), destinationFolder);

Modified: trunk/Scribus/scribus/ui/smcellstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/ui/smcellstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smcellstyle.cpp	(original)
+++ trunk/Scribus/scribus/ui/smcellstyle.cpp	Tue Sep  4 22:08:23 2018
@@ -118,7 +118,7 @@
 	for (int i = 0; i < m_cachedStyles.count(); ++i)
 		cellStyles << m_cachedStyles[i];
 
-	foreach (const QString& styleName, styleNames)
+	for (const QString& styleName : styleNames)
 	{
 		int index = m_cachedStyles.find(styleName);
 		// FIXME: #7133: Use .isDefaultStyle() instead here rather than relying on tr text comparison
@@ -277,7 +277,7 @@
 
 void SMCellStyle::deleteStyles(const QList<RemoveItem> &removeList)
 {
-	foreach (const RemoveItem& removeItem, removeList)
+	for (const RemoveItem& removeItem : removeList)
 	{
 		for (int i = 0; i < m_selection.count(); ++i)
 		{

Modified: trunk/Scribus/scribus/ui/smtablestyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22665&path=/trunk/Scribus/scribus/ui/smtablestyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smtablestyle.cpp	(original)
+++ trunk/Scribus/scribus/ui/smtablestyle.cpp	Tue Sep  4 22:08:23 2018
@@ -114,7 +114,7 @@
 	for (int i = 0; i < m_cachedStyles.count(); ++i)
 		tableStyles << m_cachedStyles[i];
 
-	foreach (const QString& styleName, styleNames)
+	for (const QString& styleName : styleNames)
 	{
 		int index = m_cachedStyles.find(styleName);
 		// FIXME: #7133: Use .isDefaultStyle() instead here rather than relying on tr text comparison
@@ -273,7 +273,7 @@
 
 void SMTableStyle::deleteStyles(const QList<RemoveItem> &removeList)
 {
-	foreach (const RemoveItem& removeItem, removeList)
+	for (const RemoveItem& removeItem : removeList)
 	{
 		for (int i = 0; i < m_selection.count(); ++i)
 		{




More information about the scribus-commit mailing list