r23100 by jghali - Remove some unnecessarily big "if" blocks by exiting/continuing early when possible

scribus-commit scribus-commit at lists.scribus.net
Sun Aug 4 02:34:43 UTC 2019


Author: jghali
Date: Sun Aug  4 02:34:43 2019
New Revision: 23100

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23100
Log:
Remove some unnecessarily big "if" blocks by exiting/continuing early when possible

Modified:
    trunk/Scribus/scribus/langmgr.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
    trunk/Scribus/scribus/ui/colorsandfills.cpp

Modified: trunk/Scribus/scribus/langmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23100&path=/trunk/Scribus/scribus/langmgr.cpp
==============================================================================
--- trunk/Scribus/scribus/langmgr.cpp	(original)
+++ trunk/Scribus/scribus/langmgr.cpp	Sun Aug  4 02:34:43 2019
@@ -655,23 +655,21 @@
 	QString langAbbrev;
 	QMap<QString, langPair>::Iterator it;
 	QDir dir(path , "*.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
-	if (dir.exists() && (dir.count() != 0))
-	{
-		for (uint i = 0; i < dir.count(); ++i)
-		{
-			QFileInfo file(path + dir[i]);
-			if (file.suffix().toLower() == "qm")
-			{
-				langAbbrev = file.completeSuffix().remove(".qm");
-				int j=langTableIndex(langAbbrev);
-				if (j!=-1)
-				{
-					m_langTable[j].m_transAvailable=true;
-					m_langTable[j].m_transFile=file.absoluteFilePath();
-					//qDebug()<<"Found installed GUI translation file:"<<langAbbrev<<" : "<<langTable[j].m_transFile<<langTable[j].m_transName;
-				}
-			}
-		}
+	if (!dir.exists() || (dir.count() == 0))
+		return;
+
+	for (uint i = 0; i < dir.count(); ++i)
+	{
+		QFileInfo file(path + dir[i]);
+		if (file.suffix().toLower() != "qm")
+			continue;
+		langAbbrev = file.completeSuffix().remove(".qm");
+		int j = langTableIndex(langAbbrev);
+		if (j < 0)
+			continue;
+		m_langTable[j].m_transAvailable = true;
+		m_langTable[j].m_transFile = file.absoluteFilePath();
+		//qDebug()<<"Found installed GUI translation file:"<<langAbbrev<<" : "<<langTable[j].m_transFile<<langTable[j].m_transName;
 	}
 }
 

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23100&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp	Sun Aug  4 02:34:43 2019
@@ -124,19 +124,18 @@
 void ScripterCore::buildScribusScriptsMenu()
 {
 	QString pfad = ScPaths::instance().scriptDir();
-	QString pfad2;
-	pfad2 = QDir::toNativeSeparators(pfad);
+	QString pfad2 = QDir::toNativeSeparators(pfad);
 	QDir ds(pfad2, "*.py", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
-	if ((ds.exists()) && (ds.count() != 0))
-	{
-		for (uint dc = 0; dc < ds.count(); ++dc)
-		{
-			QFileInfo fs(ds[dc]);
-			QString strippedName=fs.baseName();
-			m_scripterActions.insert(strippedName, new ScrAction( ScrAction::RecentScript, strippedName, QKeySequence(), this, strippedName));
-			connect( m_scripterActions[strippedName], SIGNAL(triggeredData(QString)), this, SLOT(StdScript(QString)) );
-			m_menuMgr->addMenuItemString(strippedName, "ScribusScripts");
-		}
+	if ((!ds.exists()) || (ds.count() == 0))
+		return;
+
+	for (uint dc = 0; dc < ds.count(); ++dc)
+	{
+		QFileInfo fs(ds[dc]);
+		QString strippedName=fs.baseName();
+		m_scripterActions.insert(strippedName, new ScrAction( ScrAction::RecentScript, strippedName, QKeySequence(), this, strippedName));
+		connect( m_scripterActions[strippedName], SIGNAL(triggeredData(QString)), this, SLOT(StdScript(QString)) );
+		m_menuMgr->addMenuItemString(strippedName, "ScribusScripts");
 	}
 }
 

Modified: trunk/Scribus/scribus/ui/colorsandfills.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23100&path=/trunk/Scribus/scribus/ui/colorsandfills.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/colorsandfills.cpp	(original)
+++ trunk/Scribus/scribus/ui/colorsandfills.cpp	Sun Aug  4 02:34:43 2019
@@ -1226,77 +1226,76 @@
 	PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs");
 	QString wdir = dirs->get("patterndir", ".");
 	QString fileName = QFileDialog::getExistingDirectory(this, tr("Choose a Directory"), wdir);
-	if (!fileName.isEmpty())
-	{
-		QStringList formats;
-		formats += "eps";
-		formats += "epsi";
-		formats += "pdf";
-		QString form1 = "";
-		for ( int i = 0; i < QImageReader::supportedImageFormats().count(); ++i )
-		{
-			form1 = QString(QImageReader::supportedImageFormats().at(i)).toLower();
-			if (form1 == "jpeg")
-				form1 = "jpg";
-			if ((form1 == "png") || (form1 == "xpm") || (form1 == "gif"))
-			formats += form1;
-			else if (form1 == "jpg")
-			{
-				formats += "jpg";
-				formats += "jpeg";
-			}
-		}
-		formats += "tif";
-	 	formats += "tiff";
-		formats += "psd";
-		formats += "pat";
-		QDir d(fileName, "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
-		if ((d.exists()) && (d.count() != 0))
-		{
-			mainWin->setStatusBarInfoText( tr("Loading Patterns"));
-			mainWin->mainWindowProgressBar->reset();
-			mainWin->mainWindowProgressBar->setMaximum(d.count() * 2);
-			qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
-			qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
-			for (uint dc = 0; dc < d.count(); ++dc)
-			{
-				mainWin->mainWindowProgressBar->setValue(dc);
-				qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
-				QFileInfo fi(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
-				QString ext = fi.suffix().toLower();
-				if ((ext == "sce") || (!formats.contains(ext)))
-					loadVectors(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
-			}
-			for (uint dc = 0; dc < d.count(); ++dc)
-			{
-				mainWin->mainWindowProgressBar->setValue(d.count() + dc);
-				qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
-				QFileInfo fi(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
-				QString ext = fi.suffix().toLower();
-				if ((ext == "sce") || (!formats.contains(ext)))
-					continue;
-				if (formats.contains(ext))
-				{
-					QString patNam = fi.baseName().trimmed().simplified().replace(" ", "_");
-					if (!dialogPatterns.contains(patNam))
-					{
-						ScPattern pat = ScPattern();
-						pat.setDoc(m_doc);
-						pat.setPattern(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
-						dialogPatterns.insert(patNam, pat);
-						origNamesPatterns.insert(patNam, patNam);
-					}
-				}
-				else
-					continue;
-			}
-			d.cdUp();
-			dirs->set("patterndir", d.absolutePath());
-			qApp->restoreOverrideCursor();
-			mainWin->setStatusBarInfoText("");
-			mainWin->mainWindowProgressBar->reset();
-		}
-	}
+	if (fileName.isEmpty())
+		return;
+
+	QStringList formats;
+	formats += "eps";
+	formats += "epsi";
+	formats += "pdf";
+	QString form1 = "";
+	for (int i = 0; i < QImageReader::supportedImageFormats().count(); ++i)
+	{
+		form1 = QString(QImageReader::supportedImageFormats().at(i)).toLower();
+		if (form1 == "jpeg")
+			form1 = "jpg";
+		if ((form1 == "png") || (form1 == "xpm") || (form1 == "gif"))
+		formats += form1;
+		else if (form1 == "jpg")
+		{
+			formats += "jpg";
+			formats += "jpeg";
+		}
+	}
+	formats += "tif";
+	formats += "tiff";
+	formats += "psd";
+	formats += "pat";
+	QDir d(fileName, "*", QDir::Name, QDir::Files | QDir::Readable | QDir::NoSymLinks);
+	if ((!d.exists()) || (d.count() == 0))
+		return;
+
+	mainWin->setStatusBarInfoText( tr("Loading Patterns"));
+	mainWin->mainWindowProgressBar->reset();
+	mainWin->mainWindowProgressBar->setMaximum(d.count() * 2);
+	qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
+	qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+	for (uint dc = 0; dc < d.count(); ++dc)
+	{
+		mainWin->mainWindowProgressBar->setValue(dc);
+		qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+		QFileInfo fi(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
+		QString ext = fi.suffix().toLower();
+		if ((ext == "sce") || (!formats.contains(ext)))
+			loadVectors(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
+	}
+	for (uint dc = 0; dc < d.count(); ++dc)
+	{
+		mainWin->mainWindowProgressBar->setValue(d.count() + dc);
+		qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+
+		QFileInfo fi(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
+		QString ext = fi.suffix().toLower();
+		if ((ext == "sce") || (!formats.contains(ext)))
+			continue;
+		if (!formats.contains(ext))
+			continue;
+
+		QString patNam = fi.baseName().trimmed().simplified().replace(" ", "_");
+		if (!dialogPatterns.contains(patNam))
+		{
+			ScPattern pat = ScPattern();
+			pat.setDoc(m_doc);
+			pat.setPattern(QDir::cleanPath(QDir::toNativeSeparators(fileName + "/" + d[dc])));
+			dialogPatterns.insert(patNam, pat);
+			origNamesPatterns.insert(patNam, patNam);
+		}
+	}
+	d.cdUp();
+	dirs->set("patterndir", d.absolutePath());
+	qApp->restoreOverrideCursor();
+	mainWin->setStatusBarInfoText("");
+	mainWin->mainWindowProgressBar->reset();
 }
 
 void ColorsAndFillsDialog::loadVectors(const QString& data)




More information about the scribus-commit mailing list