Skip to content

Commit

Permalink
field model only works with vector layer, add convenience slots for Q…
Browse files Browse the repository at this point in the history
…gsMapLayer in QgsFieldExpressionWidget and QgsFieldComboBox
  • Loading branch information
3nids committed May 2, 2014
1 parent 41cc509 commit 31d52d9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/gui/qgsfieldcombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ QgsFieldComboBox::QgsFieldComboBox( QWidget *parent ) :
}

void QgsFieldComboBox::setLayer( QgsMapLayer *layer )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( vl )
{
setLayer( vl );
}
}

void QgsFieldComboBox::setLayer( QgsVectorLayer *layer )
{
mFieldModel->setLayer( layer );
}
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsfieldcombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class GUI_EXPORT QgsFieldComboBox : public QComboBox

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

//! convenience slot to connect QgsMapLayerComboBox layer signal
void setLayer( QgsMapLayer* layer );

//! setField sets the currently selected field
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsfieldexpressionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ QgsVectorLayer *QgsFieldExpressionWidget::layer()
return mFieldModel->layer();
}

void QgsFieldExpressionWidget::setLayer( QgsMapLayer *layer )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( vl )
{
setLayer( vl );
}
}

void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )
{
mFieldModel->setLayer( layer );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsfieldexpressionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
//! set the layer used to display the fields and expression
void setLayer( QgsVectorLayer* layer );

//! convenience slot to connect QgsMapLayerComboBox layer signal
void setLayer( QgsMapLayer* layer );

//! sets the current field or expression in the widget
void setField( QString fieldName );

Expand Down
11 changes: 2 additions & 9 deletions src/gui/qgsfieldmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QModelIndex QgsFieldModel::indexFromName( QString fieldName )
return QModelIndex();
}

void QgsFieldModel::setLayer( QgsMapLayer *layer )
void QgsFieldModel::setLayer( QgsVectorLayer *layer )
{
if ( mLayer )
{
Expand All @@ -63,15 +63,8 @@ void QgsFieldModel::setLayer( QgsMapLayer *layer )
updateModel();
return;
}
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vl )
{
mLayer = 0;
updateModel();
return;
}

mLayer = vl;
mLayer = layer;
connect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateModel() ) );
connect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( layerDeleted() ) );
updateModel();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsfieldmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel

public slots:
//! set the layer of whch fields are displayed
void setLayer( QgsMapLayer *layer );
void setLayer( QgsVectorLayer *layer );

protected slots:
virtual void updateModel();
Expand Down

0 comments on commit 31d52d9

Please sign in to comment.