From e72060407ce26f83421f09cb32516bf841681c02 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 2 Dec 2021 20:30:19 +0100 Subject: [PATCH] WIP: enabling QLatin1String, QStringView, QByteArrayView for GSI --- scripts/mkqtdecl6/mkqtdecl.conf | 7 +- src/gsi/gsi/gsiSerialisation.h | 230 ++++++++++++++++++++++++++++++++ src/gsi/gsi/gsiTypes.h | 30 +++++ 3 files changed, 265 insertions(+), 2 deletions(-) diff --git a/scripts/mkqtdecl6/mkqtdecl.conf b/scripts/mkqtdecl6/mkqtdecl.conf index 0706912dd..43137ae86 100644 --- a/scripts/mkqtdecl6/mkqtdecl.conf +++ b/scripts/mkqtdecl6/mkqtdecl.conf @@ -309,6 +309,7 @@ drop_class "QWeakPointer" drop_enum_const "QEvent", /CocoaRequestModal/ # not available on WIN +drop_method "QDeadlineTimer", /QDeadlineTimer::_q_data/ # internal (@@@ TODO: QDealineTimer is present twice?) drop_method "QObject", /QObject::bindingStorage/ # no QBindingStorage drop_method "QPluginLoader", /QPluginLoader::staticPlugins/ # no QStaticPlugin drop_method "QKeyCombination", /QKeyCombination::operator<\(/ # deleted @@ -444,8 +445,8 @@ drop_method "", /::operator\s*==\(const\s+QVariant\s*&\w+,\s*const\s+QVariantCom drop_method "", /::operator\s*!=\(const\s+QVariant\s*&\w+,\s*const\s+QVariantComparisonHelper/ # requires QVariantComparisonHelper drop_method "QByteArrayMatcher", /QByteArrayMatcher::indexIn\(const\s+QByteArray/ # clashes with const char * variant drop_method "QRegion", /QRegion::setRects/ # gets a new implementation -drop_method "QRegion", /QRegion::crbegin/ # iterator not available -drop_method "QRegion", /QRegion::crend/ # iterator not available +drop_method "QRegion", /QRegion::c?rbegin/ # iterator not available +drop_method "QRegion", /QRegion::c?rend/ # iterator not available drop_method "QTimer", /static\s+void\s+QTimer::singleShot\(/ # requires slots, alternative impl? drop_method "QDebug", /QDebug::operator\s*<<\((?!const\s+QString\s*&)/ # don't map the others right now - too many (TODO: how to map?) drop_method "", /::operator\s*<<\(QDebug\s*\w*\s*,\s*(?!const\s+QString\s*&)/ # don't map the others right now - too many (TODO: how to map?) @@ -836,6 +837,8 @@ drop_method "QTextDocument", /QTextDocument::resourceProvider/ # needs std::func drop_method "QTextDocument", /QTextDocument::setResourceProvider/ # needs std::function drop_method "QTextDocument", /QTextDocument::defaultResourceProvider/ # needs std::function drop_method "QTextDocument", /QTextDocument::setDefaultResourceProvider/ # needs std::function +drop_method "QLabel", /QLabel::resourceProvider/ # needs std::function +drop_method "QLabel", /QLabel::setResourceProvider/ # needs std::function drop_method "QAccessibleInterface", /QAccessibleInterface::editableTextInterface/ # requires QAccessibleEditableTextInterface which is not available drop_method "QAccessibleInterface", /QAccessibleInterface::tableInterface/ # requires QAccessibleTableInterface which is not available drop_method "QAccessibleInterface", /QAccessibleInterface::textInterface/ # requires QAccessibleTextInterface which is not available diff --git a/src/gsi/gsi/gsiSerialisation.h b/src/gsi/gsi/gsiSerialisation.h index 69c3aa056..7e2be6a51 100644 --- a/src/gsi/gsi/gsiSerialisation.h +++ b/src/gsi/gsi/gsiSerialisation.h @@ -895,6 +895,158 @@ private: mutable QByteArray m_s_utf8; }; +#if QT_VERSION >= 0x60000 + +/** + * @brief Specialization for QString + */ +template <> +class GSI_PUBLIC StringAdaptorImpl + : public StringAdaptor +{ +public: + StringAdaptorImpl (QStringView *s) + : mp_s (s), m_is_const (false) + { + // .. nothing yet .. + } + + StringAdaptorImpl (const QStringView *s) + : mp_s (const_cast (s)), m_is_const (true) + { + // .. nothing yet .. + } + + StringAdaptorImpl (const QStringView &s) + : m_is_const (false), m_s (s) + { + mp_s = &m_s; + } + + StringAdaptorImpl () + : m_is_const (false) + { + mp_s = &m_s; + } + + virtual ~StringAdaptorImpl () + { + // .. nothing yet .. + } + + virtual size_t size () const + { + return mp_s->toUtf8 ().size (); + } + + virtual const char *c_str () const + { + m_s_utf8 = mp_s->toUtf8 (); + return m_s_utf8.constData (); + } + + virtual void set (const char *c_str, size_t s, tl::Heap &heap) + { + if (! m_is_const) { + QString *hstr = heap.create (); + *hstr = QString::fromUtf8 (c_str, int (s)); + *mp_s = QStringView (hstr->constData (), hstr->size ()); + } + } + + virtual void copy_to (AdaptorBase *target, tl::Heap &heap) const + { + StringAdaptorImpl *s = dynamic_cast *>(target); + if (s) { + QString *hstr = heap.create (); + *hstr = mp_s->toString (); + *s->mp_s = QStringView (hstr->constData (), hstr->size ()); + } else { + StringAdaptor::copy_to (target, heap); + } + } + +private: + QStringView *mp_s; + bool m_is_const; + QStringView m_s; + mutable QByteArray m_s_utf8; +}; + +/** + * @brief Specialization for QLatin1String + */ +template <> +class GSI_PUBLIC StringAdaptorImpl + : public StringAdaptor +{ +public: + StringAdaptorImpl (QLatin1String *s) + : mp_s (s), m_is_const (false) + { + // .. nothing yet .. + } + + StringAdaptorImpl (const QLatin1String *s) + : mp_s (const_cast (s)), m_is_const (true) + { + // .. nothing yet .. + } + + StringAdaptorImpl (const QLatin1String &s) + : m_is_const (false), m_s (s) + { + mp_s = &m_s; + } + + StringAdaptorImpl () + : m_is_const (false) + { + mp_s = &m_s; + } + + virtual ~StringAdaptorImpl () + { + // .. nothing yet .. + } + + virtual size_t size () const + { + return mp_s->toString ().toUtf8 ().size (); + } + + virtual const char *c_str () const + { + m_s_utf8 = mp_s->toString ().toUtf8 (); + return m_s_utf8.constData (); + } + + virtual void set (const char *c_str, size_t s, tl::Heap &) + { + if (! m_is_const) { + *mp_s = QLatin1String (QString::fromUtf8 (c_str, int (s)).toLatin1 ()); + } + } + + virtual void copy_to (AdaptorBase *target, tl::Heap &heap) const + { + StringAdaptorImpl *s = dynamic_cast *>(target); + if (s) { + *s->mp_s = *mp_s; + } else { + StringAdaptor::copy_to (target, heap); + } + } + +private: + QLatin1String *mp_s; + bool m_is_const; + QLatin1String m_s; + mutable QByteArray m_s_utf8; +}; + +#endif + #endif /** @@ -1211,6 +1363,84 @@ private: QByteArray m_s; }; +#if QT_VERSION > 0x60000 + +/** + * @brief Specialization for QByteArray + */ +template <> +class GSI_PUBLIC ByteArrayAdaptorImpl + : public ByteArrayAdaptor +{ +public: + ByteArrayAdaptorImpl (QByteArrayView *s) + : mp_s (s), m_is_const (false) + { + // .. nothing yet .. + } + + ByteArrayAdaptorImpl (const QByteArrayView *s) + : mp_s (const_cast (s)), m_is_const (true) + { + // .. nothing yet .. + } + + ByteArrayAdaptorImpl (const QByteArrayView &s) + : m_is_const (false), m_s (s) + { + mp_s = &m_s; + } + + ByteArrayAdaptorImpl () + : m_is_const (false) + { + mp_s = &m_s; + } + + virtual ~ByteArrayAdaptorImpl () + { + // .. nothing yet .. + } + + virtual size_t size () const + { + return mp_s->size (); + } + + virtual const char *c_str () const + { + return mp_s->constData (); + } + + virtual void set (const char *c_str, size_t s, tl::Heap &heap) + { + if (! m_is_const) { + QByteArray *str = heap.create (); + *str = QByteArray (c_str, s); + *mp_s = QByteArrayView (str->constData (), str->size ()); + } + } + + virtual void copy_to (AdaptorBase *target, tl::Heap &heap) const + { + ByteArrayAdaptorImpl *s = dynamic_cast *>(target); + if (s) { + QByteArray *str = heap.create (); + *str = QByteArray (mp_s->constData (), mp_s->size ()); + *s->mp_s = *str; + } else { + ByteArrayAdaptor::copy_to (target, heap); + } + } + +private: + QByteArrayView *mp_s; + bool m_is_const; + QByteArrayView m_s; +}; + +#endif + #endif /** diff --git a/src/gsi/gsi/gsiTypes.h b/src/gsi/gsi/gsiTypes.h index 1cfde544b..ec63385e1 100644 --- a/src/gsi/gsi/gsiTypes.h +++ b/src/gsi/gsi/gsiTypes.h @@ -46,6 +46,11 @@ #include #include #include +# if QT_VERSION >= 0x60000 +# include +# include +# include +# endif #endif namespace tl @@ -440,6 +445,11 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits > : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if QT_VERSION >= 0x60000 +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +#endif #endif template <> struct type_traits : generic_type_traits { }; @@ -473,6 +483,11 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits &> : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if QT_VERSION >= 0x60000 +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +#endif #endif template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -503,6 +518,11 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits &> : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if QT_VERSION >= 0x60000 +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +#endif #endif template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -534,6 +554,11 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits *> : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if QT_VERSION >= 0x60000 +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +#endif #endif template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; @@ -565,6 +590,11 @@ template <> struct type_traits : generic_type_trait template <> struct type_traits : generic_type_traits { }; template <> struct type_traits *> : generic_type_traits { }; template <> struct type_traits : generic_type_traits { }; +#if QT_VERSION >= 0x60000 +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +template <> struct type_traits : generic_type_traits { }; +#endif #endif template <> struct type_traits : generic_type_traits { }; template <> struct type_traits : generic_type_traits { };