File indexing completed on 2024-05-12 16:29:16

0001 /* This file is part of the KDE project
0002   *
0003   * Copyright (C) 2013 Inge Wallin <inge@lysator.liu.se>
0004   * Copyright (C) 2013 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
0005   *
0006   * This library is free software; you can redistribute it and/or
0007   * modify it under the terms of the GNU Library General Public
0008   * License as published by the Free Software Foundation; either
0009   * version 2 of the License, or (at your option) any later version.
0010   *
0011   * This library is distributed in the hope that it will be useful,
0012   * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014   * Library General Public License for more details.
0015   *
0016   * You should have received a copy of the GNU Library General Public License
0017   * along with this library; see the file COPYING.LIB.  If not, write to
0018   * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019   * Boston, MA 02110-1301, USA.
0020   */
0021 
0022 // Own
0023 #include "KoOdfListLevelProperties.h"
0024 
0025 // Qt
0026 #include <QString>
0027 
0028 // odflib
0029 #include <KoXmlStreamReader.h>
0030 #include <KoXmlWriter.h>
0031 
0032 #include "Odf2Debug.h"
0033 
0034 // ----------------------------------------------------------------
0035 //                         private class
0036 
0037 
0038 class Q_DECL_HIDDEN KoOdfListLevelProperties::Private
0039 {
0040 public:
0041     Private()
0042         :hasLabelAlignment(false){};
0043     ~Private() {};
0044 
0045     bool hasLabelAlignment;
0046     AttributeSet propertiesAttributes;  // name, value
0047     AttributeSet labelAlignmentAttributes;  // name, value
0048 };
0049 
0050 
0051 // ----------------------------------------------------------------
0052 
0053 
0054 KoOdfListLevelProperties::KoOdfListLevelProperties()
0055     : KoOdfStyleProperties()
0056     , d(new KoOdfListLevelProperties::Private())
0057 {
0058 }
0059 
0060 KoOdfListLevelProperties::~KoOdfListLevelProperties()
0061 {
0062     delete d;
0063 }
0064 
0065 
0066 void KoOdfListLevelProperties::clear()
0067 {
0068     KoOdfStyleProperties::clear();
0069 }
0070 
0071 
0072 bool KoOdfListLevelProperties::readOdf(KoXmlStreamReader &reader)
0073 {
0074     //FIXME: Handle child element
0075     bool retval = readAttributes(reader);
0076 
0077     KoXmlStreamAttributes attrs = reader.attributes();
0078     foreach (const KoXmlStreamAttribute &attr, attrs) {
0079         d->propertiesAttributes.insert(attr.qualifiedName().toString(), attr.value().toString());
0080     }
0081     debugOdf2 << "level properties attributes:" << d->propertiesAttributes;
0082 
0083     while (reader.readNextStartElement()) {
0084         QString child = reader.qualifiedName().toString();
0085 
0086         // style:list-level-label-alignment just is uesd in this place.
0087         // Save the list-level-label-alignment and list-level-properties in separate Attributeset for saveOdf.
0088         if (child == "style:list-level-label-alignment") {
0089             d->hasLabelAlignment = true;
0090             // FIXME: Should create a class for  this element or not.
0091             retval = readAttributes(reader);
0092 
0093             KoXmlStreamAttributes attrs = reader.attributes();
0094             foreach (const KoXmlStreamAttribute &attr, attrs) {
0095                 d->labelAlignmentAttributes.insert(attr.qualifiedName().toString(), attr.value().toString());
0096             }
0097             debugOdf2 << "Label alignment attributes:" << d->labelAlignmentAttributes;
0098         }
0099     }
0100     reader.skipCurrentElement();
0101     return retval;
0102 }
0103 
0104 bool KoOdfListLevelProperties::saveOdf(const QString &propertySet, KoXmlWriter *writer)
0105 {
0106     Q_UNUSED(propertySet);
0107 
0108     writer->startElement("style:list-level-properties");
0109     ::saveAttributes(d->propertiesAttributes, writer);
0110     if (d->hasLabelAlignment) {
0111         writer->startElement("style:list-level-label-alignment");
0112         ::saveAttributes(d->labelAlignmentAttributes, writer);
0113         writer->endElement();
0114     }
0115     writer->endElement(); // style:text-properties
0116 
0117     return true;
0118 }