18 #include <QHBoxLayout> 30 QgsLayerTreeTransparencyWidget::QgsLayerTreeTransparencyWidget(
QgsMapLayer* layer )
33 setAutoFillBackground(
true );
35 mSlider =
new QSlider( Qt::Horizontal,
this );
36 mSlider->setRange( 0, 100 );
43 mTimer =
new QTimer(
this );
44 mTimer->setSingleShot(
true );
45 mTimer->setInterval( 100 );
46 connect( mTimer, SIGNAL( timeout() ),
this, SLOT( updateTransparencyFromSlider() ) );
48 connect( mSlider, SIGNAL( valueChanged(
int ) ),
this, SLOT( sliderValueChanged(
int ) ) );
53 mSlider->setValue( qobject_cast<QgsVectorLayer*>( mLayer )->layerTransparency() );
54 connect( mLayer, SIGNAL( layerTransparencyChanged(
int ) ),
this, SLOT( layerTrChanged() ) );
58 mSlider->setValue( 100 - qobject_cast<QgsRasterLayer*>( mLayer )->renderer()->opacity() * 100 );
63 QSize QgsLayerTreeTransparencyWidget::sizeHint()
const 69 void QgsLayerTreeTransparencyWidget::sliderValueChanged(
int value )
73 if ( mTimer->isActive() )
78 void QgsLayerTreeTransparencyWidget::updateTransparencyFromSlider()
80 int value = mSlider->value();
84 qobject_cast<
QgsVectorLayer*>( mLayer )->setLayerTransparency( value );
88 qobject_cast<
QgsRasterLayer*>( mLayer )->renderer()->setOpacity( 1 - value / 100. );
94 void QgsLayerTreeTransparencyWidget::layerTrChanged()
96 mSlider->blockSignals(
true );
97 mSlider->setValue( qobject_cast<QgsVectorLayer*>( mLayer )->layerTransparency() );
98 mSlider->blockSignals(
false );
103 QString QgsLayerTreeTransparencyWidget::Provider::id()
const 105 return "transparency";
108 QString QgsLayerTreeTransparencyWidget::Provider::name()
const 110 return tr(
"Transparency slider" );
113 QgsLayerTreeTransparencyWidget* QgsLayerTreeTransparencyWidget::Provider::createWidget(
QgsMapLayer* layer,
int widgetIndex )
115 Q_UNUSED( widgetIndex );
116 return new QgsLayerTreeTransparencyWidget( layer );
119 bool QgsLayerTreeTransparencyWidget::Provider::supportsLayer(
QgsMapLayer* layer )
Base class for all map layer types.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsMapLayer::LayerType type() const
Get the type of the layer.
void triggerRepaint()
Will advice the map canvas (and any other interested party) that this layer requires to be repainted...
Represents a vector layer which manages a vector based data sets.