File indexing completed on 2024-05-26 16:15:58
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2011 Smit Patel <smitpatel24@gmail.com> 0003 * Copyright (C) 2011 Gopalakrishna Bhat A <gopalakbhat@gmail.com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "ToCBibGeneratorInfo.h" 0022 0023 #include <KoXmlWriter.h> 0024 #include <KoUnit.h> 0025 0026 IndexEntry::IndexEntry(const QString &_styleName, IndexEntry::IndexEntryName _name) 0027 : styleName(_styleName), 0028 name(_name) 0029 { 0030 0031 } 0032 0033 IndexEntry *IndexEntry::clone() 0034 { 0035 IndexEntry *newIndexEntry = new IndexEntry(styleName, name); 0036 return newIndexEntry; 0037 } 0038 0039 IndexEntry::~IndexEntry() 0040 { 0041 0042 } 0043 0044 0045 void IndexEntry::addAttributes(KoXmlWriter* writer) const 0046 { 0047 Q_UNUSED(writer); 0048 } 0049 0050 void IndexEntry::saveOdf(KoXmlWriter* writer) const 0051 { 0052 switch (name) { 0053 case LINK_START: 0054 writer->startElement("text:index-entry-link-start"); 0055 break; 0056 case CHAPTER: 0057 writer->startElement("text:index-entry-chapter"); 0058 break; 0059 case BIBLIOGRAPHY: 0060 writer->startElement("text:index-entry-bibliography"); 0061 break; 0062 case SPAN: 0063 writer->startElement("text:index-entry-span"); 0064 break; 0065 case TEXT: 0066 writer->startElement("text:index-entry-text"); 0067 break; 0068 case TAB_STOP: 0069 writer->startElement("text:index-entry-tab-stop"); 0070 break; 0071 case PAGE_NUMBER: 0072 writer->startElement("text:index-entry-page-number"); 0073 break; 0074 case LINK_END: 0075 writer->startElement("text:index-entry-link-end"); 0076 break; 0077 case UNKNOWN: 0078 break; 0079 } 0080 0081 if (!styleName.isNull()) { 0082 writer->addAttribute("text:style-name", styleName); 0083 } 0084 0085 addAttributes(writer); 0086 writer->endElement(); 0087 } 0088 0089 IndexEntryBibliography::IndexEntryBibliography(const QString &_styleName) 0090 : IndexEntry(_styleName, IndexEntry::BIBLIOGRAPHY) 0091 , dataField(QString()) 0092 { 0093 0094 } 0095 0096 IndexEntry *IndexEntryBibliography::clone() 0097 { 0098 IndexEntryBibliography *newIndexEntry = new IndexEntryBibliography(styleName); 0099 newIndexEntry->dataField = dataField; 0100 return newIndexEntry; 0101 } 0102 0103 void IndexEntryBibliography::addAttributes(KoXmlWriter* writer) const 0104 { 0105 if (!dataField.isNull()) { 0106 writer->addAttribute("text:bibliography-data-field", dataField); 0107 } 0108 } 0109 0110 0111 IndexEntrySpan::IndexEntrySpan(const QString &_styleName): IndexEntry(_styleName, IndexEntry::SPAN) 0112 { 0113 } 0114 0115 IndexEntry *IndexEntrySpan::clone() 0116 { 0117 IndexEntrySpan *newIndexEntry = new IndexEntrySpan(styleName); 0118 newIndexEntry->text = text; 0119 return newIndexEntry; 0120 } 0121 0122 void IndexEntrySpan::addAttributes(KoXmlWriter* writer) const 0123 { 0124 if (!text.isNull() && !text.isEmpty()) { 0125 writer->addTextNode(text); 0126 } 0127 } 0128 0129 IndexEntryTabStop::IndexEntryTabStop(const QString &_styleName): IndexEntry(_styleName, IndexEntry::TAB_STOP) 0130 { 0131 0132 } 0133 0134 IndexEntry *IndexEntryTabStop::clone() 0135 { 0136 IndexEntryTabStop *newIndexEntry = new IndexEntryTabStop(styleName); 0137 newIndexEntry->tab = tab; 0138 newIndexEntry->m_position = m_position; 0139 return newIndexEntry; 0140 } 0141 0142 void IndexEntryTabStop::addAttributes(KoXmlWriter* writer) const 0143 { 0144 writer->addAttribute("style:leader-char",tab.leaderText); 0145 // If the value of this attribute is left, the style:position attribute shall also be present. 0146 // Otherwise, this attribute shall be omitted. 0147 if (tab.type == QTextOption::LeftTab) { 0148 writer->addAttribute("style:type", "left"); 0149 writer->addAttribute("style:position", m_position); 0150 } else { 0151 Q_ASSERT(tab.type == QTextOption::RightTab); 0152 writer->addAttribute("style:type", "right"); 0153 } 0154 } 0155 0156 0157 void IndexEntryTabStop::setPosition(const QString& position) 0158 { 0159 m_position = position; 0160 tab.position = KoUnit::parseValue(position); 0161 } 0162 0163 void BibliographyEntryTemplate::saveOdf(KoXmlWriter* writer) const 0164 { 0165 writer->startElement("text:bibliography-entry-template"); 0166 writer->addAttribute("text:style-name", styleName); 0167 writer->addAttribute("text:bibliography-type", bibliographyType); 0168 foreach(IndexEntry* e,indexEntries) { 0169 e->saveOdf(writer); 0170 } 0171 0172 writer->endElement(); 0173 } 0174 0175 void IndexTitleTemplate::saveOdf(KoXmlWriter* writer) const 0176 { 0177 writer->startElement("text:index-title-template"); 0178 writer->addAttribute("text:style-name", styleName); 0179 if (!text.isEmpty() && !text.isNull()) { 0180 writer->addTextNode(text); 0181 } 0182 writer->endElement(); 0183 } 0184 0185 IndexSourceStyle::IndexSourceStyle() 0186 { 0187 } 0188 0189 IndexSourceStyle::IndexSourceStyle(const IndexSourceStyle& indexSourceStyle) 0190 { 0191 styleName = indexSourceStyle.styleName; 0192 styleId = indexSourceStyle.styleId; 0193 } 0194 0195 void IndexSourceStyle::saveOdf(KoXmlWriter* writer) const 0196 { 0197 writer->startElement("text:index-source-style"); 0198 if (!styleName.isNull()) { 0199 writer->addAttribute("text:style-name",styleName); 0200 } 0201 writer->endElement(); 0202 } 0203 0204 IndexSourceStyles::IndexSourceStyles() 0205 { 0206 } 0207 0208 IndexSourceStyles::IndexSourceStyles(const IndexSourceStyles &indexSourceStyles) 0209 { 0210 outlineLevel = indexSourceStyles.outlineLevel; 0211 0212 foreach (const IndexSourceStyle &style, indexSourceStyles.styles) { 0213 styles.append(style); 0214 } 0215 } 0216 0217 void IndexSourceStyles::saveOdf(KoXmlWriter* writer) const 0218 { 0219 writer->startElement("text:index-source-styles"); 0220 writer->addAttribute("text:outline-level", outlineLevel); 0221 foreach(const IndexSourceStyle &s, styles) { 0222 s.saveOdf(writer); 0223 } 0224 writer->endElement(); 0225 } 0226 0227 IndexEntryPageNumber::IndexEntryPageNumber(const QString &_styleName): IndexEntry(_styleName, IndexEntry::PAGE_NUMBER) 0228 { 0229 0230 } 0231 0232 IndexEntry *IndexEntryPageNumber::clone() 0233 { 0234 IndexEntryPageNumber *newIndexEntry = new IndexEntryPageNumber(styleName); 0235 return newIndexEntry; 0236 } 0237 0238 IndexEntryLinkEnd::IndexEntryLinkEnd(const QString &_styleName): IndexEntry(_styleName, IndexEntry::LINK_END) 0239 { 0240 0241 } 0242 0243 IndexEntry *IndexEntryLinkEnd::clone() 0244 { 0245 IndexEntryLinkEnd *newIndexEntry = new IndexEntryLinkEnd(styleName); 0246 return newIndexEntry; 0247 } 0248 0249 TocEntryTemplate::TocEntryTemplate() 0250 { 0251 } 0252 0253 TocEntryTemplate::TocEntryTemplate(const TocEntryTemplate &entryTemplate) 0254 { 0255 outlineLevel = entryTemplate.outlineLevel; 0256 styleName = entryTemplate.styleName; 0257 styleId = entryTemplate.styleId; 0258 0259 foreach (IndexEntry *entry, entryTemplate.indexEntries) { 0260 indexEntries.append(entry->clone()); 0261 } 0262 } 0263 0264 void TocEntryTemplate::saveOdf(KoXmlWriter* writer) const 0265 { 0266 writer->startElement("text:table-of-content-entry-template"); 0267 writer->addAttribute("text:outline-level", outlineLevel); 0268 writer->addAttribute("text:style-name", styleName); 0269 0270 foreach(IndexEntry* e,indexEntries) { 0271 e->saveOdf(writer); 0272 } 0273 0274 writer->endElement(); 0275 } 0276 0277 IndexEntryText::IndexEntryText(const QString &_styleName): IndexEntry(_styleName,IndexEntry::TEXT) 0278 { 0279 0280 } 0281 0282 IndexEntry *IndexEntryText::clone() 0283 { 0284 IndexEntryText *newIndexEntry = new IndexEntryText(styleName); 0285 return newIndexEntry; 0286 } 0287 0288 IndexEntryLinkStart::IndexEntryLinkStart(const QString &_styleName) 0289 : IndexEntry(_styleName, IndexEntry::LINK_START) 0290 { 0291 0292 } 0293 0294 IndexEntry *IndexEntryLinkStart::clone() 0295 { 0296 return new IndexEntryLinkStart(styleName); 0297 } 0298 0299 0300 IndexEntryChapter::IndexEntryChapter(const QString &_styleName) 0301 : IndexEntry(_styleName, IndexEntry::CHAPTER) 0302 , display(QString()) 0303 , outlineLevel(INVALID_OUTLINE_LEVEL) 0304 { 0305 0306 } 0307 0308 IndexEntry *IndexEntryChapter::clone() 0309 { 0310 IndexEntryChapter *newIndexEntry = new IndexEntryChapter(styleName); 0311 newIndexEntry->outlineLevel = outlineLevel; 0312 newIndexEntry->display = display; 0313 return newIndexEntry; 0314 } 0315 0316 void IndexEntryChapter::addAttributes(KoXmlWriter* writer) const 0317 { 0318 if (!display.isNull()) { 0319 writer->addAttribute("text:display", display); 0320 } 0321 writer->addAttribute("text:outline-level", outlineLevel); 0322 } 0323 0324 BibliographyEntryTemplate::BibliographyEntryTemplate() 0325 { 0326 } 0327 0328 BibliographyEntryTemplate::BibliographyEntryTemplate(const BibliographyEntryTemplate &entryTemplate) 0329 { 0330 styleName = entryTemplate.styleName; 0331 styleId = entryTemplate.styleId; 0332 0333 foreach (IndexEntry *entry, entryTemplate.indexEntries) { 0334 indexEntries.append(entry->clone()); 0335 } 0336 0337 bibliographyType = entryTemplate.bibliographyType; 0338 } 0339