[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bcalligra=5D_libs/kotext=3A_Reduce_the_number_of_chi?=
From: Casper Boemann <cbo () boemann ! dk>
Date: 2011-05-16 9:13:34
Message-ID: 20110516091334.A7B3EA60DE () git ! kde ! org
[Download RAW message or body]
Git commit 4b13abe61bfc617feed72f8fa0207ae33a208aec by Casper Boemann.
Committed on 14/05/2011 at 19:29.
Pushed by boemann into branch 'master'.
Reduce the number of child classes
M +31 -45 libs/kotext/KoTableOfContentsGeneratorInfo.cpp
M +17 -37 libs/kotext/KoTableOfContentsGeneratorInfo.h
M +2 -2 libs/kotext/opendocument/KoTextLoader.cpp
M +20 -23 libs/kotext/opendocument/KoTextWriter.cpp
http://commits.kde.org/calligra/4b13abe61bfc617feed72f8fa0207ae33a208aec
diff --git a/libs/kotext/KoTableOfContentsGeneratorInfo.cpp \
b/libs/kotext/KoTableOfContentsGeneratorInfo.cpp index e678cfb..4aab0be 100644
--- a/libs/kotext/KoTableOfContentsGeneratorInfo.cpp
+++ b/libs/kotext/KoTableOfContentsGeneratorInfo.cpp
@@ -215,36 +215,6 @@ void IndexSourceStyles::saveOdf(KoXmlWriter* writer) const
}
-void TableOfContentSource::saveOdf(KoXmlWriter* writer) const
-{
- writer->startElement("text:table-of-content-source");
- writer->addAttribute("text:index-scope", indexScope);
- writer->addAttribute("text:outline-level", outlineLevel);
- writer->addAttribute("text:relative-tab-stop-position", \
relativeTabStopPosition);
- writer->addAttribute("text:use-index-marks", useIndexMarks);
- writer->addAttribute("text:use-index-source-styles", useIndexSourceStyles);
- writer->addAttribute("text:use-outline-level", useOutlineLevel);
-
- indexTitleTemplate.saveOdf(writer);
-
- foreach (const TocEntryTemplate &entry, entryTemplate) {
- entry.saveOdf(writer);
- }
-
- foreach (const IndexSourceStyles &sourceStyle, indexSourceStyles) {
- sourceStyle.saveOdf(writer);
- }
-
- writer->endElement(); // text:table-of-content-source
-}
-
-
-TableOfContent* KoTableOfContentsGeneratorInfo::tableOfContentData() const
-{
- return m_toc;
-}
-
-
int KoTableOfContentsGeneratorInfo::styleNameToStyleId(KoTextSharedLoadingData \
*sharedLoadingData, QString styleName) {
KoParagraphStyle * style = sharedLoadingData->paragraphStyle(styleName, true);
@@ -258,15 +228,13 @@ int \
KoTableOfContentsGeneratorInfo::styleNameToStyleId(KoTextSharedLoadingData *
KoTableOfContentsGeneratorInfo::KoTableOfContentsGeneratorInfo()
{
- m_toc = new TableOfContent;
}
KoTableOfContentsGeneratorInfo::~KoTableOfContentsGeneratorInfo()
{
- foreach (const TocEntryTemplate &entryTemplate, m_toc->tocSource.entryTemplate) \
{ + foreach (const TocEntryTemplate &entryTemplate, m_entryTemplate) {
qDeleteAll(entryTemplate.indexEntries);
}
- delete m_toc;
}
@@ -274,12 +242,12 @@ void \
KoTableOfContentsGeneratorInfo::loadOdf(KoTextSharedLoadingData *sharedLoad {
Q_ASSERT(element.localName() == "table-of-content-source" && \
element.namespaceURI() == KoXmlNS::text);
- m_toc->tocSource.indexScope = element.attribute("index-scope", "document"); // \
enum {document, chapter}
- m_toc->tocSource.outlineLevel = element.attribute("outline-level").toInt();
- m_toc->tocSource.relativeTabStopPosition = \
element.attribute("relative-tab-stop-position","true") == "true";
- m_toc->tocSource.useIndexMarks = element.attribute("use-index-marks","true") == \
"true";
- m_toc->tocSource.useIndexSourceStyles = \
element.attribute("use-index-source-styles","true") == "true";
- m_toc->tocSource.useOutlineLevel = element.attribute("use-outline-level","true") \
== "true"; + m_indexScope = element.attribute("index-scope", "document"); // enum \
{document, chapter} + m_outlineLevel = element.attribute("outline-level").toInt();
+ m_relativeTabStopPosition = \
element.attribute("relative-tab-stop-position","true") == "true"; + \
m_useIndexMarks = element.attribute("use-index-marks","true") == "true"; + \
m_useIndexSourceStyles = element.attribute("use-index-source-styles","true") == \
"true"; + m_useOutlineLevel = element.attribute("use-outline-level","true") == \
"true";
// three other children to visit
KoXmlElement p;
@@ -290,9 +258,9 @@ void \
KoTableOfContentsGeneratorInfo::loadOdf(KoTextSharedLoadingData *sharedLoad
// first child
if (p.localName() == "index-title-template") {
- m_toc->tocSource.indexTitleTemplate.styleName = \
p.attribute("style-name");
- m_toc->tocSource.indexTitleTemplate.styleId = \
styleNameToStyleId(sharedLoadingData, \
m_toc->tocSource.indexTitleTemplate.styleName);
- m_toc->tocSource.indexTitleTemplate.text = p.text();
+ m_indexTitleTemplate.styleName = p.attribute("style-name");
+ m_indexTitleTemplate.styleId = styleNameToStyleId(sharedLoadingData, \
m_indexTitleTemplate.styleName); + m_indexTitleTemplate.text = p.text();
// second child
} else if (p.localName() == "table-of-content-entry-template") {
TocEntryTemplate tocEntryTemplate;
@@ -352,7 +320,7 @@ void \
KoTableOfContentsGeneratorInfo::loadOdf(KoTextSharedLoadingData \
*sharedLoad
\
tocEntryTemplate.indexEntries.append(static_cast<IndexEntry*>(link)); }
}
- m_toc->tocSource.entryTemplate.append(tocEntryTemplate);
+ m_entryTemplate.append(tocEntryTemplate);
// third child
} else if (p.localName() == "index-source-styles" && p.namespaceURI() == \
KoXmlNS::text) { @@ -368,7 +336,7 @@ void \
KoTableOfContentsGeneratorInfo::loadOdf(KoTextSharedLoadingData *sharedLoad \
indexStyles.styles.append(indexStyle); }
}
- m_toc->tocSource.indexSourceStyles.append(indexStyles);
+ m_indexSourceStyles.append(indexStyles);
}
}// forEachElement
}
@@ -376,5 +344,23 @@ void \
KoTableOfContentsGeneratorInfo::loadOdf(KoTextSharedLoadingData *sharedLoad
void KoTableOfContentsGeneratorInfo::saveOdf(KoXmlWriter * writer) const
{
- m_toc->tocSource.saveOdf(writer);
+ writer->startElement("text:table-of-content-source");
+ writer->addAttribute("text:index-scope", m_indexScope);
+ writer->addAttribute("text:outline-level", m_outlineLevel);
+ writer->addAttribute("text:relative-tab-stop-position", \
m_relativeTabStopPosition); + writer->addAttribute("text:use-index-marks", \
m_useIndexMarks); + writer->addAttribute("text:use-index-source-styles", \
m_useIndexSourceStyles); + writer->addAttribute("text:use-outline-level", \
m_useOutlineLevel); +
+ m_indexTitleTemplate.saveOdf(writer);
+
+ foreach (const TocEntryTemplate &entry, m_entryTemplate) {
+ entry.saveOdf(writer);
+ }
+
+ foreach (const IndexSourceStyles &sourceStyle, m_indexSourceStyles) {
+ sourceStyle.saveOdf(writer);
+ }
+
+ writer->endElement(); // text:table-of-content-source
}
diff --git a/libs/kotext/KoTableOfContentsGeneratorInfo.h \
b/libs/kotext/KoTableOfContentsGeneratorInfo.h index 24ba33f..0a6a65e 100644
--- a/libs/kotext/KoTableOfContentsGeneratorInfo.h
+++ b/libs/kotext/KoTableOfContentsGeneratorInfo.h
@@ -170,58 +170,38 @@ public:
QList<IndexSourceStyle> styles;
};
-
-class TableOfContentSource
+class KOTEXT_EXPORT KoTableOfContentsGeneratorInfo
{
public:
- void saveOdf(KoXmlWriter * writer) const;
-
- QString indexScope; // enum {document, chapter}
- int outlineLevel;
- bool relativeTabStopPosition;
- bool useIndexMarks;
- bool useIndexSourceStyles;
- bool useOutlineLevel;
-
- IndexTitleTemplate indexTitleTemplate;
- QList<TocEntryTemplate> entryTemplate; // N-entries
- QList<IndexSourceStyles> indexSourceStyles;
-};
-
-
-class TableOfContent
-{
+ KoTableOfContentsGeneratorInfo();
+ ~KoTableOfContentsGeneratorInfo();
+ void loadOdf(KoTextSharedLoadingData *sharedLoadingData, const KoXmlElement \
&element); + void saveOdf(KoXmlWriter *writer) const;
-public:
- QString name;
- QString styleName;
+ QString m_name;
+ QString m_styleName;
// TODO: add support for those according ODF v1.2
// text: protected
// text: protection-key
// text:protection-key-digest-algorithm
// xml:id
- TableOfContentSource tocSource;
-};
-
-
-class KOTEXT_EXPORT KoTableOfContentsGeneratorInfo
-{
-
-public:
- KoTableOfContentsGeneratorInfo();
- ~KoTableOfContentsGeneratorInfo();
- void loadOdf(KoTextSharedLoadingData *sharedLoadingData, const KoXmlElement \
&element);
- void saveOdf(KoXmlWriter *writer) const;
+ QString m_indexScope; // enum {document, chapter}
+ int m_outlineLevel;
+ bool m_relativeTabStopPosition;
+ bool m_useIndexMarks;
+ bool m_useIndexSourceStyles;
+ bool m_useOutlineLevel;
- TableOfContent *tableOfContentData() const;
+ IndexTitleTemplate m_indexTitleTemplate;
+ QList<TocEntryTemplate> m_entryTemplate; // N-entries
+ QList<IndexSourceStyles> m_indexSourceStyles;
private:
int styleNameToStyleId(KoTextSharedLoadingData *sharedLoadingData, QString \
styleName);
- TableOfContent *m_toc;
};
-Q_DECLARE_METATYPE(KoTableOfContentsGeneratorInfo*)
+Q_DECLARE_METATYPE(KoTableOfContentsGeneratorInfo *)
#endif
diff --git a/libs/kotext/opendocument/KoTextLoader.cpp \
b/libs/kotext/opendocument/KoTextLoader.cpp index 04f31ec..6ceb167 100644
--- a/libs/kotext/opendocument/KoTextLoader.cpp
+++ b/libs/kotext/opendocument/KoTextLoader.cpp
@@ -2276,8 +2276,8 @@ void KoTextLoader::loadTableOfContents(const KoXmlElement \
&element, QTextCursor // for "meta-information" about the TOC we use this class
KoTableOfContentsGeneratorInfo *info = new KoTableOfContentsGeneratorInfo();
- info->tableOfContentData()->name = element.attribute("name");
- info->tableOfContentData()->styleName = element.attribute("style-name");
+ info->m_name = element.attribute("name");
+ info->m_styleName = element.attribute("style-name");
KoXmlElement e;
forEachElement(e, element) {
diff --git a/libs/kotext/opendocument/KoTextWriter.cpp \
b/libs/kotext/opendocument/KoTextWriter.cpp index fc5a011..426f3a2 100644
--- a/libs/kotext/opendocument/KoTextWriter.cpp
+++ b/libs/kotext/opendocument/KoTextWriter.cpp
@@ -1430,31 +1430,28 @@ void KoTextWriter::Private::saveTable(QTextTable *table, \
QHash<QTextList *, QStr
void KoTextWriter::Private::saveTableOfContents(QTextDocument *document, int from, \
int to, QHash<QTextList *, QString> &listStyles, QTextTable *currentTable, QTextFrame \
*toc) {
-
writer->startElement("text:table-of-content");
- KoTableOfContentsGeneratorInfo *info = \
toc->frameFormat().property(KoText::TableOfContentsData).value<KoTableOfContentsGeneratorInfo*>();
- if (!info->tableOfContentData()->styleName.isNull())
- {
- writer->addAttribute("text:style-name",info->tableOfContentData()->styleName);
- }
- writer->addAttribute("text:name",info->tableOfContentData()->name);
-
- info->saveOdf(writer);
+ KoTableOfContentsGeneratorInfo *info = \
toc->frameFormat().property(KoText::TableOfContentsData).value<KoTableOfContentsGeneratorInfo*>();
+ if (!info->m_styleName.isNull()) {
+ writer->addAttribute("text:style-name",info->m_styleName);
+ }
+ writer->addAttribute("text:name",info->m_name);
- writer->startElement("text:index-body");
- // write the title (one p block)
- QTextCursor localBlock = toc->firstCursorPosition();
- localBlock.movePosition(QTextCursor::NextBlock);
- int endTitle = localBlock.position();
- writer->startElement("text:index-title");
- writeBlocks(document, from, endTitle, listStyles, currentTable, \
toc);
- writer->endElement(); // text:index-title
- from = endTitle;
+ info->saveOdf(writer);
- QTextBlock block = toc->lastCursorPosition().block();
- writeBlocks(document, from, to, listStyles, currentTable, toc);
+ writer->startElement("text:index-body");
+ // write the title (one p block)
+ QTextCursor localBlock = toc->firstCursorPosition();
+ localBlock.movePosition(QTextCursor::NextBlock);
+ int endTitle = localBlock.position();
+ writer->startElement("text:index-title");
+ writeBlocks(document, from, endTitle, listStyles, currentTable, toc);
+ writer->endElement(); // text:index-title
+ from = endTitle;
+ QTextBlock block = toc->lastCursorPosition().block();
+ writeBlocks(document, from, to, listStyles, currentTable, toc);
writer->endElement(); // table:index-body
writer->endElement(); // table:table-of-content
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic