QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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 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 && otherFunctor->mVersion == mVersion && mExtent == otherFunctor->mExtent;
53 }
54
55 // marked as deprecated in 5.15, but undeprecated for Qt 6.0. TODO -- remove when we require 6.0
57 QT3D_FUNCTOR( TerrainTextureImageDataGenerator )
59
60 private:
61 QgsRectangle mExtent;
62 QString mDebugText;
63 QImage mImage;
64 int mVersion;
65};
66
67
69
70
71QgsTerrainTextureImage::QgsTerrainTextureImage( const QImage &image, const QgsRectangle &extent, const QString &debugText, Qt3DCore::QNode *parent )
72 : Qt3DRender::QAbstractTextureImage( parent )
73 , mExtent( extent )
74 , mDebugText( debugText )
75 , mImage( image )
76{
77}
78
79Qt3DRender::QTextureImageDataGeneratorPtr QgsTerrainTextureImage::dataGenerator() const
80{
81 return Qt3DRender::QTextureImageDataGeneratorPtr( new TerrainTextureImageDataGenerator( mExtent, mDebugText, mImage, mVersion ) );
82}
83
84void QgsTerrainTextureImage::invalidate()
85{
86 mImage = QImage();
87 mVersion++;
88 notifyDataGeneratorChanged();
89}
90
91void QgsTerrainTextureImage::setImage( const QImage &img )
92{
93 this->mImage = img;
94 mVersion++;
95 notifyDataGeneratorChanged();
96}
97
A rectangle specified with double values.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6643
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6642
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)