Skip to content
Permalink
Browse files

checkable interfaces in pipe

  • Loading branch information
blazek committed Jul 1, 2012
1 parent 7d14802 commit 2b53f49e57c99c6f36ab92bfb0386878e75b87c7
@@ -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();
@@ -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 );
}
}
@@ -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 );
@@ -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;
};
@@ -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 )
{
@@ -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
@@ -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;
}

@@ -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;
@@ -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 ) ) )
@@ -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 )
{
@@ -82,6 +95,7 @@ bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
}

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

0 comments on commit 2b53f49

Please sign in to comment.
You can’t perform that action at this time.