Skip to content

Commit

Permalink
checkable interfaces in pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent 7d14802 commit 2b53f49
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 9 deletions.
46 changes: 46 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -1621,6 +1621,7 @@ void QgsRasterLayerProperties::updatePipeList()
QStringList labels;
labels << tr( "Filter" ) << tr( "Bands" ) << tr( "Time" );
mPipeTreeWidget->setHeaderLabels( labels );
connect( mPipeTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem *, int ) ), this, SLOT( pipeItemClicked( QTreeWidgetItem *, int ) ) );
}

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

bool on = interface->on();
item->setCheckState( 0, on ? Qt::Checked : Qt::Unchecked );

Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
item->setFlags( flags );

mPipeTreeWidget->addTopLevelItem( item );
}
updatePipeItems();
#endif
}

void QgsRasterLayerProperties::pipeItemClicked( QTreeWidgetItem * item, int column )
{
QgsDebugMsg( "Entered" );
int idx = mPipeTreeWidget->indexOfTopLevelItem( item );

// This should not fail because we have enabled only checkboxes of items
// which may be changed
mRasterLayer->pipe()->setOn( idx, item->checkState( 0 ) );

updatePipeItems();
}

void QgsRasterLayerProperties::updatePipeItems()
{
QgsDebugMsg( "Entered" );

QgsRasterPipe *pipe = mRasterLayer->pipe();

for ( int i = 0; i < pipe->size(); i++ )
{
if ( i >= mPipeTreeWidget->topLevelItemCount() ) break;
QgsRasterInterface * interface = pipe->at( i );
QTreeWidgetItem *item = mPipeTreeWidget->topLevelItem( i );
if ( !item ) continue;
bool on = interface->on();
Qt::ItemFlags flags = item->flags();
if ( pipe->canSetOn( i, !on ) )
{
flags |= Qt::ItemIsUserCheckable;
}
else
{
flags |= ( Qt::ItemFlags )~Qt::ItemIsUserCheckable;
}
item->setFlags( flags );
}
}
8 changes: 7 additions & 1 deletion src/app/qgsrasterlayerproperties.h
Expand Up @@ -99,6 +99,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
/**Enable or disable Build pyramids button depending on selection in pyramids list*/
void toggleBuildPyramidsButton();

/** Update items in pipe list */
void pipeItemClicked( QTreeWidgetItem * item, int column );

signals:
/** emitted when changes to layer were saved to update legend */
void refreshLegend( QString layerID, bool expandItem );
Expand Down Expand Up @@ -151,9 +154,12 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
qreal mGradientHeight;
qreal mGradientWidth;

/** Update pipe tab - filters list */
/** Update pipe tab - interfaces list */
void updatePipeList();

/** Update items in pipe list */
void updatePipeItems();

QgsMapCanvas* mMapCanvas;
QgsMapToolEmitPoint* mPixelSelectorTool;
};
Expand Down
19 changes: 13 additions & 6 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -81,16 +81,23 @@ QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format

void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int width, int height )
{
QTime time;
time.start();

void * b = 0;

if ( !mOn )
{
// Switched off, pass input data unchanged
if ( !mInput ) return 0;
return mInput->block( bandNo, extent, width, height );
if ( mInput )
{
b = mInput->block( bandNo, extent, width, height );
}
}
else
{
b = readBlock( bandNo, extent, width, height );
}

QTime time;
time.start();
void * b = readBlock( bandNo, extent, width, height );

if ( mStatsOn )
{
Expand Down
22 changes: 21 additions & 1 deletion src/core/raster/qgsrasterpipe.cpp
Expand Up @@ -242,8 +242,9 @@ bool QgsRasterPipe::remove( QgsRasterInterface * theInterface )
return remove( mInterfaces.indexOf( theInterface ) );
}

bool QgsRasterPipe::setOn( int idx, bool on )
bool QgsRasterPipe::canSetOn( int idx, bool on )
{
QgsDebugMsg( QString( "idx = %1 on = %2" ).arg( idx ).arg( on ) );
if ( !checkBounds( idx ) ) return false;

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

mInterfaces[idx]->setOn( on );

bool success = connect( mInterfaces );

mInterfaces[idx]->setOn( onOrig );
connect( mInterfaces );
return success;
}

bool QgsRasterPipe::setOn( int idx, bool on )
{
QgsDebugMsg( QString( "idx = %1 on = %2" ).arg( idx ).arg( on ) );
if ( !checkBounds( idx ) ) return false;

bool onOrig = mInterfaces[idx]->on();

if ( onOrig == on ) return true;

mInterfaces[idx]->setOn( on );

if ( connect( mInterfaces ) ) return true;

mInterfaces[idx]->setOn( onOrig );
connect( mInterfaces );

return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterpipe.h
Expand Up @@ -85,6 +85,9 @@ class CORE_EXPORT QgsRasterPipe
* Returns true on success */
bool setOn( int idx, bool on );

/** Test if interface at index may be swithed on/off */
bool canSetOn( int idx, bool on );

// Getters for special types of interfaces
QgsRasterDataProvider * provider() const;
QgsRasterRenderer * renderer() const;
Expand Down
7 changes: 7 additions & 0 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -65,6 +65,13 @@ bool QgsRasterRenderer::setInput( QgsRasterInterface* input )
// Renderer can only work with numerical values in at least 1 band
if ( !input ) return false;

if ( !mOn )
{
// In off mode we can connect to anything
mInput = input;
return true;
}

for ( int i = 1; i <= input->bandCount(); i++ )
{
if ( typeIsNumeric( input->dataType( i ) ) )
Expand Down
16 changes: 15 additions & 1 deletion src/core/raster/qgsrasterresamplefilter.cpp
Expand Up @@ -66,8 +66,21 @@ QgsRasterInterface::DataType QgsRasterResampleFilter::dataType( int bandNo ) con
bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
{
QgsDebugMsg( "Entered" );

// Resampler can only work with single band ARGB32_Premultiplied
if ( !input ) return false;
if ( !input )
{
QgsDebugMsg( "No input" );
return false;
}

if ( !mOn )
{
// In off mode we can connect to anything
QgsDebugMsg( "OK" );
mInput = input;
return true;
}

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

mInput = input;
QgsDebugMsg( "OK" );
return true;
}

Expand Down

0 comments on commit 2b53f49

Please sign in to comment.