Skip to content

Commit 8c8be00

Browse files
committedNov 21, 2016
Remove redundant setLayer slots from QgsField(ComboBox|ExpressionWidget)
and switch uses of remaining slot to new style connects
1 parent 22dc096 commit 8c8be00

14 files changed

+65
-52
lines changed
 

‎doc/api_break.dox

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,18 @@ QgsFeatureRendererV2 {#qgis_api_break_3_0_QgsFeatureRendererV2}
842842
- copyPaintEffect() was removed. copyRendererData() should be used instead.
843843

844844

845+
QgsFieldCombobox {#qgis_api_break_3_0_QgsFieldCombobox}
846+
----------------
847+
848+
- The setLayer( QgsVectorlayer* ) slot has been removed. Use the setLayer( QgsMapLayer* ) slot instead.
849+
850+
851+
QgsFieldExpressionWidget {#qgis_api_break_3_0_QgsFieldExpressionWidget}
852+
------------------------
853+
854+
- The setLayer( QgsVectorlayer* ) slot has been removed. Use the setLayer( QgsMapLayer* ) slot instead.
855+
856+
845857
QgsFields {#qgis_api_break_3_0_QgsFields}
846858
---------
847859

‎python/gui/qgsfieldcombobox.sip

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,23 @@ class QgsFieldComboBox : QComboBox
4242
//! return the currently selected field
4343
QString currentField() const;
4444

45-
//! Returns the currently used layer
45+
/**
46+
* Returns the layer currently associated with the combobox.
47+
* @see setLayer()
48+
*/
4649
QgsVectorLayer* layer() const;
4750

4851
signals:
4952
//! the signal is emitted when the currently selected field changes
5053
void fieldChanged( const QString& fieldName );
5154

5255
public slots:
53-
//! set the layer of which the fields are listed
54-
void setLayer( QgsVectorLayer* layer );
5556

56-
//! convenience slot to connect QgsMapLayerComboBox layer signal
57+
/**
58+
* Sets the layer for which fields are listed in the combobox. If no layer is set
59+
* or a non-vector layer is set then the combobox will be empty.
60+
* @see layer()
61+
*/
5762
void setLayer( QgsMapLayer* layer );
5863

5964
//! setField sets the currently selected field

‎python/gui/qgsfieldexpressionwidget.sip

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ class QgsFieldExpressionWidget : QWidget
6464
*/
6565
QString expression() const;
6666

67-
//! Returns the currently used layer
67+
/**
68+
* Returns the layer currently associated with the widget.
69+
* @see setLayer()
70+
*/
6871
QgsVectorLayer* layer() const;
6972

7073
/**
@@ -86,10 +89,10 @@ class QgsFieldExpressionWidget : QWidget
8689
// void returnPressed();
8790

8891
public slots:
89-
//! set the layer used to display the fields and expression
90-
void setLayer( QgsVectorLayer* layer );
91-
92-
//! convenience slot to connect QgsMapLayerComboBox layer signal
92+
/**
93+
* Sets the layer used to display the fields and expression.
94+
* @see layer()
95+
*/
9396
void setLayer( QgsMapLayer* layer );
9497

9598
//! sets the current row in the widget

‎src/app/composer/qgsatlascompositionwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
3333

3434
mAtlasCoverageLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
3535

36-
connect( mAtlasCoverageLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mAtlasSortFeatureKeyComboBox, SLOT( setLayer( QgsMapLayer* ) ) );
37-
connect( mAtlasCoverageLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mPageNameWidget, SLOT( setLayer( QgsMapLayer* ) ) );
36+
connect( mAtlasCoverageLayerComboBox, &QgsMapLayerComboBox::layerChanged, mAtlasSortFeatureKeyComboBox, &QgsFieldComboBox::setLayer );
37+
connect( mAtlasCoverageLayerComboBox, &QgsMapLayerComboBox::layerChanged, mPageNameWidget, &QgsFieldExpressionWidget::setLayer );
3838
connect( mAtlasCoverageLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( changeCoverageLayer( QgsMapLayer* ) ) );
3939
connect( mAtlasSortFeatureKeyComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( changesSortFeatureField( QString ) ) );
4040
connect( mPageNameWidget, SIGNAL( fieldChanged( QString, bool ) ), this, SLOT( pageNameExpressionChanged( QString, bool ) ) );

‎src/app/qgsjoindialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList<QgsMapLayer*> already
4343

4444
mJoinLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
4545
mJoinLayerComboBox->setExceptedLayerList( alreadyJoinedLayers );
46-
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mJoinFieldComboBox, SLOT( setLayer( QgsMapLayer* ) ) );
47-
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( joinedLayerChanged( QgsMapLayer* ) ) );
46+
connect( mJoinLayerComboBox, &QgsMapLayerComboBox::layerChanged, mJoinFieldComboBox, &QgsFieldComboBox::setLayer );
47+
connect( mJoinLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsJoinDialog::joinedLayerChanged );
4848

4949
mCacheInMemoryCheckBox->setChecked( true );
5050

@@ -55,7 +55,7 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QList<QgsMapLayer*> already
5555
joinedLayerChanged( joinLayer );
5656
}
5757

58-
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( checkDefinitionValid() ) );
58+
connect( mJoinLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsJoinDialog::checkDefinitionValid );
5959
connect( mJoinFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( checkDefinitionValid() ) );
6060
connect( mTargetFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( checkDefinitionValid() ) );
6161

‎src/app/qgslayerstylingwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas* canvas, const QList<
8383

8484
connect( mOptionsListWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( updateCurrentWidgetLayer() ) );
8585
connect( mButtonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
86-
connect( mLayerCombo, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( setLayer( QgsMapLayer* ) ) );
86+
connect( mLayerCombo, &QgsMapLayerComboBox::layerChanged, this, &QgsLayerStylingWidget::setLayer );
8787
connect( mLiveApplyCheck, SIGNAL( toggled( bool ) ), this, SLOT( liveApplyToggled( bool ) ) );
8888

8989
mStackedWidget->setCurrentIndex( 0 );

‎src/app/qgsrelationadddlg.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ QgsRelationAddDlg::QgsRelationAddDlg( QWidget *parent )
2525
{
2626
setupUi( this );
2727

28-
connect( mCbxReferencingLayer, &QgsMapLayerComboBox::layerChanged, this, [=]( QgsMapLayer * layer ) { mCbxReferencingField->setLayer( layer ); }
29-
);
30-
connect( mCbxReferencedLayer, &QgsMapLayerComboBox::layerChanged, this, [=]( QgsMapLayer * layer ) { mCbxReferencedField->setLayer( layer ); }
31-
);
28+
connect( mCbxReferencingLayer, &QgsMapLayerComboBox::layerChanged, mCbxReferencingField, &QgsFieldComboBox::setLayer );
29+
connect( mCbxReferencedLayer, &QgsMapLayerComboBox::layerChanged, mCbxReferencedField, &QgsFieldComboBox::setLayer );
3230

3331
mCbxReferencingLayer->setFilters( QgsMapLayerProxyModel::VectorLayer );
3432
mCbxReferencingField->setLayer( mCbxReferencingLayer->currentLayer() );

‎src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ QgsValueRelationConfigDlg::QgsValueRelationConfigDlg( QgsVectorLayer* vl, int fi
2323
{
2424
setupUi( this );
2525
mLayerName->setFilters( QgsMapLayerProxyModel::VectorLayer );
26-
connect( mLayerName, SIGNAL( layerChanged( QgsMapLayer* ) ), mKeyColumn, SLOT( setLayer( QgsMapLayer* ) ) );
27-
connect( mLayerName, SIGNAL( layerChanged( QgsMapLayer* ) ), mValueColumn, SLOT( setLayer( QgsMapLayer* ) ) );
26+
connect( mLayerName, &QgsMapLayerComboBox::layerChanged, mKeyColumn, &QgsFieldComboBox::setLayer );
27+
connect( mLayerName, &QgsMapLayerComboBox::layerChanged, mValueColumn, &QgsFieldComboBox::setLayer );
2828
connect( mEditExpression, SIGNAL( clicked() ), this, SLOT( editExpression() ) );
2929

3030
connect( mLayerName, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SIGNAL( changed() ) );

‎src/gui/qgsfieldcombobox.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,8 @@ bool QgsFieldComboBox::allowEmptyFieldName() const
4545

4646
void QgsFieldComboBox::setLayer( QgsMapLayer *layer )
4747
{
48-
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
49-
if ( vl )
50-
{
51-
setLayer( vl );
52-
}
53-
}
54-
55-
void QgsFieldComboBox::setLayer( QgsVectorLayer *layer )
56-
{
57-
mFieldProxyModel->sourceFieldModel()->setLayer( layer );
48+
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( layer );
49+
mFieldProxyModel->sourceFieldModel()->setLayer( vl );
5850
}
5951

6052
QgsVectorLayer *QgsFieldComboBox::layer() const

‎src/gui/qgsfieldcombobox.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,23 @@ class GUI_EXPORT QgsFieldComboBox : public QComboBox
6868
//! return the currently selected field
6969
QString currentField() const;
7070

71-
//! Returns the currently used layer
71+
/**
72+
* Returns the layer currently associated with the combobox.
73+
* @see setLayer()
74+
*/
7275
QgsVectorLayer* layer() const;
7376

7477
signals:
7578
//! the signal is emitted when the currently selected field changes
7679
void fieldChanged( const QString& fieldName );
7780

7881
public slots:
79-
//! set the layer of which the fields are listed
80-
void setLayer( QgsVectorLayer* layer );
8182

82-
//! convenience slot to connect QgsMapLayerComboBox layer signal
83+
/**
84+
* Sets the layer for which fields are listed in the combobox. If no layer is set
85+
* or a non-vector layer is set then the combobox will be empty.
86+
* @see layer()
87+
*/
8388
void setLayer( QgsMapLayer* layer );
8489

8590
//! setField sets the currently selected field

‎src/gui/qgsfieldexpressionwidget.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,17 @@ void QgsFieldExpressionWidget::registerExpressionContextGenerator( const QgsExpr
154154

155155
void QgsFieldExpressionWidget::setLayer( QgsMapLayer *layer )
156156
{
157-
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
158-
if ( vl )
159-
{
160-
setLayer( vl );
161-
}
162-
}
157+
QgsVectorLayer* vl = qobject_cast< QgsVectorLayer* >( layer );
163158

164-
void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )
165-
{
166159
if ( mFieldProxyModel->sourceFieldModel()->layer() )
167160
disconnect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), this, SLOT( reloadLayer() ) );
168161

169-
if ( layer )
170-
mExpressionContext = layer->createExpressionContext();
162+
if ( vl )
163+
mExpressionContext = vl->createExpressionContext();
171164
else
172165
mExpressionContext = QgsProject::instance()->createExpressionContext();
173166

174-
mFieldProxyModel->sourceFieldModel()->setLayer( layer );
167+
mFieldProxyModel->sourceFieldModel()->setLayer( vl );
175168

176169
if ( mFieldProxyModel->sourceFieldModel()->layer() )
177170
connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), SLOT( reloadLayer() ), Qt::UniqueConnection );

‎src/gui/qgsfieldexpressionwidget.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
111111
*/
112112
QString expression() const;
113113

114-
//! Returns the currently used layer
114+
/**
115+
* Returns the layer currently associated with the widget.
116+
* @see setLayer()
117+
*/
115118
QgsVectorLayer* layer() const;
116119

117120
/**
@@ -133,10 +136,11 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
133136
// void returnPressed();
134137

135138
public slots:
136-
//! set the layer used to display the fields and expression
137-
void setLayer( QgsVectorLayer* layer );
138139

139-
//! convenience slot to connect QgsMapLayerComboBox layer signal
140+
/**
141+
* Sets the layer used to display the fields and expression.
142+
* @see layer()
143+
*/
140144
void setLayer( QgsMapLayer* layer );
141145

142146
//! sets the current row in the widget

‎src/gui/qgsorderbydialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "qgsexpressionbuilderdialog.h"
2020
#include "qgsfieldexpressionwidget.h"
21+
#include "qgsvectorlayer.h"
2122

2223
#include <QTableWidget>
2324
#include <QKeyEvent>

‎src/plugins/heatmap/heatmapgui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WindowFlags fl, QMap<QString, QVari
7171

7272
mRadiusFieldCombo->setFilters( QgsFieldProxyModel::Numeric );
7373
mWeightFieldCombo->setFilters( QgsFieldProxyModel::Numeric );
74-
connect( mInputLayerCombo, SIGNAL( layerChanged( QgsMapLayer* ) ), mRadiusFieldCombo, SLOT( setLayer( QgsMapLayer* ) ) );
75-
connect( mInputLayerCombo, SIGNAL( layerChanged( QgsMapLayer* ) ), mWeightFieldCombo, SLOT( setLayer( QgsMapLayer* ) ) );
74+
connect( mInputLayerCombo, &QgsMapLayerComboBox::layerChanged, mRadiusFieldCombo, &QgsFieldComboBox::setLayer );
75+
connect( mInputLayerCombo, &QgsMapLayerComboBox::layerChanged, mWeightFieldCombo, &QgsFieldComboBox::setLayer );
7676
mRadiusFieldCombo->setLayer( mInputLayerCombo->currentLayer() );
7777
mWeightFieldCombo->setLayer( mInputLayerCombo->currentLayer() );
7878

0 commit comments

Comments
 (0)
Please sign in to comment.