lib Library API Documentation

KoGenStyles Class Reference

Repository of styles used during saving of OASIS/OOo file. More...

#include <koGenStyles.h>

Collaboration diagram for KoGenStyles:

Collaboration graph
[legend]
List of all members.

Public Types

typedef QMap< KoGenStyle,
QString
StyleMap

Public Member Functions

QString lookup (const KoGenStyle &style, const QString &name=QString::null, bool forceNumbering=true)
const StyleMapstyles () const
QValueList< NamedStyle > styles (int type, bool markedForStylesXml=false) const
const KoGenStylestyle (const QString &name) const
KoGenStylestyleForModification (const QString &name)
void markStyleForStylesXml (const QString &name)

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@kde.org>

Definition at line 59 of file koGenStyles.h.


Member Function Documentation

QString KoGenStyles::lookup const KoGenStyle style,
const QString name = QString::null,
bool  forceNumbering = true
 

Look up a style in the collection, inserting it if necessary.

This assigns a name to the style and returns it.

Parameters:
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.
forceNumbering if true, the generated style names will look like "name1", "name2". If false, the first name that will be tried is "name". Set it to false if name is supposed to be the full style name.
Returns:
the name for this style

Definition at line 32 of file koGenStyles.cpp.

References KoGenStyle::m_parentName, KoGenStyle::parentName(), and style().

Referenced by KoOasisStyles::saveOasisTextStyle().

const StyleMap& KoGenStyles::styles  )  const [inline]
 

Return the entire collection of styles Use this for saving the styles.

Definition at line 89 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:
markStyleForStylesXml

Definition at line 90 of file koGenStyles.cpp.

References QValueVector::end().

const KoGenStyle * KoGenStyles::style const QString name  )  const
 

Returns:
an existing style by name

Definition at line 106 of file koGenStyles.cpp.

References QValueVector::end().

Referenced by lookup(), styleForModification(), and KoGenStyle::writeStyle().

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 117 of file koGenStyles.cpp.

References style().

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.

This isn't a KoGenStyle property since it doesn't make the style any different, it's only the file in which it gets saved which differs; it's still usable from content.xml of course. This operation can't be undone; once styles are promoted they can't go back to being content.xml-only.

See also:
styles

Definition at line 80 of file koGenStyles.cpp.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:41:00 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003