Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QObject>
- #include <QImage>
- #include "ImageProvider.h"
- class Item : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QImage getItemPhoto READ getItemPhoto WRITE setItemPhoto NOTIFY photoChanged)
- public:
- // ---- PUBLIC METHODS ----
- //! Sets up unique ID for Item
- explicit Item();
- //! Returns image source path
- QImage getItemPhoto() const { return photo_; }
- //! Sets source path for the image of the Item
- void setItemPhoto(const QImage &imageSource);
- signals:
- // ---- SIGNALS ----
- photoChanged();
- private:
- // ---- PRIVATE METHODS ----
- //! Set id of Item
- void setId(const int &ID);
- private:
- // ---- PRIVATE ATTRIBUTES ---
- QImage photo_;
- QImage heatMap_;
- };
- #include <QObject>
- #include <QImage>
- #include <QQuickImageProvider>
- class ImageProvider : public QObject, QQuickImageProvider
- {
- Q_OBJECT
- public:
- ImageProvider();
- QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
- public slots:
- void setPhoto(const QImage &photo);
- signals:
- void photoChanged();
- private:
- QImage photo_;
- };
- #include "ImageProvider.h"
- ImageProvider::ImageProvider() : QQuickImageProvider(QQuickImageProvider::Image)
- {
- this->blockSignals(false);
- }
- QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
- {
- Q_UNUSED(id)
- QImage res = this->photo_;
- if(res.isNull())
- return QImage();
- if(size)
- {
- *size = res.size();
- }
- if(requestedSize.width() > 0 && requestedSize.height() > 0)
- res = res.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio); //TODO
- return res;
- }
- void ImageProvider::setPhoto(const QImage &photo)
- {
- if(photo_ != photo)
- {
- photo_ = photo;
- emit photoChanged();
- }
- }
- GridView {
- //....
- model:filterModel
- delegate: Image {
- id: item
- //....
- source: item.getItemPhoto //item is role name for Item
- }
- }
Add Comment
Please, Sign In to add comment