Skip to content
Permalink
Browse files

[styledock] Keep dock state updated from external changes

  • Loading branch information
NathanW2 committed Jun 5, 2016
1 parent e7b04f2 commit 53a57e19e0d4485c7562dd6148a3f6e856f9a69f
@@ -66,8 +66,8 @@ QgsMapStylingWidget::QgsMapStylingWidget( QgsMapCanvas* canvas, QList<QgsMapStyl

mStyleManagerFactory = new QgsMapLayerStyleManagerWidgetFactory();

connect( mUndoButton, SIGNAL( pressed() ), mUndoWidget, SLOT( undo() ) );
connect( mRedoButton, SIGNAL( pressed() ), mUndoWidget, SLOT( redo() ) );
connect( mUndoButton, SIGNAL( pressed() ), this, SLOT( undo() ) );
connect( mRedoButton, SIGNAL( pressed() ), this, SLOT( redo() ) );

connect( mAutoApplyTimer, SIGNAL( timeout() ), this, SLOT( apply() ) );

@@ -109,6 +109,7 @@ void QgsMapStylingWidget::setLayer( QgsMapLayer *layer )
}

mCurrentLayer = layer;
connect( mCurrentLayer, SIGNAL( repaintRequested() ), this, SLOT( updateCurrentWidgetLayer() ) );

int lastPage = mOptionsListWidget->currentIndex().row();
mOptionsListWidget->clear();
@@ -152,6 +153,7 @@ void QgsMapStylingWidget::setLayer( QgsMapLayer *layer )

void QgsMapStylingWidget::apply()
{
disconnect( mCurrentLayer, SIGNAL( repaintRequested() ), this, SLOT( updateCurrentWidgetLayer() ) );
QString undoName = "Style Change";
if ( !mCurrentLayer )
return;
@@ -197,7 +199,7 @@ void QgsMapStylingWidget::apply()
mMapCanvas->clearCache();
mMapCanvas->refresh();
}

disconnect( mCurrentLayer, SIGNAL( repaintRequested() ), this, SLOT( updateCurrentWidgetLayer() ) );
}

void QgsMapStylingWidget::autoApply()
@@ -208,8 +210,21 @@ void QgsMapStylingWidget::autoApply()
}
}

void QgsMapStylingWidget::undo()
{
mUndoWidget->undo();
updateCurrentWidgetLayer();
}

void QgsMapStylingWidget::redo()
{
mUndoWidget->redo();
updateCurrentWidgetLayer();
}

void QgsMapStylingWidget::updateCurrentWidgetLayer()
{
QgsDebugMsg( "UPDATE!!!" );
mBlockAutoApply = true;

QgsMapLayer* layer = mCurrentLayer;
@@ -353,6 +368,16 @@ void QgsMapStylingWidget::layerAboutToBeRemoved( QgsMapLayer* layer )
}
}

void QgsMapStylingWidget::syncWidgetState()
{
QWidget* current = mWidgetArea->widget();

if ( QgsRendererV2PropertiesDialog* widget = qobject_cast<QgsRendererV2PropertiesDialog*>( current ) )
{
widget->syncToLayer();
}
}

void QgsMapStylingWidget::pushUndoItem( const QString &name )
{
QString errorMsg;
@@ -79,10 +79,13 @@ class APP_EXPORT QgsMapStylingWidget : public QWidget, private Ui::QgsMapStyling
void setLayer( QgsMapLayer* layer );
void apply();
void autoApply();
void undo();
void redo();

private slots:
void updateCurrentWidgetLayer();
void layerAboutToBeRemoved( QgsMapLayer* layer );
void syncWidgetState();

private:
void pushUndoItem( const QString& name );
@@ -95,37 +95,9 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
}


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 ) ) );

//paint effect widget
if ( mLayer->rendererV2() )
{
if ( mLayer->rendererV2()->paintEffect() )
{
mPaintEffect = mLayer->rendererV2()->paintEffect()->clone();
mEffectWidget->setPaintEffect( mPaintEffect );
}

mOrderBy = mLayer->rendererV2()->orderBy();
}

QgsRendererV2Registry* reg = QgsRendererV2Registry::instance();
QStringList renderers = reg->renderersList();
Q_FOREACH ( const QString& name, renderers )
@@ -136,34 +108,18 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la

cboRenderers->setCurrentIndex( -1 ); // set no current renderer

// setup slot rendererChanged()
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) );

// 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 ) ) );

connect( cboRenderers, SIGNAL( currentIndexChanged( int ) ), this, SLOT( rendererChanged() ) );
//setup order by
if ( mLayer->rendererV2()->orderByEnabled() )
{
checkboxEnableOrderBy->setChecked( true );
}
else
{
btnOrderBy->setEnabled( false );
checkboxEnableOrderBy->setChecked( false );
lineEditOrderBy->setEnabled( false );
}
lineEditOrderBy->setReadOnly( true );
connect( checkboxEnableOrderBy, SIGNAL( toggled( bool ) ), btnOrderBy, SLOT( setEnabled( bool ) ) );
connect( checkboxEnableOrderBy, SIGNAL( toggled( bool ) ), lineEditOrderBy, SLOT( setEnabled( bool ) ) );
connect( btnOrderBy, SIGNAL( clicked( bool ) ), this, SLOT( showOrderByDialog() ) );
lineEditOrderBy->setText( mOrderBy.dump() );

// set current renderer from layer
QString rendererName = mLayer->rendererV2()->type();

int rendererIdx = cboRenderers->findData( rendererName );
cboRenderers->setCurrentIndex( rendererIdx );

// no renderer found... this mustn't happen
Q_ASSERT( rendererIdx != -1 && "there must be a renderer!" );
connectValueChanged( findChildren<QWidget*>(), SIGNAL( widgetChanged() ) );
syncToLayer();
}

void QgsRendererV2PropertiesDialog::connectValueChanged( QList<QWidget *> widgets, const char *slot )
@@ -206,6 +162,47 @@ void QgsRendererV2PropertiesDialog::connectValueChanged( QList<QWidget *> widget
}
}

void QgsRendererV2PropertiesDialog::disconnectValueChanged( QList<QWidget *> widgets, const char *slot )
{
Q_FOREACH ( QWidget* widget, widgets )
{
if ( QgsDataDefinedButton* w = qobject_cast<QgsDataDefinedButton*>( widget ) )
{
disconnect( w, SIGNAL( dataDefinedActivated( bool ) ), this, slot );
disconnect( w, SIGNAL( dataDefinedChanged( QString ) ), this, slot );
}
else if ( QgsFieldExpressionWidget* w = qobject_cast<QgsFieldExpressionWidget*>( widget ) )
{
disconnect( w, SIGNAL( fieldChanged( QString ) ), this, slot );
}
else if ( QComboBox* w = qobject_cast<QComboBox*>( widget ) )
{
disconnect( w, SIGNAL( currentIndexChanged( int ) ), this, slot );
}
else if ( QSpinBox* w = qobject_cast<QSpinBox*>( widget ) )
{
disconnect( w, SIGNAL( valueChanged( int ) ), this, slot );
}
else if ( QDoubleSpinBox* w = qobject_cast<QDoubleSpinBox*>( widget ) )
{
disconnect( w , SIGNAL( valueChanged( double ) ), this, slot );
}
else if ( QgsColorButtonV2* w = qobject_cast<QgsColorButtonV2*>( widget ) )
{
disconnect( w, SIGNAL( colorChanged( QColor ) ), this, slot );
}
else if ( QCheckBox* w = qobject_cast<QCheckBox*>( widget ) )
{
disconnect( w, SIGNAL( toggled( bool ) ), this, slot );
}
else if ( QLineEdit* w = qobject_cast<QLineEdit*>( widget ) )
{
disconnect( w, SIGNAL( textEdited( QString ) ), this, slot );
}
}

}

QgsRendererV2PropertiesDialog::~QgsRendererV2PropertiesDialog()
{
delete mPaintEffect;
@@ -222,6 +219,7 @@ void QgsRendererV2PropertiesDialog::setMapCanvas( QgsMapCanvas* canvas )
void QgsRendererV2PropertiesDialog::rendererChanged()
{

QgsDebugMsg( "RENDERER CHANGED" );
if ( cboRenderers->currentIndex() == -1 )
{
QgsDebugMsg( "No current item -- this should never happen!" );
@@ -312,6 +310,61 @@ void QgsRendererV2PropertiesDialog::onOK()
accept();
}

void QgsRendererV2PropertiesDialog::syncToLayer()
{
QgsDebugMsg( "SYNC TO LAYER!!" );
disconnectValueChanged( findChildren<QWidget*>(), SIGNAL( widgetChanged() ) );
// Blend mode
mBlendModeComboBox->setBlendMode( mLayer->blendMode() );

// Feature blend mode
mFeatureBlendComboBox->setBlendMode( mLayer->featureBlendMode() );

// Layer transparency
mLayerTransparencySlider->setValue( mLayer->layerTransparency() );
mLayerTransparencySpnBx->setValue( mLayer->layerTransparency() );

QgsDebugMsg( QString( "VALUE: %1" ).arg( mLayer->layerTransparency() ) );
//paint effect widget
if ( mLayer->rendererV2() )
{
if ( mLayer->rendererV2()->paintEffect() )
{
mPaintEffect = mLayer->rendererV2()->paintEffect()->clone();
mEffectWidget->setPaintEffect( mPaintEffect );
}

mOrderBy = mLayer->rendererV2()->orderBy();
}

lineEditOrderBy->setText( mOrderBy.dump() );

// setup slot rendererChanged()
//setup order by
if ( mLayer->rendererV2()->orderByEnabled() )
{
checkboxEnableOrderBy->setChecked( true );
}
else
{
btnOrderBy->setEnabled( false );
checkboxEnableOrderBy->setChecked( false );
lineEditOrderBy->setEnabled( false );
}
lineEditOrderBy->setReadOnly( true );

// set current renderer from layer
QString rendererName = mLayer->rendererV2()->type();

int rendererIdx = cboRenderers->findData( rendererName );
cboRenderers->setCurrentIndex( rendererIdx );

// no renderer found... this mustn't happen
Q_ASSERT( rendererIdx != -1 && "there must be a renderer!" );

connectValueChanged( findChildren<QWidget*>(), SIGNAL( widgetChanged() ) );
}

void QgsRendererV2PropertiesDialog::showOrderByDialog()
{
QgsOrderByDialog dlg( mLayer, this );
@@ -72,6 +72,8 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
//! Apply and accept the changes for the dialog.
void onOK();

void syncToLayer();

private slots:
void showOrderByDialog();

@@ -90,6 +92,8 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
*/
void connectValueChanged( QList<QWidget *> widgets, const char *slot );

void disconnectValueChanged( QList<QWidget *> widgets, const char *slot );

//! Reimplements dialog keyPress event so we can ignore it
void keyPressEvent( QKeyEvent * event ) override;

0 comments on commit 53a57e1

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