Skip to content
Permalink
Browse files

FieldExpressionWidget: preserve expression when join is removed

  • Loading branch information
m-kuhn authored and 3nids committed Feb 1, 2016
1 parent 4ddd1cc commit d6169b8d3ddb94c6e0143c318e95e5aca3f5637e
Showing with 26 additions and 9 deletions.
  1. +15 −1 src/gui/qgsfieldexpressionwidget.cpp
  2. +4 −0 src/gui/qgsfieldexpressionwidget.h
  3. +7 −8 src/gui/qgsfieldmodel.h
@@ -58,6 +58,8 @@ QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent )
connect( mCombo->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( expressionEditingFinished() ) );
connect( mCombo, SIGNAL( activated( int ) ), this, SLOT( currentFieldChanged() ) );
connect( mButton, SIGNAL( clicked() ), this, SLOT( editExpression() ) );
connect( mFieldProxyModel, SIGNAL( modelAboutToBeReset() ), this, SLOT( beforeResetModel() ) );
connect( mFieldProxyModel, SIGNAL( modelReset() ), this, SLOT( afterResetModel() ) );
// NW TODO - Fix in 2.6
// connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) );

@@ -158,7 +160,7 @@ void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )

mFieldProxyModel->sourceFieldModel()->setLayer( layer );

connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), this, SLOT( reloadLayer() ) );
connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), SLOT( reloadLayer() ), Qt::UniqueConnection );
}

void QgsFieldExpressionWidget::setField( const QString &fieldName )
@@ -240,6 +242,18 @@ void QgsFieldExpressionWidget::reloadLayer()
setLayer( mFieldProxyModel->sourceFieldModel()->layer() );
}

void QgsFieldExpressionWidget::beforeResetModel()
{
// Backup expression
mBackupExpression = mCombo->currentText();
}

void QgsFieldExpressionWidget::afterResetModel()
{
// Restore expression
mCombo->lineEdit()->setText( mBackupExpression );
}

void QgsFieldExpressionWidget::currentFieldChanged()
{
updateLineEditStyle();
@@ -150,6 +150,9 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
private slots:
void reloadLayer();

void beforeResetModel();
void afterResetModel();

private:
QComboBox* mCombo;
QToolButton* mButton;
@@ -159,6 +162,7 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
QScopedPointer< QgsExpressionContext > mExpressionContext;
ExpressionContextCallback mExpressionContextCallback;
const void* mExpressionContextCallbackContext;
QString mBackupExpression;

friend class TestQgsFieldExpressionWidget;
};
@@ -67,6 +67,13 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
//! returns the currently used layer
QgsVectorLayer* layer() { return mLayer; }

// QAbstractItemModel interface
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
QModelIndex parent( const QModelIndex &child ) const override;
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;

public slots:
//! set the layer of whch fields are displayed
void setLayer( QgsVectorLayer *layer );
@@ -86,14 +93,6 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel

private:
void fetchFeature();

// QAbstractItemModel interface
public:
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
QModelIndex parent( const QModelIndex &child ) const override;
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
};

#endif // QGSFIELDMODEL_H

0 comments on commit d6169b8

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