r22508 by jghali - replace more Qt's foreach by c++11 range-based for()

scribus-commit scribus-commit at lists.scribus.net
Tue May 1 16:46:55 UTC 2018


Author: jghali
Date: Tue May  1 16:46:55 2018
New Revision: 22508

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22508
Log:
replace more Qt's foreach by c++11 range-based for()

Modified:
    trunk/Scribus/scribus/canvas.cpp
    trunk/Scribus/scribus/canvasgesture_table.cpp
    trunk/Scribus/scribus/iconmanager.cpp
    trunk/Scribus/scribus/iconmanager.h
    trunk/Scribus/scribus/pageitem_table.cpp
    trunk/Scribus/scribus/plugins/picbrowser/previewimage.cpp
    trunk/Scribus/scribus/scpageoutput.cpp
    trunk/Scribus/scribus/scpainter.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/tableborder.cpp
    trunk/Scribus/scribus/ui/copypagetomasterpagedialog.cpp
    trunk/Scribus/scribus/ui/preferencesdialog.cpp
    trunk/Scribus/scribus/ui/propertiespalette_table.cpp
    trunk/Scribus/scribus/ui/unicodesearch.cpp
    trunk/Scribus/scribus/ui/unicodesearch.h

Modified: trunk/Scribus/scribus/canvas.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/canvas.cpp
==============================================================================
--- trunk/Scribus/scribus/canvas.cpp	(original)
+++ trunk/Scribus/scribus/canvas.cpp	Tue May  1 16:46:55 2018
@@ -2596,7 +2596,8 @@
 			+ item->currentStyle().rightMargin()	* 9.0
 			+ (item->imageFlippedH() ? 32.32 : 13.13);
 	
-	foreach(const ParagraphStyle::TabRecord& tabrec, item->currentStyle().tabValues())
+	const ParagraphStyle& currParaStyle = item->currentStyle();
+	for (const ParagraphStyle::TabRecord& tabrec : currParaStyle.tabValues())
 	{
 		controlHash += tabrec.tabPosition;
 	}

Modified: trunk/Scribus/scribus/canvasgesture_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/canvasgesture_table.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_table.cpp	(original)
+++ trunk/Scribus/scribus/canvasgesture_table.cpp	Tue May  1 16:46:55 2018
@@ -141,7 +141,7 @@
 	const QPointF offset = m_table->gridOffset();
 	QPainterPath selectionPath;
 
-	foreach (const TableCell& cell, m_table->selectedCells())
+	for (const TableCell& cell : m_table->selectedCells())
 	{
 		QRectF cellRect = cell.boundingRect();
 		cellRect.translate(offset);

Modified: trunk/Scribus/scribus/iconmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/iconmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/iconmanager.cpp	(original)
+++ trunk/Scribus/scribus/iconmanager.cpp	Tue May  1 16:46:55 2018
@@ -254,10 +254,10 @@
 	return false;
 }
 
-QString IconManager::baseNameForTranslation(QString transName)
+QString IconManager::baseNameForTranslation(QString transName) const
 {
 	QString name;
-	foreach (ScIconSetData value, m_iconSets)
+	for (const ScIconSetData& value : m_iconSets)
 	{
 		QMapIterator<QString, QString> nameValue(value.nameTranslations);
 		while (nameValue.hasNext())
@@ -294,18 +294,18 @@
 	return "";
 }
 
-QStringList IconManager::pathList()
+QStringList IconManager::pathList() const
 {
 	QStringList paths;
-	foreach (ScIconSetData value, m_iconSets)
+	for (const ScIconSetData& value :  m_iconSets)
 		paths << value.path;
 	return paths;
 }
 
-QStringList IconManager::nameList(QString language)
+QStringList IconManager::nameList(QString language) const
 {
 	QStringList names;
-	foreach (ScIconSetData value, m_iconSets)
+	for (const ScIconSetData& value : m_iconSets)
 	{
 		if (value.nameTranslations.contains(language))
 			names << value.nameTranslations.value(language);

Modified: trunk/Scribus/scribus/iconmanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/iconmanager.h
==============================================================================
--- trunk/Scribus/scribus/iconmanager.h	(original)
+++ trunk/Scribus/scribus/iconmanager.h	Tue May  1 16:46:55 2018
@@ -55,12 +55,12 @@
 		QIcon loadIcon(const QString nam, bool forceUseColor=false);
 		QPixmap loadPixmap(const QString nam, bool forceUseColor=false, bool rtlFlip=false);
 		QString pathForIcon(const QString nam);
-		QStringList pathList();
-		QStringList nameList(QString language);
+		QStringList pathList() const;
+		QStringList nameList(QString language) const;
 		void iconToGrayscale(QPixmap *pm);
 		bool setActiveFromPrefs(QString prefsSet);
 		QString activeSetBasename() { return m_activeSetBasename; }
-		QString baseNameForTranslation(QString transName);
+		QString baseNameForTranslation(QString transName) const;
 
 	public slots:
 		void languageChange();

Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp	(original)
+++ trunk/Scribus/scribus/pageitem_table.cpp	Tue May  1 16:46:55 2018
@@ -1504,7 +1504,7 @@
 			Q_ASSERT(m_activeCell.row() == cellArea.row() && m_activeCell.column() == cellArea.column());
 
 		// Check that the selected cells are not covered.
-		foreach (const TableCell& cell, m_selection)
+		for (const TableCell& cell : m_selection)
 			if (cellArea.contains(cell.row(), cell.column()))
 				Q_ASSERT(cell.row() == cellArea.row() && cell.column() == cellArea.column());
 	}

Modified: trunk/Scribus/scribus/plugins/picbrowser/previewimage.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/plugins/picbrowser/previewimage.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/picbrowser/previewimage.cpp	(original)
+++ trunk/Scribus/scribus/plugins/picbrowser/previewimage.cpp	Tue May  1 16:46:55 2018
@@ -577,22 +577,22 @@
 }
 
 
-QMimeData *PreviewImagesModel::mimeData ( const QModelIndexList &indexes ) const
+QMimeData *PreviewImagesModel::mimeData (const QModelIndexList &indexes) const
 {
 	QMimeData *mimeData = new QMimeData();
 	int row;
 	QList<QUrl> urls;
 	QString imageFile;
 
-	foreach ( QModelIndex index, indexes )
-	{
-		if ( index.isValid() )
+	for (const QModelIndex& index : indexes)
+	{
+		if (index.isValid())
 		{
 			row = index.row();
 
-			if ( ( row >= 0 ) && ( row < modelItemsList.size() ) )
+			if ((row >= 0) && (row < modelItemsList.size()))
 			{
-				imageFile = modelItemsList.at ( row )->fileInformation.absoluteFilePath();
+				imageFile = modelItemsList.at(row)->fileInformation.absoluteFilePath();
 				urls.append (QUrl::fromLocalFile(imageFile));
 			}
 		}

Modified: trunk/Scribus/scribus/scpageoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/scpageoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/scpageoutput.cpp	(original)
+++ trunk/Scribus/scribus/scpageoutput.cpp	Tue May  1 16:46:55 2018
@@ -1024,7 +1024,8 @@
 
 		setupState();
 		double current_x = 0.0;
-		foreach (const GlyphLayout& gl, gc.glyphs()) {
+		for (const GlyphLayout& gl : gc.glyphs())
+		{
 			m_painter->save();
 			m_painter->translate(gl.xoffset + current_x, -(fontSize() * gc.scaleV()) + gl.yoffset);
 

Modified: trunk/Scribus/scribus/scpainter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/scpainter.cpp
==============================================================================
--- trunk/Scribus/scribus/scpainter.cpp	(original)
+++ trunk/Scribus/scribus/scpainter.cpp	Tue May  1 16:46:55 2018
@@ -1715,12 +1715,12 @@
 		story.setCharStyle(0, textList[a].count(), style);
 
 		TextShaper textShaper(story, 0);
-		QList<GlyphCluster> glyphRuns = textShaper.shape(0, story.length()).glyphs();
+		const QList<GlyphCluster> glyphRuns = textShaper.shape(0, story.length()).glyphs();
 
 		double tmpx = x;
-		foreach (const GlyphCluster &run, glyphRuns)
-		{
-			foreach (const GlyphLayout &gl, run.glyphs())
+		for (const GlyphCluster &run : glyphRuns)
+		{
+			for (const GlyphLayout &gl : run.glyphs())
 			{
 				cairo_glyph_t glyph;
 				glyph.index = gl.glyph;

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Tue May  1 16:46:55 2018
@@ -4476,7 +4476,8 @@
 	{
 		if (gc.isControlGlyphs())
 			return;
-		foreach (const GlyphLayout& gl, gc.glyphs()) {
+		for (const GlyphLayout& gl : gc.glyphs())
+		{
 			QString replacementName = font().replacementName();
 			if (!replacementName.isEmpty())
 			{
@@ -4607,11 +4608,11 @@
 			story.setCharStyle(0, txtList[a].count(), style);
 
 			TextShaper textShaper(story, 0);
-			QList<GlyphCluster> glyphRuns = textShaper.shape(0, story.length()).glyphs();
-
-			foreach (const GlyphCluster &run, glyphRuns)
-			{
-				foreach (const GlyphLayout &gl, run.glyphs())
+			const QList<GlyphCluster> glyphRuns = textShaper.shape(0, story.length()).glyphs();
+
+			for (const GlyphCluster &run : glyphRuns)
+			{
+				for (const GlyphLayout &gl : run.glyphs())
 				{
 					FPointArray outline(font.glyphOutline(gl.glyph));
 					if (!fontName.isEmpty())

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp	(original)
+++ trunk/Scribus/scribus/scribusview.cpp	Tue May  1 16:46:55 2018
@@ -3094,7 +3094,8 @@
 
 	void drawGlyph(const GlyphCluster& gc)
 	{
-		foreach (const GlyphLayout& gl, gc.glyphs()) {
+		for (const GlyphLayout& gl : gc.glyphs())
+		{
 			FPointArray outline = font().glyphOutline(gl.glyph);
 			if (outline.size() < 4)
 				return;
@@ -3141,7 +3142,8 @@
 	}
 	void drawGlyphOutline(const GlyphCluster& gc, bool fill)
 	{
-		foreach (const GlyphLayout& gl, gc.glyphs()) {
+		for (const GlyphLayout& gl : gc.glyphs())
+		{
 			FPointArray outline = font().glyphOutline(gl.glyph);
 			if (outline.size() < 4)
 				return;

Modified: trunk/Scribus/scribus/tableborder.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/tableborder.cpp
==============================================================================
--- trunk/Scribus/scribus/tableborder.cpp	(original)
+++ trunk/Scribus/scribus/tableborder.cpp	Tue May  1 16:46:55 2018
@@ -89,7 +89,7 @@
 QString TableBorder::asString() const
 {
 	QStringList lines;
-	foreach (TableBorderLine line, m_borderLines)
+	for (const TableBorderLine& line : m_borderLines)
 		lines << line.asString();
 	return QString("TableBorder(%1)").arg(lines.join(","));
 }

Modified: trunk/Scribus/scribus/ui/copypagetomasterpagedialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/ui/copypagetomasterpagedialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/copypagetomasterpagedialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/copypagetomasterpagedialog.cpp	Tue May  1 16:46:55 2018
@@ -17,12 +17,12 @@
 	setupUi(this);
 
 	QList<QAbstractButton *> buttonList = buttonBox->buttons();
-	foreach (QAbstractButton* b, buttonList)
+	for (QAbstractButton* b : buttonList)
 	{
-		if (buttonBox->buttonRole(b)==QDialogButtonBox::AcceptRole)
+		if (buttonBox->buttonRole(b) == QDialogButtonBox::AcceptRole)
 			b->setText(CommonStrings::tr_OK);
 		else
-		if (buttonBox->buttonRole(b)==QDialogButtonBox::RejectRole)
+		if (buttonBox->buttonRole(b) == QDialogButtonBox::RejectRole)
 			b->setText(CommonStrings::tr_Cancel);
 	}
 
@@ -31,7 +31,7 @@
 		pagePositionComboBox->hide();
 	else
 	{
-		foreach (const QString& untranslatedPageName, pageLocations)
+		for (const QString& untranslatedPageName : pageLocations)
 			pagePositionComboBox->addItem(CommonStrings::translatePageSetLocString(untranslatedPageName));
 		pagePositionComboBox->setCurrentIndex(currentLocation);
 	}

Modified: trunk/Scribus/scribus/ui/preferencesdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/ui/preferencesdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/preferencesdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/preferencesdialog.cpp	Tue May  1 16:46:55 2018
@@ -368,30 +368,29 @@
 	QPixmap panelIcon;
 
 	PluginManager& pluginManager = PluginManager::instance();
-	QStringList pluginNames(pluginManager.pluginNames(true));
-
-	foreach (QString pName, pluginManager.pluginNames(true))
+	const QStringList pluginNames(pluginManager.pluginNames(true));
+
+	for (const QString& pName : pluginNames)
 	{
 		// Ask the plugin manager for a plugin (skipping disabled plugins).
 		plugin = pluginManager.getPlugin(pName, false);
+		if (!plugin)
+			continue;
 		// If we got a plugin (which we know is enabled):
-		if (plugin)
+		// Ask the plugin for a prefs widget
+		bool wantPanel = plugin->newPrefsPanelWidget(prefsStackWidget, panel, panelCaption, panelIcon);
+		// If it gave us one...
+		if (wantPanel)
 		{
-			// Ask the plugin for a prefs widget
-			bool wantPanel = plugin->newPrefsPanelWidget(prefsStackWidget, panel, panelCaption, panelIcon);
-			// If it gave us one...
-			if (wantPanel)
-			{
-				// Ensure that we got sane return values
-				Q_ASSERT(panel);
-				Q_ASSERT(!panelIcon.isNull());
-				Q_ASSERT(!panelCaption.isNull());
-				// plug it in to the dialog,
-				addItem(panelCaption, panelIcon, panel);
-				// and connect a signal to tell it to save its
-				// settings.
-				connect(this, SIGNAL(accepted()), panel, SLOT(apply()));
-			}
+			// Ensure that we got sane return values
+			Q_ASSERT(panel);
+			Q_ASSERT(!panelIcon.isNull());
+			Q_ASSERT(!panelCaption.isNull());
+			// plug it in to the dialog,
+			addItem(panelCaption, panelIcon, panel);
+			// and connect a signal to tell it to save its
+			// settings.
+			connect(this, SIGNAL(accepted()), panel, SLOT(apply()));
 		}
 	}
 }

Modified: trunk/Scribus/scribus/ui/propertiespalette_table.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/ui/propertiespalette_table.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_table.cpp	(original)
+++ trunk/Scribus/scribus/ui/propertiespalette_table.cpp	Tue May  1 16:46:55 2018
@@ -311,7 +311,7 @@
 void PropertiesPalette_Table::updateBorderLineList()
 {
 	borderLineList->clear();
-	foreach (const TableBorderLine& borderLine, m_currentBorder.borderLines())
+	for (const TableBorderLine& borderLine : m_currentBorder.borderLines())
 	{
 		QString text = QString(" %1%2 %3").arg(borderLine.width()).arg(borderLineWidth->suffix()).arg(CommonStrings::translatePenStyleName(borderLine.style()));
 		if (borderLine.color() != CommonStrings::None)

Modified: trunk/Scribus/scribus/ui/unicodesearch.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/ui/unicodesearch.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/unicodesearch.cpp	(original)
+++ trunk/Scribus/scribus/ui/unicodesearch.cpp	Tue May  1 16:46:55 2018
@@ -117,12 +117,12 @@
 {
 }
 
-QString UnicodeSearchModel::descriptionFromHex(const QString& hex)
-{
-	foreach( UnicodeStruct I, m_unicode )
-	{
-		if ( I.hex == hex )
-			return I.description;
+QString UnicodeSearchModel::descriptionFromHex(const QString& hex) const
+{
+	for (const UnicodeStruct& uni : m_unicode)
+	{
+		if (uni.hex == hex)
+			return uni.description;
 	}
 	return QString();
 }

Modified: trunk/Scribus/scribus/ui/unicodesearch.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22508&path=/trunk/Scribus/scribus/ui/unicodesearch.h
==============================================================================
--- trunk/Scribus/scribus/ui/unicodesearch.h	(original)
+++ trunk/Scribus/scribus/ui/unicodesearch.h	Tue May  1 16:46:55 2018
@@ -83,7 +83,7 @@
 		QString hexData(const QModelIndex & index);
 
 		//! \brief Return character unicode description from hex code
-		QString descriptionFromHex(const QString& hex);
+		QString descriptionFromHex(const QString& hex) const;
 
 	private:
 




More information about the scribus-commit mailing list