1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #include "cmdvar.h"
8 
9 #include "scribusstructs.h"
10 #include "scribusdoc.h"
11 #include "scribus.h"
12 #include <QList>
13 
14 // This file contains some basic methods for testing purposes,
15 // providing access to the docParagraphStyles member of the current
16 // ScribusDoc. It's a dirty hack that won't stay around.
17 //
18 // This will probably need to be replaced with a fake mapping class, since the
19 // styles are actually stored in a rather clumsy QValueList.
20 
21 
22 
23 using namespace boost::python;
24 
getStyleRef(const QString & styleName)25 ParagraphStyle & getStyleRef(const QString & styleName)
26 {
27 	QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
28 	QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
29 	for ( ; it != itEnd; ++it)
30 	{
31 		if ((*it).Vname == styleName)
32 			return *it;
33 	}
34 	throw "Style not found";
35 }
36 
getStyleRefi(int index)37 ParagraphStyle & getStyleRefi(int index)
38 {
39 	return ScCore->primaryMainWindow()->doc->docParagraphStyles[index];
40 }
41 
getStyleVal(const QString & styleName)42 ParagraphStyle getStyleVal(const QString & styleName)
43 {
44 	return getStyleRef(styleName);
45 }
46 
getStyleVali(int index)47 ParagraphStyle getStyleVali(int index)
48 {
49 	return getStyleRefi(index);
50 }
51 
addStyle(const ParagraphStyle & style)52 void addStyle(const ParagraphStyle & style)
53 {
54 	QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
55 	QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
56 	for ( ; it != itEnd; ++it)
57 	{
58 		if ((*it).Vname == style.Vname)
59 			throw "Style of same name already exists";
60 	}
61 	ScCore->primaryMainWindow()->doc->docParagraphStyles.append(style);
62 }
63 
64 // This returns a COPY of the paragraph styles; modifications to this list do
65 // NOT affect the real paragraph style list. That'll have to happen much later,
66 // probably with a "fake mapping" class wrapper around the docParagraphStyles
67 // list, since we don't want Python users seeing the int-indexed list.
getStylesVal()68 dict getStylesVal()
69 {
70 	dict d;
71 	QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
72 	QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
73 	for ( ; it != itEnd; ++it)
74 		d[(*it).Vname] = *it;
75 	return d;
76 }
77 
getStylesRef()78 dict getStylesRef()
79 {
80 	dict d;
81 	QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
82 	QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
83 	for ( ; it != itEnd; ++it)
84 		d[(*it).Vname] = boost::ref(*it);
85 	return d;
86 }
87 
getStyleNames()88 list getStyleNames()
89 {
90 	list l;
91 	QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
92 	QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
93 	for ( ; it != itEnd; ++it)
94 		l.append((*it).Vname);
95 	return l;
96 }
97 
nothing()98 void nothing() { }
99 
100 
export_styles()101 void export_styles()
102 {
103 	def("getStyleRef", getStyleRef, return_internal_reference<>());
104 	def("getStyleVal", getStyleVal);
105 	def("getStyleRefi", getStyleRefi, return_internal_reference<>());
106 	def("getStyleVali", getStyleVali);
107 	def("addStyle", addStyle);
108 	def("getStylesVal", getStylesVal);
109 	def("getStylesRef", getStylesRef);
110 	def("getStyleNames", getStyleNames);
111 }
112 
113 
114