Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scripter2_styles.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "cmdvar.h"
00008 
00009 #include "scribusstructs.h"
00010 #include "scribusdoc.h"
00011 #include "scribus.h"
00012 
00013 // This file contains some basic methods for testing purposes,
00014 // providing access to the docParagraphStyles member of the current
00015 // ScribusDoc. It's a dirty hack that won't stay around.
00016 //
00017 // This will probably need to be replaced with a fake mapping class, since the
00018 // styles are actually stored in a rather clumsy QValueList.
00019 
00020 
00021 
00022 using namespace boost::python;
00023 
00024 ParagraphStyle & getStyleRef(const QString & styleName)
00025 {
00026        QValueList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
00027        QValueList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
00028        for ( ; it != itEnd; ++it)
00029        {
00030               if ((*it).Vname == styleName)
00031                      return *it;
00032        }
00033        throw "Style not found";
00034 }
00035 
00036 ParagraphStyle & getStyleRefi(int index)
00037 {
00038        return ScCore->primaryMainWindow()->doc->docParagraphStyles[index];
00039 }
00040 
00041 ParagraphStyle getStyleVal(const QString & styleName)
00042 {
00043        return getStyleRef(styleName);
00044 }
00045 
00046 ParagraphStyle getStyleVali(int index)
00047 {
00048        return getStyleRefi(index);
00049 }
00050 
00051 void addStyle(const ParagraphStyle & style)
00052 {
00053        QValueList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
00054        QValueList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
00055        for ( ; it != itEnd; ++it)
00056        {
00057               if ((*it).Vname == style.Vname)
00058                      throw "Style of same name already exists";
00059        }
00060        ScCore->primaryMainWindow()->doc->docParagraphStyles.append(style);
00061 }
00062 
00063 // This returns a COPY of the paragraph styles; modifications to this list do
00064 // NOT affect the real paragraph style list. That'll have to happen much later,
00065 // probably with a "fake mapping" class wrapper around the docParagraphStyles
00066 // list, since we don't want Python users seeing the int-indexed list.
00067 dict getStylesVal()
00068 {
00069        dict d;
00070        QValueList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
00071        QValueList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
00072        for ( ; it != itEnd; ++it)
00073               d[(*it).Vname] = *it;
00074        return d;
00075 }
00076 
00077 dict getStylesRef()
00078 {
00079        dict d;
00080        QValueList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
00081        QValueList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
00082        for ( ; it != itEnd; ++it)
00083               d[(*it).Vname] = boost::ref(*it);
00084        return d;
00085 }
00086 
00087 list getStyleNames()
00088 {
00089        list l;
00090        QValueList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin());
00091        QValueList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end());
00092        for ( ; it != itEnd; ++it)
00093               l.append((*it).Vname);
00094        return l;
00095 }
00096 
00097 void nothing() { }
00098 
00099 
00100 void export_styles()
00101 {
00102        def("getStyleRef", getStyleRef, return_internal_reference<>());
00103        def("getStyleVal", getStyleVal);
00104        def("getStyleRefi", getStyleRefi, return_internal_reference<>());
00105        def("getStyleVali", getStyleVali);
00106        def("addStyle", addStyle);
00107        def("getStylesVal", getStylesVal);
00108        def("getStylesRef", getStylesRef);
00109        def("getStyleNames", getStyleNames);
00110 }
00111 
00112