r20942 by craig -

scribus-commit scribus-commit at lists.scribus.net
Tue Feb 9 13:24:51 UTC 2016


Author: craig
Date: Tue Feb  9 13:24:51 2016
New Revision: 20942

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20942
Log:
coverity #1351290: rewrite as PathText cannot have selected text (boo!), and switch to isItemType instead of asItemType functions

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

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20942&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	Tue Feb  9 13:24:51 2016
@@ -56,7 +56,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!(it->isTextFrame()) && !(it->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font size of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -82,7 +82,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!(it->isTextFrame()) && !(it->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -108,7 +108,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!(i->asTextFrame()) && !(i->asPathText()))
+	if (!(i->isTextFrame()) && !(i->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text size of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -126,7 +126,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!(i->asTextFrame()) && !(i->asPathText()))
+	if (!(i->isTextFrame()) && !(i->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get number of lines of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -144,15 +144,33 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
+	if (!i->isTextFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column count of non-text frame.","python error").toLocal8Bit().constData());
+		return NULL;
+	}
+	return PyInt_FromLong(static_cast<long>(i->Cols));
+}
+
+PyObject *scribus_getlinespace(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return NULL;
+	if(!checkHaveDocument())
+		return NULL;
+	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+	if (i == NULL)
+		return NULL;
 	if (!i->asTextFrame())
 	{
-		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column count of non-text frame.","python error").toLocal8Bit().constData());
-		return NULL;
-	}
-	return PyInt_FromLong(static_cast<long>(i->Cols));
-}
-
-PyObject *scribus_getlinespace(PyObject* /* self */, PyObject* args)
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get line space of non-text frame.","python error").toLocal8Bit().constData());
+		return NULL;
+	}
+	return PyFloat_FromDouble(static_cast<double>(i->currentStyle().lineSpacing()));
+}
+
+PyObject *scribus_gettextdistances(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
 	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
@@ -162,25 +180,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
-	{
-		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get line space of non-text frame.","python error").toLocal8Bit().constData());
-		return NULL;
-	}
-	return PyFloat_FromDouble(static_cast<double>(i->currentStyle().lineSpacing()));
-}
-
-PyObject *scribus_gettextdistances(PyObject* /* self */, PyObject* args)
-{
-	char *Name = const_cast<char*>("");
-	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
-		return NULL;
-	if(!checkHaveDocument())
-		return NULL;
-	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
-	if (i == NULL)
-		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text distances of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -202,7 +202,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column gap of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -221,7 +221,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!(it->isTextFrame()) && !(it->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -252,7 +252,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!(it->isTextFrame()) && !(it->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -285,7 +285,7 @@
 	PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
 	if (currItem == NULL)
 		return NULL;
-	if (!(currItem->asTextFrame()) && !(currItem->asPathText()))
+	if (!(currItem->isTextFrame()) && !(currItem->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text of non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -315,7 +315,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!(it->isTextFrame()) && !(it->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -360,7 +360,7 @@
 		return NULL;
 	}
 
-	if (!(it->asTextFrame()) && !(it->asPathText())) {
+	if (!(it->isTextFrame()) && !(it->isPathText())) {
 		PyErr_SetString(WrongFrameTypeError,
 				QObject::tr("Cannot insert text into non-text frame.",
 					"python error").toLocal8Bit().constData());
@@ -427,7 +427,7 @@
 	if (i == NULL)
 		return NULL;
 
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -456,7 +456,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!(i->asTextFrame()) && !(i->asPathText()))
+	if (!(i->isTextFrame()) && !(i->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -498,7 +498,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -535,7 +535,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing mode on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -569,7 +569,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text distances on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -595,7 +595,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set column gap on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -622,7 +622,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set number of columns on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -658,7 +658,7 @@
 		PyErr_SetString(PyExc_IndexError, QObject::tr("Selection index out of bounds", "python error").toLocal8Bit().constData());
 		return NULL;
 	}
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!(it->isTextFrame()) && !(it->isPathText()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot select text in a non-text frame", "python error").toLocal8Bit().constData());
 		return NULL;
@@ -695,16 +695,25 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	PageItem_TextFrame* item = it->asTextFrame();
-	if (!(item) && !(it->asPathText()))
+	if (!it->isTextFrame() && !it->isPathText())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot delete text from a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
 	}
-	if (it->HasSel)
-		item->deleteSelectedTextFromFrame();
+	PageItem_TextFrame* tf_item = it->asTextFrame();
+	if (tf_item)
+	{
+		if (tf_item->HasSel)
+			tf_item->deleteSelectedTextFromFrame();
+		else
+			tf_item->itemText.clear();
+	}
 	else
-		item->itemText.clear();
+	{
+		//Path text cannot have selected text, :( FIXME
+		if(it->isPathText())
+			it->itemText.clear();
+	}
 	Py_RETURN_NONE;
 }
 
@@ -719,7 +728,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!it->isTextFrame() && !it->isPathText())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text fill on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -756,7 +765,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && (it->asPathText()))
+	if (!it->isTextFrame() && !it->isPathText())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text stroke on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -799,7 +808,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -834,7 +843,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -870,7 +879,7 @@
 	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
 	if (it == NULL)
 		return NULL;
-	if (!(it->asTextFrame()) && !(it->asPathText()))
+	if (!it->isTextFrame() && !it->isPathText())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text shade on a non-text frame.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -911,7 +920,7 @@
 	PageItem *toitem = GetUniqueItem(QString::fromUtf8(name2));
 	if (toitem == NULL)
 		return NULL;
-	if (!(fromitem->asTextFrame()) || !(toitem->asTextFrame()))
+	if (!(fromitem->isTextFrame()) || !(toitem->isTextFrame()))
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only link text frames.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -1011,7 +1020,7 @@
 	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
 	if (item == NULL)
 		return NULL;
-	if (!item->asTextFrame())
+	if (!item->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot convert a non-text frame to outlines.","python error").toLocal8Bit().constData());
 		return NULL;
@@ -1038,7 +1047,7 @@
 	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
 	if (item == NULL)
 		return NULL;
-	if (!item->asTextFrame())
+	if (!item->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Only text frames can be checked for overflowing", "python error").toLocal8Bit().constData());
 		return NULL;
@@ -1087,7 +1096,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only hyphenate text frame", "python error").toLocal8Bit().constData());
 		return NULL;
@@ -1110,7 +1119,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only dehyphenate text frame", "python error").toLocal8Bit().constData());
 		return NULL;
@@ -1130,7 +1139,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't set bookmark on a non-text frame", "python error").toLocal8Bit().constData());
 		return NULL;
@@ -1164,7 +1173,7 @@
 	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
 	if (i == NULL)
 		return NULL;
-	if (!i->asTextFrame())
+	if (!i->isTextFrame())
 	{
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't get info from a non-text frame", "python error").toLocal8Bit().constData());
 		return NULL;




More information about the scribus-commit mailing list