r22666 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 23:08:23 UTC 2018


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

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

Modified:
    trunk/Scribus/scribus/guidesmodel.cpp
    trunk/Scribus/scribus/guidesmodel.h
    trunk/Scribus/scribus/latexhelpers.cpp
    trunk/Scribus/scribus/menumanager.cpp
    trunk/Scribus/scribus/scpaths.cpp
    trunk/Scribus/scribus/ui/latexeditor.cpp
    trunk/Scribus/scribus/ui/prefs_externaltools.cpp
    trunk/Scribus/scribus/ui/prefs_spelling.cpp
    trunk/Scribus/scribus/ui/propertywidget_pareffect.cpp
    trunk/Scribus/scribus/util_file.cpp

Modified: trunk/Scribus/scribus/guidesmodel.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/guidesmodel.cpp
==============================================================================
--- trunk/Scribus/scribus/guidesmodel.cpp	(original)
+++ trunk/Scribus/scribus/guidesmodel.cpp	Tue Sep  4 23:08:23 2018
@@ -87,11 +87,11 @@
 	return "";
 }
 
-void GuidesModel::removeValues(const Guides & v)
+void GuidesModel::removeValues(const Guides & guides)
 {
 	beginResetModel();
-	foreach(double i, v)
-		m_values.removeAll(value2pts(i, m_docUnitIndex));
+	for (double d : guides)
+		m_values.removeAll(value2pts(d, m_docUnitIndex));
 	endResetModel();
 }
 

Modified: trunk/Scribus/scribus/guidesmodel.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/guidesmodel.h
==============================================================================
--- trunk/Scribus/scribus/guidesmodel.h	(original)
+++ trunk/Scribus/scribus/guidesmodel.h	Tue Sep  4 23:08:23 2018
@@ -37,7 +37,7 @@
 
 		QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
-		void removeValues(const Guides & v);
+		void removeValues(const Guides & guides);
 		// qt4 api is "wrokarounded" with insertRow() and removeValues()
 		// these removeRows() and insertRows() does not handle margin items correctly
 // 		bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());

Modified: trunk/Scribus/scribus/latexhelpers.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/latexhelpers.cpp
==============================================================================
--- trunk/Scribus/scribus/latexhelpers.cpp	(original)
+++ trunk/Scribus/scribus/latexhelpers.cpp	Tue Sep  4 23:08:23 2018
@@ -474,9 +474,10 @@
 
 QMap<QString, QString> LatexConfigCache::defaultCommands()
 {
-	QStringList configFiles = PrefsManager::instance()->latexConfigs();
 	QMap<QString, QString> configCmds;
-	foreach (const QString& configFile, configFiles)
+
+	const QStringList configFiles = PrefsManager::instance()->latexConfigs();
+	for (const QString& configFile : configFiles)
 	{
 		LatexConfigParser *config = LatexConfigCache::instance()->parser(configFile);
 		configCmds.insert(configFile, config->executable());

Modified: trunk/Scribus/scribus/menumanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/menumanager.cpp
==============================================================================
--- trunk/Scribus/scribus/menumanager.cpp	(original)
+++ trunk/Scribus/scribus/menumanager.cpp	Tue Sep  4 23:08:23 2018
@@ -109,23 +109,24 @@
 
 bool MenuManager::addMenuStringToMenuBarBefore(const QString &menuName, const QString &beforeMenuName)
 {
-	bool retVal=false;
-	if (menuStrings.contains(menuName))
-	{
-		QList<QAction*> mba=scribusMenuBar->actions();
-		QAction* beforeAct=nullptr;
-		foreach (beforeAct, mba)
-		{
-			if (beforeMenuName==beforeAct->text().remove('&').remove("..."))
-				break;
-		}
-		if (beforeAct)
-		{
-			QMenu *m=new QMenu(menuName);
-			scribusMenuBar->insertMenu(beforeAct, m);
-			menuBarMenus.insert(menuName, m);
-			retVal=true;
-		}
+	bool retVal = false;
+
+	if (!menuStrings.contains(menuName))
+		return false;
+
+	QList<QAction*> mba = scribusMenuBar->actions();
+	QAction* beforeAct=nullptr;
+	foreach (beforeAct, mba)
+	{
+		if (beforeMenuName==beforeAct->text().remove('&').remove("..."))
+			break;
+	}
+	if (beforeAct)
+	{
+		QMenu *m=new QMenu(menuName);
+		scribusMenuBar->insertMenu(beforeAct, m);
+		menuBarMenus.insert(menuName, m);
+		retVal=true;
 	}
 	return retVal;
 }
@@ -369,9 +370,10 @@
 
 void MenuManager::languageChange()
 {
-	foreach (const QString &menuName, menuBarMenus.keys())
-	{
-		QMenu *m=menuBarMenus.value(menuName);
+	const auto menuBarKeys = menuBarMenus.keys();
+	for (const QString &menuName : menuBarKeys)
+	{
+		QMenu *m = menuBarMenus.value(menuName);
 		if (m && menuStringTexts.contains(menuName))
 			m->setTitle(menuStringTexts[menuName]);
 	}

Modified: trunk/Scribus/scribus/scpaths.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/scpaths.cpp
==============================================================================
--- trunk/Scribus/scribus/scpaths.cpp	(original)
+++ trunk/Scribus/scribus/scpaths.cpp	Tue Sep  4 23:08:23 2018
@@ -28,7 +28,7 @@
 #include <shlobj.h>
 #endif
 
-#ifdef _WIN32
+#if defined(Q_OS_WIN32) || defined (Q_OS_OS2)
 const char ScPaths::envPathSeparator = ';';
 #else
 const char ScPaths::envPathSeparator = ':';

Modified: trunk/Scribus/scribus/ui/latexeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/ui/latexeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/latexeditor.cpp	(original)
+++ trunk/Scribus/scribus/ui/latexeditor.cpp	Tue Sep  4 23:08:23 2018
@@ -45,8 +45,9 @@
 	
 	//Fill application list
 	programComboBox->clear();
-	QStringList configs = PrefsManager::instance()->latexConfigs();
-	foreach (QString config, configs)
+
+	const QStringList configs = PrefsManager::instance()->latexConfigs();
+	for (const QString& config : configs)
 	{
 		QString name = LatexConfigCache::instance()->parser(config)->description();
 		programComboBox->addItem(name, config);

Modified: trunk/Scribus/scribus/ui/prefs_externaltools.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/ui/prefs_externaltools.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_externaltools.cpp	(original)
+++ trunk/Scribus/scribus/ui/prefs_externaltools.cpp	Tue Sep  4 23:08:23 2018
@@ -61,9 +61,9 @@
 	latexForceDPICheckBox->setCheckState(prefsData->extToolPrefs.latexForceDpi?Qt::Checked:Qt::Unchecked);
 	latexEmptyFrameCheckBox->setCheckState(prefsData->extToolPrefs.latexStartWithEmptyFrames?Qt::Checked:Qt::Unchecked);
 	latexConfigsListWidget->clear();
-	QStringList configs = prefsData->extToolPrefs.latexConfigs;
+	const QStringList configs = prefsData->extToolPrefs.latexConfigs;
 	commands = prefsData->extToolPrefs.latexCommands;
-	foreach (const QString& config, configs)
+	for (const QString& config : configs)
 		insertConfigItem(config);
 	latexConfigsListWidget->setCurrentRow(0);
 	pdfViewerLineEdit->setText(QDir::toNativeSeparators(prefsData->extToolPrefs.pdfViewerExecutable));

Modified: trunk/Scribus/scribus/ui/prefs_spelling.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/ui/prefs_spelling.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_spelling.cpp	(original)
+++ trunk/Scribus/scribus/ui/prefs_spelling.cpp	Tue Sep  4 23:08:23 2018
@@ -93,8 +93,8 @@
 			if (d.filetype=="plain")
 			{
 				//qDebug()<<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, downloadLocation, userDictDir);
 					++i;

Modified: trunk/Scribus/scribus/ui/propertywidget_pareffect.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/ui/propertywidget_pareffect.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertywidget_pareffect.cpp	(original)
+++ trunk/Scribus/scribus/ui/propertywidget_pareffect.cpp	Tue Sep  4 23:08:23 2018
@@ -124,7 +124,8 @@
 	QStringList numNames;
 	if (m_doc)
 	{
-		foreach (const QString& numName, m_doc->numerations.keys())
+		const auto numerationKeys = m_doc->numerations.keys();
+		for (const QString& numName : numerationKeys)
 			numNames.append(numName);
 		numNames.sort();
 	}

Modified: trunk/Scribus/scribus/util_file.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22666&path=/trunk/Scribus/scribus/util_file.cpp
==============================================================================
--- trunk/Scribus/scribus/util_file.cpp	(original)
+++ trunk/Scribus/scribus/util_file.cpp	Tue Sep  4 23:08:23 2018
@@ -25,6 +25,7 @@
 #include "fileloader.h"
 #include "loadsaveplugin.h"
 #include "prefsmanager.h"
+#include "scpaths.h"
 #include "scribusdoc.h"
 #include "scstreamfilter.h"
 #include "selection.h"
@@ -215,9 +216,9 @@
 	}
 
 	//Get $PATH
-	QStringList env = QProcess::systemEnvironment();
 	QString path;
-	foreach (const QString& line, env)
+	const QStringList env = QProcess::systemEnvironment();
+	for (const QString& line : env)
 	{
 		if (line.indexOf("PATH") == 0)
 		{
@@ -225,13 +226,10 @@
 			break;
 		}
 	}
-	QStringList splitpath;
-	#if defined(Q_OS_WIN32) || defined (Q_OS_OS2)
-		splitpath = path.split(';', QString::SkipEmptyParts);
-	#else
-		splitpath = path.split(':', QString::SkipEmptyParts);
-	#endif
-	foreach (const QString& dir, splitpath)
+
+	QChar envPathSeparator(ScPaths::envPathSeparator);
+	const QStringList splitpath = path.split(envPathSeparator, QString::SkipEmptyParts);
+	for (const QString& dir : splitpath)
 	{
 		QFileInfo info(dir, file);
 		if (info.exists())
@@ -257,7 +255,7 @@
 			if (testResult != -1)
 			{
 				const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
-				if( fmt )
+				if (fmt)
 				{
 					doc->m_Selection->clear();
 					doc->m_Selection->delaySignalsOn();




More information about the scribus-commit mailing list