[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Re: Review Request: KoGenStyle(s) cleanup
From: Jaroslaw Staniek <staniek () kde ! org>
Date: 2010-03-10 11:15:21
Message-ID: 56a746381003100315v26500a7lfa902eb43b6c2d79 () mail ! gmail ! com
[Download RAW message or body]
Sending patch here, reviewboard does not work with updated SVN today
(tried too many times). It's a known bug.
Changes: use <= LastPropertyType instead of < LastPropertyType.
--
regards / pozdrawiam, Jaroslaw Staniek
http://www.linkedin.com/in/jstaniek
Kexi & KOffice (http://www.kexi-project.org, http://www.koffice.org)
KDE Software Development Platform on MS Windows (http://windows.kde.org)
["kogenstyles_cleanup3.patch" (text/x-patch)]
Index: libs/odf/KoGenStyles.h
===================================================================
--- libs/odf/KoGenStyles.h (revision 1100893)
+++ libs/odf/KoGenStyles.h (working copy)
@@ -2,6 +2,7 @@
Copyright (C) 2004-2006 David Faure <faure@kde.org>
Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2009 Thomas Zander <zander@kde.org>
+ Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -27,19 +28,19 @@
#include <QtCore/QMultiMap>
#include <QtCore/QSet>
#include <QtCore/QString>
-#include "koodf_export.h"
+#include <QtCore/QFlags>
#include "KoGenStyle.h"
class KoStore;
class KoFontFace;
/**
- * @brief Repository of styles used during saving of OASIS/OOo file.
+ * @brief Repository of styles used during saving ODF documents.
*
* 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
+ * This means there should be one instance for all styles in <office:styles>,
+ * and <office: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".
@@ -54,7 +55,7 @@
* 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
+ * @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).
@@ -64,54 +65,51 @@
class KOODF_EXPORT KoGenStyles
{
public:
+ /// Single style with assigned name
struct NamedStyle {
const KoGenStyle* style; ///< @note owned by the collection
QString name;
};
typedef QMultiMap<KoGenStyle, QString> StyleMap;
- typedef QSet<QString> NameMap;
- typedef QList<NamedStyle> StyleArray;
KoGenStyles();
~KoGenStyles();
/**
- * Those are flags for the lookup() call.
+ * Those are flags for the insert() 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 + * By default (NoFlag), the generated style names will look like \
"name1", "name2". + * If DontAddNumberToName 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.
* If AllowDuplicates is set, a unique style name is generated even if a similar \
KoGenStyle
* already exists. In other words, the collection will now contain two equal \
KoGenStyle
* and generate them with different style names.
*/
- enum Flags { // bitfield
- NoFlag = 0,
- ForceNumbering = 0, // it's the default anyway
- DontForceNumbering = 1,
- AllowDuplicates = 2
+ enum InsertionFlag {
+ NoFlag,
+ DontAddNumberToName,
+ AllowDuplicates
};
- // KDE4 TODO: use QFlags and change the arg type in lookup
+ Q_DECLARE_FLAGS(InsertionFlags, InsertionFlag)
/**
* Look up a style in the collection, inserting it if necessary.
* This assigns a name to the style and returns it.
*
* @param style the style to look up.
- * @param name proposed (base) name for the style. Note that with the OASIS \
format, + * @param baseName proposed (base) name for the style. Note that with \
the ODF,
* 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.
+ * to it until unused name is found.
* @param flags see Flags
*
- * @return the name for this style
- * @todo ### rename lookup to insert
+ * @return the name that has been assigned for the inserted style
*/
- QString lookup(const KoGenStyle& style, const QString& name = QString(), int \
flags = NoFlag); + QString insert(const KoGenStyle& style, const QString& baseName \
= QString(), InsertionFlags flags = NoFlag);
/**
* Return the entire collection of styles
@@ -120,25 +118,33 @@
StyleMap styles() const;
/**
- * Return all styles of a given type
- * Use this for saving the styles
+ * Return all styles of a given type (NOT marked for styles.xml).
+ * Use this for saving the styles.
+ *
+ * @param type the style type, see the KoGenStyle constructor
+ * @see insert()
+ */
+ QList<KoGenStyles::NamedStyle> styles(KoGenStyle::Type type) const;
+
+ /**
+ * Return styles of a given type, marked for styles.xml,
+ * Use this for saving the styles.
*
* @param type the style type, see the KoGenStyle constructor
- * @param markedForStylesXml if true, return only style marked for styles.xml,
- * otherwise only those NOT marked for styles.xml.
- * @see lookup
+ * @see insert()
*/
- QList<NamedStyle> styles(int type, bool markedForStylesXml = false) const;
+ QList<KoGenStyles::NamedStyle> stylesForStylesXml(KoGenStyle::Type type) const;
/**
- * @return an existing style by name
+ * @return an existing style by name. If no such style exists, 0 is returned.
*/
const KoGenStyle* style(const QString& name) const;
/**
* @return an existing style by name, which can be modified.
+ * If no such style exists, 0 is returned.
* @warning This is DANGEROUS.
- * It basically defeats the purpose of lookup()!
+ * It basically defeats the purpose of insert()!
* Only do this if you know for sure no other 'user' of that style will
* be affected.
*/
@@ -149,7 +155,7 @@
* 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. + * Equivalent to using \
KoGenStyle::setAutoStyleInStylesDotXml() but this can be done after \
insert().
*
* This operation can't be undone; once styles are promoted they can't go back
* to being content.xml-only.
@@ -159,15 +165,15 @@
void markStyleForStylesXml(const QString& name);
/**
- * Add a font face declaration.
+ * Insert a font face declaration.
* @a face should have non-empty "name" parameter, i.e. should not be null.
*
- * Declaration with given name replaces previously added declaration with the \
same name. + * Declaration with given name replaces previously inserted \
declaration with the same name.
*
* See odf 2.6 Font Face Declarations
* and odf 14.6 Font Face Declaration.
*/
- void addFontFace(const KoFontFace& face);
+ void insertFontFace(const KoFontFace& face);
/**
* @return font face declaration for name @a name
@@ -179,11 +185,6 @@
KoFontFace fontFace(const QString& name) const;
/**
- * Outputs debug information
- */
- void dump();
-
- /**
* Save the styles into the styles.xml file
*
* This saves all styles and font face declarations to the styles.xml file which
@@ -193,36 +194,53 @@
* @param mainfestwriter
* @return if it was successful
*/
- bool saveOdfStylesDotXml(KoStore* store, KoXmlWriter* manifestWriter);
+ bool saveOdfStylesDotXml(KoStore* store, KoXmlWriter* manifestWriter) const;
/**
- * Save automatic styles.
- *
- * This creates the office:automatic-styles tag containing all
- * automatic styles.
- *
- * @param xmlWriter
- * @param stylesDotXml
+ * Placement of styles saved in saveOdfStyles() or inserted in \
insertRawOdfStyles().
*/
- void saveOdfAutomaticStyles(KoXmlWriter* xmlWriter, bool stylesDotXml) const;
+ enum StylesPlacement {
+ /**
+ * Creates document's office:styles tag and saves all document styles there
+ * or inserts raw styles into document's office:styles.
+ */
+ DocumentStyles,
+ /**
+ * Creates styles.xml's office:master-styles tag and saves all master styles \
there + * or inserts raw styles into styles.xml's office:automatic-styles.
+ */
+ MasterStyles, ///< office:master-styles
+ /**
+ * Creates document's office:automatic-styles tag and saves all automatic \
styles there + * or inserts raw styles into document's \
office:automatic-styles. + */
+ DocumentAutomaticStyles,
+ /**
+ * Creates styles.xml's office:automatic-styles tag and saves all automatic \
styles there + * or inserts raw styles into style.xml's \
office:automatic-styles. + */
+ StylesXmlAutomaticStyles
+ };
/**
- * Save document styles.
- *
- * This creates the office:styles tag containing all document styles.
+ * Save styles of given type.
*
- * @param xmlWriter
+ * @param placement see StylesPlacement
+ * @param xmlWriter target writer
*/
- void saveOdfDocumentStyles(KoXmlWriter* xmlWriter) const;
+ void saveOdfStyles(StylesPlacement placement, KoXmlWriter* xmlWriter) const;
/**
- * Save master styles.
+ * Insert extra styles of given type.
*
- * This creates the office:master-styles tag containing all master styles.
+ * This inserts extra styles as raw xml into a given placement.
+ * The information is collected and written back when saveOdfStyles() is called.
+ * This method is useful for testing purposes.
*
- * @param xmlWriter
+ * @param placement see StylesPlacement
+ * @param xml the raw xml string
*/
- void saveOdfMasterStyles(KoXmlWriter* xmlWriter) const;
+ void insertRawOdfStyles(StylesPlacement placement, const QByteArray& xml);
/**
* Save font face declarations
@@ -234,49 +252,30 @@
/**
* register a relation for a previously inserted style to a previously inserted \
target style.
- * This allows you to add a style relation based on generated names.
+ * This allows you to insert a style relation based on generated names.
*/
void insertStyleRelation(const QString &source, const QString &target, const \
char *tagName);
- /**
- * Adds extra document styles.
- *
- * This adds extra document styles as raw xml within the office:styles tag.
- * The information is collected and written back when saveOdfDocumentStyles() is \
called.
- * This method is useful for testing purposes.
- *
- * @param xml the raw xml string
- */
- void addRawOdfDocumentStyles(const QByteArray& xml);
-
- /**
- * Adds extra master styles.
- *
- * This adds extra master styles as raw xml within the office:master-styles tag.
- * The information is collected and written back when saveOdfMasterStyles() is \
called.
- * This method is useful for testing purposes.
- *
- * @param xml the raw xml string
- */
- void addRawOdfMasterStyles(const QByteArray& xml);
-
- /**
- * Adds extra automatic styles.
- *
- * This adds extra master automatic as raw xml within the \
office:automatic-styles tag.
- * The information is collected and written back when saveOdfAutomaticStyles() \
is called.
- * This method is useful for testing purposes.
- *
- * @param xml the raw xml string
- * @param stylesDotXml true if the xml should go to styles.xml instead of \
content.xml
- */
- void addRawOdfAutomaticStyles(const QByteArray& xml, bool stylesDotXml);
-
private:
- QString makeUniqueName(const QString& base, int flags) const;
+ QList<KoGenStyles::NamedStyle> styles(const QSet<QString>& names, \
KoGenStyle::Type type) const; + void saveOdfAutomaticStyles(KoXmlWriter* \
xmlWriter, const QSet<QString>& styleNames, + const \
QByteArray& rawOdfAutomaticStyles) const; + void \
saveOdfDocumentStyles(KoXmlWriter* xmlWriter) const; + void \
saveOdfMasterStyles(KoXmlWriter* xmlWriter) const; + QString makeUniqueName(const \
QString& base, InsertionFlags flags) const; + QList<KoGenStyles::NamedStyle> \
styleList() const; + QSet<QString> styleNames() const;
+ QSet<QString> autoStylesInStylesDotXml() const;
+
+ friend QDebug operator<<(QDebug dbg, const KoGenStyles& styles);
class Private;
Private * const d;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(KoGenStyles::InsertionFlags)
+
+//! Debug stream operator.
+QDebug KOODF_EXPORT operator<<(QDebug dbg, const KoGenStyles& styles);
+
#endif /* KOGENSTYLES_H */
Index: libs/odf/KoGenStyle.cpp
===================================================================
--- libs/odf/KoGenStyle.cpp (revision 1100893)
+++ libs/odf/KoGenStyle.cpp (working copy)
@@ -1,6 +1,7 @@
/* This file is part of the KDE project
Copyright (C) 2004-2006 David Faure <faure@kde.org>
Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
+ Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -29,9 +30,9 @@
// Returns -1, 0 (equal) or 1
static int compareMap(const QMap<QString, QString>& map1, const QMap<QString, \
QString>& map2) {
- QMap<QString, QString>::const_iterator it = map1.begin();
- QMap<QString, QString>::const_iterator oit = map2.begin();
- for (; it != map1.end(); ++it, ++oit) { // both maps have been checked for \
size already + QMap<QString, QString>::const_iterator it = map1.constBegin();
+ QMap<QString, QString>::const_iterator oit = map2.constBegin();
+ for (; it != map1.constEnd(); ++it, ++oit) { // both maps have been checked \
for size already if (it.key() != oit.key())
return it.key() < oit.key() ? -1 : + 1;
if (it.value() != oit.value())
@@ -109,8 +110,8 @@
const StyleMap& map = m_properties[type];
if (!map.isEmpty()) {
writer->startElement(elementName);
- QMap<QString, QString>::const_iterator it = map.begin();
- const QMap<QString, QString>::const_iterator end = map.end();
+ QMap<QString, QString>::const_iterator it = map.constBegin();
+ const QMap<QString, QString>::const_iterator end = map.constEnd();
for (; it != end; ++it) {
if (!parentStyle || parentStyle->property(it.key(), type) != it.value())
writer->addAttribute(it.key().toUtf8(), it.value().toUtf8());
@@ -166,8 +167,8 @@
// We only look at the direct parent style because we assume
// that styles are fully specified, i.e. the inheritance is
// only in the final file, not in the caller's code.
- QMap<QString, QString>::const_iterator it = m_attributes.begin();
- for (; it != m_attributes.end(); ++it) {
+ QMap<QString, QString>::const_iterator it = m_attributes.constBegin();
+ for (; it != m_attributes.constEnd(); ++it) {
bool writeit = true;
if (parentStyle && it.key() != "style:family" // always write the family \
out && parentStyle->attribute(it.key()) == it.value())
@@ -185,24 +186,24 @@
!m_properties[defaultPropertyType].isEmpty()) {
if (createPropertiesTag)
writer->startElement(propertiesElementName); // e.g. \
paragraph-properties
- it = m_properties[i].begin();
- for (; it != m_properties[i].end(); ++it) {
+ it = m_properties[i].constBegin();
+ for (; it != m_properties[i].constEnd(); ++it) {
if (!parentStyle || parentStyle->property(it.key(), i) != it.value())
writer->addAttribute(it.key().toUtf8(), it.value().toUtf8());
}
//write the explicitly-defined properties that are the same type as the \
default,
//but only if defaultPropertyType is Text, Paragraph, or GraphicType
if (defaultPropertyType != 0) {
- it = m_properties[defaultPropertyType].begin();
- for (; it != m_properties[defaultPropertyType].end(); ++it) {
+ it = m_properties[defaultPropertyType].constBegin();
+ for (; it != m_properties[defaultPropertyType].constEnd(); ++it) {
if (!parentStyle || parentStyle->property(it .key(), \
defaultPropertyType) != it.value())
writer->addAttribute(it.key().toUtf8(), it.value().toUtf8());
}
}
//write child elements of the properties elements
i = KoGenStyle::ChildElement;
- it = m_properties[i].begin();
- for (; it != m_properties[i].end(); ++it) {
+ it = m_properties[i].constBegin();
+ for (; it != m_properties[i].constEnd(); ++it) {
if (!parentStyle || parentStyle->property(it.key(), i) != it.value()) {
writer->addCompleteElement(it.value().toUtf8());
}
@@ -222,8 +223,8 @@
//write child elements that aren't in any of the properties elements
i = KoGenStyle::StyleChildElement;
- it = m_properties[i].begin();
- for (; it != m_properties[i].end(); ++it) {
+ it = m_properties[i].constBegin();
+ for (; it != m_properties[i].constEnd(); ++it) {
if (!parentStyle || parentStyle->property(it.key(), i) != it.value()) {
writer->addCompleteElement(it.value().toUtf8());
}
@@ -236,8 +237,8 @@
writeit = false;
if (writeit) {
writer->startElement("style:map");
- QMap<QString, QString>::const_iterator it = m_maps[i].begin();
- for (; it != m_maps[i].end(); ++it) {
+ QMap<QString, QString>::const_iterator it = m_maps[i].constBegin();
+ for (; it != m_maps[i].constEnd(); ++it) {
writer->addAttribute(it.key().toUtf8(), it.value().toUtf8());
}
writer->endElement(); // style:map
@@ -282,32 +283,32 @@
{
int i = DefaultType;
kDebug(30003) << m_properties[i].count() << " properties.";
- for (QMap<QString, QString>::ConstIterator it = m_properties[i].begin(); it != \
m_properties[i].end(); ++it) { + for (QMap<QString, QString>::ConstIterator it = \
m_properties[i].constBegin(); it != m_properties[i].constEnd(); ++it) { \
kDebug(30003) << "" << it.key() << " =" << it.value(); }
i = TextType;
kDebug(30003) << m_properties[i].count() << " text properties.";
- for (QMap<QString, QString>::ConstIterator it = m_properties[i].begin(); it != \
m_properties[i].end(); ++it) { + for (QMap<QString, QString>::ConstIterator it = \
m_properties[i].constBegin(); it != m_properties[i].constEnd(); ++it) { \
kDebug(30003) << "" << it.key() << " =" << it.value(); }
i = ParagraphType;
kDebug(30003) << m_properties[i].count() << " paragraph properties.";
- for (QMap<QString, QString>::ConstIterator it = m_properties[i].begin(); it != \
m_properties[i].end(); ++it) { + for (QMap<QString, QString>::ConstIterator it = \
m_properties[i].constBegin(); it != m_properties[i].constEnd(); ++it) { \
kDebug(30003) << "" << it.key() << " =" << it.value(); }
i = ChildElement;
kDebug(30003) << m_properties[i].count() << " child elements.";
- for (QMap<QString, QString>::ConstIterator it = m_properties[i].begin(); it != \
m_properties[i].end(); ++it) { + for (QMap<QString, QString>::ConstIterator it = \
m_properties[i].constBegin(); it != m_properties[i].constEnd(); ++it) { \
kDebug(30003) << "" << it.key() << " =" << it.value(); }
kDebug(30003) << m_attributes.count() << " attributes.";
- for (QMap<QString, QString>::ConstIterator it = m_attributes.begin(); it != \
m_attributes.end(); ++it) { + for (QMap<QString, QString>::ConstIterator it = \
m_attributes.constBegin(); it != m_attributes.constEnd(); ++it) { kDebug(30003) << \
"" << it.key() << " =" << it.value(); }
kDebug(30003) << m_maps.count() << " maps.";
for (int i = 0; i < m_maps.count(); ++i) {
kDebug(30003) << "map" << i << ":";
- for (QMap<QString, QString>::ConstIterator it = m_maps[i].begin(); it != \
m_maps[i].end(); ++it) { + for (QMap<QString, QString>::ConstIterator it = \
m_maps[i].constBegin(); it != m_maps[i].constEnd(); ++it) { kDebug(30003) << "" << \
it.key() << " =" << it.value(); }
}
@@ -321,13 +322,13 @@
if (m_parentName != other.m_parentName) return m_parentName < \
other.m_parentName;
if (m_familyName != other.m_familyName) return m_familyName < \
other.m_familyName;
if (m_autoStyleInStylesDotXml != other.m_autoStyleInStylesDotXml) return \
m_autoStyleInStylesDotXml;
- for (uint i = 0 ; i < N_NumTypes ; ++i)
+ for (uint i = 0 ; i <= LastPropertyType; ++i)
if (m_properties[i].count() != other.m_properties[i].count())
return m_properties[i].count() < other.m_properties[i].count();
if (m_attributes.count() != other.m_attributes.count()) return \
m_attributes.count() < other.m_attributes.count();
if (m_maps.count() != other.m_maps.count()) return m_maps.count() < \
other.m_maps.count();
// Same number of properties and attributes, no other choice than iterating
- for (uint i = 0 ; i < N_NumTypes ; ++i) {
+ for (uint i = 0 ; i <= LastPropertyType; ++i) {
int comp = compareMap(m_properties[i], other.m_properties[i]);
if (comp != 0)
return comp < 0;
@@ -349,13 +350,13 @@
if (m_parentName != other.m_parentName) return false;
if (m_familyName != other.m_familyName) return false;
if (m_autoStyleInStylesDotXml != other.m_autoStyleInStylesDotXml) return false;
- for (uint i = 0 ; i < N_NumTypes ; ++i)
+ for (uint i = 0 ; i <= LastPropertyType; ++i)
if (m_properties[i].count() != other.m_properties[i].count())
return false;
if (m_attributes.count() != other.m_attributes.count()) return false;
if (m_maps.count() != other.m_maps.count()) return false;
// Same number of properties and attributes, no other choice than iterating
- for (uint i = 0 ; i < N_NumTypes ; ++i) {
+ for (uint i = 0 ; i <= LastPropertyType; ++i) {
int comp = compareMap(m_properties[i], other.m_properties[i]);
if (comp != 0)
return false;
@@ -370,3 +371,13 @@
}
return true;
}
+
+bool KoGenStyle::isEmpty() const
+{
+ if (!m_attributes.isEmpty() || ! m_maps.isEmpty())
+ return false;
+ for (uint i = 0 ; i <= LastPropertyType; ++i)
+ if (! m_properties[i].isEmpty())
+ return false;
+ return true;
+}
Index: libs/odf/KoGenStyles.cpp
===================================================================
--- libs/odf/KoGenStyles.cpp (revision 1100893)
+++ libs/odf/KoGenStyles.cpp (working copy)
@@ -5,6 +5,7 @@
Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
Copyright (C) 2009 Inge Wallin <inge@lysator.liu.se>
Copyright (C) 2010 KO GmbH <jos.van.den.oever@kogmbh.com>
+ Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -37,28 +38,28 @@
const char * m_propertiesElementName;
bool m_drawElement;
} styleData[] = {
- { KoGenStyle::StyleText, "style:style", "style:text-properties", \
false },
- { KoGenStyle::StyleUser, "style:style", "style:paragraph-properties", \
false },
- { KoGenStyle::StyleSection, "style:style", "style:section-properties", \
false },
- { KoGenStyle::StyleRuby, "style:style", "style:ruby-properties", \
false },
- { KoGenStyle::StyleTable, "style:style", "style:table-properties", \
false },
- { KoGenStyle::StyleTableColumn, "style:style", \
"style:table-column-properties", false },
- { KoGenStyle::StyleTableRow, "style:style", "style:table-row-properties", \
false },
- { KoGenStyle::StyleTableCell, "style:style", \
"style:table-cell-properties", false },
- { KoGenStyle::StyleGraphic, "style:style", "style:graphic-properties", \
false },
- { KoGenStyle::StylePresentation, "style:style", "style:graphic-properties", \
false },
- { KoGenStyle::StyleDrawingPage, "style:style", \
"style:drawing-page-properties", false },
- { KoGenStyle::StyleChart, "style:style", "style:chart-properties", \
false },
- { KoGenStyle::StyleList, "text:list-style", 0, false },
- { KoGenStyle::StyleGradientLinear, "svg:linearGradient", 0, true },
- { KoGenStyle::StyleGradientRadial, "svg:radialGradient", 0, true },
- { KoGenStyle::StyleGradientConical, "koffice:conicalGradient", 0, true },
- { KoGenStyle::StyleStrokeDash, "draw:stroke-dash", 0, true },
- { KoGenStyle::StyleFillImage, "draw:fill-image", 0, true },
- { KoGenStyle::StyleHatch, "draw:hatch", "style:graphic-properties", \
true },
- { KoGenStyle::StyleGradient, "draw:gradient", "style:graphic-properties", \
true },
- { KoGenStyle::StyleMarker, "draw:marker", "style:graphic-properties", \
true },
- { KoGenStyle::StylePresentationPageLayout, "style:presentation-page-layout", 0, \
false } + { KoGenStyle::TextStyle, "style:style", \
"style:text-properties", false }, + { KoGenStyle::ParagraphStyle, \
"style:style", "style:paragraph-properties", false }, + { \
KoGenStyle::SectionStyle, "style:style", "style:section-properties", \
false }, + { KoGenStyle::RubyStyle, "style:style", \
"style:ruby-properties", false }, + { KoGenStyle::TableStyle, \
"style:style", "style:table-properties", false }, + { \
KoGenStyle::TableColumnStyle, "style:style", "style:table-column-properties", \
false }, + { KoGenStyle::TableRowStyle, "style:style", \
"style:table-row-properties", false }, + { KoGenStyle::TableCellStyle, \
"style:style", "style:table-cell-properties", false }, + { \
KoGenStyle::GraphicStyle, "style:style", "style:graphic-properties", \
false }, + { KoGenStyle::PresentationStyle, "style:style", \
"style:graphic-properties", false }, + { KoGenStyle::DrawingPageStyle, \
"style:style", "style:drawing-page-properties", false }, + { \
KoGenStyle::ChartStyle, "style:style", "style:chart-properties", \
false }, + { KoGenStyle::ListStyle, "text:list-style", 0, false },
+ { KoGenStyle::GradientLinearStyle, "svg:linearGradient", 0, true },
+ { KoGenStyle::GradientRadialStyle, "svg:radialGradient", 0, true },
+ { KoGenStyle::GradientConicalStyle, "koffice:conicalGradient", 0, true },
+ { KoGenStyle::StrokeDashStyle, "draw:stroke-dash", 0, true },
+ { KoGenStyle::FillImageStyle, "draw:fill-image", 0, true },
+ { KoGenStyle::HatchStyle, "draw:hatch", "style:graphic-properties", \
true }, + { KoGenStyle::GradientStyle, "draw:gradient", \
"style:graphic-properties", true }, + { KoGenStyle::MarkerStyle, \
"draw:marker", "style:graphic-properties", true }, + { \
KoGenStyle::PresentationPageLayoutStyle, "style:presentation-page-layout", 0, false \
} };
static const unsigned int numStyleData = sizeof(styleData) / sizeof(*styleData);
@@ -69,34 +70,34 @@
const char * m_propertiesElementName;
bool m_drawElement;
} autoStyleData[] = {
- { KoGenStyle::StyleTextAuto, "style:style", "style:text-properties", \
false },
- { KoGenStyle::StyleAuto, "style:style", \
"style:paragraph-properties", false },
- { KoGenStyle::StyleSectionAuto, "style:style", "style:section-properties", \
false },
- { KoGenStyle::StyleRubyAuto, "style:style", "style:ruby-properties", \
false },
- { KoGenStyle::StyleAutoTable, "style:style", "style:table-properties", \
false },
- { KoGenStyle::StyleAutoTableColumn, "style:style", \
"style:table-column-properties", false },
- { KoGenStyle::StyleAutoTableRow, "style:style", \
"style:table-row-properties", false },
- { KoGenStyle::StyleAutoTableCell, "style:style", \
"style:table-cell-properties", false },
- { KoGenStyle::StyleGraphicAuto, "style:style", "style:graphic-properties", \
false },
- { KoGenStyle::StylePresentationAuto, "style:style", "style:graphic-properties", \
false },
- { KoGenStyle::StyleDrawingPageAuto, "style:style", \
"style:drawing-page-properties", false },
- { KoGenStyle::StyleChartAuto, "style:style", "style:chart-properties", \
false },
- { KoGenStyle::StylePageLayout, "style:page-layout", \
"style:page-layout-properties", false },
- { KoGenStyle::StyleListAuto, "text:list-style", 0, false },
- { KoGenStyle::StyleNumericNumber, "number:number-style", 0, false },
- { KoGenStyle::StyleNumericFraction, "number:number-style", 0, false },
- { KoGenStyle::StyleNumericScientific, "number:number-style", 0, false },
- { KoGenStyle::StyleNumericDate, "number:date-style", 0, false },
- { KoGenStyle::StyleNumericTime, "number:time-style", 0, false },
- { KoGenStyle::StyleNumericPercentage, "number:percentage-style", 0, false },
- { KoGenStyle::StyleNumericCurrency, "number:currency-style", 0, false },
- { KoGenStyle::StyleNumericBoolean, "number:boolean-style", 0, false },
- { KoGenStyle::StyleNumericText, "number:text-style", 0, false }
+ { KoGenStyle::TextAutoStyle, "style:style", "style:text-properties", \
false }, + { KoGenStyle::ParagraphAutoStyle, "style:style", \
"style:paragraph-properties", false }, + { KoGenStyle::SectionAutoStyle, \
"style:style", "style:section-properties", false }, + { \
KoGenStyle::RubyAutoStyle, "style:style", "style:ruby-properties", \
false }, + { KoGenStyle::TableAutoStyle, "style:style", \
"style:table-properties", false }, + { KoGenStyle::TableColumnAutoStyle, \
"style:style", "style:table-column-properties", false }, + { \
KoGenStyle::TableRowAutoStyle, "style:style", "style:table-row-properties", \
false }, + { KoGenStyle::TableCellAutoStyle, "style:style", \
"style:table-cell-properties", false }, + { KoGenStyle::GraphicAutoStyle, \
"style:style", "style:graphic-properties", false }, + { \
KoGenStyle::PresentationAutoStyle, "style:style", "style:graphic-properties", \
false }, + { KoGenStyle::DrawingPageAutoStyle, "style:style", \
"style:drawing-page-properties", false }, + { KoGenStyle::ChartAutoStyle, \
"style:style", "style:chart-properties", false }, + { \
KoGenStyle::PageLayoutStyle, "style:page-layout", "style:page-layout-properties", \
false }, + { KoGenStyle::ListAutoStyle, "text:list-style", 0, false },
+ { KoGenStyle::NumericNumberStyle, "number:number-style", 0, false },
+ { KoGenStyle::NumericFractionStyle, "number:number-style", 0, false },
+ { KoGenStyle::NumericScientificStyle, "number:number-style", 0, false },
+ { KoGenStyle::NumericDateStyle, "number:date-style", 0, false },
+ { KoGenStyle::NumericTimeStyle, "number:time-style", 0, false },
+ { KoGenStyle::NumericPercentageStyle, "number:percentage-style", 0, false },
+ { KoGenStyle::NumericCurrencyStyle, "number:currency-style", 0, false },
+ { KoGenStyle::NumericBooleanStyle, "number:boolean-style", 0, false },
+ { KoGenStyle::NumericTextStyle, "number:text-style", 0, false }
};
static const unsigned int numAutoStyleData = sizeof(autoStyleData) / \
sizeof(*autoStyleData);
-static void addRawOdfStyles(const QByteArray& xml, QByteArray& styles)
+static void insertRawOdfStyles(const QByteArray& xml, QByteArray& styles)
{
if (xml.isEmpty())
return;
@@ -122,11 +123,11 @@
/// Map with the style name as key.
/// This map is mainly used to check for name uniqueness
- NameMap styleNames;
- NameMap autoStylesInStylesDotXml;
+ QSet<QString> styleNames;
+ QSet<QString> autoStylesInStylesDotXml;
/// List of styles (used to preserve ordering)
- StyleArray styleArray;
+ QList<KoGenStyles::NamedStyle> styleList;
/// map for saving default styles
QMap<int, KoGenStyle> defaultStyles;
@@ -134,7 +135,7 @@
/// font faces
QMap<QString, KoFontFace> fontFaces;
- StyleMap::iterator insertStyle(const KoGenStyle &style, const QString &name, int \
flags); + StyleMap::iterator insertStyle(const KoGenStyle &style, const QString \
&name, InsertionFlags flags);
struct RelationTarget {
QString target; // the style we point to
@@ -142,10 +143,6 @@
};
QHash<QString, RelationTarget> relations; // key is the name of the source style
- QByteArray& rawOdfAutomaticStyles(bool stylesDotXml) {
- return stylesDotXml ? rawOdfAutomaticStyles_stylesDotXml : \
rawOdfAutomaticStyles_contentDotXml;
- }
-
QByteArray rawOdfDocumentStyles;
QByteArray rawOdfAutomaticStyles_stylesDotXml;
QByteArray rawOdfAutomaticStyles_contentDotXml;
@@ -164,25 +161,25 @@
delete d;
}
-QString KoGenStyles::lookup(const KoGenStyle& style, const QString& name, int flags)
+QString KoGenStyles::insert(const KoGenStyle& style, const QString& baseName, \
InsertionFlags flags) {
// if it is a default style it has to be saved differently
if (style.isDefaultStyle()) {
// we can have only one default style per type
Q_ASSERT(!d->defaultStyles.contains(style.type()));
// default style is only possible for style:style in office:style types
- Q_ASSERT(style.type() == KoGenStyle::StyleText ||
- style.type() == KoGenStyle::StyleUser ||
- style.type() == KoGenStyle::StyleSection ||
- style.type() == KoGenStyle::StyleRuby ||
- style.type() == KoGenStyle::StyleTable ||
- style.type() == KoGenStyle::StyleTableColumn ||
- style.type() == KoGenStyle::StyleTableRow ||
- style.type() == KoGenStyle::StyleTableCell ||
- style.type() == KoGenStyle::StyleGraphic ||
- style.type() == KoGenStyle::StylePresentation ||
- style.type() == KoGenStyle::StyleDrawingPage ||
- style.type() == KoGenStyle::StyleChart);
+ Q_ASSERT(style.type() == KoGenStyle::TextStyle ||
+ style.type() == KoGenStyle::ParagraphStyle ||
+ style.type() == KoGenStyle::SectionStyle ||
+ style.type() == KoGenStyle::RubyStyle ||
+ style.type() == KoGenStyle::TableStyle ||
+ style.type() == KoGenStyle::TableColumnStyle ||
+ style.type() == KoGenStyle::TableRowStyle ||
+ style.type() == KoGenStyle::TableCellStyle ||
+ style.type() == KoGenStyle::GraphicStyle ||
+ style.type() == KoGenStyle::PresentationStyle ||
+ style.type() == KoGenStyle::DrawingPageStyle ||
+ style.type() == KoGenStyle::ChartStyle);
d->defaultStyles.insert(style.type(), style);
// default styles don't have a name
@@ -190,7 +187,7 @@
}
if (flags & AllowDuplicates) {
- StyleMap::iterator it = d->insertStyle(style, name, flags);
+ StyleMap::iterator it = d->insertStyle(style, baseName, flags);
return it.value();
}
@@ -202,10 +199,13 @@
KoGenStyle testStyle(style);
const KoGenStyle* parentStyle = this->style(style.parentName()); // ## \
linear search if (!parentStyle) {
- kDebug(30003) << "KoGenStyles::lookup(" << name << "): parent style \
'" << style.parentName() << "' not found in collection"; + \
kDebug(30003) << "baseName=" << baseName << "parent style" << style.parentName() + \
<< "not found in collection"; } else {
if (testStyle.m_familyName != parentStyle->m_familyName) {
- kWarning(30003) << "KoGenStyles::lookup(" << name << ", family=" \
<< testStyle.m_familyName << ") parent style '" << style.parentName() << "' has a \
different family: " << parentStyle->m_familyName; + \
kWarning(30003) << "baseName=" << baseName << "family=" << testStyle.m_familyName + \
<< "parent style" << style.parentName() << "has a different family:" + \
<< parentStyle->m_familyName; }
testStyle.m_parentName = parentStyle->m_parentName;
@@ -223,23 +223,24 @@
}
}
- it = d->insertStyle(style, name, flags);
+ it = d->insertStyle(style, baseName, flags);
}
return it.value();
}
-KoGenStyles::StyleMap::iterator KoGenStyles::Private::insertStyle(const KoGenStyle \
&style, const QString &name, int flags) +KoGenStyles::StyleMap::iterator \
KoGenStyles::Private::insertStyle(const KoGenStyle &style, + \
const QString& baseName, InsertionFlags flags) {
- QString styleName(name);
+ QString styleName(baseName);
if (styleName.isEmpty()) {
switch (style.type()) {
- case KoGenStyle::StyleAuto: styleName = 'P'; break;
- case KoGenStyle::StyleListAuto: styleName = 'L'; break;
- case KoGenStyle::StyleTextAuto: styleName = 'T'; break;
+ case KoGenStyle::ParagraphAutoStyle: styleName = 'P'; break;
+ case KoGenStyle::ListAutoStyle: styleName = 'L'; break;
+ case KoGenStyle::TextAutoStyle: styleName = 'T'; break;
default:
styleName = 'A'; // for "auto".
}
- flags &= ~DontForceNumbering; // i.e. force numbering
+ flags &= ~DontAddNumberToName; // i.e. force numbering
}
styleName = q->makeUniqueName(styleName, flags);
if (style.autoStyleInStylesDotXml())
@@ -250,7 +251,7 @@
NamedStyle s;
s.style = &it.key();
s.name = styleName;
- styleArray.append(s);
+ styleList.append(s);
return it;
}
@@ -259,42 +260,65 @@
return d->styleMap;
}
-QString KoGenStyles::makeUniqueName(const QString& base, int flags) const
+QString KoGenStyles::makeUniqueName(const QString& base, InsertionFlags flags) const
{
// If this name is not used yet, and numbering isn't forced, then the given name \
is ok.
- if ((flags & DontForceNumbering)
+ if ((flags & DontAddNumberToName)
&& ! d->autoStylesInStylesDotXml.contains(base)
&& ! d->styleNames.contains(base))
return base;
int num = 1;
QString name;
do {
- name = base;
- name += QString::number(num++);
+ name = base + QString::number(num++);
} while (d->autoStylesInStylesDotXml.contains(name)
|| d->styleNames.contains(name));
return name;
}
-QList<KoGenStyles::NamedStyle> KoGenStyles::styles(int type, bool \
markedForStylesXml) const +QList<KoGenStyles::NamedStyle> KoGenStyles::styles(const \
QSet<QString>& names, KoGenStyle::Type type) const {
QList<KoGenStyles::NamedStyle> lst;
- const NameMap& nameMap = markedForStylesXml ? d->autoStylesInStylesDotXml : \
d->styleNames;
- StyleArray::const_iterator it = d->styleArray.constBegin();
- const StyleArray::const_iterator end = d->styleArray.constEnd();
+ QList<KoGenStyles::NamedStyle>::const_iterator it = d->styleList.constBegin();
+ const QList<KoGenStyles::NamedStyle>::const_iterator end = \
d->styleList.constEnd(); + const QSet<QString>::const_iterator mapEnd = \
names.constEnd(); for (; it != end ; ++it) {
- // Look up if it's marked for styles.xml or not by looking up in the \
corresponding style map.
- if ((*it).style->type() == type && nameMap.find((*it).name) != \
nameMap.end()) { + if ((*it).style->type() == type && \
names.constFind((*it).name) != mapEnd) { lst.append(*it);
}
}
return lst;
}
+QList<KoGenStyles::NamedStyle> KoGenStyles::styles(KoGenStyle::Type type) const
+{
+ return styles(d->styleNames, type);
+}
+
+QList<KoGenStyles::NamedStyle> KoGenStyles::styleList() const
+{
+ return d->styleList;
+}
+
+QSet<QString> KoGenStyles::styleNames() const
+{
+ return d->styleNames;
+}
+
+QSet<QString> KoGenStyles::autoStylesInStylesDotXml() const
+{
+ return d->autoStylesInStylesDotXml;
+}
+
+QList<KoGenStyles::NamedStyle> KoGenStyles::stylesForStylesXml(KoGenStyle::Type \
type) const +{
+ return styles(d->autoStylesInStylesDotXml, type);
+}
+
const KoGenStyle* KoGenStyles::style(const QString& name) const
{
- StyleArray::const_iterator it = d->styleArray.constBegin();
- const StyleArray::const_iterator end = d->styleArray.constEnd();
+ QList<KoGenStyles::NamedStyle>::const_iterator it = d->styleList.constBegin();
+ const QList<KoGenStyles::NamedStyle>::const_iterator end = \
d->styleList.constEnd(); for (; it != end ; ++it) {
if ((*it).name == name)
return (*it).style;
@@ -315,28 +339,7 @@
styleForModification(name)->setAutoStyleInStylesDotXml(true);
}
-void KoGenStyles::dump()
-{
- kDebug(30003) << "Style array:";
- StyleArray::const_iterator it = d->styleArray.constBegin();
- const StyleArray::const_iterator end = d->styleArray.constEnd();
- for (; it != end ; ++it) {
- kDebug(30003) << (*it).name;
- }
- for (NameMap::const_iterator it = d->styleNames.constBegin(); it != \
d->styleNames.constEnd(); ++it) {
- kDebug(30003) << "style:" << *it;
- }
- for (NameMap::const_iterator it = d->autoStylesInStylesDotXml.constBegin(); it \
!= d->autoStylesInStylesDotXml.constEnd(); ++it) {
-#ifndef NDEBUG
- kDebug(30003) << "auto style for style.xml:" << *it;
- const KoGenStyle* s = style(*it);
- Q_ASSERT(s);
- Q_ASSERT(s->autoStyleInStylesDotXml());
-#endif
- }
-}
-
-void KoGenStyles::addFontFace(const KoFontFace &face)
+void KoGenStyles::insertFontFace(const KoFontFace &face)
{
Q_ASSERT(!face.isNull());
if (face.isNull()) {
@@ -351,7 +354,7 @@
return d->fontFaces.value(name);
}
-bool KoGenStyles::saveOdfStylesDotXml(KoStore* store, KoXmlWriter* manifestWriter)
+bool KoGenStyles::saveOdfStylesDotXml(KoStore* store, KoXmlWriter* manifestWriter) \
const {
if (!store->open("styles.xml"))
return false;
@@ -363,7 +366,7 @@
saveOdfFontFaceDecls(stylesWriter);
saveOdfDocumentStyles(stylesWriter);
- saveOdfAutomaticStyles(stylesWriter, true);
+ saveOdfAutomaticStyles(stylesWriter, d->autoStylesInStylesDotXml, \
d->rawOdfAutomaticStyles_stylesDotXml); saveOdfMasterStyles(stylesWriter);
stylesWriter->endElement(); // root element (office:document-styles)
@@ -376,12 +379,25 @@
return true;
}
-void KoGenStyles::saveOdfAutomaticStyles(KoXmlWriter* xmlWriter, bool stylesDotXml) \
const +void KoGenStyles::saveOdfStyles(StylesPlacement placement, KoXmlWriter* \
xmlWriter) const +{
+ if (placement == DocumentStyles)
+ saveOdfDocumentStyles(xmlWriter);
+ else if (placement == MasterStyles)
+ saveOdfMasterStyles(xmlWriter);
+ else if (placement == DocumentAutomaticStyles)
+ saveOdfAutomaticStyles(xmlWriter, d->styleNames, \
d->rawOdfAutomaticStyles_contentDotXml); + else // StylesXmlAutomaticStyles
+ saveOdfAutomaticStyles(xmlWriter, d->autoStylesInStylesDotXml, \
d->rawOdfAutomaticStyles_stylesDotXml); +}
+
+void KoGenStyles::saveOdfAutomaticStyles(KoXmlWriter* xmlWriter, const \
QSet<QString>& styleNames, + const \
QByteArray& rawOdfAutomaticStyles) const {
xmlWriter->startElement("office:automatic-styles");
for (uint i = 0; i < numAutoStyleData; ++i) {
- QList<KoGenStyles::NamedStyle> stylesList = \
styles(int(autoStyleData[i].m_type), stylesDotXml); + \
QList<KoGenStyles::NamedStyle> stylesList = styles(styleNames, \
autoStyleData[i].m_type);
QList<KoGenStyles::NamedStyle>::const_iterator it = stylesList.constBegin();
for (; it != stylesList.constEnd() ; ++it) {
(*it).style->writeStyle(xmlWriter, *this, \
autoStyleData[i].m_elementName, (*it).name, @@ -389,7 +405,6 @@
}
}
- const QByteArray &rawOdfAutomaticStyles = \
d->rawOdfAutomaticStyles(stylesDotXml); if (!rawOdfAutomaticStyles.isEmpty()) {
xmlWriter->addCompleteElement(rawOdfAutomaticStyles.constData());
}
@@ -397,21 +412,20 @@
xmlWriter->endElement(); // office:automatic-styles
}
-
void KoGenStyles::saveOdfDocumentStyles(KoXmlWriter* xmlWriter) const
{
xmlWriter->startElement("office:styles");
for (uint i = 0; i < numStyleData; ++i) {
- QMap<int, KoGenStyle>::iterator \
it(d->defaultStyles.find(styleData[i].m_type));
- if (it != d->defaultStyles.end()) {
+ const QMap<int, KoGenStyle>::const_iterator \
it(d->defaultStyles.constFind(styleData[i].m_type)); + if (it != \
d->defaultStyles.constEnd()) {
it.value().writeStyle(xmlWriter, *this, "style:default-style", "",
styleData[i].m_propertiesElementName, true, \
styleData[i].m_drawElement); }
}
for (uint i = 0; i < numStyleData; ++i) {
- QList<KoGenStyles::NamedStyle> stylesList = \
styles(int(styleData[i].m_type)); + QList<KoGenStyles::NamedStyle> \
stylesList(styles(styleData[i].m_type));
QList<KoGenStyles::NamedStyle>::const_iterator it = stylesList.constBegin();
for (; it != stylesList.constEnd() ; ++it) {
if (d->relations.contains(it->name)) {
@@ -438,7 +452,7 @@
{
xmlWriter->startElement("office:master-styles");
- QList<KoGenStyles::NamedStyle> stylesList = styles(KoGenStyle::StyleMaster);
+ QList<KoGenStyles::NamedStyle> stylesList = styles(KoGenStyle::MasterPageStyle);
QList<KoGenStyles::NamedStyle>::const_iterator it = stylesList.constBegin();
for (; it != stylesList.constEnd() ; ++it) {
(*it).style->writeStyle(xmlWriter, *this, "style:master-page", (*it).name, \
0); @@ -451,19 +465,16 @@
xmlWriter->endElement(); // office:master-styles
}
-void KoGenStyles::addRawOdfDocumentStyles(const QByteArray& xml)
-{
- addRawOdfStyles(xml, d->rawOdfDocumentStyles);
-}
-
-void KoGenStyles::addRawOdfAutomaticStyles(const QByteArray& xml, bool stylesDotXml)
-{
- addRawOdfStyles(xml, d->rawOdfAutomaticStyles(stylesDotXml));
-}
-
-void KoGenStyles::addRawOdfMasterStyles(const QByteArray& xml)
+void KoGenStyles::insertRawOdfStyles(StylesPlacement placement, const QByteArray& \
xml) {
- addRawOdfStyles(xml, d->rawOdfMasterStyles);
+ if (placement == DocumentStyles)
+ ::insertRawOdfStyles(xml, d->rawOdfDocumentStyles);
+ else if (placement == MasterStyles)
+ ::insertRawOdfStyles(xml, d->rawOdfMasterStyles);
+ else if (placement == DocumentAutomaticStyles)
+ ::insertRawOdfStyles(xml, d->rawOdfAutomaticStyles_contentDotXml);
+ else // StylesXmlAutomaticStyles
+ ::insertRawOdfStyles(xml, d->rawOdfAutomaticStyles_stylesDotXml);
}
void KoGenStyles::saveOdfFontFaceDecls(KoXmlWriter* xmlWriter) const
@@ -488,3 +499,27 @@
relation.attribute = QString(tagName);
d->relations.insert(source, relation);
}
+
+QDebug operator<<(QDebug dbg, const KoGenStyles& styles)
+{
+ dbg.nospace() << "KoGenStyles:";
+ QList<KoGenStyles::NamedStyle>::const_iterator it = \
styles.styleList().constBegin(); + const \
QList<KoGenStyles::NamedStyle>::const_iterator end = styles.styleList().constEnd(); + \
for (; it != end ; ++it) { + dbg.nospace() << (*it).name;
+ }
+ for (QSet<QString>::const_iterator it = styles.styleNames().constBegin(); it != \
styles.styleNames().constEnd(); ++it) { + dbg.space() << "style:" << *it;
+ }
+#ifndef NDEBUG
+ for (QSet<QString>::const_iterator it = \
styles.autoStylesInStylesDotXml().constBegin(); + it != \
styles().autoStylesInStylesDotXml().constEnd(); ++it) + {
+ dbg.space() << "auto style for style.xml:" << *it;
+ const KoGenStyle* s = style(*it);
+ Q_ASSERT(s);
+ Q_ASSERT(s->autoStyleInStylesDotXml());
+ }
+#endif
+ return dbg.space();
+}
Index: libs/odf/KoGenStyle.h
===================================================================
--- libs/odf/KoGenStyle.h (revision 1100893)
+++ libs/odf/KoGenStyle.h (working copy)
@@ -3,6 +3,7 @@
Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2009 Inge Wallin <inge@lysator.liu.se>
Copyright (C) 2010 KO GmbH <jos.van.den.oever@kogmbh.com>
+ Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -35,7 +36,7 @@
/**
* 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.
+ * or created (e.g. on the stack) and given to KoGenStyles::insert().
*
* @author David Faure <faure@kde.org>
*/
@@ -48,68 +49,91 @@
* saving code in all applications.
*/
enum Type {
- StylePageLayout, ///< style:page-layout as in odf 14.3 Page \
Layout
- /* twelve style families
- TODO:
- - rename StyleUser to StyleParagraph
- - rename StyleAuto to StyleParagraphAuto
- - move the 'Auto' to the end for the table style families
- */
- StyleText, ///< style:style from family "text" as in odf \
14.8.1 Text Styles (office:styles)
- StyleTextAuto, ///< style:style from family "text" as in odf \
14.8.1 Text Styles (office:automatic-styles)
- StyleUser, ///< style:style from family "paragraph" as in \
odf 14.1 Style Element (office:styles)
- StyleAuto, ///< style:style from family "paragraph" as in \
odf 14.1 Style Element (office:automatic-styles)
- StyleSection, ///< style:style from family "section" as in \
odf 14.8.3 Section Styles (office:styles)
- StyleSectionAuto, ///< style:style from family "section" as in \
odf 14.8.3 Section Styles (office:automatic-styles)
- StyleRuby, ///< style:style from family "ruby"
- StyleRubyAuto, ///< style:style from family "ruby"
- StyleTable, ///< style:style from family "table" as in \
odf1.2 16.9 Table Formatting Properties (office:style)
- StyleAutoTable, ///< style:style from family "table" as in odf \
15.8 Table Formatting Properties (office:automatic-styles)
- StyleTableColumn, ///< style:style from family "table-column" as \
in odf 15.9 Column Formatting Properties (office:style)
- StyleAutoTableColumn, ///< style:style from family "table-column" as \
in odf 15.9 Column Formatting Properties (office:automatic-styles)
- StyleTableRow, ///< style:style from family "table-row" as in \
odf 15.10 Table Row Formatting Properties (office:style)
- StyleAutoTableRow, ///< style:style from family "table-row" as in \
odf 15.10 Table Row Formatting Properties (office:automatic-styles)
- StyleTableCell, ///< style:style from family "table-cell" as in \
odf 15.11 Table Cell Formatting Properties (office:style)
- StyleAutoTableCell, ///< style:style from family "table-cell" as in \
odf 15.11 Table Cell Formatting Properties (office:automatic-styles)
- StyleGraphic, ///< style:style from family "graphic" as in \
14.13.1 Graphic and Presentation Styles (office:automatic-styles)
- StyleGraphicAuto, ///< style:style from family "graphic" as in \
14.13.1 Graphic and Presentation Styles (office:automatic-styles)
- StylePresentation, ///< style:style from family "presentation" as \
in 14.13.1 Graphic and Presentation Styles (office:automatic-styles)
- StylePresentationAuto, ///< style:style from family "presentation" as \
in 14.13.1 Graphic and Presentation Styles (office:automatic-styles)
- StyleDrawingPage, ///< style:style from family "drawing-page" as \
in odf 14.13.2 Drawing Page Style
- StyleDrawingPageAuto, ///< style:style from family "drawing-page" as \
in odf 14.13.2 Drawing Page Style
- StyleChart, ///< style:style from family "chart"
- StyleChartAuto, ///< style:style from family "chart"
-
- StyleList, ///< text:list-style as in odf 14.10 List Style \
(office:styles)
- StyleListAuto, ///< text:list-style as in odf 14.10 List Style \
(office:automatic-styles)
- StyleNumericNumber, ///< number:number-style as in odf 14.7.1 \
Number Style
- StyleNumericDate, ///< number:date-style as in odf 14.7.4 Date \
Style
- StyleNumericTime, ///< number:time-style as in odf 14.7.5 Time \
Style
- StyleNumericFraction, ///< number:number-style as in odf 14.7.1 \
Number Style
- StyleNumericPercentage, ///< number:percentage-style as in odf 14.7.3 \
Percentage Style
- StyleNumericScientific, ///< number:number-style as in odf 14.7.1 \
Number Style
- StyleNumericCurrency, ///< number:currency-style as in odf 14.7.2 \
Currency Style
- StyleNumericText, ///< number:text-style 14.7.7 Text Style not \
used
- StyleHatch, ///< draw:hatch as in odf 14.14.3 Hatch \
(office:styles)
- StyleStrokeDash, ///< draw:stroke-dash as in odf 14.14.7 Stroke \
Dash (office:styles)
- StyleGradient, ///< draw:gradient as in odf 14.14.1 Gradient \
(office:styles)
- StyleGradientLinear, ///< svg:linearGradient as in odf 14.14.2 SVG \
Gradients (office:styles)
- StyleGradientRadial, ///< svg:radialGradient as in odf 14.14.2 SVG \
Gradients (office:styles)
- StyleGradientConical, ///< koffice:conicalGradient koffice extension \
for conical gradients
- StyleFillImage, ///< draw:fill-image as in odf 14.14.4 Fill \
Image (office:styles)
- StyleNumericBoolean, ///< number:boolean 14.7.6 Boolean Style not \
used
- StyleOpacity, ///< draw:opacity as in odf 14.14.5 Opacity \
Gradient not used
- StyleMarker, ///< draw:marker as in odf 14.14.6 Marker
- StylePresentationPageLayout, ///< style:presentation-page-layout as in odf \
14.15 Presentation Page Layouts + PageLayoutStyle, ///< \
style:page-layout as in odf 14.3 Page Layout + TextStyle, \
///< style:style from family "text" as in odf 14.8.1 Text Styles + \
///< (office:styles) + TextAutoStyle, ///< style:style from \
family "text" as in odf 14.8.1 Text Styles + ///< \
(office:automatic-styles) + ParagraphStyle, ///< style:style from \
family "paragraph" as in odf 14.1 Style Element + \
///< (office:styles) + ParagraphAutoStyle, ///< style:style from \
family "paragraph" as in odf 14.1 Style Element + \
///< (office:automatic-styles) + SectionStyle, ///< \
style:style from family "section" as in odf 14.8.3 Section Styles + \
///< (office:styles) + SectionAutoStyle, ///< style:style from \
family "section" as in odf 14.8.3 Section Styles + \
///< (office:automatic-styles) + RubyStyle, ///< \
style:style from family "ruby" as in odf 14.8.4 Ruby Style + \
///< (office:styles) + RubyAutoStyle, ///< style:style from \
family "ruby" as in odf 14.8.4 Ruby Style + ///< \
(office:automatic-styles) + TableStyle, ///< style:style from \
family "table" as in odf 14.12 Table Formatting + \
///< Properties (office:styles) + TableAutoStyle, ///< \
style:style from family "table" as in odf 14.12 Table Formatting Properties + \
///< (office:automatic-styles) + TableColumnStyle, ///< \
style:style from family "table-column" as in odf 15.9 Column Formatting + \
///< Properties (office:styles) + TableColumnAutoStyle, ///< \
style:style from family "table-column" as in odf 15.9 Column Formatting + \
///< Properties (office:automatic-styles) + TableRowStyle, ///< \
style:style from family "table-row" as in odf 15.10 Table Row Formatting + \
///< Properties (office:styles) + TableRowAutoStyle, ///< \
style:style from family "table-row" as in odf 15.10 Table Row Formatting + \
///< Properties (office:automatic-styles) + TableCellStyle, ///< \
style:style from family "table-cell" as in odf 15.11 Table Cell Formatting + \
///< Properties (office:styles) + TableCellAutoStyle, ///< \
style:style from family "table-cell" as in odf 15.11 Table Cell Formatting + \
///< Properties (office:automatic-styles) + GraphicStyle, ///< \
style:style from family "graphic" as in 14.13.1 Graphic and Presentation + \
///< Styles (office:automatic-styles) + GraphicAutoStyle, ///< \
style:style from family "graphic" as in 14.13.1 Graphic and Presentation + \
///< Styles (office:automatic-styles) + PresentationStyle, ///< \
style:style from family "presentation" as in 14.13.1 Graphic and + \
///< Presentation Styles (office:styles) + PresentationAutoStyle, ///< \
style:style from family "presentation" as in 14.13.1 Graphic and + \
///< Presentation Styles (office:automatic-styles) + DrawingPageStyle, \
///< style:style from family "drawing-page" as in odf 14.13.2 Drawing Page Style + \
///< (office:styles) + DrawingPageAutoStyle, ///< style:style from \
family "drawing-page" as in odf 14.13.2 Drawing Page Style + \
///< (office:automatic-styles) + ChartStyle, ///< \
style:style from family "chart" as in odf 14.16 Chart Styles + \
///< (office:styles) + ChartAutoStyle, ///< style:style from \
family "chart" as in odf 14.16 Chart Styles + \
///< (office:automatic-styles) +
+ ListStyle, ///< text:list-style as in odf 14.10 List Style \
(office:styles) + ListAutoStyle, ///< text:list-style as in odf \
14.10 List Style (office:automatic-styles) + NumericNumberStyle, ///< \
number:number-style as in odf 14.7.1 Number Style + NumericDateStyle, \
///< number:date-style as in odf 14.7.4 Date Style + NumericTimeStyle, \
///< number:time-style as in odf 14.7.5 Time Style + NumericFractionStyle, \
///< number:number-style as in odf 14.7.1 Number Style + \
NumericPercentageStyle, ///< number:percentage-style as in odf 14.7.3 Percentage \
Style + NumericScientificStyle, ///< number:number-style as in odf 14.7.1 \
Number Style + NumericCurrencyStyle, ///< number:currency-style as in \
odf 14.7.2 Currency Style + NumericTextStyle, ///< \
number:text-style 14.7.7 Text Style + ///< @note \
unused + HatchStyle, ///< draw:hatch as in odf 14.14.3 Hatch \
(office:styles) + StrokeDashStyle, ///< draw:stroke-dash as in odf \
14.14.7 Stroke Dash (office:styles) + GradientStyle, ///< \
draw:gradient as in odf 14.14.1 Gradient (office:styles) + \
GradientLinearStyle, ///< svg:linearGradient as in odf 14.14.2 SVG Gradients \
(office:styles) + GradientRadialStyle, ///< svg:radialGradient as in \
odf 14.14.2 SVG Gradients (office:styles) + GradientConicalStyle, ///< \
koffice:conicalGradient koffice extension for conical gradients + \
FillImageStyle, ///< draw:fill-image as in odf 14.14.4 Fill Image \
(office:styles) + NumericBooleanStyle, ///< number:boolean 14.7.6 \
Boolean Style + ///< @note unused
+ OpacityStyle, ///< draw:opacity as in odf 14.14.5 Opacity \
Gradient + ///< @note unused
+ MarkerStyle, ///< draw:marker as in odf 14.14.6 Marker
+ PresentationPageLayoutStyle, ///< style:presentation-page-layout as in odf \
14.15 Presentation Page Layouts // TODO differently
- StyleMaster ///< 14.4 Master Pages
- /// style:default-style as in odf 14.2 Default Styles
- /// 14.5 Table Templates
- /// 14.6 Font Face Declaration
+ MasterPageStyle, ///< style:master-page as in odf 14.4 14.4 \
Master Pages (office:master-styles) + // style:default-style as in odf 14.2 \
Default Styles + // 14.5 Table Templates
+ // 14.6 Font Face Declaration
+ /// @internal @note always update when adding values to this enum
+ LastStyle = MasterPageStyle
};
/**
- * Start the definition of a new style. Its name will be set later by \
KoGenStyles::lookup(), + * Start the definition of a new style. Its name will be \
set later by KoGenStyles::insert(),
* but first you must define its properties and attributes.
*
* @param type this is a hook for the application to categorize styles
@@ -120,7 +144,7 @@
*
* @param parentName If set, name of the parent style from which this one \
inherits.
*/
- explicit KoGenStyle(Type type = StylePageLayout, const char* familyName = 0,
+ explicit KoGenStyle(Type type = PageLayoutStyle, const char* familyName = 0,
const QString& parentName = QString());
~KoGenStyle();
@@ -197,7 +221,7 @@
* or on the type of style (e.g. page-layout -> page-layout-properties).
* (In fact that tag name is the one passed to writeStyle)
*/
- DefaultType = 0,
+ DefaultType,
/// TextType is always text-properties.
TextType,
/// ParagraphType is always paragraph-properties.
@@ -226,7 +250,8 @@
/// For elements that are children of the style itself, not any of the \
properties StyleChildElement,
ChildElement, ///< @internal
- N_NumTypes ///< @internal - warning, adding items here affects binary \
compatibility (size of KoGenStyle) + /// @internal @note always update when \
adding values to this enum + LastPropertyType = ChildElement
};
/// Add a property to the style
@@ -316,16 +341,9 @@
/**
* @return 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... + * but only those that differ from the parent. But note that \
KoGenStyles::insert() can't find this out...
*/
- bool isEmpty() const {
- if (!m_attributes.isEmpty() || ! m_maps.isEmpty())
- return false;
- for (uint i = 0 ; i < N_NumTypes ; ++i)
- if (! m_properties[i].isEmpty())
- return false;
- return true;
- }
+ bool isEmpty() const;
/**
* Write the definition of this style to @p writer, using the OASIS format.
@@ -366,15 +384,15 @@
private:
QString property(const QString& propName, PropertyType type) const {
- QMap<QString, QString>::const_iterator it = \
m_properties[type].find(propName);
- if (it != m_properties[type].end())
+ const QMap<QString, QString>::const_iterator it = \
m_properties[type].constFind(propName); + if (it != \
m_properties[type].constEnd()) return it.value();
return QString();
}
QString attribute(const QString& propName) const {
- QMap<QString, QString>::const_iterator it = m_attributes.find(propName);
- if (it != m_attributes.end())
+ const QMap<QString, QString>::const_iterator it = \
m_attributes.constFind(propName); + if (it != m_attributes.constEnd())
return it.value();
return QString();
}
@@ -393,7 +411,7 @@
QString m_parentName;
/// We use QMaps since they provide automatic sorting on the key (important for \
unicity!) typedef QMap<QString, QString> StyleMap;
- StyleMap m_properties[N_NumTypes];
+ StyleMap m_properties[LastPropertyType+1];
StyleMap m_attributes;
QList<StyleMap> m_maps; // we can't really sort the maps between themselves...
@@ -401,7 +419,7 @@
bool m_defaultStyle;
short m_unused2;
- // For lookup
+ // For insert()
friend class KoGenStyles;
};
_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic