r22773 by jghali - refactor cmdannotations.cpp

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 18 15:02:46 UTC 2018


Author: jghali
Date: Sun Nov 18 15:02:45 2018
New Revision: 22773

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22773
Log:
refactor cmdannotations.cpp

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

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22773&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdannotations.cpp	Sun Nov 18 15:02:45 2018
@@ -11,10 +11,10 @@
 #include "scribuscore.h"
 
 static PyObject *getLinkData(PyObject *rv, int page, const QString& action);
-static void prepareannotation(PageItem *i);
+static void prepareannotation(PageItem *item);
 static void setactioncoords(Annotation &a, int x, int y);
-static bool testPageItem(PageItem *i);
-static void add_text_to_dict(PyObject *drv, PageItem *i);
+static bool testPageItem(PageItem *item);
+static void add_text_to_dict(PyObject *drv, PageItem *item);
 
 PyObject *scribus_setjsactionscript(PyObject * /*self*/, PyObject* args)
 {
@@ -184,19 +184,19 @@
 	if (!checkHaveDocument())
 		return nullptr;
 
-	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
-	if (i == nullptr)
-		return nullptr;
-
-	if (i->isAnnotation())
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (item == nullptr)
+		return nullptr;
+
+	if (item->isAnnotation())
 	{
 		if (PyObject_IsTrue(deannotate)==1)
 		{
-			i->setIsAnnotation(false);
+			item->setIsAnnotation(false);
 			Py_RETURN_NONE;
 		}
 
-		Annotation a = i->annotation();
+		Annotation a = item->annotation();
 		int atype = a.Type();
 		int actype = a.ActionType();
 
@@ -214,7 +214,7 @@
 			PyObject *pathkey = PyString_FromString(path);
 			PyObject *pathvalue = PyString_FromString(a.Extern().toUtf8());
 			PyDict_SetItem(drv, pathkey, pathvalue);
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name3, drv);
 			return rv;
 		}
@@ -224,7 +224,7 @@
 			PyObject *ukey = PyString_FromString(uri);
 			PyObject *uval = PyString_FromString(a.Extern().toUtf8());
 			PyDict_SetItem(drv, ukey, uval);
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			char *name4= const_cast<char*>("Link URI");
 			PyObject *rv = Py_BuildValue("(sO)", name4, drv);
 			return rv;
@@ -233,49 +233,49 @@
 		{
 			getLinkData(drv, a.Ziel(), a.Action());
 			const char name2[] = "Link";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name2, drv);
 			return rv;
 		}
 		if (atype == Annotation::Button)
 		{
 			const char name5[] = "Button";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name5, drv);
 			return rv;
 		}
 		if (atype == Annotation::RadioButton)
 		{
 			const char name4[] = "RadioButton";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name4, drv);
 			return rv;
 		}
 		if (atype == Annotation::Textfield)
 		{
 			const char name6[] = "Textfield";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name6, drv);
 			return rv;
 		}
 		if (atype == Annotation::Checkbox)
 		{
 			const char name7[] = "Checkbox";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name7, drv);
 			return rv;
 		}
 		if (atype == Annotation::Combobox)
 		{
 			const char name4[] = "Combobox";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name4, drv);
 			return rv;
 		}
 		if (atype == Annotation::Listbox)
 		{
 			const char name8[] = "Listbox";
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name8, drv);
 			return rv;
 		}
@@ -306,7 +306,7 @@
 				open = Py_True;
 			PyDict_SetItem(drv, openkey, open);
 
-			add_text_to_dict(drv, i);
+			add_text_to_dict(drv, item);
 			PyObject *rv = Py_BuildValue("(sO)", name9, drv);
 			return rv;
 		}
@@ -335,8 +335,8 @@
 	if (!checkHaveDocument())
 		return nullptr;
 
-	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
-	if (!testPageItem(i))
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (!testPageItem(item))
 		return nullptr;
 
 	int numpages = ScCore->primaryMainWindow()->doc->Pages->count();
@@ -347,8 +347,8 @@
 		return nullptr;
 	}
 
-	prepareannotation(i);
-	Annotation &a = i->annotation();
+	prepareannotation(item);
+	Annotation &a = item->annotation();
 	a.setType(Annotation::Link);
 	page -= 1;
 	a.setZiel(page);
@@ -378,12 +378,12 @@
 	if (!checkHaveDocument())
 		return nullptr;
 
-	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
-	if (!testPageItem(i))
-		return nullptr;
-
-	prepareannotation(i);
-	Annotation &a = i->annotation();
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (!testPageItem(item))
+		return nullptr;
+
+	prepareannotation(item);
+	Annotation &a = item->annotation();
 	a.setType(Annotation::Link);
 	a.setZiel(page - 1);
 	a.setExtern(QString::fromUtf8(path));
@@ -407,12 +407,12 @@
 	if (!checkHaveDocument())
 		return nullptr;
 
-	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
-	if (!testPageItem(i))
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (!testPageItem(item))
 		return nullptr;
 		
-	prepareannotation(i);
-	Annotation &a = i->annotation();
+	prepareannotation(item);
+	Annotation &a = item->annotation();
 	a.setAction(QString::fromUtf8(""));
 	a.setExtern(QString::fromUtf8(uri));
 	a.setActionType(Annotation::Action_URI);
@@ -448,13 +448,13 @@
 		return nullptr;
 	}
 
-	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
-	if (!testPageItem(i))
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+	if (!testPageItem(item))
 		return nullptr;
 	
-	prepareannotation(i);
-
-	Annotation &a = i->annotation();
+	prepareannotation(item);
+
+	Annotation &a = item->annotation();
 	a.setAnOpen(PyObject_IsTrue(isopen));
 	a.setActionType(Annotation::Action_None);
 	a.setIcon(icon);
@@ -527,11 +527,8 @@
 		}
 	}
 
-
 	PageItem *pi = m_doc->Items->at(i);
 	pi->AutoName=false;
-
-
 
 	if (strlen(name) > 0)
 	{
@@ -639,14 +636,14 @@
 
 }
 
-static void prepareannotation(PageItem *i)
-{
-	if (i->isBookmark)
-	{
-		i->isBookmark = false;
-		ScCore->primaryMainWindow()->DelBookMark(i);
-	}
-	i->setIsAnnotation(true);
+static void prepareannotation(PageItem *item)
+{
+	if (item->isBookmark)
+	{
+		item->isBookmark = false;
+		ScCore->primaryMainWindow()->DelBookMark(item);
+	}
+	item->setIsAnnotation(true);
 }
 
 static void setactioncoords(Annotation &a, int x, int y)
@@ -656,11 +653,11 @@
 	a.setAction(xstring.setNum(x) + " " + ystring.setNum(height - y) + " 0");
 }
 
-static bool testPageItem(PageItem *i)
-{
-	if (i == nullptr)
+static bool testPageItem(PageItem *item)
+{
+	if (item == nullptr)
 		return false;
-	if (!i->asTextFrame())
+	if (!item->asTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, 
 				QObject::tr("Can't set annotation on a non-text frame", "python error").toLocal8Bit().constData());
@@ -670,22 +667,22 @@
 	return true;
 }
 
-static void add_text_to_dict(PyObject *drv, PageItem * i)
+static void add_text_to_dict(PyObject *drv, PageItem * item)
 {
 	const char text[] = "text";
 	PyObject *textkey = PyString_FromString(text);
-	QString txt = i->itemText.text(0, i->itemText.length());
+	QString txt = item->itemText.text(0, item->itemText.length());
 	PyObject *textvalue = PyString_FromString(txt.toUtf8());
 	PyDict_SetItem(drv, textkey, textvalue);
 
-	Annotation &a = i->annotation();
+	Annotation &a = item->annotation();
 	int actype = a.ActionType();
 
 	if (actype == Annotation::Action_JavaScript)
 	{
 		const char text[] = "javascript";
 		PyObject *jskey = PyString_FromString(text);
-		PyObject *jsvalue = PyString_FromString(i->annotation().Action().toUtf8());
+		PyObject *jsvalue = PyString_FromString(item->annotation().Action().toUtf8());
 		PyDict_SetItem(drv, jskey, jsvalue);
 	}
 




More information about the scribus-commit mailing list