Warning, file /office/calligra/libs/odf/KoGenChanges.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002   Copyright (C) 2008 Pierre Stirnweiss <pierre.stirnweiss_calligra@gadz.org>
0003    Copyright (C) 2010 Thomas Zander <zander@kde.org>
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 "KoGenChanges.h"
0022 #include <KoXmlWriter.h>
0023 #include <KoElementReference.h>
0024 
0025 #include <QList>
0026 #include <QMap>
0027 #include <QString>
0028 
0029 #include <OdfDebug.h>
0030 
0031 class Q_DECL_HIDDEN KoGenChanges::Private
0032 {
0033 public:
0034     Private(KoGenChanges *q)
0035        : q(q)
0036     { }
0037 
0038 
0039     struct NamedChange {
0040         const KoGenChange* change; ///< @note owned by the collection
0041         QString name;
0042     };
0043 
0044     /// style definition -> name
0045     QMap<KoGenChange, QString>  changeMap;
0046 
0047     /// List of styles (used to preserve ordering)
0048     QList<NamedChange> changeArray;
0049 
0050     QMap<KoGenChange, QString> ::iterator insertChange(const KoGenChange &change);
0051 
0052     KoGenChanges *q;
0053 };
0054 
0055 KoGenChanges::KoGenChanges()
0056     : d(new Private(this))
0057 {
0058 }
0059 
0060 KoGenChanges::~KoGenChanges()
0061 {
0062     delete d;
0063 }
0064 
0065 QString KoGenChanges::insert(const KoGenChange& change)
0066 {
0067     QMap<KoGenChange, QString> ::iterator it = d->changeMap.find(change);
0068     if (it == d->changeMap.end()) {
0069         it = d->insertChange(change);
0070     }
0071     return it.value();
0072 }
0073 
0074 QMap<KoGenChange, QString>::iterator KoGenChanges::Private::insertChange(const KoGenChange &change)
0075 {
0076     QString changeName;
0077     switch (change.type()) {
0078     case KoGenChange::InsertChange: changeName = 'I'; break;
0079     case KoGenChange::FormatChange: changeName = 'F'; break;
0080     case KoGenChange::DeleteChange: changeName = 'D'; break;
0081     default:
0082         changeName = 'C';
0083     }
0084     KoElementReference ref(changeName);
0085     changeName = ref.toString();
0086 
0087     QMap<KoGenChange, QString>::iterator it = changeMap.insert(change, changeName);
0088     NamedChange s;
0089     s.change = &it.key();
0090     s.name = changeName;
0091     changeArray.append(s);
0092 
0093     return it;
0094 }
0095 
0096 void KoGenChanges::saveOdfChanges(KoXmlWriter* xmlWriter, bool trackChanges) const
0097 {
0098     QMap<KoGenChange, QString>::const_iterator it = d->changeMap.constBegin();
0099 
0100     if ((it != d->changeMap.constEnd()) && (it.key().changeFormat() == KoGenChange::DELTAXML)) {
0101         xmlWriter->startElement("delta:tracked-changes");
0102     } else {
0103         xmlWriter->startElement("text:tracked-changes");
0104         xmlWriter->addAttribute("text:track-changes", trackChanges);
0105    }
0106 
0107     for (; it != d->changeMap.constEnd() ; ++it) {
0108         KoGenChange change = it.key();
0109         change.writeChange(xmlWriter, it.value());
0110     }
0111 
0112     xmlWriter->endElement(); // text:tracked-changes
0113 }