From: Friedemann Kleint Date: Fri, 15 Nov 2013 12:51:00 +0000 (+0100) Subject: QUiLoader: Provide operators for streaming QUiTranslatableStringValue. X-Git-Tag: accepted/tizen/20131212.181521~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=240f4da9bf2f07392470e8e9a2b720a2b11d9ce0;p=platform%2Fupstream%2Fqttools.git QUiLoader: Provide operators for streaming QUiTranslatableStringValue. When trying to encode mime data in startDrag(), the code hits the internal item data storing the untranslated text attached by QUiLoader and triggers an assert as they cannot be serialized to QDataStream. Add the missing operators. Task-number: QTBUG-34859 Change-Id: I87a0f59fb42772bf08039915bc7418940ca5a80f Reviewed-by: hjk Reviewed-by: Oswald Buddenhagen Reviewed-by: Friedemann Kleint --- diff --git a/src/designer/src/uitools/quiloader.cpp b/src/designer/src/uitools/quiloader.cpp index 84695d6..4542439 100644 --- a/src/designer/src/uitools/quiloader.cpp +++ b/src/designer/src/uitools/quiloader.cpp @@ -50,6 +50,7 @@ #include #include +#include #include #include #include @@ -74,6 +75,22 @@ Q_GLOBAL_STATIC(widget_map, g_widgets) class QUiLoader; class QUiLoaderPrivate; +#ifndef QT_NO_DATASTREAM +// QUiTranslatableStringValue must be streamable since they become part of the QVariant-based +// mime data when dragging items in views with QAbstractItemView::InternalMove. +QDataStream &operator<<(QDataStream &out, const QUiTranslatableStringValue &s) +{ + out << s.comment() << s.value(); + return out; +} + +QDataStream &operator>>(QDataStream &in, QUiTranslatableStringValue &s) +{ + in >> s.m_comment >> s.m_value; + return in; +} +#endif // QT_NO_DATASTREAM + #ifdef QFORMINTERNAL_NAMESPACE namespace QFormInternal { @@ -620,6 +637,13 @@ QUiLoader::QUiLoader(QObject *parent) { Q_D(QUiLoader); +#ifndef QT_NO_DATASTREAM + static int metaTypeId = 0; + if (!metaTypeId) { + metaTypeId = qRegisterMetaType("QUiTranslatableStringValue"); + qRegisterMetaTypeStreamOperators("QUiTranslatableStringValue"); + } +#endif // QT_NO_DATASTREAM d->builder.loader = this; QStringList paths; diff --git a/src/designer/src/uitools/quiloader_p.h b/src/designer/src/uitools/quiloader_p.h index e7cbfb6..c8df5dc 100644 --- a/src/designer/src/uitools/quiloader_p.h +++ b/src/designer/src/uitools/quiloader_p.h @@ -56,6 +56,8 @@ #include #include +QT_FORWARD_DECLARE_CLASS(QDataStream) + // This file is here for use by the form preview in Linguist. If you change anything // here or in the code which uses it, remember to adapt Linguist accordingly. @@ -77,6 +79,8 @@ public: void setComment(const QByteArray &comment) { m_comment = comment; } private: + friend QDataStream &operator>>(QDataStream &in, QUiTranslatableStringValue &s); + QByteArray m_value; QByteArray m_comment; };