r17220 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:04:57 UTC 2012


Author: jghali
Date: Sun Jan 22 15:04:57 2012
New Revision: 17220

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

Modified:
    branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp

Modified: branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17220&path=/branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/scriptplugin/cmdmisc.cpp Sun Jan 22 15:04:57 2012
@@ -12,9 +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)
 {
@@ -202,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->SelectItemNr(i->ItemNr);
-	bool found = false;
-	for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
-	{
-		ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr);
-		for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
-			if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Layer))
-			{
-				i->LayerNr = 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->SelectItemNr(item->ItemNr);
+	if ((Name == EMPTY_STRING) || (item->isGroupControl) || (item->Groups.count() > 0))
+	{
+		for (int i = 0; i < currentDoc->m_Selection->count(); ++i)
+		{
+			item = currentDoc->m_Selection->itemAt(i);
+			item->LayerNr = scLayer->LNr;
+		}
+	}
+	else
+	{
+		item->LayerNr = scLayer->LNr;
 	}
 
 //	Py_INCREF(Py_None);




More information about the scribus-commit mailing list