r24220 by jghali - Code style fixes and readability improvements

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 10 21:54:50 UTC 2020


Author: jghali
Date: Tue Nov 10 21:54:50 2020
New Revision: 24220

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24220
Log:
Code style fixes and readability improvements

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.h
    trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.cpp
    trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.h

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24220&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.cpp	Tue Nov 10 21:54:50 2020
@@ -60,20 +60,21 @@
 	return PointToValue(pageUnitY - ScCore->primaryMainWindow()->doc->currentPage()->yOffset());
 }
 
-PageItem *GetItem(const QString& Name)
-{
-	if (!Name.isEmpty())
-	{
-		for (int i = 0; i < ScCore->primaryMainWindow()->doc->Items->count(); i++)
-		{
-			if (ScCore->primaryMainWindow()->doc->Items->at(i)->itemName() == Name)
-				return ScCore->primaryMainWindow()->doc->Items->at(i);
+PageItem *GetItem(const QString& name)
+{
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	if (!name.isEmpty())
+	{
+		for (int i = 0; i < currentDoc->Items->count(); ++i)
+		{
+			if (currentDoc->Items->at(i)->itemName() == name)
+				return currentDoc->Items->at(i);
 		}
 	}
 	else
 	{
-		if (ScCore->primaryMainWindow()->doc->m_Selection->count() != 0)
-			return ScCore->primaryMainWindow()->doc->m_Selection->itemAt(0);
+		if (currentDoc->m_Selection->count() != 0)
+			return currentDoc->m_Selection->itemAt(0);
 	}
 	return nullptr;
 }
@@ -118,11 +119,14 @@
 		PyErr_SetString(PyExc_ValueError, QString("Cannot accept empty name for pageitem").toLocal8Bit().constData());
 		return nullptr;
 	}
-	for (int i = 0; i < ScCore->primaryMainWindow()->doc->Items->count(); i++)
-	{
-		if (name == ScCore->primaryMainWindow()->doc->Items->at(i)->itemName())
-			return ScCore->primaryMainWindow()->doc->Items->at(i);
-	} // for items
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	for (int i = 0; i < currentDoc->Items->count(); ++i)
+	{
+		if (name == currentDoc->Items->at(i)->itemName())
+			return currentDoc->Items->at(i);
+	}
+
 	PyErr_SetString(NoValidObjectError, QString("Object not found").toLocal8Bit().constData());
 	return nullptr;
 }
@@ -137,11 +141,13 @@
 {
 	if (name.length() == 0)
 		return false;
-	for (int i = 0; i < ScCore->primaryMainWindow()->doc->Items->count(); i++)
-	{
-		if (name == ScCore->primaryMainWindow()->doc->Items->at(i)->itemName())
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	for (int i = 0; i < currentDoc->Items->count(); ++i)
+	{
+		if (name == currentDoc->Items->at(i)->itemName())
 			return true;
-	} // for items
+	}
 	return false;
 }
 
@@ -185,23 +191,27 @@
 	return ScCore->primaryMainWindow()->doc->m_Selection->getSelectedItemsByName();
 }
 
-bool setSelectedItemsByName(QStringList& itemNames)
-{
-	ScCore->primaryMainWindow()->view->deselectItems();
+bool setSelectedItemsByName(const QStringList& itemNames)
+{
+	ScribusDoc* currentDoc =  ScCore->primaryMainWindow()->doc;
+	ScribusView* currentView = ScCore->primaryMainWindow()->view;
+
+	currentView->deselectItems();
+
 	// For each named item
-	for (QStringList::Iterator it = itemNames.begin() ; it != itemNames.end() ; it++)
+	for (auto it = itemNames.begin() ; it != itemNames.end() ; it++)
 	{
 		// Search for the named item
 		PageItem* item = nullptr;
-		for (int j = 0; j < ScCore->primaryMainWindow()->doc->Items->count(); j++)
-		{
-			if (*it == ScCore->primaryMainWindow()->doc->Items->at(j)->itemName())
-				item = ScCore->primaryMainWindow()->doc->Items->at(j);
+		for (int j = 0; j < currentDoc->Items->count(); j++)
+		{
+			if (*it == currentDoc->Items->at(j)->itemName())
+				item = currentDoc->Items->at(j);
 		}
 		if (!item)
 			return false;
-		// and select it
-		ScCore->primaryMainWindow()->view->selectItem(item);
+		// And select it
+		currentView->selectItem(item);
 	}
 	return true;
 }
@@ -228,7 +238,8 @@
 
 	// Parse each tuple decribing a border line and append it to the border.
 	int nBorderLines = PyList_Size(borderLinesList);
-	for (int i = 0; i < nBorderLines; i++) {
+	for (int i = 0; i < nBorderLines; ++i)
+	{
 		double width = 0.0;
 		double shade = 100.0;
 		int style;

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24220&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.h	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.h	Tue Nov 10 21:54:50 2020
@@ -27,7 +27,7 @@
 /// \brief Doc units -> page-relative units
 double docUnitYToPageY(double pageUnitY);
 
-PageItem *GetItem(const QString& Name);
+PageItem *GetItem(const QString& name);
 void ReplaceColor(const QString& col, const QString& rep);
 
 /*!
@@ -80,7 +80,7 @@
  * Returns false if one or more items can't be selected, true if all were selected.
  * Selection state is undefined on failure.
  */
-bool setSelectedItemsByName(QStringList& itemNames);
+bool setSelectedItemsByName(const QStringList& itemNames);
 
 /*!
  * @brief Helper method to parse a border from a list of tuples.

Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24220&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.cpp	Tue Nov 10 21:54:50 2020
@@ -60,20 +60,21 @@
 	return PointToValue(pageUnitY - ScCore->primaryMainWindow()->doc->currentPage()->yOffset());
 }
 
-PageItem *GetItem(const QString& Name)
-{
-	if (!Name.isEmpty())
-	{
-		for (int i = 0; i < ScCore->primaryMainWindow()->doc->Items->count(); i++)
-		{
-			if (ScCore->primaryMainWindow()->doc->Items->at(i)->itemName() == Name)
-				return ScCore->primaryMainWindow()->doc->Items->at(i);
+PageItem *GetItem(const QString& name)
+{
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	if (!name.isEmpty())
+	{
+		for (int i = 0; i < currentDoc->Items->count(); ++i)
+		{
+			if (currentDoc->Items->at(i)->itemName() == name)
+				return currentDoc->Items->at(i);
 		}
 	}
 	else
 	{
-		if (ScCore->primaryMainWindow()->doc->m_Selection->count() != 0)
-			return ScCore->primaryMainWindow()->doc->m_Selection->itemAt(0);
+		if (currentDoc->m_Selection->count() != 0)
+			return currentDoc->m_Selection->itemAt(0);
 	}
 	return nullptr;
 }
@@ -118,11 +119,14 @@
 		PyErr_SetString(PyExc_ValueError, QString("Cannot accept empty name for pageitem").toLocal8Bit().constData());
 		return nullptr;
 	}
-	for (int i = 0; i < ScCore->primaryMainWindow()->doc->Items->count(); i++)
-	{
-		if (name == ScCore->primaryMainWindow()->doc->Items->at(i)->itemName())
-			return ScCore->primaryMainWindow()->doc->Items->at(i);
-	} // for items
+
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	for (int i = 0; i < currentDoc->Items->count(); ++i)
+	{
+		if (name == currentDoc->Items->at(i)->itemName())
+			return currentDoc->Items->at(i);
+	}
+
 	PyErr_SetString(NoValidObjectError, QString("Object not found").toLocal8Bit().constData());
 	return nullptr;
 }
@@ -137,11 +141,13 @@
 {
 	if (name.length() == 0)
 		return false;
-	for (int i = 0; i < ScCore->primaryMainWindow()->doc->Items->count(); i++)
-	{
-		if (name == ScCore->primaryMainWindow()->doc->Items->at(i)->itemName())
+	
+	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+	for (int i = 0; i < currentDoc->Items->count(); ++i)
+	{
+		if (name == currentDoc->Items->at(i)->itemName())
 			return true;
-	} // for items
+	}
 	return false;
 }
 
@@ -185,23 +191,27 @@
 	return ScCore->primaryMainWindow()->doc->m_Selection->getSelectedItemsByName();
 }
 
-bool setSelectedItemsByName(QStringList& itemNames)
-{
-	ScCore->primaryMainWindow()->view->deselectItems();
+bool setSelectedItemsByName(const QStringList& itemNames)
+{
+	ScribusDoc* currentDoc =  ScCore->primaryMainWindow()->doc;
+	ScribusView* currentView = ScCore->primaryMainWindow()->view;
+
+	currentView->deselectItems();
+
 	// For each named item
-	for (QStringList::Iterator it = itemNames.begin() ; it != itemNames.end() ; it++)
+	for (auto it = itemNames.begin() ; it != itemNames.end() ; it++)
 	{
 		// Search for the named item
 		PageItem* item = nullptr;
-		for (int j = 0; j < ScCore->primaryMainWindow()->doc->Items->count(); j++)
-		{
-			if (*it == ScCore->primaryMainWindow()->doc->Items->at(j)->itemName())
-				item = ScCore->primaryMainWindow()->doc->Items->at(j);
+		for (int j = 0; j < currentDoc->Items->count(); j++)
+		{
+			if (*it == currentDoc->Items->at(j)->itemName())
+				item = currentDoc->Items->at(j);
 		}
 		if (!item)
 			return false;
-		// and select it
-		ScCore->primaryMainWindow()->view->selectItem(item);
+		// And select it
+		currentView->selectItem(item);
 	}
 	return true;
 }
@@ -228,7 +238,8 @@
 
 	// Parse each tuple decribing a border line and append it to the border.
 	int nBorderLines = PyList_Size(borderLinesList);
-	for (int i = 0; i < nBorderLines; i++) {
+	for (int i = 0; i < nBorderLines; ++i)
+	{
 		double width = 0.0;
 		double shade = 100.0;
 		int style;

Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24220&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.h	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.h	Tue Nov 10 21:54:50 2020
@@ -27,7 +27,7 @@
 /// \brief Doc units -> page-relative units
 double docUnitYToPageY(double pageUnitY);
 
-PageItem *GetItem(const QString& Name);
+PageItem *GetItem(const QString& name);
 void ReplaceColor(const QString& col, const QString& rep);
 
 /*!
@@ -80,7 +80,7 @@
  * Returns false if one or more items can't be selected, true if all were selected.
  * Selection state is undefined on failure.
  */
-bool setSelectedItemsByName(QStringList& itemNames);
+bool setSelectedItemsByName(const QStringList& itemNames);
 
 /*!
  * @brief Helper method to parse a border from a list of tuples.




More information about the scribus-commit mailing list