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

0001 /*
0002  *  Copyright (c) 2011 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KoElementReference.h"
0021 
0022 #include "KoXmlReader.h"
0023 #include "KoXmlWriter.h"
0024 #include <KoXmlNS.h>
0025 
0026 KoElementReference::KoElementReference()
0027     : d(new KoElementReferenceData())
0028 {
0029     d->xmlid = "id-" + d->xmlid;
0030 }
0031 
0032 KoElementReference::KoElementReference(const QString &prefix)
0033     : d(new KoElementReferenceData)
0034 {
0035     d->xmlid = prefix + "-" + d->xmlid;
0036 }
0037 
0038 KoElementReference::KoElementReference(const QString &prefix, int counter)
0039     : d(new KoElementReferenceData)
0040 {
0041     d->xmlid = QString("%1-%2").arg(prefix).arg(counter);
0042 }
0043 
0044 KoElementReference::KoElementReference(const KoElementReference &other)
0045     : d(other.d)
0046 {
0047 }
0048 
0049 KoElementReference &KoElementReference::operator=(const KoElementReference &rhs)
0050 {
0051     if (this == &rhs) return *this;
0052     d = rhs.d;
0053 
0054     return *this;
0055 }
0056 
0057 bool KoElementReference::operator==(const KoElementReference &other) const
0058 {
0059     return d->xmlid == other.d->xmlid;
0060 }
0061 
0062 bool KoElementReference::operator!=(const KoElementReference &other) const
0063 {
0064     return !(*this == other);
0065 }
0066 
0067 bool KoElementReference::isValid() const
0068 {
0069     return (!d->xmlid.isEmpty());
0070 }
0071 
0072 void KoElementReference::saveOdf(KoXmlWriter *writer, SaveOption saveOptions) const
0073 {
0074     if (d->xmlid.isEmpty()) return;
0075 
0076     writer->addAttribute("xml:id", d->xmlid);
0077 
0078     if (saveOptions & DrawId) {
0079         writer->addAttribute("draw:id", d->xmlid);
0080     }
0081     if (saveOptions & TextId) {
0082         writer->addAttribute("text:id", d->xmlid);
0083     }
0084 }
0085 
0086 QString KoElementReference::toString() const
0087 {
0088     return d->xmlid;
0089 }
0090 
0091 
0092 KoElementReference KoElementReference::loadOdf(const KoXmlElement &element)
0093 {
0094     QString xmlid;
0095 
0096     if (element.hasAttributeNS(KoXmlNS::xml, "id")) {
0097         xmlid = element.attributeNS(KoXmlNS::xml, "id");
0098     }
0099     else if (element.hasAttributeNS(KoXmlNS::draw, "id")) {
0100         xmlid = element.attributeNS(KoXmlNS::draw, "id");
0101     }
0102     else if (element.hasAttributeNS(KoXmlNS::text, "id")) {
0103         xmlid = element.attributeNS(KoXmlNS::text, "id");
0104     }
0105 
0106     d->xmlid = xmlid;
0107 
0108     return *this;
0109 }
0110 
0111 void KoElementReference::invalidate()
0112 {
0113     d->xmlid.clear();
0114 }