Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use expression widget for attribute table update bar
  • Loading branch information
NathanW2 committed Jun 14, 2014
1 parent 31dbea9 commit 2d4945f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
17 changes: 5 additions & 12 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -157,7 +157,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mAttributeViewButton->setIcon( QgsApplication::getThemeIcon( "/mActionPropertyItem.png" ) );
mExpressionSelectButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
mAddFeature->setIcon( QgsApplication::getThemeIcon( "/mActionNewTableRow.png" ) );
mOpenExpressionWidget->setIcon( QgsApplication::getThemeIcon( "/mIconExpression.svg" ) );

// toggle editing
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
Expand Down Expand Up @@ -205,14 +204,16 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mFieldModel = new QgsFieldModel();
mFieldModel->setLayer( mLayer );
mFieldCombo->setModel( mFieldModel );
connect( mOpenExpressionWidget, SIGNAL( clicked() ), this, SLOT( openExpressionBuilder() ) );
connect( mRunFieldCalc, SIGNAL( clicked() ), this, SLOT( updateFieldFromExpression() ) );
connect( mUpdateExpressionText, SIGNAL( returnPressed() ), this, SLOT( updateFieldFromExpression() ) );
mUpdateExpressionText->setLayer( mLayer );
mUpdateExpressionText->setLeftHandButtonStyle( true );
editingToggled();
}

QgsAttributeTableDialog::~QgsAttributeTableDialog()
{
delete myDa;
}

void QgsAttributeTableDialog::updateTitle()
Expand Down Expand Up @@ -302,7 +303,8 @@ void QgsAttributeTableDialog::updateFieldFromExpression()
bool calculationSuccess = true;
QString error;

QgsExpression exp( mUpdateExpressionText->text() );

QgsExpression exp( mUpdateExpressionText->currentField() );
exp.setGeomCalculator( *myDa );
bool useGeometry = exp.needsGeometry();

Expand Down Expand Up @@ -364,15 +366,6 @@ void QgsAttributeTableDialog::updateFieldFromExpression()
mLayer->endEditCommand();
}

void QgsAttributeTableDialog::openExpressionBuilder()
{
QgsExpressionBuilderDialog dlg( mLayer, mUpdateExpressionText->text(), this );
if ( dlg.exec() )
{
mUpdateExpressionText->setText( dlg.expressionText() );
}
}

void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
{
mFilterButton->setDefaultAction( qobject_cast<QAction *>( filterAction ) );
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsattributetabledialog.h
Expand Up @@ -185,8 +185,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
*/
void columnBoxInit();

void openExpressionBuilder();

void updateFieldFromExpression();

private:
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsfieldexpressionwidget.cpp
Expand Up @@ -52,6 +52,7 @@ 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( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SLOT( returnPressed() ) );
}

void QgsFieldExpressionWidget::setExpressionDialogTitle( QString title )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsfieldexpressionwidget.h
Expand Up @@ -95,6 +95,8 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
//! fieldChanged signal with indication of the validity of the expression
void fieldChanged( QString fieldName, bool isValid );

void returnPressed();

public slots:
//! set the layer used to display the fields and expression
void setLayer( QgsVectorLayer* layer );
Expand Down
29 changes: 18 additions & 11 deletions src/ui/qgsattributetabledialog.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>891</width>
<width>837</width>
<height>570</height>
</rect>
</property>
Expand Down Expand Up @@ -564,22 +564,24 @@
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>=</string>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mOpenExpressionWidget">
<property name="text">
<string>...</string>
<string>=</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mUpdateExpressionText">
<property name="placeholderText">
<string>[update field expression]</string>
<widget class="QgsFieldExpressionWidget" name="mUpdateExpressionText" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
Expand Down Expand Up @@ -671,6 +673,11 @@
<header>qgsdualview.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFieldExpressionWidget</class>
<extends>QWidget</extends>
<header location="global">qgsfieldexpressionwidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mRemoveSelectionButton</tabstop>
Expand Down

0 comments on commit 2d4945f

Please sign in to comment.