lib
KoGenStyles Class Reference
#include <KoGenStyles.h>
Detailed Description
Repository of styles used during saving of OASIS/OOo file.Each instance of KoGenStyles is a collection of styles whose names are in the same "namespace". This means there should be one instance for all styles in <office:styles>, and automatic-styles, another instance for number formats, another one for draw styles, and another one for list styles.
"Style" in this context only means "a collection of properties". The "Gen" means both "Generic" and "Generated" :)
The basic design principle is the flyweight pattern: if you need a style with the same properties from two different places, you get the same object. Here it means rather you get the same name for the style, and it will get saved only once to the file.
KoGenStyles features sharing, creation on demand, and name generation. Since this is used for saving only, it doesn't feature refcounting, nor removal of individual styles.
NOTE: the use of KoGenStyles isn't mandatory, of course. If the application is already designed with user and automatic styles in mind for a given set of properties, it can go ahead and save all styles directly (after ensuring they have unique names).
Definition at line 59 of file KoGenStyles.h.
Public Types | |
enum | Flags { NoFlag = 0, ForceNumbering = 0, DontForceNumbering = 1 } |
typedef QMap< KoGenStyle, QString > | StyleMap |
Public Member Functions | |
QString | lookup (const KoGenStyle &style, const QString &name=QString::null, int flags=NoFlag) |
const StyleMap & | styles () const |
QValueList< NamedStyle > | styles (int type, bool markedForStylesXml=false) const |
const KoGenStyle * | style (const QString &name) const |
KoGenStyle * | styleForModification (const QString &name) |
void | markStyleForStylesXml (const QString &name) |
void | dump () |
Member Enumeration Documentation
enum KoGenStyles::Flags |
Those are flags for the lookup() call.
By default, the generated style names will look like "name1", "name2". If DontForceNumbering is set, the first name that will be tried is "name", and only if that one exists, then "name1" is tried. Set DontForceNumbering if the name given as argument is supposed to be the full style name.
Definition at line 74 of file KoGenStyles.h.
Member Function Documentation
QString KoGenStyles::lookup | ( | const KoGenStyle & | style, | |
const QString & | name = QString::null , |
|||
int | flags = NoFlag | |||
) |
Look up a style in the collection, inserting it if necessary.
This assigns a name to the style and returns it.
- Parameters:
-
style the style to look up. name proposed (base) name for the style. Note that with the OASIS format, the style name is never shown to the user (there's a separate display-name attribute for that). So there are little reasons to use named styles anyway. But this attribute can be used for clarity of the files. If this name is already in use (for another style), then a number is appended to it until unique. flags see Flags
- Returns:
- the name for this style
- Todo:
- ### rename lookup to insert
Definition at line 32 of file KoGenStyles.cpp.
const StyleMap& KoGenStyles::styles | ( | ) | const [inline] |
Return the entire collection of styles Use this for saving the styles.
Definition at line 104 of file KoGenStyles.h.
QValueList< KoGenStyles::NamedStyle > KoGenStyles::styles | ( | int | type, | |
bool | markedForStylesXml = false | |||
) | const |
Return all styles of a given type Use this for saving the styles.
- Parameters:
-
type the style type, see the KoGenStyle constructor markedForStylesXml if true, return only style marked for styles.xml, otherwise only those NOT marked for styles.xml.
- See also:
- lookup
Definition at line 100 of file KoGenStyles.cpp.
const KoGenStyle * KoGenStyles::style | ( | const QString & | name | ) | const |
KoGenStyle * KoGenStyles::styleForModification | ( | const QString & | name | ) |
- Returns:
- an existing style by name, which can be modified.
- Warning:
- This is DANGEROUS. It basically defeats the purpose of lookup()! Only do this if you know for sure no other 'user' of that style will be affected.
Definition at line 126 of file KoGenStyles.cpp.
void KoGenStyles::markStyleForStylesXml | ( | const QString & | name | ) |
Mark a given automatic style as being needed in styles.xml.
For instance styles used by headers and footers need to go there, since they are saved in styles.xml, and styles.xml must be independent from content.xml.
Equivalent to using KoGenStyle::setAutoStyleInStylesDotXml() but this can be done after lookup.
This operation can't be undone; once styles are promoted they can't go back to being content.xml-only.
- See also:
- styles, KoGenStyle::setAutoStyleInStylesDotXml
Definition at line 131 of file KoGenStyles.cpp.
void KoGenStyles::dump | ( | ) |
The documentation for this class was generated from the following files: