text:id is deprecated
C. Boemann
cbo at boemann.dk
Wed Dec 14 15:12:51 GMT 2011
On Wednesday 14 December 2011 16:06:15 Boudewijn Rempt wrote:
> On Wednesday 14 December 2011 Dec, Boudewijn Rempt wrote:
> > On Friday 02 December 2011 Dec, Jos van den Oever wrote:
> > > After upgrading the calligra source code to the latest version of the
> > > Relax NG schema, a problem became apparent.
> > >
> > > In various places, Calligra uses text:id. In ODF 1.2, text:id has been
> > > deprecated in many places in favor of xml:id.
> >
> > I see that the same has happened to draw:id from your commits. In many
> > places, the id we use for draw:id isn't a unique identifier, but things
> > like "QString("object%1").arg(m_objectIndex)".
> >
> > Moreover, we also use xml-id to mark RDF data, using something like
> > rdfid-27e0f6aa-b85d-4620-a05a-2a4fb2381853, which links back to items in
> > manifest.rdf. The xml:id's for rdf are recreated on every save, and on
> > loading used to link elements to rdf data. The xml:id is kept and used
> > during run-time in KoTextInLineRdf.
> >
> > Previously, xml-id was used _only_ for marking RDF.
> >
> > Since we cannot add more than one xml-id to an element, we should create
> > something that hands out per-element unique rdf id's that do not contain
> > hidden data that calligra apps can interpret, but that we can use to
> > link objects to extra data, like rdf.
> >
> > I'm not sure what that would look like yet. Comments or suggestions for a
> > redesign?
>
> Hm, after discussing with Jos, I think that using this class everywhere
> necessary (for instance, in void KoShapeLoadingContext::addShapeId(KoShape
> * shape, const QString & id), among many other places) would be working
> solution:
>
> #ifndef KOELEMENTREFERENCE_H
> #define KOELEMENTREFERENCE_H
>
> #include <QSharedDataPointer>
> #include <QSharedData>
> #include <QUuid>
>
> class KoXmlWriter;
> class KoXmlElement;
>
> #include "koodf_export.h"
>
> class KoElementReferenceData : public QSharedData
> {
> public:
>
> KoElementReferenceData()
> {
> xmlid = QUuid::createUuid().toString();
> xmlid.remove('{');
> xmlid.remove('}');
> }
>
> KoElementReferenceData(const KoElementReferenceData &other)
>
> : QSharedData(other)
>
> , xmlid(other.xmlid)
> {
> }
>
> ~KoElementReferenceData() {}
>
> QString xmlid;
> };
> /**
> * KoElementReference is used to store unique identifiers for elements in
> an odf document. * Element references are saved as xml:id and optionally
> for compatibility also as draw:id * and text:id.
> *
> * You can use element references wherever you would have used a QString to
> refer to the id * of an object.
> *
> * Element references are implicitly shared, so you can pass them along by
> value. */
> class KOODF_EXPORT KoElementReference
> {
> public:
>
> enum SaveOption {
> XMLID = 0x0,
> DRAWID = 0x1,
> TEXTID = 0x2
> };
> Q_DECLARE_FLAGS(SaveOptions, SaveOption)
>
> KoElementReference();
> KoElementReference(const QString &xmlid);
> KoElementReference(const KoElementReference &other);
> KoElementReference &operator=(const KoElementReference &rhs);
> bool operator==(const KoElementReference &other);
> bool operator!=(const KoElementReference &other);
>
> /**
> * @return true if the xmlid is valid, i.e., not null
> */
> bool isValid() const;
>
> /**
> * @brief loadOdf creates a new KoElementReference from the given
> element. If the element * does not have an xml:id, draw:id or text:id
> attribute, and invalid element reference * is returned.
> * @param element the element that may contain xml:id, text:id or
> draw:id. xml:id has * priority.
> * @return a new element reference
> */
> static KoElementReference loadOdf(const KoXmlElement &element);
>
> /**
> * @brief saveOdf saves this element reference into the currently open
> element in the xml writer. * @param writer the writer we save to
> * @param saveOptions determins which attributes we save.
> */
> void saveOdf(KoXmlWriter *writer, SaveOptions saveOptions) const;
>
>
> private:
>
>
>
> QSharedDataPointer<KoElementReferenceData> d;
>
> };
>
> Q_DECLARE_OPERATORS_FOR_FLAGS(KoElementReference::SaveOptions)
>
> #endif // KOELEMENTREFERENCE_H
all well, except how do the animation framework get the related qobject from
this?
More information about the calligra-devel
mailing list