lib

KoGenStyles Class Reference

#include <KoGenStyles.h>

Public Types

enum  Flags { NoFlag = 0 , ForceNumbering = 0 , DontForceNumbering = 1 }
typedef TQMap< KoGenStyle, TQString > StyleMap

Public Member Functions

TQString lookup (const KoGenStyle &style, const TQString &name=TQString(), int flags=NoFlag)
const StyleMap & styles () const
TQValueList< NamedStyle > styles (int type, bool markedForStylesXml=false) const
const KoGenStyle * style (const TQString &name) const
KoGenStyle * styleForModification (const TQString &name)
void markStyleForStylesXml (const TQString &name)
void dump ()

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).

Author
David Faure faure.nosp@m.@kde.nosp@m..org

Definition at line 59 of file KoGenStyles.h.

Member Typedef Documentation

◆ StyleMap

typedef TQMap<KoGenStyle, TQString> KoGenStyles::StyleMap

Definition at line 99 of file KoGenStyles.h.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ KoGenStyles()

KoGenStyles::KoGenStyles ( )

Definition at line 24 of file KoGenStyles.cpp.

◆ ~KoGenStyles()

KoGenStyles::~KoGenStyles ( )

Definition at line 28 of file KoGenStyles.cpp.

Member Function Documentation

◆ dump()

void KoGenStyles::dump ( )

Outputs debug information.

Definition at line 139 of file KoGenStyles.cpp.

◆ lookup()

TQString KoGenStyles::lookup ( const KoGenStyle & style,
const TQString & name = TQString(),
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
stylethe style to look up.
nameproposed (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.
flagssee Flags
Returns
the name for this style
Todo
### rename lookup to insert

Definition at line 32 of file KoGenStyles.cpp.

◆ markStyleForStylesXml()

void KoGenStyles::markStyleForStylesXml ( const TQString & 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.

◆ style()

const KoGenStyle * KoGenStyles::style ( const TQString & name) const
Returns
an existing style by name

Definition at line 115 of file KoGenStyles.cpp.

◆ styleForModification()

KoGenStyle * KoGenStyles::styleForModification ( const TQString & 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.

◆ styles() [1/2]

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.

◆ styles() [2/2]

TQValueList< KoGenStyles::NamedStyle > KoGenStyles::styles ( int type,
bool markedForStylesXml = false ) const

Return all styles of a given type Use this for saving the styles.

Parameters
typethe style type, see the KoGenStyle constructor
markedForStylesXmlif 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.


The documentation for this class was generated from the following files: