diff --git a/lib/include/DOtherSide/DOtherSide.h b/lib/include/DOtherSide/DOtherSide.h index 9cabc6b..5673a3b 100644 --- a/lib/include/DOtherSide/DOtherSide.h +++ b/lib/include/DOtherSide/DOtherSide.h @@ -129,7 +129,7 @@ DOS_API void DOS_CALL dos_qqmlapplicationengine_delete(DosQQmlApplicationEngine /// \brief Create a new QQuickImageProvider /// \return A new QQuickImageProvider /// \note The returned QQuickImageProvider should be freed by using dos_qquickimageprovider_delete(DosQQuickImageProvider*) unless the QQuickImageProvider has been bound to a QQmlApplicationEngine -DOS_API DosQQuickImageProvider *DOS_CALL dos_qquickimageprovider_create(PixmapCallback callback); +DOS_API DosQQuickImageProvider *DOS_CALL dos_qquickimageprovider_create(RequestPixmapCallback callback); /// \breif Frees a QQuickImageProvider DOS_API void DOS_CALL dos_qquickimageprovider_delete(DosQQuickImageProvider *vptr); /// @} diff --git a/lib/include/DOtherSide/DOtherSideTypes.h b/lib/include/DOtherSide/DOtherSideTypes.h index ea4a6d0..ae51dc4 100644 --- a/lib/include/DOtherSide/DOtherSideTypes.h +++ b/lib/include/DOtherSide/DOtherSideTypes.h @@ -73,10 +73,10 @@ typedef void DosPixmap; /// \param height pointer to the height of the image /// \param requestedHeight sourceSize.height attribute /// \param requestedWidth sourcesSize.width attribute -/// \param the returned DosPixmap will be deleted by the library itself +/// \param[out] result The result QPixmap. This should be assigned from the binded language /// \note \p id is the trailing part of an image source url for example "image:/// -typedef DosPixmap* (DOS_CALL *PixmapCallback)(const char *id, int *width, int *height, int requestedWidth, int requestedHeight); - +/// \note The \p result arg is an out parameter so it \b shouldn't be deleted. See the dos_qpixmap_assign +typedef void (DOS_CALL *RequestPixmapCallback)(const char *id, int *width, int *height, int requestedWidth, int requestedHeight, DosPixmap* result); /// Called when a property is readed/written or a slot should be executed /// \param self The pointer of QObject in the binded language @@ -96,7 +96,7 @@ typedef void (DOS_CALL *DObjectCallback)(void *self, DosQVariant *slotName, int /// \param index The parent DosQModelIndex /// \param[out] result The rowCount result. This must be deferenced and filled from the binded language /// \note The \p parent QModelIndex is owned by the DOtherSide library thus it \b shouldn't be deleted -/// \note The \p result arg is an out parameter so it should be deleted +/// \note The \p result arg is an out parameter so it \b shouldn't be deleted typedef void (DOS_CALL *RowCountCallback)(void *self, const DosQModelIndex *parent, int *result); /// Called when the QAbstractItemModel::columnCount method must be executed @@ -104,7 +104,7 @@ typedef void (DOS_CALL *RowCountCallback)(void *self, const DosQModelIndex *pare /// \param index The parent DosQModelIndex /// \param[out] result The rowCount result. This must be deferenced and filled from the binded language /// \note The \p parent QModelIndex is owned by the DOtherSide library thus it \b shouldn't be deleted -/// \note The \p result arg is an out parameter so it should be deleted +/// \note The \p result arg is an out parameter so it \b shouldn't be deleted typedef void (DOS_CALL *ColumnCountCallback)(void *self, const DosQModelIndex *parent, int *result); /// Called when the QAbstractItemModel::data method must be executed @@ -112,7 +112,7 @@ typedef void (DOS_CALL *ColumnCountCallback)(void *self, const DosQModelIndex *p /// \param index The DosQModelIndex to which we request the data /// \param[out] result The DosQVariant result. This must be deferenced and filled from the binded language. /// \note The \p index QModelIndex is owned by the DOtherSide library thus it \b shouldn't be deleted -/// \note The \p result arg is an out parameter so it should be deleted +/// \note The \p result arg is an out parameter so it \b shouldn't be deleted typedef void (DOS_CALL *DataCallback)(void *self, const DosQModelIndex *index, int role, DosQVariant *result); /// Called when the QAbstractItemModel::setData method must be executed diff --git a/lib/include/DOtherSide/DosQQuickImageProvider.h b/lib/include/DOtherSide/DosQQuickImageProvider.h index 748f67f..e1ff5b9 100644 --- a/lib/include/DOtherSide/DosQQuickImageProvider.h +++ b/lib/include/DOtherSide/DosQQuickImageProvider.h @@ -12,9 +12,10 @@ class DosImageProvider : public QQuickImageProvider { public: - DosImageProvider(PixmapCallback callback); - QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); + DosImageProvider(RequestPixmapCallback callback); + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; private: - PixmapCallback m_pixmap_callback; + RequestPixmapCallback m_pixmap_callback; }; diff --git a/lib/src/DOtherSide.cpp b/lib/src/DOtherSide.cpp index 442b6e0..10b7d6d 100644 --- a/lib/src/DOtherSide.cpp +++ b/lib/src/DOtherSide.cpp @@ -151,7 +151,7 @@ void dos_qqmlapplicationengine_delete(::DosQQmlApplicationEngine *vptr) } -::DosQQuickImageProvider *dos_qquickimageprovider_create(PixmapCallback callback) +::DosQQuickImageProvider *dos_qquickimageprovider_create(RequestPixmapCallback callback) { return new DosImageProvider(callback); } diff --git a/lib/src/DosQQuickImageProvider.cpp b/lib/src/DosQQuickImageProvider.cpp index 6d21879..2b66996 100644 --- a/lib/src/DosQQuickImageProvider.cpp +++ b/lib/src/DosQQuickImageProvider.cpp @@ -1,14 +1,13 @@ #include "DOtherSide/DosQQuickImageProvider.h" -DosImageProvider::DosImageProvider(PixmapCallback callback) : QQuickImageProvider(QQuickImageProvider::Pixmap), +DosImageProvider::DosImageProvider(RequestPixmapCallback callback) : QQuickImageProvider(QQuickImageProvider::Pixmap), m_pixmap_callback(callback) { } QPixmap DosImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) { - auto pixmap = m_pixmap_callback(id.toLatin1().data(), &size->rwidth(), &size->rheight(), size->width(), size->height()); - auto pixmap_copy = *(static_cast(pixmap)); - delete (static_cast(pixmap)); - return pixmap_copy; + QPixmap result; + m_pixmap_callback(id.toLatin1().data(), &size->rwidth(), &size->rheight(), size->width(), size->height(), &result); + return result; }