r17935 by jainbasil - add pages attribute in document api, fix issues with page number attribute

scribus-commit scribus-commit at lists.scribus.net
Wed Dec 5 12:41:19 UTC 2012


Author: jainbasil
Date: Wed Dec  5 12:41:18 2012
New Revision: 17935

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17935
Log:
add pages attribute in document api, fix issues with page number attribute

Modified:
    trunk/Scribus/scribus/plugins/scripter/api_document.cpp
    trunk/Scribus/scribus/plugins/scripter/api_document.h
    trunk/Scribus/scribus/plugins/scripter/api_page.cpp
    trunk/Scribus/scribus/plugins/scripter/api_page.h

Modified: trunk/Scribus/scribus/plugins/scripter/api_document.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17935&path=/trunk/Scribus/scribus/plugins/scripter/api_document.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scripter/api_document.cpp (original)
+++ trunk/Scribus/scribus/plugins/scripter/api_document.cpp Wed Dec  5 12:41:18 2012
@@ -159,7 +159,7 @@
  */
 QObject *DocumentAPI::activePage()
 {
-	return new PageAPI(this);
+	return new PageAPI(ScCore->primaryMainWindow()->doc->currentPage());
 }
 
 
@@ -528,6 +528,33 @@
 	ScCore->primaryMainWindow()->view->showMasterPage(*it);
 }
 
+QList< QVariant > DocumentAPI::pages()
+{
+	QList<QVariant> pages;
+	if (!check())
+		return pages;
+	QList<ScPage*> *allPages = ScCore->primaryMainWindow()->doc->Pages;
+	for(int i=0; i< allPages->count(); i++) {
+	  pages.append(qVariantFromValue((QObject *)(new PageAPI(allPages->at(i)))));
+	}
+	return pages;
+}
+
+
+void DocumentAPI::setActivePage(int pageNumber)
+{
+	if(!check())
+	    return;
+	pageNumber--;
+	if ((pageNumber < 0) || (pageNumber > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())-1))
+	{
+		RAISE("Page number out of range.");
+		return;
+	}
+	ScCore->primaryMainWindow()->view->GotoPage(pageNumber);
+}
+
+
 void DocumentAPI::loadStylesFromFile(QString name)
 {
 	if (!check())

Modified: trunk/Scribus/scribus/plugins/scripter/api_document.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17935&path=/trunk/Scribus/scribus/plugins/scripter/api_document.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scripter/api_document.h (original)
+++ trunk/Scribus/scribus/plugins/scripter/api_document.h Wed Dec  5 12:41:18 2012
@@ -33,6 +33,7 @@
     Q_PROPERTY(QList<QVariant> layers READ layers)
     Q_PROPERTY(QList<QVariant> masterPages READ masterPages)
     Q_PROPERTY(QList<QVariant> styles READ styles)
+    Q_PROPERTY(QList<QVariant> pages READ pages)
 
 public:
 	DocumentAPI();
@@ -43,8 +44,6 @@
 	bool close();
 	bool save();
 	bool saveAs(QString name);
-	QList<QVariant> items(); //TODO move this to private section
-	QList<QVariant> layers(); //TODO move this to private section
 	void setInformation(QString author, QString title, QString desc);
 
 	QObject *newLayer(QString name);
@@ -67,6 +66,9 @@
 	void deleteMasterPage(QString name);
 	void closeMasterPage(QString name);
 	void editMasterPage(QString name);
+	
+	QList<QVariant> pages();
+	void setActivePage(int pageNumber);
 	
 	void loadStylesFromFile(QString name);
 
@@ -103,6 +105,8 @@
 	QObject *dimensions();
 	QList<QVariant> colors();
 	QList<QVariant> styles();
+	QList<QVariant> items();
+	QList<QVariant> layers();
 };
 
 

Modified: trunk/Scribus/scribus/plugins/scripter/api_page.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17935&path=/trunk/Scribus/scribus/plugins/scripter/api_page.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scripter/api_page.cpp (original)
+++ trunk/Scribus/scribus/plugins/scripter/api_page.cpp Wed Dec  5 12:41:18 2012
@@ -20,10 +20,11 @@
 
 
 
-PageAPI::PageAPI(QObject *parent) : QObject(COLLECTOR)
+PageAPI::PageAPI(ScPage *thisPage) : QObject(COLLECTOR)
 {
 	qDebug() << "PageAPI loaded";
 	setObjectName("page");
+	page = thisPage;
 }
 
 
@@ -60,8 +61,6 @@
 	return ScCore->primaryMainWindow()->doc->locationOfPage(number());
 }
 
-
-
 /**
  * Scripter.activeDocument.activePage.position
  * Property
@@ -71,20 +70,6 @@
 {
 	return ScCore->primaryMainWindow()->doc->currentPageNumber() + 1;
 }
-
-
-
-void PageAPI::setNumber(int value)
-{
-	value--;
-	if ((value < 0) || (value > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())-1))
-	{
-		RAISE("Page number out of range.");
-		return;
-	}
-	ScCore->primaryMainWindow()->view->GotoPage(value);
-}
-
 
 
 /**
@@ -122,7 +107,6 @@
 }
 
 
-
 /**
  * Scripter.activeDocument.activePage.selection
  * Property

Modified: trunk/Scribus/scribus/plugins/scripter/api_page.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17935&path=/trunk/Scribus/scribus/plugins/scripter/api_page.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scripter/api_page.h (original)
+++ trunk/Scribus/scribus/plugins/scripter/api_page.h Wed Dec  5 12:41:18 2012
@@ -12,12 +12,13 @@
 #include <QApplication>
 
 #include "scripterimpl.h"
+#include "scpage.h"
 
 
 class PageAPI : public QObject
 {
 	Q_OBJECT
-    Q_PROPERTY(int number READ number WRITE setNumber)
+    Q_PROPERTY(int number READ number)
     Q_PROPERTY(int position READ position)
     Q_PROPERTY(QList<QVariant> items READ items)
     Q_PROPERTY(QList<QVariant> selection READ selection)
@@ -37,13 +38,12 @@
 	void savePageAsEPS(const QString & filename);
 
 public:
-    PageAPI(QObject *parent);
+    PageAPI(ScPage* thisPage);
     virtual ~PageAPI();
 
 private:
 	int position();
 	int number();
-	void setNumber(int value);
 	QList<QVariant> items();
 	QList<QVariant> selection();
 	PageItem *newItem(const PageItem::ItemType itemType,
@@ -56,6 +56,8 @@
 	bool isMasterPage;
 	int type();
 	double pageYtoDocY(double y);
-	double pageXtoDocX(double x); 
+	double pageXtoDocX(double x);
+	
+	ScPage* page;
 };
 #endif /*API_PAGE_H_*/




More information about the scribus-commit mailing list