QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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#include "moc_qgsterraintextureimage_p.cpp"
18
19#include <Qt3DRender/QTextureImageDataGenerator>
20
22
24
25class TerrainTextureImageDataGenerator : public Qt3DRender::QTextureImageDataGenerator
26{
27 public:
28
29 static QImage placeholderImage()
30 {
31 // simple placeholder image
32 QImage i( 2, 2, QImage::Format_RGB32 );
33 i.setPixelColor( 0, 0, Qt::darkGray );
34 i.setPixelColor( 1, 0, Qt::lightGray );
35 i.setPixelColor( 0, 1, Qt::lightGray );
36 i.setPixelColor( 1, 1, Qt::darkGray );
37 return i;
38 }
39
40 TerrainTextureImageDataGenerator( const QgsRectangle &extent, const QString &debugText, const QImage &img, int version )
41 : mExtent( extent ), mDebugText( debugText ), mImage( img ), mVersion( version ) {}
42
43 Qt3DRender::QTextureImageDataPtr operator()() override
44 {
45 Qt3DRender::QTextureImageDataPtr dataPtr = Qt3DRender::QTextureImageDataPtr::create();
46 dataPtr->setImage( mImage.isNull() ? placeholderImage() : mImage ); // will copy image data to the internal byte array
47 return dataPtr;
48 }
49
50 bool operator ==( const QTextureImageDataGenerator &other ) const override
51 {
52 const TerrainTextureImageDataGenerator *otherFunctor = functor_cast<TerrainTextureImageDataGenerator>( &other );
53 return otherFunctor && otherFunctor->mVersion == mVersion &&
54 mExtent == otherFunctor->mExtent;
55 }
56
57 // marked as deprecated in 5.15, but undeprecated for Qt 6.0. TODO -- remove when we require 6.0
59 QT3D_FUNCTOR( TerrainTextureImageDataGenerator )
61
62 private:
63 QgsRectangle mExtent;
64 QString mDebugText;
65 QImage mImage;
66 int mVersion;
67};
68
69
70
72
73
74QgsTerrainTextureImage::QgsTerrainTextureImage( const QImage &image, const QgsRectangle &extent, const QString &debugText, Qt3DCore::QNode *parent )
75 : Qt3DRender::QAbstractTextureImage( parent )
76 , mExtent( extent )
77 , mDebugText( debugText )
78 , mImage( image )
79{
80}
81
82Qt3DRender::QTextureImageDataGeneratorPtr QgsTerrainTextureImage::dataGenerator() const
83{
84 return Qt3DRender::QTextureImageDataGeneratorPtr( new TerrainTextureImageDataGenerator( mExtent, mDebugText, mImage, mVersion ) );
85}
86
87void QgsTerrainTextureImage::invalidate()
88{
89 mImage = QImage();
90 mVersion++;
91 notifyDataGeneratorChanged();
92}
93
94void QgsTerrainTextureImage::setImage( const QImage &img )
95{
96 this->mImage = img;
97 mVersion++;
98 notifyDataGeneratorChanged();
99}
100
A rectangle specified with double values.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6535
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6534
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)