Fixed the RequestPixmapCallback

This commit is contained in:
Filippo Cucchetto 2018-02-13 21:41:53 +01:00
parent f1dbfba45c
commit 0a9f2242a4
5 changed files with 16 additions and 16 deletions

View File

@ -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);
/// @}

View File

@ -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://<provider_id>/<id>
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

View File

@ -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;
};

View File

@ -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);
}

View File

@ -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<QPixmap*>(pixmap));
delete (static_cast<QPixmap*>(pixmap));
return pixmap_copy;
QPixmap result;
m_pixmap_callback(id.toLatin1().data(), &size->rwidth(), &size->rheight(), size->width(), size->height(), &result);
return result;
}