View Issue Details

IDProjectCategoryView StatusLast Update
0016318ScribusScripterpublic2020-11-10 21:20
Reporterale Assigned Toale  
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Product Version1.5.6.svn 
Target VersionFixed in Version1.5.7.svn 
Summary0016318: Add checkValidPageNumber()
Descriptionadd checkValidPageNumber(), based on checkHaveDocument().
TagsNo tags attached.
PatchYes

Relationships

related to 0016300 new [PATCHJ] add moveToPage() to the scripter 

Activities

ale

2020-11-05 10:34

manager  

valid-page-number.diff (1,526 bytes)
diff --git a/scribus/plugins/scriptplugin/cmdutil.cpp b/scribus/plugins/scriptplugin/cmdutil.cpp
index 7e1b80050..dcf8a208c 100644
--- a/scribus/plugins/scriptplugin/cmdutil.cpp
+++ b/scribus/plugins/scriptplugin/cmdutil.cpp
@@ -162,6 +162,27 @@ bool checkHaveDocument()
 	return false;
 }
 
+bool checkValidPageNumber(int page)
+{
+	const uint 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()
 {
 	/*
diff --git a/scribus/plugins/scriptplugin/cmdutil.h b/scribus/plugins/scriptplugin/cmdutil.h
index 33f785dc2..099f7939c 100644
--- a/scribus/plugins/scriptplugin/cmdutil.h
+++ b/scribus/plugins/scriptplugin/cmdutil.h
@@ -54,6 +54,18 @@ PageItem* getPageItemByName(const QString& name);
 // 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);
 
valid-page-number.diff (1,526 bytes)

Issue History

Date Modified Username Field Change
2020-11-05 10:34 ale New Issue
2020-11-05 10:34 ale File Added: valid-page-number.diff
2020-11-10 13:16 ale Relationship added related to 0016300
2020-11-10 21:20 jghali Summary [PATCH] add checkValidPageNumber() => Add checkValidPageNumber()
2020-11-10 21:20 jghali Assigned To => ale
2020-11-10 21:20 jghali Status new => resolved
2020-11-10 21:20 jghali Resolution open => fixed
2020-11-10 21:20 jghali Fixed in Version => 1.5.7.svn