void QgsMapStylingWidget::apply() { if ( mStackedWidget->currentIndex() == mVectorPage ) { QString undoName = "Style Change"; int currentPage = mMapStyleTabs->currentIndex(); if ( currentPage == mLabelTabIndex ) { mLabelingWidget->apply(); emit styleChanged( mCurrentLayer ); undoName = "Label Change"; } else if ( currentPage == mStyleTabIndex ) { mVectorStyleWidget->apply(); QgsProject::instance()->setDirty( true ); mMapCanvas->clearCache(); mMapCanvas->refresh(); emit styleChanged( mCurrentLayer ); QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mCurrentLayer ); QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( layer->rendererV2()->type() ); undoName = QString( "Style Change - %1" ).arg( m->visibleName() ); } QString errorMsg; QDomDocument doc( "style" ); QDomElement rootNode = doc.createElement( "qgis" ); doc.appendChild( rootNode ); mCurrentLayer->writeStyle( rootNode, doc, errorMsg ); mCurrentLayer->undoStackStyles()->beginMacro( undoName ); mCurrentLayer->undoStackStyles()->push( new QgsMapLayerStyleCommand( mCurrentLayer, rootNode, mLastStyleXml ) ); mCurrentLayer->undoStackStyles()->endMacro(); // Override the last style on the stack mLastStyleXml = rootNode.cloneNode(); } }
QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* layer, QgsStyleV2* style, bool embedded ) : mLayer( layer ), mStyle( style ), mActiveWidget( NULL ) { setupUi( this ); // can be embedded in vector layer properties if ( embedded ) { buttonBox->hide(); layout()->setContentsMargins( 0, 0, 0, 0 ); } connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) ); connect( btnSymbolLevels, SIGNAL( clicked() ), this, SLOT( showSymbolLevels() ) ); connect( btnOldSymbology, SIGNAL( clicked() ), this, SLOT( useOldSymbology() ) ); // initialize registry's widget functions _initRendererWidgetFunctions(); QPixmap pix; QgsRendererV2Registry* reg = QgsRendererV2Registry::instance(); QStringList renderers = reg->renderersList(); foreach( QString name, renderers ) { QgsRendererV2AbstractMetadata* m = reg->rendererMetadata( name ); cboRenderers->addItem( m->icon(), m->visibleName(), name ); }
void QgsLayerStylingWidget::apply() { if ( !mCurrentLayer ) return; disconnect( mCurrentLayer, SIGNAL( styleChanged() ), this, SLOT( updateCurrentWidgetLayer() ) ); QString undoName = "Style Change"; QWidget* current = mWidgetStack->mainWidget(); bool styleWasChanged = false; if ( QgsLabelingWidget* widget = qobject_cast<QgsLabelingWidget*>( current ) ) { widget->apply(); styleWasChanged = true; undoName = "Label Change"; } if ( QgsPanelWidgetWrapper* wrapper = qobject_cast<QgsPanelWidgetWrapper*>( current ) ) { if ( QgsRendererV2PropertiesDialog* widget = qobject_cast<QgsRendererV2PropertiesDialog*>( wrapper->widget() ) ) { widget->apply(); QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mCurrentLayer ); QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( layer->rendererV2()->type() ); undoName = QString( "Style Change - %1" ).arg( m->visibleName() ); styleWasChanged = true; } } else if ( QgsRasterTransparencyWidget* widget = qobject_cast<QgsRasterTransparencyWidget*>( current ) ) { widget->apply(); styleWasChanged = true; } else if ( qobject_cast<QgsRasterHistogramWidget*>( current ) ) { mRasterStyleWidget->apply(); styleWasChanged = true; } else if ( QgsLayerStylingPanel* widget = qobject_cast<QgsLayerStylingPanel*>( current ) ) { widget->apply(); styleWasChanged = true; } pushUndoItem( undoName ); if ( styleWasChanged ) { emit styleChanged( mCurrentLayer ); QgsProject::instance()->setDirty( true ); mMapCanvas->clearCache(); mMapCanvas->refresh(); } connect( mCurrentLayer, SIGNAL( styleChanged() ), this, SLOT( updateCurrentWidgetLayer() ) ); }
QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* layer, QgsStyleV2* style, bool embedded ) : mLayer( layer ), mStyle( style ), mActiveWidget( NULL ) { setupUi( this ); // can be embedded in vector layer properties if ( embedded ) { buttonBox->hide(); layout()->setContentsMargins( 0, 0, 0, 0 ); } connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) ); // initialize registry's widget functions _initRendererWidgetFunctions(); // Blend mode mBlendModeComboBox->setBlendMode( mLayer->blendMode() ); // Feature blend mode mFeatureBlendComboBox->setBlendMode( mLayer->featureBlendMode() ); // Layer transparency mLayerTransparencySlider->setValue( mLayer->layerTransparency() ); mLayerTransparencySpnBx->setValue( mLayer->layerTransparency() ); // connect layer transparency slider and spin box connect( mLayerTransparencySlider, SIGNAL( valueChanged( int ) ), mLayerTransparencySpnBx, SLOT( setValue( int ) ) ); connect( mLayerTransparencySpnBx, SIGNAL( valueChanged( int ) ), mLayerTransparencySlider, SLOT( setValue( int ) ) ); QPixmap pix; QgsRendererV2Registry* reg = QgsRendererV2Registry::instance(); QStringList renderers = reg->renderersList(); foreach ( QString name, renderers ) { QgsRendererV2AbstractMetadata* m = reg->rendererMetadata( name ); cboRenderers->addItem( m->icon(), m->visibleName(), name ); }
QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) : QgsRendererV2Widget( layer, style ) , mRenderer( NULL ) , mEmbeddedRendererWidget( 0 ) { if ( !layer ) { return; } //the renderer only applies to point vector layers if ( layer->wkbType() != QGis::WKBPoint && layer->wkbType() != QGis::WKBPoint25D ) { //setup blank dialog mRenderer = 0; setupBlankUi( layer->name() ); return; } setupUi( this ); mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel ); if ( renderer ) { mRenderer = QgsPointDisplacementRenderer::convertFromRenderer( renderer ); } if ( !mRenderer ) { mRenderer = new QgsPointDisplacementRenderer(); } blockAllSignals( true ); mPlacementComboBox->addItem( tr( "Ring" ), QgsPointDisplacementRenderer::Ring ); mPlacementComboBox->addItem( tr( "Concentric rings" ), QgsPointDisplacementRenderer::ConcentricRings ); //insert attributes into combo box if ( layer ) { const QgsFields& layerAttributes = layer->fields(); for ( int idx = 0; idx < layerAttributes.count(); ++idx ) { mLabelFieldComboBox->addItem( layerAttributes[idx].name() ); } mLabelFieldComboBox->addItem( tr( "None" ) ); QString currentLabelAttribute = mRenderer->labelAttributeName(); if ( !currentLabelAttribute.isEmpty() ) { mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( currentLabelAttribute ) ); } else { mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( tr( "None" ) ) ); } } //insert possible renderer types QStringList rendererList = QgsRendererV2Registry::instance()->renderersList(); QStringList::const_iterator it = rendererList.constBegin(); for ( ; it != rendererList.constEnd(); ++it ) { if ( *it != "pointDisplacement" ) { QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( *it ); mRendererComboBox->addItem( m->icon(), m->visibleName(), *it ); } } mCircleColorButton->setColorDialogTitle( tr( "Select color" ) ); mCircleColorButton->setContext( "symbology" ); mCircleColorButton->setAllowAlpha( true ); mCircleColorButton->setShowNoColor( true ); mCircleColorButton->setNoColorString( tr( "No outline" ) ); mLabelColorButton->setContext( "symbology" ); mLabelColorButton->setColorDialogTitle( tr( "Select color" ) ); mLabelColorButton->setAllowAlpha( true ); mCircleWidthSpinBox->setValue( mRenderer->circleWidth() ); mCircleColorButton->setColor( mRenderer->circleColor() ); mLabelColorButton->setColor( mRenderer->labelColor() ); mCircleModificationSpinBox->setClearValue( 0.0 ); mCircleModificationSpinBox->setValue( mRenderer->circleRadiusAddition() ); mDistanceSpinBox->setValue( mRenderer->tolerance() ); mDistanceUnitWidget->setUnit( mRenderer->toleranceUnit() ); mDistanceUnitWidget->setMapUnitScale( mRenderer->toleranceMapUnitScale() ); mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( mRenderer->placement() ) ); //scale dependent labelling mMaxScaleDenominatorEdit->setText( QString::number( mRenderer->maxLabelScaleDenominator() ) ); mMaxScaleDenominatorEdit->setValidator( new QDoubleValidator( mMaxScaleDenominatorEdit ) ); if ( mRenderer->maxLabelScaleDenominator() > 0 ) { mScaleDependentLabelsCheckBox->setCheckState( Qt::Checked ); } else { mScaleDependentLabelsCheckBox->setCheckState( Qt::Unchecked ); mMaxScaleDenominatorEdit->setEnabled( false ); } blockAllSignals( false ); //set the appropriate renderer dialog if ( mRenderer->embeddedRenderer() ) { QString rendererName = mRenderer->embeddedRenderer()->type(); int rendererIndex = mRendererComboBox->findData( rendererName ); if ( rendererIndex != -1 ) { mRendererComboBox->setCurrentIndex( rendererIndex ); on_mRendererComboBox_currentIndexChanged( rendererIndex ); } } updateCenterIcon(); }
QgsInvertedPolygonRendererWidget::QgsInvertedPolygonRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) : QgsRendererV2Widget( layer, style ) { if ( !layer ) { return; } // the renderer only applies to polygon vector layers if ( layer->wkbType() != QGis::WKBPolygon && layer->wkbType() != QGis::WKBPolygon25D && layer->wkbType() != QGis::WKBMultiPolygon && layer->wkbType() != QGis::WKBMultiPolygon25D ) { //setup blank dialog mRenderer.reset( 0 ); QGridLayout* layout = new QGridLayout( this ); QLabel* label = new QLabel( tr( "The inverted polygon renderer only applies to polygon and multipolygon layers. \n" "'%1' is not a polygon layer and then cannot be displayed" ) .arg( layer->name() ), this ); layout->addWidget( label ); return; } setupUi( this ); // try to recognize the previous renderer // (null renderer means "no previous renderer") if ( renderer ) { mRenderer.reset( QgsInvertedPolygonRenderer::convertFromRenderer( renderer ) ); } if ( ! mRenderer ) { mRenderer.reset( new QgsInvertedPolygonRenderer() ); } mMergePolygonsCheckBox->blockSignals( true ); mMergePolygonsCheckBox->setCheckState( mRenderer->preprocessingEnabled() ? Qt::Checked : Qt::Unchecked ); mMergePolygonsCheckBox->blockSignals( false ); int currentEmbeddedIdx = 0; //insert possible renderer types QStringList rendererList = QgsRendererV2Registry::instance()->renderersList(); QStringList::const_iterator it = rendererList.constBegin(); int idx = 0; mRendererComboBox->blockSignals( true ); for ( ; it != rendererList.constEnd(); ++it, ++idx ) { if (( *it != "invertedPolygonRenderer" ) && //< an inverted renderer cannot contain another inverted renderer ( *it != "pointDisplacement" ) ) //< an inverted renderer can only contain a polygon renderer { QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( *it ); mRendererComboBox->addItem( m->icon(), m->visibleName(), /* data */ *it ); const QgsFeatureRendererV2* embeddedRenderer = mRenderer->embeddedRenderer(); if ( embeddedRenderer && embeddedRenderer->type() == m->name() ) { // store the combo box index of the current renderer currentEmbeddedIdx = idx; } } } mRendererComboBox->blockSignals( false ); int oldIdx = mRendererComboBox->currentIndex(); mRendererComboBox->setCurrentIndex( currentEmbeddedIdx ); if ( oldIdx == currentEmbeddedIdx ) { // force update on_mRendererComboBox_currentIndexChanged( currentEmbeddedIdx ); } }
QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer ) : QgsRendererV2Widget( layer, style ), mEmbeddedRendererWidget( 0 ) { if ( !layer ) { return; } //the renderer only applies to point vector layers if ( layer->wkbType() != QGis::WKBPoint && layer->wkbType() != QGis::WKBPoint25D ) { //setup blank dialog mRenderer = 0; setupBlankUi( layer->name() ); return; } setupUi( this ); if ( renderer && renderer->type() == "pointDisplacement" ) { mRenderer = dynamic_cast<QgsPointDisplacementRenderer*>( renderer->clone() ); } else { mRenderer = new QgsPointDisplacementRenderer(); } blockAllSignals( true ); //insert attributes into combo box if ( layer ) { const QgsFields& layerAttributes = layer->pendingFields(); for ( int idx = 0; idx < layerAttributes.count(); ++idx ) { mLabelFieldComboBox->addItem( layerAttributes[idx].name() ); } mLabelFieldComboBox->addItem( tr( "None" ) ); QString currentLabelAttribute = mRenderer->labelAttributeName(); if ( !currentLabelAttribute.isEmpty() ) { mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( currentLabelAttribute ) ); } else { mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( tr( "None" ) ) ); } } //insert possible renderer types QStringList rendererList = QgsRendererV2Registry::instance()->renderersList(); QStringList::const_iterator it = rendererList.constBegin(); for ( ; it != rendererList.constEnd(); ++it ) { if ( *it != "pointDisplacement" ) { QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( *it ); mRendererComboBox->addItem( m->icon(), m->visibleName(), *it ); } } mCircleWidthSpinBox->setValue( mRenderer->circleWidth() ); mCircleColorButton->setColor( mRenderer->circleColor() ); mLabelColorButton->setColor( mRenderer->labelColor() ); mCircleModificationSpinBox->setValue( mRenderer->circleRadiusAddition() ); mDistanceSpinBox->setValue( mRenderer->tolerance() ); //scale dependent labelling mMaxScaleDenominatorEdit->setText( QString::number( mRenderer->maxLabelScaleDenominator() ) ); mMaxScaleDenominatorEdit->setValidator( new QDoubleValidator( mMaxScaleDenominatorEdit ) ); if ( mRenderer->maxLabelScaleDenominator() > 0 ) { mScaleDependentLabelsCheckBox->setCheckState( Qt::Checked ); } else { mScaleDependentLabelsCheckBox->setCheckState( Qt::Unchecked ); mMaxScaleDenominatorEdit->setEnabled( false ); } blockAllSignals( false ); //set the appropriate renderer dialog if ( mRenderer && mRenderer->embeddedRenderer() ) { QString rendererName = mRenderer->embeddedRenderer()->type(); int rendererIndex = mRendererComboBox->findData( rendererName ); if ( rendererIndex != -1 ) { mRendererComboBox->setCurrentIndex( rendererIndex ); on_mRendererComboBox_currentIndexChanged( rendererIndex ); } } updateCenterIcon(); }