Skip to content
Permalink
Browse files

Update layer transparency after 100ms delay

  • Loading branch information
wonder-sk committed Jun 3, 2016
1 parent 301fd98 commit 19f83ae28d71ab350cbc47e3c29953625f7a8c08
@@ -15,9 +15,11 @@

#include "qgslayertreeembeddedwidgetsimpl.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>
#include <QHBoxLayout>
#include <QTimer>

#include "qgsrasterlayer.h"
#include "qgsrasterrenderer.h"
#include "qgsvectorlayer.h"
@@ -37,6 +39,12 @@ QgsLayerTreeTransparencyWidget::QgsLayerTreeTransparencyWidget( QgsMapLayer* lay
lay->addWidget( mSlider );
setLayout( lay );

// timer for delayed transparency update - for more responsive GUI
mTimer = new QTimer( this );
mTimer->setSingleShot( true );
mTimer->setInterval( 100 );
connect( mTimer, SIGNAL( timeout() ), this, SLOT( updateTransparencyFromSlider() ) );

connect( mSlider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderValueChanged( int ) ) );

// init from layer
@@ -60,6 +68,17 @@ QSize QgsLayerTreeTransparencyWidget::sizeHint() const

void QgsLayerTreeTransparencyWidget::sliderValueChanged( int value )
{
Q_UNUSED( value );

if ( mTimer->isActive() )
return;
mTimer->start();
}

void QgsLayerTreeTransparencyWidget::updateTransparencyFromSlider()
{
int value = mSlider->value();

if ( mLayer->type() == QgsMapLayer::VectorLayer )
{
qobject_cast<QgsVectorLayer*>( mLayer )->setLayerTransparency( value );
@@ -21,6 +21,7 @@


class QSlider;
class QTimer;
class QgsMapLayer;

/**
@@ -47,11 +48,13 @@ class QgsLayerTreeTransparencyWidget : public QWidget

public slots:
void sliderValueChanged( int value );
void updateTransparencyFromSlider();
void layerTrChanged();

private:
QgsMapLayer* mLayer;
QSlider* mSlider;
QTimer* mTimer;
};

#endif // QGSLAYERTREEEMBEDDEDWIDGETSIMPL_H

0 comments on commit 19f83ae

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