QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsterraintextureimage_p.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsterraintextureimage_p.cpp
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include <Qt3DRender/QTextureImageDataGenerator>
19
21
23
24class TerrainTextureImageDataGenerator : public Qt3DRender::QTextureImageDataGenerator
25{
26 public:
27
28 static QImage placeholderImage()
29 {
30 // simple placeholder image
31 QImage i( 2, 2, QImage::Format_RGB32 );
32 i.setPixelColor( 0, 0, Qt::darkGray );
33 i.setPixelColor( 1, 0, Qt::lightGray );
34 i.setPixelColor( 0, 1, Qt::lightGray );
35 i.setPixelColor( 1, 1, Qt::darkGray );
36 return i;
37 }
38
39 TerrainTextureImageDataGenerator( const QgsRectangle &extent, const QString &debugText, const QImage &img, int version )
40 : mExtent( extent ), mDebugText( debugText ), mImage( img ), mVersion( version ) {}
41
42 Qt3DRender::QTextureImageDataPtr operator()() override
43 {
44 Qt3DRender::QTextureImageDataPtr dataPtr = Qt3DRender::QTextureImageDataPtr::create();
45 dataPtr->setImage( mImage.isNull() ? placeholderImage() : mImage ); // will copy image data to the internal byte array
46 return dataPtr;
47 }
48
49 bool operator ==( const QTextureImageDataGenerator &other ) const override
50 {
51 const TerrainTextureImageDataGenerator *otherFunctor = functor_cast<TerrainTextureImageDataGenerator>( &other );
52 return otherFunctor != nullptr && otherFunctor->mVersion == mVersion &&
53 mExtent == otherFunctor->mExtent;
54 }
55
56 // marked as deprecated in 5.15, but undeprecated for Qt 6.0. TODO -- remove when we require 6.0
58 QT3D_FUNCTOR( TerrainTextureImageDataGenerator )
60
61 private:
62 QgsRectangle mExtent;
63 QString mDebugText;
64 QImage mImage;
65 int mVersion;
66};
67
68
69
71
72
73QgsTerrainTextureImage::QgsTerrainTextureImage( const QImage &image, const QgsRectangle &extent, const QString &debugText, Qt3DCore::QNode *parent )
74 : Qt3DRender::QAbstractTextureImage( parent )
75 , mExtent( extent )
76 , mDebugText( debugText )
77 , mImage( image )
78{
79}
80
81Qt3DRender::QTextureImageDataGeneratorPtr QgsTerrainTextureImage::dataGenerator() const
82{
83 return Qt3DRender::QTextureImageDataGeneratorPtr( new TerrainTextureImageDataGenerator( mExtent, mDebugText, mImage, mVersion ) );
84}
85
86void QgsTerrainTextureImage::invalidate()
87{
88 mImage = QImage();
89 mVersion++;
90 notifyDataGeneratorChanged();
91}
92
93void QgsTerrainTextureImage::setImage( const QImage &img )
94{
95 this->mImage = img;
96 mVersion++;
97 notifyDataGeneratorChanged();
98}
99
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:4572
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:4571
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)