34 for (
int i = 0; i < pipe.
size(); i++ )
39 Role role = interfaceRole( clone );
40 QgsDebugMsgLevel( QStringLiteral(
"cloned interface with role %1" ).arg( role ), 4 );
43 clone->setInput( mInterfaces.at( i - 1 ) );
45 mInterfaces.append( clone );
48 mRoleMap.insert( role, i );
55 const auto constMInterfaces = mInterfaces;
62 bool QgsRasterPipe::connect( QVector<QgsRasterInterface *> interfaces )
65 for (
int i = 1; i < interfaces.size(); i++ )
67 if ( ! interfaces[i]->setInput( interfaces[i - 1] ) )
72 QgsDebugMsg( QStringLiteral(
"cannot connect %1 to %2" ).arg(
typeid( a ).name(),
typeid( b ).name() ) );
82 QgsDebugMsgLevel( QStringLiteral(
"insert %1 at %2" ).arg(
typeid( *interface ).name() ).arg( idx ), 4 );
83 if ( idx > mInterfaces.size() )
85 idx = mInterfaces.size();
89 QVector<QgsRasterInterface *> interfaces = mInterfaces;
91 interfaces.insert( idx, interface );
93 if ( connect( interfaces ) )
96 mInterfaces.insert( idx, interface );
97 setRole( interface, idx );
102 connect( mInterfaces );
108 if ( !interface )
return false;
110 QgsDebugMsgLevel( QStringLiteral(
"replace by %1 at %2" ).arg(
typeid( *interface ).name() ).arg( idx ), 4 );
111 if ( !checkBounds( idx ) )
return false;
115 QVector<QgsRasterInterface *> interfaces = mInterfaces;
117 interfaces[idx] = interface;
118 bool success =
false;
119 if ( connect( interfaces ) )
122 delete mInterfaces.at( idx );
123 mInterfaces[idx] = interface;
124 setRole( interface, idx );
129 connect( mInterfaces );
136 if ( dynamic_cast<QgsRasterDataProvider *>( interface ) ) role =
ProviderRole;
137 else if ( dynamic_cast<QgsRasterRenderer *>( interface ) ) role =
RendererRole;
138 else if ( dynamic_cast<QgsRasterResampleFilter *>( interface ) ) role =
ResamplerRole;
139 else if ( dynamic_cast<QgsBrightnessContrastFilter *>( interface ) ) role =
BrightnessRole;
140 else if ( dynamic_cast<QgsHueSaturationFilter *>( interface ) ) role =
HueSaturationRole;
141 else if ( dynamic_cast<QgsRasterProjector *>( interface ) ) role =
ProjectorRole;
142 else if ( dynamic_cast<QgsRasterNuller *>( interface ) ) role =
NullerRole;
144 QgsDebugMsgLevel( QStringLiteral(
"%1 role = %2" ).arg(
typeid( *interface ).name() ).arg( role ), 4 );
150 Role role = interfaceRole( interface );
152 mRoleMap.insert( role, idx );
157 Role role = interfaceRole( interface );
159 mRoleMap.remove( role );
164 if ( !interface )
return false;
166 QgsDebugMsgLevel( QStringLiteral(
"%1" ).arg(
typeid( *interface ).name() ), 4 );
167 Role role = interfaceRole( interface );
173 if ( mRoleMap.contains( role ) )
177 return replace( mRoleMap.value( role ), interface );
200 idx = providerIdx + 1;
204 idx = std::max( providerIdx, rendererIdx ) + 1;
208 idx = std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ) + 1;
212 idx = std::max( std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ), hueSaturationIdx ) + 1;
216 idx = std::max( std::max( std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ), hueSaturationIdx ), resamplerIdx ) + 1;
219 return insert( idx, interface );
225 if ( mRoleMap.contains( role ) )
227 return mInterfaces.value( mRoleMap.value( role ) );
271 if ( !checkBounds( idx ) )
return false;
275 QVector<QgsRasterInterface *> interfaces = mInterfaces;
277 interfaces.remove( idx );
278 bool success =
false;
279 if ( connect( interfaces ) )
282 unsetRole( mInterfaces.at( idx ) );
283 delete mInterfaces.at( idx );
284 mInterfaces.remove( idx );
289 connect( mInterfaces );
295 if ( !interface )
return false;
297 return remove( mInterfaces.indexOf( interface ) );
302 QgsDebugMsgLevel( QStringLiteral(
"idx = %1 on = %2" ).arg( idx ).arg( on ), 4 );
303 if ( !checkBounds( idx ) )
return false;
307 bool onOrig = mInterfaces.at( idx )->on();
309 if ( onOrig == on )
return true;
311 mInterfaces.at( idx )->setOn( on );
313 bool success = connect( mInterfaces );
315 mInterfaces.at( idx )->setOn( onOrig );
316 connect( mInterfaces );
322 QgsDebugMsgLevel( QStringLiteral(
"idx = %1 on = %2" ).arg( idx ).arg( on ), 4 );
323 if ( !checkBounds( idx ) )
return false;
325 bool onOrig = mInterfaces.at( idx )->on();
327 if ( onOrig == on )
return true;
329 mInterfaces.at( idx )->setOn( on );
331 if ( connect( mInterfaces ) )
return true;
333 mInterfaces.at( idx )->setOn( onOrig );
334 connect( mInterfaces );
339 bool QgsRasterPipe::checkBounds(
int idx )
const 341 return !( idx < 0 || idx >= mInterfaces.size() );
Base class for processing modules.
QgsRasterRenderer * renderer() const
QgsRasterResampleFilter * resampleFilter() const
QgsRasterProjector * projector() const
Raster pipe that deals with null values.
bool insert(int idx, QgsRasterInterface *interface)
Try to insert interface at specified index and connect if connection would fail, the interface is not...
Resample filter pipe for rasters.
bool replace(int idx, QgsRasterInterface *interface)
Try to replace interface at specified index and connect if connection would fail, the interface is no...
#define QgsDebugMsgLevel(str, level)
Base class for processing filters like renderers, reprojector, resampler etc.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
bool canSetOn(int idx, bool on)
Test if interface at index may be switched on/off.
bool set(QgsRasterInterface *interface)
Insert a new known interface in default place or replace interface of the same role if it already exi...
bool remove(int idx)
Remove and delete interface at given index if possible.
bool setOn(int idx, bool on)
Set interface at index on/off Returns true on success.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Brightness/contrast filter pipe for rasters.
Color and saturation filter pipe for rasters.
QgsRasterDataProvider * provider() const
QgsRasterNuller * nuller() const
QgsBrightnessContrastFilter * brightnessFilter() const
QgsHueSaturationFilter * hueSaturationFilter() const
Raster renderer pipe that applies colors to a raster.
Base class for raster data providers.
QgsRasterPipe()=default
Constructor for QgsRasterPipe.