lib

KoGenStyle Class Reference

#include <KoGenStyles.h>

List of all members.


Detailed Description

A generic style, i.e.

basically a collection of properties and a name. Instances of KoGenStyle can either be held in the KoGenStyles collection, or created (e.g. on the stack) and given to KoGenStyles::lookup.

Author:
David Faure <faure@kde.org>

Definition at line 182 of file KoGenStyles.h.


Public Types

enum  {
  STYLE_PAGELAYOUT = 0, STYLE_USER = 1, STYLE_AUTO = 2, STYLE_MASTER = 3,
  STYLE_LIST = 4, STYLE_AUTO_LIST = 5, STYLE_NUMERIC_NUMBER = 6, STYLE_NUMERIC_DATE = 7,
  STYLE_NUMERIC_TIME = 8, STYLE_NUMERIC_FRACTION = 9, STYLE_NUMERIC_PERCENTAGE = 10, STYLE_NUMERIC_SCIENTIFIC = 11,
  STYLE_NUMERIC_CURRENCY = 12, STYLE_NUMERIC_TEXT = 13, STYLE_HATCH = 14, STYLE_GRAPHICAUTO = 15
}
enum  PropertyType {
  DefaultType = 0, TextType, ParagraphType, GraphicType,
  Reserved1, Reserved2, ChildElement, N_NumTypes
}

Public Member Functions

 KoGenStyle (int type=0, const char *familyName=0, const QString &parentName=QString::null)
 ~KoGenStyle ()
void setAutoStyleInStylesDotXml (bool b)
bool autoStyleInStylesDotXml () const
void setDefaultStyle (bool b)
bool isDefaultStyle () const
int type () const
const char * familyName () const
QString parentName () const
void addProperty (const QString &propName, const QString &propValue, PropertyType type=DefaultType)
void addProperty (const QString &propName, const char *propValue, PropertyType type=DefaultType)
void addProperty (const QString &propName, int propValue, PropertyType type=DefaultType)
void addProperty (const QString &propName, bool propValue, PropertyType type=DefaultType)
void addPropertyPt (const QString &propName, double propValue, PropertyType type=DefaultType)
void addAttribute (const QString &attrName, const QString &attrValue)
void addAttribute (const QString &attrName, const char *attrValue)
void addAttribute (const QString &attrName, int attrValue)
void addAttribute (const QString &attrName, bool attrValue)
void addAttributePt (const QString &attrName, double attrValue)
void addChildElement (const QString &elementName, const QString &elementContents)
void addStyleMap (const QMap< QString, QString > &styleMap)
bool isEmpty () const
void writeStyle (KoXmlWriter *writer, KoGenStyles &styles, const char *elementName, const QString &name, const char *propertiesElementName, bool closeElement=true, bool drawElement=false) const
bool operator< (const KoGenStyle &other) const
bool operator== (const KoGenStyle &other) const

Friends

class KoGenStyles

Member Enumeration Documentation

anonymous enum

Possible values for the "type" argument of the KoGenStyle constructor.

Those values can be extended by applications (starting at number 20), it's for their own consumption anyway. (The reason for having the very common ones here, is to make it possible to use them from libkotext).

Definition at line 192 of file KoGenStyles.h.

The types of properties.

Simple styles only write one foo-properties tag, in which case they can just use DefaultType. However a given style might want to write several kinds of properties, in which case it would need to use other property types than the default one.

For instance this style:

  <style:style style:family="chart">
    <style:chart-properties .../>
    <style:graphic-properties .../>
    <style:text-properties .../>
  </style:style>
would use DefaultType for chart-properties (and would pass "style:chart-properties" to writeStyle(), and would use GraphicType and TextType.
Enumerator:
DefaultType  DefaultType depends on family: e.g.

paragraph-properties if family=paragraph or on the type of style (e.g. page-layout -> page-layout-properties). (In fact that tag name is the one passed to writeStyle)

TextType  TextType is always text-properties.
ParagraphType  ParagraphType is always paragraph-properties.
GraphicType  GraphicType is always graphic-properties.
N_NumTypes 

Definition at line 273 of file KoGenStyles.h.


Constructor & Destructor Documentation

KoGenStyle::KoGenStyle ( int  type = 0,
const char *  familyName = 0,
const QString &  parentName = QString::null 
) [explicit]

Start the definition of a new style.

Its name will be set later by KoGenStyles::lookup(), but first you must define its properties and attributes.

Parameters:
type this is a hook for the application to categorize styles See the STYLE_* enum. Ignored when writing out the style.
familyName The value for style:family, e.g. text, paragraph, graphic etc. The family is for style:style elements only; number styles and list styles don't have one.
parentName If set, name of the parent style from which this one inherits.

Definition at line 175 of file KoGenStyles.cpp.


Member Function Documentation

bool KoGenStyle::autoStyleInStylesDotXml (  )  const [inline]

Returns:
the value passed to setAutoStyleInStylesDotXml; false by default

Definition at line 235 of file KoGenStyles.h.

bool KoGenStyle::isDefaultStyle (  )  const [inline]

Returns:
the value passed to setDefaultStyle; false by default

Definition at line 244 of file KoGenStyles.h.

int KoGenStyle::type (  )  const [inline]

Return the type of this style, as set in the constructor.

Definition at line 247 of file KoGenStyles.h.

const char* KoGenStyle::familyName (  )  const [inline]

Return the family name.

Definition at line 250 of file KoGenStyles.h.

QString KoGenStyle::parentName (  )  const [inline]

Return the name of style's parent, if set.

Definition at line 253 of file KoGenStyles.h.

void KoGenStyle::addProperty ( const QString &  propName,
const QString &  propValue,
PropertyType  type = DefaultType 
) [inline]

Add a property to the style.

Definition at line 294 of file KoGenStyles.h.

void KoGenStyle::addProperty ( const QString &  propName,
const char *  propValue,
PropertyType  type = DefaultType 
) [inline]

Overloaded version of addProperty that takes a char*, usually for "...".

Definition at line 298 of file KoGenStyles.h.

void KoGenStyle::addProperty ( const QString &  propName,
int  propValue,
PropertyType  type = DefaultType 
) [inline]

Overloaded version of addProperty that converts an int to a string.

Definition at line 302 of file KoGenStyles.h.

void KoGenStyle::addProperty ( const QString &  propName,
bool  propValue,
PropertyType  type = DefaultType 
) [inline]

Overloaded version of addProperty that converts a bool to a string (false/true).

Definition at line 306 of file KoGenStyles.h.

void KoGenStyle::addPropertyPt ( const QString &  propName,
double  propValue,
PropertyType  type = DefaultType 
)

Add a property which represents a distance, measured in pt The number is written out with the highest possible precision (unlike QString::number and setNum, which default to 6 digits), and the unit name ("pt") is appended to it.

Definition at line 299 of file KoGenStyles.cpp.

void KoGenStyle::addAttribute ( const QString &  attrName,
const QString &  attrValue 
) [inline]

Add an attribute to the style The difference between property and attributes is a bit oasis-format-specific: attributes are for the style element itself, and properties are in the style:properties child element.

Definition at line 323 of file KoGenStyles.h.

void KoGenStyle::addAttribute ( const QString &  attrName,
const char *  attrValue 
) [inline]

Overloaded version of addAttribute that takes a char*, usually for "...".

Definition at line 327 of file KoGenStyles.h.

void KoGenStyle::addAttribute ( const QString &  attrName,
int  attrValue 
) [inline]

Overloaded version of addAttribute that converts an int to a string.

Definition at line 331 of file KoGenStyles.h.

void KoGenStyle::addAttribute ( const QString &  attrName,
bool  attrValue 
) [inline]

Overloaded version of addAttribute that converts a bool to a string.

Definition at line 336 of file KoGenStyles.h.

void KoGenStyle::addAttributePt ( const QString &  attrName,
double  attrValue 
)

Add an attribute which represents a distance, measured in pt The number is written out with the highest possible precision (unlike QString::number and setNum, which default to 6 digits), and the unit name ("pt") is appended to it.

Definition at line 307 of file KoGenStyles.cpp.

void KoGenStyle::addChildElement ( const QString &  elementName,
const QString &  elementContents 
) [inline]

Add a child element to the style properties.

What is meant here is that the contents of the QString will be written out literally. This means you should use KoXmlWriter to generate it:

 QBuffer buffer;
 buffer.open( IO_WriteOnly );
 KoXmlWriter elementWriter( &buffer );  // TODO pass indentation level
 elementWriter.startElement( "..." );
 ...
 elementWriter.endElement();
 QString elementContents = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
 gs.addChildElement( "...", elementContents );

The value of elementName isn't used, except that it must be unique.

Definition at line 367 of file KoGenStyles.h.

void KoGenStyle::addStyleMap ( const QMap< QString, QString > &  styleMap  )  [inline]

Add a style:map to the style.

Parameters:
styleMap the attributes for the map, associated as (name,value).

Definition at line 375 of file KoGenStyles.h.

bool KoGenStyle::isEmpty (  )  const [inline]

Returns:
true if the style has no attributes, no properties, no style map etc.

This can be used by applications which do not save all attributes unconditionally, but only those that differ from the parent. But note that lookup() can't find this out...

Definition at line 384 of file KoGenStyles.h.

void KoGenStyle::writeStyle ( KoXmlWriter writer,
KoGenStyles styles,
const char *  elementName,
const QString &  name,
const char *  propertiesElementName,
bool  closeElement = true,
bool  drawElement = false 
) const

Write the definition of this style to writer, using the OASIS format.

Parameters:
writer the KoXmlWriter in which elementName will be created and filled in
styles the styles collection, used to look up the parent style
elementName the name of the XML element, e.g. "style:style". Don't forget to pass style:default-style if isDefaultStyle().
name must come from the collection. It will be ignored if isDefaultStyle() is true.
propertiesElementName the name of the XML element with the style properties, e.g. "style:text-properties". Can be 0 in special cases where there should be no such item, in which case the attributes and elements are added under the style itself.
closeElement set it to false to be able to add more child elements to the style element
drawElement set it to true to add "draw:name" (used for gradient/hatch style) otherwise add "style:name"

Definition at line 201 of file KoGenStyles.cpp.

bool KoGenStyle::operator< ( const KoGenStyle other  )  const

QMap requires a complete sorting order.

Another solution would have been a qdict and a key() here, a la KoTextFormat, but the key was difficult to generate. Solutions with only a hash value (not representative of the whole data) require us to write a hashtable by hand....

Definition at line 353 of file KoGenStyles.cpp.

bool KoGenStyle::operator== ( const KoGenStyle other  )  const

Not needed for QMap, but can still be useful.

Definition at line 380 of file KoGenStyles.cpp.


The documentation for this class was generated from the following files:
KDE Home | KDE Accessibility Home | Description of Access Keys