r24218 by jghali - #16318: add checkValidPageNumber() <ale>
scribus-commit
scribus-commit at lists.scribus.net
Tue Nov 10 21:19:55 UTC 2020
Author: jghali
Date: Tue Nov 10 21:19:55 2020
New Revision: 24218
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24218
Log:
#16318: add checkValidPageNumber() <ale>
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=24218&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:19:55 2020
@@ -160,6 +160,17 @@
// and return nullptr.
PyErr_SetString(NoDocOpenError, QString("Command does not make sense without an open document").toLocal8Bit().constData());
return false;
+}
+
+bool checkValidPageNumber(int page)
+{
+ const int numPages = ScCore->primaryMainWindow()->doc->Pages->count();
+ if (page < 0 || page >= numPages)
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("%1 is not a valid page number.", "python error").arg(page).toLocal8Bit().constData());
+ return false;
+ }
+ return true;
}
QStringList getSelectedItemsByName()
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdutil.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24218&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:19:55 2020
@@ -54,6 +54,18 @@
// 2004-10-27 Craig Ringer see cmdutil.cpp for description
bool checkHaveDocument();
+/*!
+ * @brief Returns true if the page number is between 0 and the number of pages.
+ *
+ * If the page number is smaller than 0 or bigger than the number of pages
+ * a Python exception is set, before returning false.
+ *
+ * The caller is required to check the returned value and return nullptr on false.
+ *
+ * @author ale rimoldi
+ */
+bool checkValidPageNumber(int page);
+
// 2004-11-12 Craig Ringer see cmdutil.cpp for description
bool ItemExists(const QString& name);
Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24218&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:19:55 2020
@@ -160,6 +160,17 @@
// and return nullptr.
PyErr_SetString(NoDocOpenError, QString("Command does not make sense without an open document").toLocal8Bit().constData());
return false;
+}
+
+bool checkValidPageNumber(int page)
+{
+ const int numPages = ScCore->primaryMainWindow()->doc->Pages->count();
+ if (page < 0 || page >= numPages)
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("%1 is not a valid page number.", "python error").arg(page).toLocal8Bit().constData());
+ return false;
+ }
+ return true;
}
QStringList getSelectedItemsByName()
Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdutil.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24218&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:19:55 2020
@@ -54,6 +54,18 @@
// 2004-10-27 Craig Ringer see cmdutil.cpp for description
bool checkHaveDocument();
+/*!
+ * @brief Returns true if the page number is between 0 and the number of pages.
+ *
+ * If the page number is smaller than 0 or bigger than the number of pages
+ * a Python exception is set, before returning false.
+ *
+ * The caller is required to check the returned value and return nullptr on false.
+ *
+ * @author ale rimoldi
+ */
+bool checkValidPageNumber(int page);
+
// 2004-11-12 Craig Ringer see cmdutil.cpp for description
bool ItemExists(const QString& name);
More information about the scribus-commit
mailing list