Skip to content

Commit 2b53f49

Browse files
committedJul 1, 2012
checkable interfaces in pipe
1 parent 7d14802 commit 2b53f49

File tree

7 files changed

+112
-9
lines changed

7 files changed

+112
-9
lines changed
 

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ void QgsRasterLayerProperties::updatePipeList()
16211621
QStringList labels;
16221622
labels << tr( "Filter" ) << tr( "Bands" ) << tr( "Time" );
16231623
mPipeTreeWidget->setHeaderLabels( labels );
1624+
connect( mPipeTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem *, int ) ), this, SLOT( pipeItemClicked( QTreeWidgetItem *, int ) ) );
16241625
}
16251626

16261627
QgsRasterPipe *pipe = mRasterLayer->pipe();
@@ -1645,7 +1646,52 @@ void QgsRasterLayerProperties::updatePipeList()
16451646
texts << QString( "%1 ms" ).arg( interface->time() );
16461647
QTreeWidgetItem *item = new QTreeWidgetItem( texts );
16471648

1649+
bool on = interface->on();
1650+
item->setCheckState( 0, on ? Qt::Checked : Qt::Unchecked );
1651+
1652+
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
1653+
item->setFlags( flags );
1654+
16481655
mPipeTreeWidget->addTopLevelItem( item );
16491656
}
1657+
updatePipeItems();
16501658
#endif
16511659
}
1660+
1661+
void QgsRasterLayerProperties::pipeItemClicked( QTreeWidgetItem * item, int column )
1662+
{
1663+
QgsDebugMsg( "Entered" );
1664+
int idx = mPipeTreeWidget->indexOfTopLevelItem( item );
1665+
1666+
// This should not fail because we have enabled only checkboxes of items
1667+
// which may be changed
1668+
mRasterLayer->pipe()->setOn( idx, item->checkState( 0 ) );
1669+
1670+
updatePipeItems();
1671+
}
1672+
1673+
void QgsRasterLayerProperties::updatePipeItems()
1674+
{
1675+
QgsDebugMsg( "Entered" );
1676+
1677+
QgsRasterPipe *pipe = mRasterLayer->pipe();
1678+
1679+
for ( int i = 0; i < pipe->size(); i++ )
1680+
{
1681+
if ( i >= mPipeTreeWidget->topLevelItemCount() ) break;
1682+
QgsRasterInterface * interface = pipe->at( i );
1683+
QTreeWidgetItem *item = mPipeTreeWidget->topLevelItem( i );
1684+
if ( !item ) continue;
1685+
bool on = interface->on();
1686+
Qt::ItemFlags flags = item->flags();
1687+
if ( pipe->canSetOn( i, !on ) )
1688+
{
1689+
flags |= Qt::ItemIsUserCheckable;
1690+
}
1691+
else
1692+
{
1693+
flags |= ( Qt::ItemFlags )~Qt::ItemIsUserCheckable;
1694+
}
1695+
item->setFlags( flags );
1696+
}
1697+
}

‎src/app/qgsrasterlayerproperties.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
9999
/**Enable or disable Build pyramids button depending on selection in pyramids list*/
100100
void toggleBuildPyramidsButton();
101101

102+
/** Update items in pipe list */
103+
void pipeItemClicked( QTreeWidgetItem * item, int column );
104+
102105
signals:
103106
/** emitted when changes to layer were saved to update legend */
104107
void refreshLegend( QString layerID, bool expandItem );
@@ -151,9 +154,12 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
151154
qreal mGradientHeight;
152155
qreal mGradientWidth;
153156

154-
/** Update pipe tab - filters list */
157+
/** Update pipe tab - interfaces list */
155158
void updatePipeList();
156159

160+
/** Update items in pipe list */
161+
void updatePipeItems();
162+
157163
QgsMapCanvas* mMapCanvas;
158164
QgsMapToolEmitPoint* mPixelSelectorTool;
159165
};

‎src/core/raster/qgsrasterinterface.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,23 @@ QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format
8181

8282
void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int width, int height )
8383
{
84+
QTime time;
85+
time.start();
86+
87+
void * b = 0;
88+
8489
if ( !mOn )
8590
{
8691
// Switched off, pass input data unchanged
87-
if ( !mInput ) return 0;
88-
return mInput->block( bandNo, extent, width, height );
92+
if ( mInput )
93+
{
94+
b = mInput->block( bandNo, extent, width, height );
95+
}
96+
}
97+
else
98+
{
99+
b = readBlock( bandNo, extent, width, height );
89100
}
90-
91-
QTime time;
92-
time.start();
93-
void * b = readBlock( bandNo, extent, width, height );
94101

95102
if ( mStatsOn )
96103
{

‎src/core/raster/qgsrasterpipe.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ bool QgsRasterPipe::remove( QgsRasterInterface * theInterface )
242242
return remove( mInterfaces.indexOf( theInterface ) );
243243
}
244244

245-
bool QgsRasterPipe::setOn( int idx, bool on )
245+
bool QgsRasterPipe::canSetOn( int idx, bool on )
246246
{
247+
QgsDebugMsg( QString( "idx = %1 on = %2" ).arg( idx ).arg( on ) );
247248
if ( !checkBounds( idx ) ) return false;
248249

249250
// Because setting interface on/off may change its output we must check if
@@ -254,10 +255,29 @@ bool QgsRasterPipe::setOn( int idx, bool on )
254255

255256
mInterfaces[idx]->setOn( on );
256257

258+
bool success = connect( mInterfaces );
259+
260+
mInterfaces[idx]->setOn( onOrig );
261+
connect( mInterfaces );
262+
return success;
263+
}
264+
265+
bool QgsRasterPipe::setOn( int idx, bool on )
266+
{
267+
QgsDebugMsg( QString( "idx = %1 on = %2" ).arg( idx ).arg( on ) );
268+
if ( !checkBounds( idx ) ) return false;
269+
270+
bool onOrig = mInterfaces[idx]->on();
271+
272+
if ( onOrig == on ) return true;
273+
274+
mInterfaces[idx]->setOn( on );
275+
257276
if ( connect( mInterfaces ) ) return true;
258277

259278
mInterfaces[idx]->setOn( onOrig );
260279
connect( mInterfaces );
280+
261281
return false;
262282
}
263283

‎src/core/raster/qgsrasterpipe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class CORE_EXPORT QgsRasterPipe
8585
* Returns true on success */
8686
bool setOn( int idx, bool on );
8787

88+
/** Test if interface at index may be swithed on/off */
89+
bool canSetOn( int idx, bool on );
90+
8891
// Getters for special types of interfaces
8992
QgsRasterDataProvider * provider() const;
9093
QgsRasterRenderer * renderer() const;

‎src/core/raster/qgsrasterrenderer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ bool QgsRasterRenderer::setInput( QgsRasterInterface* input )
6565
// Renderer can only work with numerical values in at least 1 band
6666
if ( !input ) return false;
6767

68+
if ( !mOn )
69+
{
70+
// In off mode we can connect to anything
71+
mInput = input;
72+
return true;
73+
}
74+
6875
for ( int i = 1; i <= input->bandCount(); i++ )
6976
{
7077
if ( typeIsNumeric( input->dataType( i ) ) )

‎src/core/raster/qgsrasterresamplefilter.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,21 @@ QgsRasterInterface::DataType QgsRasterResampleFilter::dataType( int bandNo ) con
6666
bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
6767
{
6868
QgsDebugMsg( "Entered" );
69+
6970
// Resampler can only work with single band ARGB32_Premultiplied
70-
if ( !input ) return false;
71+
if ( !input )
72+
{
73+
QgsDebugMsg( "No input" );
74+
return false;
75+
}
76+
77+
if ( !mOn )
78+
{
79+
// In off mode we can connect to anything
80+
QgsDebugMsg( "OK" );
81+
mInput = input;
82+
return true;
83+
}
7184

7285
if ( input->bandCount() < 1 )
7386
{
@@ -82,6 +95,7 @@ bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
8295
}
8396

8497
mInput = input;
98+
QgsDebugMsg( "OK" );
8599
return true;
86100
}
87101

0 commit comments

Comments
 (0)
Please sign in to comment.