r17221 by jghali - #10536 : sending group objects to other layer does not work from within scripter

scribus-commit scribus-commit at lists.scribus.net
Sun Jan 22 15:05:36 UTC 2012


Author: jghali
Date: Sun Jan 22 15:05:36 2012
New Revision: 17221

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17221
Log:
#10536 : sending group objects to other layer does not work from within scripter

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17221&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp Sun Jan 22 15:05:36 2012
@@ -12,10 +12,11 @@
 //Added by qt3to4:
 #include <QList>
 
+#include "prefsmanager.h"
 #include "scribuscore.h"
 #include "scribusdoc.h"
+#include "selection.h"
 #include "fonts/scfontmetrics.h"
-#include "prefsmanager.h"
 
 PyObject *scribus_setredraw(PyObject* /* self */, PyObject* args)
 {
@@ -203,26 +204,30 @@
 		PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData());
 		return NULL;
 	}
-	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
-	if (i == NULL)
-		return NULL;
-	ScCore->primaryMainWindow()->view->SelectItem(i);
-	bool found = false;
-	for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
-	{
-		ScCore->primaryMainWindow()->view->SelectItem(i);
-		for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
-			if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Layer))
-			{
-				i->LayerID = static_cast<int>(lam);
-				found = true;
-				break;
-			}
-	}
-	if (!found)
+	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+	if (item == NULL)
+		return NULL;
+	ScribusDoc* currentDoc   = ScCore->primaryMainWindow()->doc;
+	ScribusView* currentView = ScCore->primaryMainWindow()->view;
+	const ScLayer *scLayer = currentDoc->Layers.layerByName( QString::fromUtf8(Layer) );
+	if (!scLayer)
 	{
 		PyErr_SetString(ScribusException, QString("Layer not found").toLocal8Bit().constData());
 		return NULL;
+	}
+	// If no name have been specified in args, process whole selection
+	currentView->SelectItem(item);
+	if (Name == EMPTY_STRING)
+	{
+		for (int i = 0; i < currentDoc->m_Selection->count(); ++i)
+		{
+			item = currentDoc->m_Selection->itemAt(i);
+			item->LayerID = scLayer->ID;
+		}
+	}
+	else
+	{
+		item->LayerID = scLayer->ID;
 	}
 
 //	Py_INCREF(Py_None);




More information about the scribus-commit mailing list