Skip to content

Commit 2d4945f

Browse files
committed
Use expression widget for attribute table update bar
1 parent 31dbea9 commit 2d4945f

5 files changed

+26
-25
lines changed

src/app/qgsattributetabledialog.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
157157
mAttributeViewButton->setIcon( QgsApplication::getThemeIcon( "/mActionPropertyItem.png" ) );
158158
mExpressionSelectButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
159159
mAddFeature->setIcon( QgsApplication::getThemeIcon( "/mActionNewTableRow.png" ) );
160-
mOpenExpressionWidget->setIcon( QgsApplication::getThemeIcon( "/mIconExpression.svg" ) );
161160

162161
// toggle editing
163162
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
@@ -205,14 +204,16 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
205204
mFieldModel = new QgsFieldModel();
206205
mFieldModel->setLayer( mLayer );
207206
mFieldCombo->setModel( mFieldModel );
208-
connect( mOpenExpressionWidget, SIGNAL( clicked() ), this, SLOT( openExpressionBuilder() ) );
209207
connect( mRunFieldCalc, SIGNAL( clicked() ), this, SLOT( updateFieldFromExpression() ) );
210208
connect( mUpdateExpressionText, SIGNAL( returnPressed() ), this, SLOT( updateFieldFromExpression() ) );
209+
mUpdateExpressionText->setLayer( mLayer );
210+
mUpdateExpressionText->setLeftHandButtonStyle( true );
211211
editingToggled();
212212
}
213213

214214
QgsAttributeTableDialog::~QgsAttributeTableDialog()
215215
{
216+
delete myDa;
216217
}
217218

218219
void QgsAttributeTableDialog::updateTitle()
@@ -302,7 +303,8 @@ void QgsAttributeTableDialog::updateFieldFromExpression()
302303
bool calculationSuccess = true;
303304
QString error;
304305

305-
QgsExpression exp( mUpdateExpressionText->text() );
306+
307+
QgsExpression exp( mUpdateExpressionText->currentField() );
306308
exp.setGeomCalculator( *myDa );
307309
bool useGeometry = exp.needsGeometry();
308310

@@ -364,15 +366,6 @@ void QgsAttributeTableDialog::updateFieldFromExpression()
364366
mLayer->endEditCommand();
365367
}
366368

367-
void QgsAttributeTableDialog::openExpressionBuilder()
368-
{
369-
QgsExpressionBuilderDialog dlg( mLayer, mUpdateExpressionText->text(), this );
370-
if ( dlg.exec() )
371-
{
372-
mUpdateExpressionText->setText( dlg.expressionText() );
373-
}
374-
}
375-
376369
void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
377370
{
378371
mFilterButton->setDefaultAction( qobject_cast<QAction *>( filterAction ) );

src/app/qgsattributetabledialog.h

-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
185185
*/
186186
void columnBoxInit();
187187

188-
void openExpressionBuilder();
189-
190188
void updateFieldFromExpression();
191189

192190
private:

src/gui/qgsfieldexpressionwidget.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent )
5252
connect( mCombo->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( expressionEditingFinished() ) );
5353
connect( mCombo, SIGNAL( activated( int ) ), this, SLOT( currentFieldChanged() ) );
5454
connect( mButton, SIGNAL( clicked() ), this, SLOT( editExpression() ) );
55+
connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SLOT( returnPressed() ) );
5556
}
5657

5758
void QgsFieldExpressionWidget::setExpressionDialogTitle( QString title )

src/gui/qgsfieldexpressionwidget.h

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
9595
//! fieldChanged signal with indication of the validity of the expression
9696
void fieldChanged( QString fieldName, bool isValid );
9797

98+
void returnPressed();
99+
98100
public slots:
99101
//! set the layer used to display the fields and expression
100102
void setLayer( QgsVectorLayer* layer );

src/ui/qgsattributetabledialog.ui

+18-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>891</width>
9+
<width>837</width>
1010
<height>570</height>
1111
</rect>
1212
</property>
@@ -564,22 +564,24 @@
564564
</item>
565565
<item>
566566
<widget class="QLabel" name="label">
567-
<property name="text">
568-
<string>=</string>
567+
<property name="sizePolicy">
568+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
569+
<horstretch>0</horstretch>
570+
<verstretch>0</verstretch>
571+
</sizepolicy>
569572
</property>
570-
</widget>
571-
</item>
572-
<item>
573-
<widget class="QToolButton" name="mOpenExpressionWidget">
574573
<property name="text">
575-
<string>...</string>
574+
<string>=</string>
576575
</property>
577576
</widget>
578577
</item>
579578
<item>
580-
<widget class="QLineEdit" name="mUpdateExpressionText">
581-
<property name="placeholderText">
582-
<string>[update field expression]</string>
579+
<widget class="QgsFieldExpressionWidget" name="mUpdateExpressionText" native="true">
580+
<property name="sizePolicy">
581+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
582+
<horstretch>0</horstretch>
583+
<verstretch>0</verstretch>
584+
</sizepolicy>
583585
</property>
584586
</widget>
585587
</item>
@@ -671,6 +673,11 @@
671673
<header>qgsdualview.h</header>
672674
<container>1</container>
673675
</customwidget>
676+
<customwidget>
677+
<class>QgsFieldExpressionWidget</class>
678+
<extends>QWidget</extends>
679+
<header location="global">qgsfieldexpressionwidget.h</header>
680+
</customwidget>
674681
</customwidgets>
675682
<tabstops>
676683
<tabstop>mRemoveSelectionButton</tabstop>

0 commit comments

Comments
 (0)