Skip to content

Commit e30cd19

Browse files
committedJul 1, 2012
filter names replaced by interface
1 parent e331238 commit e30cd19

File tree

4 files changed

+110
-121
lines changed

4 files changed

+110
-121
lines changed
 

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
858858
if ( !projector )
859859
{
860860
projector = new QgsRasterProjector;
861-
mPipe.setFilter( projector );
861+
mPipe.set( projector );
862862
}
863863

864864
// TODO add a method to interface to get provider and get provider
@@ -1671,7 +1671,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
16711671
{
16721672
return;
16731673
}
1674-
mPipe.setFilter( mDataProvider );
1674+
mPipe.set( mDataProvider );
16751675

16761676
if ( provider == "gdal" )
16771677
{
@@ -2116,14 +2116,14 @@ void QgsRasterLayer::setTransparentBandName( QString const & )
21162116
void QgsRasterLayer::setRenderer( QgsRasterRenderer* theRenderer )
21172117
{
21182118
QgsDebugMsg( "Entered" );
2119-
mPipe.setFilter( theRenderer );
2119+
mPipe.set( theRenderer );
21202120
}
21212121

21222122
// not sure if we want it
21232123
void QgsRasterLayer::setResampleFilter( QgsRasterResampleFilter* resampleFilter )
21242124
{
21252125
QgsDebugMsg( "Entered" );
2126-
mPipe.setFilter( resampleFilter );
2126+
mPipe.set( resampleFilter );
21272127
}
21282128

21292129
void QgsRasterLayer::showProgress( int theValue )
@@ -2291,7 +2291,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
22912291
{
22922292
//mRenderer = rendererEntry.rendererCreateFunction( rasterRendererElem, dataProvider() );
22932293
QgsRasterRenderer *renderer = rendererEntry.rendererCreateFunction( rasterRendererElem, dataProvider() );
2294-
mPipe.setFilter( renderer );
2294+
mPipe.set( renderer );
22952295
}
22962296
}
22972297
}
@@ -2301,7 +2301,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
23012301
//mResampleFilter = new QgsRasterResampleFilter( mRenderer );
23022302

23032303
QgsRasterResampleFilter * resampleFilter = new QgsRasterResampleFilter();
2304-
mPipe.setFilter( resampleFilter );
2304+
mPipe.set( resampleFilter );
23052305

23062306
//max oversampling
23072307
QDomElement resampleElem = layer_node.firstChildElement( "rasterresampler" );

‎src/core/raster/qgsrasterlayer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
352352

353353
/**Set raster renderer. Takes ownership of the renderer object*/
354354
void setRenderer( QgsRasterRenderer* theRenderer );
355-
//const QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
356355
QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
357356

358357
/**Set raster resample filter. Takes ownership of the resample filter object*/
359358
void setResampleFilter( QgsRasterResampleFilter* resampleFilter );
360-
//const QgsRasterResampleFilter* resampleFilter() const { return mPipe.resampleFilter(); }
361359
QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
362360

363361
/** Get raster pipe */

‎src/core/raster/qgsrasterpipe.cpp

Lines changed: 72 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -23,140 +23,136 @@
2323
#include <QByteArray>
2424

2525
QgsRasterPipe::QgsRasterPipe()
26-
: mProvider( 0 )
27-
, mRenderer( 0 )
28-
, mResampleFilter( 0 )
29-
, mProjector( 0 )
3026
{
3127
}
3228

3329
QgsRasterPipe::~QgsRasterPipe()
3430
{
35-
foreach( QgsRasterInterface* filter, mFilters )
31+
foreach( QgsRasterInterface* interface, mInterfaces )
3632
{
37-
delete filter;
33+
delete interface;
3834
}
3935
}
4036

41-
bool QgsRasterPipe::connectFilters( QVector<QgsRasterInterface*> theFilters )
37+
bool QgsRasterPipe::connect( QVector<QgsRasterInterface*> theInterfaces )
4238
{
4339
QgsDebugMsg( "Entered" );
44-
for ( int i = 1; i < theFilters.size(); i++ )
40+
for ( int i = 1; i < theInterfaces.size(); i++ )
4541
{
46-
if ( ! theFilters[i]->setInput( theFilters[i-1] ) )
42+
if ( ! theInterfaces[i]->setInput( theInterfaces[i-1] ) )
4743
{
48-
QgsDebugMsg( QString( "cannot connect %1 to %2" ).arg( typeid( *( theFilters[i] ) ).name() ).arg( typeid( *( theFilters[i-1] ) ).name() ) );
44+
QgsDebugMsg( QString( "cannot connect %1 to %2" ).arg( typeid( *( theInterfaces[i] ) ).name() ).arg( typeid( *( theInterfaces[i-1] ) ).name() ) );
4945
return false;
5046
}
5147
}
5248
return true;
5349
}
5450

55-
bool QgsRasterPipe::insert( int idx, QgsRasterInterface* theFilter )
51+
bool QgsRasterPipe::insert( int idx, QgsRasterInterface* theInterface )
5652
{
57-
QgsDebugMsg( QString( "insert %1 at %2" ).arg( typeid( *theFilter ).name() ).arg( idx ) );
58-
if ( idx > mFilters.size() )
53+
QgsDebugMsg( QString( "insert %1 at %2" ).arg( typeid( *theInterface ).name() ).arg( idx ) );
54+
if ( idx > mInterfaces.size() )
5955
{
60-
idx = mFilters.size();
56+
idx = mInterfaces.size();
6157
}
6258
// make a copy of pipe to test connection, we test the connections
6359
// of the whole pipe, because the types and band numbers may change
64-
QVector<QgsRasterInterface*> filters = mFilters;
60+
QVector<QgsRasterInterface*> interfaces = mInterfaces;
6561

66-
filters.insert( idx, theFilter );
62+
interfaces.insert( idx, theInterface );
6763
bool success = false;
68-
if ( connectFilters( filters ) )
64+
if ( connect( interfaces ) )
6965
{
7066
success = true;
71-
mFilters.insert( idx, theFilter );
72-
setRole( theFilter, idx );
67+
mInterfaces.insert( idx, theInterface );
68+
setRole( theInterface, idx );
7369
QgsDebugMsg( "inserted ok" );
7470
}
7571

76-
// Connect or reconnect (after the test) filters
77-
connectFilters( mFilters );
72+
// Connect or reconnect (after the test) interfaces
73+
connect( mInterfaces );
7874
return success;
7975
}
8076

81-
bool QgsRasterPipe::replace( int idx, QgsRasterInterface* theFilter )
77+
bool QgsRasterPipe::replace( int idx, QgsRasterInterface* theInterface )
8278
{
83-
QgsDebugMsg( QString( "replace by %1 at %2" ).arg( typeid( *theFilter ).name() ).arg( idx ) );
84-
if ( idx < 0 || idx >= mFilters.size() )
79+
QgsDebugMsg( QString( "replace by %1 at %2" ).arg( typeid( *theInterface ).name() ).arg( idx ) );
80+
if ( idx < 0 || idx >= mInterfaces.size() )
8581
{
8682
return false;
8783
}
88-
if ( !theFilter ) return false;
84+
if ( !theInterface ) return false;
8985

9086
// make a copy of pipe to test connection, we test the connections
9187
// of the whole pipe, because the types and band numbers may change
92-
QVector<QgsRasterInterface*> filters = mFilters;
88+
QVector<QgsRasterInterface*> interfaces = mInterfaces;
9389

94-
filters[idx] = theFilter;
90+
interfaces[idx] = theInterface;
9591
bool success = false;
96-
if ( connectFilters( filters ) )
92+
if ( connect( interfaces ) )
9793
{
9894
success = true;
99-
delete mFilters[idx];
100-
mFilters[idx] = theFilter;
101-
setRole( theFilter, idx );
95+
delete mInterfaces[idx];
96+
mInterfaces[idx] = theInterface;
97+
setRole( theInterface, idx );
10298
QgsDebugMsg( "replaced ok" );
10399
}
104100

105-
// Connect or reconnect (after the test) filters
106-
connectFilters( mFilters );
101+
// Connect or reconnect (after the test) interfaces
102+
connect( mInterfaces );
107103
return success;
108104
}
109105

110-
QgsRasterPipe::Role QgsRasterPipe::filterRole( QgsRasterInterface * filter ) const
106+
QgsRasterPipe::Role QgsRasterPipe::interfaceRole( QgsRasterInterface * interface ) const
111107
{
112-
if ( dynamic_cast<QgsRasterDataProvider *>( filter ) ) return ProviderRole;
113-
if ( dynamic_cast<QgsRasterRenderer *>( filter ) ) return RendererRole;
114-
if ( dynamic_cast<QgsRasterResampleFilter *>( filter ) ) return ResamplerRole;
115-
if ( dynamic_cast<QgsRasterProjector *>( filter ) ) return ProjectorRole;
108+
if ( dynamic_cast<QgsRasterDataProvider *>( interface ) ) return ProviderRole;
109+
if ( dynamic_cast<QgsRasterRenderer *>( interface ) ) return RendererRole;
110+
if ( dynamic_cast<QgsRasterResampleFilter *>( interface ) ) return ResamplerRole;
111+
if ( dynamic_cast<QgsRasterProjector *>( interface ) ) return ProjectorRole;
116112
return UnknownRole;
117113
}
118114

119-
void QgsRasterPipe::setRole( QgsRasterInterface * theFilter, int idx )
115+
void QgsRasterPipe::setRole( QgsRasterInterface * theInterface, int idx )
120116
{
121-
Role role = filterRole( theFilter );
117+
Role role = interfaceRole( theInterface );
122118
if ( role == UnknownRole ) return;
123119
mRoleMap.insert( role, idx );
124120
}
125121

126-
void QgsRasterPipe::unsetRole( QgsRasterInterface * theFilter )
122+
void QgsRasterPipe::unsetRole( QgsRasterInterface * theInterface )
127123
{
128-
Role role = filterRole( theFilter );
124+
Role role = interfaceRole( theInterface );
129125
if ( role == UnknownRole ) return;
130126
mRoleMap.remove( role );
131127
}
132128

133-
bool QgsRasterPipe::setFilter( QgsRasterInterface* theFilter )
129+
bool QgsRasterPipe::set( QgsRasterInterface* theInterface )
134130
{
135-
QgsDebugMsg( QString( "%1" ).arg( typeid( *theFilter ).name() ) );
131+
QgsDebugMsg( QString( "%1" ).arg( typeid( *theInterface ).name() ) );
136132

137-
if ( !theFilter ) return false;
133+
if ( !theInterface ) return false;
138134

139-
QgsRasterDataProvider * provider = dynamic_cast<QgsRasterDataProvider *>( theFilter );
135+
QgsRasterDataProvider * provider = dynamic_cast<QgsRasterDataProvider *>( theInterface );
140136
QgsRasterRenderer * renderer;
141137
QgsRasterResampleFilter * resampleFilter;
142138
QgsRasterProjector * projector;
143139

144-
Role role = filterRole( theFilter );
140+
Role role = interfaceRole( theInterface );
145141

146-
// We dont know where to place unknown filter
142+
// We dont know where to place unknown interface
147143
if ( role == UnknownRole ) return false;
148144

149-
//if ( mFiltersMap.value ( role ) )
145+
//if ( mInterfacesMap.value ( role ) )
150146
if ( mRoleMap.contains( role ) )
151147
{
152-
// An old filter of the same role exists -> replace
148+
// An old interface of the same role exists -> replace
153149
// replace may still fail and return false
154-
return replace( mRoleMap.value( role ), theFilter );
150+
return replace( mRoleMap.value( role ), theInterface );
155151
}
156152

157153
int idx = 0;
158154

159-
// Not found, find the best default position for this kind of filter
155+
// Not found, find the best default position for this kind of interface
160156
// QgsRasterDataProvider - ProviderRole
161157
// QgsRasterRenderer - RendererRole
162158
// QgsRasterResampler - ResamplerRole
@@ -183,71 +179,71 @@ bool QgsRasterPipe::setFilter( QgsRasterInterface* theFilter )
183179
idx = qMax( qMax( providerIdx, rendererIdx ), resamplerIdx ) + 1;
184180
}
185181

186-
return insert( idx, theFilter ); // insert may still fail and return false
182+
return insert( idx, theInterface ); // insert may still fail and return false
187183
}
188184

189-
QgsRasterInterface * QgsRasterPipe::filter( Role role ) const
190-
{
191-
QgsDebugMsg( QString( "role = %1" ).arg( role ) );
192-
if ( mRoleMap.contains( role ) )
185+
QgsRasterInterface * QgsRasterPipe::interface( Role role ) const
193186
{
194-
return mFilters.value( mRoleMap.value( role ) );
187+
QgsDebugMsg( QString( "role = %1" ).arg( role ) );
188+
if ( mRoleMap.contains( role ) )
189+
{
190+
return mInterfaces.value( mRoleMap.value( role ) );
191+
}
192+
return 0;
195193
}
196-
return 0;
197-
}
198194

199195
QgsRasterDataProvider * QgsRasterPipe::provider() const
200196
{
201-
return dynamic_cast<QgsRasterDataProvider *>( filter( ProviderRole ) );
197+
return dynamic_cast<QgsRasterDataProvider *>( interface( ProviderRole ) );
202198
}
203199

204200
QgsRasterRenderer * QgsRasterPipe::renderer() const
205201
{
206-
return dynamic_cast<QgsRasterRenderer *>( filter( RendererRole ) );
202+
return dynamic_cast<QgsRasterRenderer *>( interface( RendererRole ) );
207203
}
208204

209205
QgsRasterResampleFilter * QgsRasterPipe::resampleFilter() const
210206
{
211-
return dynamic_cast<QgsRasterResampleFilter *>( filter( ResamplerRole ) );
207+
return dynamic_cast<QgsRasterResampleFilter *>( interface( ResamplerRole ) );
212208
}
213209

214210
QgsRasterProjector * QgsRasterPipe::projector() const
215211
{
216-
return dynamic_cast<QgsRasterProjector*>( filter( ProjectorRole ) );
212+
return dynamic_cast<QgsRasterProjector*>( interface( ProjectorRole ) );
217213
}
218214

219215
bool QgsRasterPipe::remove( int idx )
220216
{
221217
QgsDebugMsg( QString( "remove at %1" ).arg( idx ) );
222218

223-
if ( idx < 0 || idx >= mFilters.size() )
219+
if ( idx < 0 || idx >= mInterfaces.size() )
224220
{
225221
return false;
226222
}
227223

228224
// make a copy of pipe to test connection, we test the connections
229225
// of the whole pipe, because the types and band numbers may change
230-
QVector<QgsRasterInterface*> filters = mFilters;
226+
QVector<QgsRasterInterface*> interfaces = mInterfaces;
231227

232-
filters.remove( idx );
228+
interfaces.remove( idx );
233229
bool success = false;
234-
if ( connectFilters( filters ) )
230+
if ( connect( interfaces ) )
235231
{
236232
success = true;
237-
unsetRole( mFilters[idx] );
238-
delete mFilters[idx];
239-
mFilters.remove( idx );
233+
unsetRole( mInterfaces[idx] );
234+
delete mInterfaces[idx];
235+
mInterfaces.remove( idx );
240236
QgsDebugMsg( "removed ok" );
241237
}
242238

243-
// Connect or reconnect (after the test) filters
244-
connectFilters( mFilters );
239+
// Connect or reconnect (after the test) interfaces
240+
connect( mInterfaces );
245241
return success;
246242
}
247243

248-
bool QgsRasterPipe::remove( QgsRasterInterface * theFilter )
244+
bool QgsRasterPipe::remove( QgsRasterInterface * theInterface )
249245
{
250-
if ( !theFilter ) return false;
246+
if ( !theInterface ) return false;
251247

252-
return remove( mFilters.indexOf( theFilter ) );
248+
return remove( mInterfaces.indexOf( theInterface ) );
253249
}

‎src/core/raster/qgsrasterpipe.h

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
/** \ingroup core
3232
* Base class for processing modules.
3333
*/
34-
class CORE_EXPORT QgsRasterPipe //: public QObject
34+
class CORE_EXPORT QgsRasterPipe
3535
{
36-
//Q_OBJECT
37-
3836
public:
39-
// Role of known filters
37+
// Role of known interfaces
4038
enum Role
4139
{
4240
UnknownRole = 0,
@@ -50,35 +48,38 @@ class CORE_EXPORT QgsRasterPipe //: public QObject
5048

5149
virtual ~QgsRasterPipe();
5250

53-
/** \brief Try to connect filters in pipe and to the provider at beginning.
51+
/** \brief Try to connect interfaces in pipe and to the provider at beginning.
5452
Returns true if connected or false if connection failed */
55-
bool connectFilters( QVector<QgsRasterInterface*> theFilters );
56-
53+
bool connect( QVector<QgsRasterInterface*> theInterfaces );
5754

58-
/** Try to insert filter at specified index and connect
59-
* if connection would fail, the filter is not inserted and false is returned */
60-
bool insert( int idx, QgsRasterInterface* theFilter );
55+
/** Try to insert interface at specified index and connect
56+
* if connection would fail, the interface is not inserted and false is returned */
57+
bool insert( int idx, QgsRasterInterface* theInterface );
6158

62-
/** Try to replace filter at specified index and connect
63-
* if connection would fail, the filter is not inserted and false is returned */
64-
bool replace( int idx, QgsRasterInterface* theFilter );
59+
/** Try to replace interface at specified index and connect
60+
* if connection would fail, the interface is not inserted and false is returned */
61+
bool replace( int idx, QgsRasterInterface* theInterface );
6562

66-
/** Insert a new filter in prefered place or replace similar filter if it
67-
* already exists */
68-
bool setFilter( QgsRasterInterface * theFilter );
63+
/** Insert a new known interface in default place or replace interface of the same
64+
* role if it already exists. Known interfaces are: QgsRasterDataProvider,
65+
* QgsRasterRenderer, QgsRasterResampleFilter, QgsRasterProjector and their
66+
* subclasses. For unknown interfaces it mus be explicitly specified position
67+
* where it should be inserted using insert() method.
68+
*/
69+
bool set( QgsRasterInterface * theInterface );
6970

70-
/** Get known filter by role */
71-
QgsRasterInterface * filter( Role role ) const;
71+
/** Get known interface by role */
72+
QgsRasterInterface * interface( Role role ) const;
7273

73-
/** Remove and delete filter at given index if possible */
74+
/** Remove and delete interface at given index if possible */
7475
bool remove( int idx );
7576

76-
/** Remove and delete filter from pipe if possible */
77-
bool remove( QgsRasterInterface * theFilter );
77+
/** Remove and delete interface from pipe if possible */
78+
bool remove( QgsRasterInterface * theInterface );
7879

79-
int size() { return mFilters.size(); }
80-
QgsRasterInterface * at( int idx ) { return mFilters.at( idx ); }
81-
QgsRasterInterface * last() { return mFilters.last(); }
80+
int size() { return mInterfaces.size(); }
81+
QgsRasterInterface * at( int idx ) { return mInterfaces.at( idx ); }
82+
QgsRasterInterface * last() { return mInterfaces.last(); }
8283

8384
// Getters for special types of interfaces
8485
QgsRasterDataProvider * provider() const;
@@ -88,24 +89,18 @@ class CORE_EXPORT QgsRasterPipe //: public QObject
8889

8990
private:
9091
/** Get known parent type_info of interface parent */
91-
Role filterRole( QgsRasterInterface * filter ) const;
92-
93-
// Filters in pipe, the first is always provider
94-
QVector<QgsRasterInterface*> mFilters;
92+
Role interfaceRole( QgsRasterInterface * interface ) const;
9593

96-
// Special types of interfaces
97-
QgsRasterDataProvider * mProvider;
98-
QgsRasterRenderer * mRenderer;
99-
QgsRasterResampleFilter * mResampleFilter;
100-
QgsRasterProjector * mProjector;
94+
// Interfaces in pipe, the first is always provider
95+
QVector<QgsRasterInterface*> mInterfaces;
10196

10297
QMap<Role, int> mRoleMap;
10398

104-
// Set role in mFiltersMap
105-
void setRole( QgsRasterInterface * theFilter, int idx );
99+
// Set role in mRoleMap
100+
void setRole( QgsRasterInterface * theInterface, int idx );
106101

107-
// Unset role in mFiltersMap
108-
void unsetRole( QgsRasterInterface * theFilter );
102+
// Unset role in mRoleMap
103+
void unsetRole( QgsRasterInterface * theInterface );
109104
};
110105

111106
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.