Skip to content

Commit d6169b8

Browse files
m-kuhn3nids
authored andcommitted
FieldExpressionWidget: preserve expression when join is removed
1 parent 4ddd1cc commit d6169b8

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/gui/qgsfieldexpressionwidget.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent )
5858
connect( mCombo->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( expressionEditingFinished() ) );
5959
connect( mCombo, SIGNAL( activated( int ) ), this, SLOT( currentFieldChanged() ) );
6060
connect( mButton, SIGNAL( clicked() ), this, SLOT( editExpression() ) );
61+
connect( mFieldProxyModel, SIGNAL( modelAboutToBeReset() ), this, SLOT( beforeResetModel() ) );
62+
connect( mFieldProxyModel, SIGNAL( modelReset() ), this, SLOT( afterResetModel() ) );
6163
// NW TODO - Fix in 2.6
6264
// connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) );
6365

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

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

161-
connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), this, SLOT( reloadLayer() ) );
163+
connect( mFieldProxyModel->sourceFieldModel()->layer(), SIGNAL( updatedFields() ), SLOT( reloadLayer() ), Qt::UniqueConnection );
162164
}
163165

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

245+
void QgsFieldExpressionWidget::beforeResetModel()
246+
{
247+
// Backup expression
248+
mBackupExpression = mCombo->currentText();
249+
}
250+
251+
void QgsFieldExpressionWidget::afterResetModel()
252+
{
253+
// Restore expression
254+
mCombo->lineEdit()->setText( mBackupExpression );
255+
}
256+
243257
void QgsFieldExpressionWidget::currentFieldChanged()
244258
{
245259
updateLineEditStyle();

src/gui/qgsfieldexpressionwidget.h

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
150150
private slots:
151151
void reloadLayer();
152152

153+
void beforeResetModel();
154+
void afterResetModel();
155+
153156
private:
154157
QComboBox* mCombo;
155158
QToolButton* mButton;
@@ -159,6 +162,7 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
159162
QScopedPointer< QgsExpressionContext > mExpressionContext;
160163
ExpressionContextCallback mExpressionContextCallback;
161164
const void* mExpressionContextCallbackContext;
165+
QString mBackupExpression;
162166

163167
friend class TestQgsFieldExpressionWidget;
164168
};

src/gui/qgsfieldmodel.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
6767
//! returns the currently used layer
6868
QgsVectorLayer* layer() { return mLayer; }
6969

70+
// QAbstractItemModel interface
71+
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
72+
QModelIndex parent( const QModelIndex &child ) const override;
73+
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
74+
int columnCount( const QModelIndex &parent ) const override;
75+
QVariant data( const QModelIndex &index, int role ) const override;
76+
7077
public slots:
7178
//! set the layer of whch fields are displayed
7279
void setLayer( QgsVectorLayer *layer );
@@ -86,14 +93,6 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel
8693

8794
private:
8895
void fetchFeature();
89-
90-
// QAbstractItemModel interface
91-
public:
92-
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
93-
QModelIndex parent( const QModelIndex &child ) const override;
94-
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
95-
int columnCount( const QModelIndex &parent ) const override;
96-
QVariant data( const QModelIndex &index, int role ) const override;
9796
};
9897

9998
#endif // QGSFIELDMODEL_H

0 commit comments

Comments
 (0)