diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 764ff947b561..c8c2acb1c65d 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -8994,7 +8994,6 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer ) bool canChangeAttributes = dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues; bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures; - bool canAddAttributes = dprovider->capabilities() & QgsVectorDataProvider::AddAttributes; bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures; bool canSupportEditing = dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities; bool canChangeGeometry = dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries; @@ -9126,7 +9125,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer ) mActionAddFeature->setIcon( QgsApplication::getThemeIcon( "/mActionNewTableRow.png" ) ); } - mActionOpenFieldCalc->setEnabled( isEditable && ( canChangeAttributes || canAddAttributes ) ); + mActionOpenFieldCalc->setEnabled( true ); return; } diff --git a/src/app/qgsaddattrdialog.cpp b/src/app/qgsaddattrdialog.cpp index a2a99a9fce11..aae49414d482 100644 --- a/src/app/qgsaddattrdialog.cpp +++ b/src/app/qgsaddattrdialog.cpp @@ -19,15 +19,12 @@ #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" #include "qgslogger.h" -#include "qgsexpressionbuilderdialog.h" #include -#include QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent, Qt::WindowFlags fl ) : QDialog( parent, fl ) , mIsShapeFile( vlayer && vlayer->providerType() == "ogr" && vlayer->storageType() == "ESRI Shapefile" ) - , mLayer( vlayer ) { setupUi( this ); @@ -53,18 +50,9 @@ QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent, Qt: } on_mTypeBox_currentIndexChanged( 0 ); - on_mFieldModeButtonGroup_buttonClicked( mButtonProviderField ); if ( mIsShapeFile ) mNameEdit->setMaxLength( 10 ); - - mExpressionWidget->setLayer( vlayer ); - - int cap = mLayer->dataProvider()->capabilities(); - - mButtonProviderField->setEnabled( cap & QgsVectorDataProvider::AddAttributes ); - - mInfoIcon->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) ); } void QgsAddAttrDialog::on_mTypeBox_currentIndexChanged( int idx ) @@ -82,22 +70,6 @@ void QgsAddAttrDialog::on_mTypeBox_currentIndexChanged( int idx ) setPrecisionMinMax(); } -void QgsAddAttrDialog::on_mFieldModeButtonGroup_buttonClicked( QAbstractButton* button ) -{ - if ( button == mButtonProviderField ) - { - mExpressionWidget->hide(); - mExpressionLabel->hide(); - } - else - { - mExpressionWidget->show(); - mExpressionLabel->show(); - } - - mLayerEditableInfo->setVisible( !mLayer->isEditable() && button == mButtonProviderField ); -} - void QgsAddAttrDialog::on_mLength_editingFinished() { setPrecisionMinMax(); @@ -128,17 +100,6 @@ void QgsAddAttrDialog::accept() tr( "No name specified. Please specify a name to create a new field." ) ); return; } - if ( mButtonVirtualField->isChecked() && mExpressionWidget->currentField().isEmpty() ) - { - QMessageBox::warning( this, tr( "Warning" ), - tr( "No expression specified. Please enter an expression that will be used to calculate the field values." ) ); - return; - } - - if ( !mLayer->isEditable() && mode() == ProviderField ) - { - mLayer->startEditing(); - } QDialog::accept(); } @@ -162,16 +123,3 @@ QgsField QgsAddAttrDialog::field() const mPrec->value(), mCommentEdit->text() ); } - -const QString QgsAddAttrDialog::expression() const -{ - return mExpressionWidget->currentField(); -} - -QgsAddAttrDialog::AttributeMode QgsAddAttrDialog::mode() const -{ - if ( mButtonVirtualField->isChecked() ) - return VirtualField; - else - return ProviderField; -} diff --git a/src/app/qgsaddattrdialog.h b/src/app/qgsaddattrdialog.h index 3777ce99f414..bad841ab9962 100644 --- a/src/app/qgsaddattrdialog.h +++ b/src/app/qgsaddattrdialog.h @@ -28,28 +28,20 @@ class APP_EXPORT QgsAddAttrDialog: public QDialog, private Ui::QgsAddAttrDialogB { Q_OBJECT public: - enum AttributeMode - { - ProviderField, - VirtualField - }; - QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags ); + QgsAddAttrDialog( const std::list& typelist, + QWidget *parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags ); QgsField field() const; - const QString expression() const; - AttributeMode mode() const; - private slots: + public slots: void on_mTypeBox_currentIndexChanged( int idx ); - void on_mFieldModeButtonGroup_buttonClicked( QAbstractButton* button ); void on_mLength_editingFinished(); void accept(); private: bool mIsShapeFile; - QgsVectorLayer* mLayer; void setPrecisionMinMax(); }; diff --git a/src/app/qgsattributetabledialog.cpp b/src/app/qgsattributetabledialog.cpp index 04c144c0f7bc..c599578f5a7d 100644 --- a/src/app/qgsattributetabledialog.cpp +++ b/src/app/qgsattributetabledialog.cpp @@ -172,7 +172,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid mToggleEditingButton->blockSignals( false ); mSaveEditsButton->setEnabled( mToggleEditingButton->isEnabled() && mLayer->isEditable() ); - mOpenFieldCalculator->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() ); + mAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() ); mDeleteSelectedButton->setEnabled( canDeleteFeatures && mLayer->isEditable() ); mAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() && mLayer->geometryType() == QGis::NoGeometry ); mAddFeature->setHidden( !canAddFeatures || mLayer->geometryType() != QGis::NoGeometry ); @@ -558,7 +558,7 @@ void QgsAttributeTableDialog::editingToggled() bool canDeleteFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures; bool canAddAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes; bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures; - mOpenFieldCalculator->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() ); + mAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() ); mDeleteSelectedButton->setEnabled( canDeleteFeatures && mLayer->isEditable() ); mAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() && mLayer->geometryType() == QGis::NoGeometry ); @@ -579,24 +579,18 @@ void QgsAttributeTableDialog::on_mAddAttribute_clicked() QgsAddAttrDialog dialog( mLayer, this ); if ( dialog.exec() == QDialog::Accepted ) { - if ( dialog.mode() == QgsAddAttrDialog::VirtualField ) + mLayer->beginEditCommand( tr( "Attribute added" ) ); + if ( mLayer->addAttribute( dialog.field() ) ) { - mLayer->addExpressionField( dialog.expression(), dialog.field() ); + mLayer->endEditCommand(); } else { - mLayer->beginEditCommand( tr( "Attribute added" ) ); - if ( mLayer->addAttribute( dialog.field() ) ) - { - mLayer->endEditCommand(); - } - else - { - mLayer->destroyEditCommand(); - QMessageBox::critical( this, tr( "Failed to add field" ), tr( "Failed to add field '%1' of type '%2'. Is the field name unique?" ).arg( dialog.field().name() ).arg( dialog.field().typeName() ) ); - } + mLayer->destroyEditCommand(); + QMessageBox::critical( this, tr( "Failed to add field" ), tr( "Failed to add field '%1' of type '%2'. Is the field name unique?" ).arg( dialog.field().name() ).arg( dialog.field().typeName() ) ); } + // update model - a field has been added or updated masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) ); columnBoxInit(); diff --git a/src/app/qgsfieldcalculator.cpp b/src/app/qgsfieldcalculator.cpp index 1ea63018fbdd..2f4e06f847d9 100644 --- a/src/app/qgsfieldcalculator.cpp +++ b/src/app/qgsfieldcalculator.cpp @@ -58,8 +58,23 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl ) mOutputFieldNameLineEdit->setMaxLength( 10 ); } - mUpdateExistingGroupBox->setEnabled( vl->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ); - mNewFieldGroupBox->setEnabled( vl->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes ); + if( !( vl->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes ) ) + { + mCreateVirtualFieldCheckbox->setChecked( true ); + mCreateVirtualFieldCheckbox->setEnabled( false ); + mOnlyVirtualFieldsInfoLabel->setVisible( true ); + } + else + { + mOnlyVirtualFieldsInfoLabel->setVisible( false ); + } + + if ( !( vl->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ) + { + mUpdateExistingGroupBox->setEnabled( false ); + mCreateVirtualFieldCheckbox->setChecked( true ); + mCreateVirtualFieldCheckbox->setEnabled( false ); + } Q_ASSERT( mNewFieldGroupBox->isEnabled() || mUpdateExistingGroupBox->isEnabled() ); @@ -85,13 +100,21 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl ) mNewFieldGroupBox->setCheckable( false ); } - bool hasselection = vl->selectedFeaturesIds().size() > 0; + if ( ( mNewFieldGroupBox->isChecked() && mCreateVirtualFieldCheckbox->isChecked() ) || mVectorLayer->isEditable() ) + { + mEditModeAutoTurnOnLabel->setVisible( false ); + } + + bool hasselection = vl->selectedFeatureCount() > 0; mOnlyUpdateSelectedCheckBox->setChecked( hasselection ); mOnlyUpdateSelectedCheckBox->setEnabled( hasselection ); - mOnlyUpdateSelectedCheckBox->setText( tr( "Only update %1 selected features" ).arg( vl->selectedFeaturesIds().size() ) ); + mOnlyUpdateSelectedCheckBox->setText( tr( "Only update %1 selected features" ).arg( vl->selectedFeatureCount() ) ); builder->loadRecent( "fieldcalc" ); + mEditModeAutoTurnOnLabel->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) ); + mOnlyVirtualFieldsInfoLabel->setPixmap( style()->standardPixmap( QStyle::SP_MessageBoxInformation ) ); + QSettings settings; restoreGeometry( settings.value( "/Windows/QgsFieldCalculator/geometry" ).toByteArray() ); } @@ -118,7 +141,7 @@ void QgsFieldCalculator::accept() QgsExpression exp( calcString ); exp.setGeomCalculator( myDa ); - if ( !mVectorLayer || !mVectorLayer->isEditable() ) + if ( !mVectorLayer ) return; if ( ! exp.prepare( mVectorLayer->pendingFields() ) ) @@ -127,118 +150,124 @@ void QgsFieldCalculator::accept() return; } - QApplication::setOverrideCursor( Qt::WaitCursor ); - - mVectorLayer->beginEditCommand( "Field calculator" ); - - //update existing field - if ( mUpdateExistingGroupBox->isChecked() || !mNewFieldGroupBox->isEnabled() ) + if ( mNewFieldGroupBox->isEnabled() && mCreateVirtualFieldCheckbox->isChecked() ) { - QMap::const_iterator fieldIt = mFieldMap.find( mExistingFieldComboBox->currentText() ); - if ( fieldIt != mFieldMap.end() ) - { - mAttributeId = fieldIt.value(); - } + mVectorLayer->addExpressionField( calcString, fieldDefinition() ); } else { - //create new field - QgsField newField( mOutputFieldNameLineEdit->text(), - ( QVariant::Type ) mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole ).toInt(), - mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole + 1 ).toString(), - mOutputFieldWidthSpinBox->value(), - mOutputFieldPrecisionSpinBox->value() ); - - if ( !mVectorLayer->addAttribute( newField ) ) + if ( !mVectorLayer->isEditable() ) + mVectorLayer->startEditing(); + + QApplication::setOverrideCursor( Qt::WaitCursor ); + + mVectorLayer->beginEditCommand( "Field calculator" ); + + //update existing field + if ( mUpdateExistingGroupBox->isChecked() || !mNewFieldGroupBox->isEnabled() ) { - QApplication::restoreOverrideCursor(); - QMessageBox::critical( 0, tr( "Provider error" ), tr( "Could not add the new field to the provider." ) ); - mVectorLayer->destroyEditCommand(); - return; + QMap::const_iterator fieldIt = mFieldMap.find( mExistingFieldComboBox->currentText() ); + if ( fieldIt != mFieldMap.end() ) + { + mAttributeId = fieldIt.value(); + } } + else + { + //create new field + const QgsField newField = fieldDefinition(); - //get index of the new field - const QgsFields& fields = mVectorLayer->pendingFields(); + if ( !mVectorLayer->addAttribute( newField ) ) + { + QApplication::restoreOverrideCursor(); + QMessageBox::critical( 0, tr( "Provider error" ), tr( "Could not add the new field to the provider." ) ); + mVectorLayer->destroyEditCommand(); + return; + } - for ( int idx = 0; idx < fields.count(); ++idx ) - { - if ( fields[idx].name() == mOutputFieldNameLineEdit->text() ) + //get index of the new field + const QgsFields& fields = mVectorLayer->pendingFields(); + + for ( int idx = 0; idx < fields.count(); ++idx ) { - mAttributeId = idx; - break; + if ( fields[idx].name() == mOutputFieldNameLineEdit->text() ) + { + mAttributeId = idx; + break; + } + } + + if ( ! exp.prepare( mVectorLayer->pendingFields() ) ) + { + QApplication::restoreOverrideCursor(); + QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() ); + return; } } - if ( ! exp.prepare( mVectorLayer->pendingFields() ) ) + if ( mAttributeId == -1 ) { + mVectorLayer->destroyEditCommand(); QApplication::restoreOverrideCursor(); - QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() ); return; } - } - if ( mAttributeId == -1 ) - { - mVectorLayer->destroyEditCommand(); - QApplication::restoreOverrideCursor(); - return; - } - - //go through all the features and change the new attribute - QgsFeature feature; - bool calculationSuccess = true; - QString error; + //go through all the features and change the new attribute + QgsFeature feature; + bool calculationSuccess = true; + QString error; - bool onlySelected = mOnlyUpdateSelectedCheckBox->isChecked(); - QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds(); + bool onlySelected = mOnlyUpdateSelectedCheckBox->isChecked(); + QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds(); - bool useGeometry = exp.needsGeometry(); - int rownum = 1; + bool useGeometry = exp.needsGeometry(); + int rownum = 1; - const QgsField& field = mVectorLayer->pendingFields()[mAttributeId]; + const QgsField& field = mVectorLayer->pendingFields()[mAttributeId]; - bool newField = !mUpdateExistingGroupBox->isChecked(); - QVariant emptyAttribute; - if ( newField ) - emptyAttribute = QVariant( field.type() ); + bool newField = !mUpdateExistingGroupBox->isChecked(); + QVariant emptyAttribute; + if ( newField ) + emptyAttribute = QVariant( field.type() ); - QgsFeatureIterator fit = mVectorLayer->getFeatures( QgsFeatureRequest().setFlags( useGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) ); - while ( fit.nextFeature( feature ) ) - { - if ( onlySelected ) + QgsFeatureIterator fit = mVectorLayer->getFeatures( QgsFeatureRequest().setFlags( useGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) ); + while ( fit.nextFeature( feature ) ) { - if ( !selectedIds.contains( feature.id() ) ) + if ( onlySelected ) { - continue; + if ( !selectedIds.contains( feature.id() ) ) + { + continue; + } } - } - exp.setCurrentRowNumber( rownum ); - QVariant value = exp.evaluate( &feature ); - field.convertCompatible( value ); - if ( exp.hasEvalError() ) - { - calculationSuccess = false; - error = exp.evalErrorString(); - break; - } - else - { - mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value, newField ? emptyAttribute : feature.attributes().value( mAttributeId ) ); + exp.setCurrentRowNumber( rownum ); + QVariant value = exp.evaluate( &feature ); + field.convertCompatible( value ); + if ( exp.hasEvalError() ) + { + calculationSuccess = false; + error = exp.evalErrorString(); + break; + } + else + { + mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value, newField ? emptyAttribute : feature.attributes().value( mAttributeId ) ); + } + + rownum++; } - rownum++; - } + QApplication::restoreOverrideCursor(); - QApplication::restoreOverrideCursor(); + if ( !calculationSuccess ) + { + QMessageBox::critical( 0, tr( "Error" ), tr( "An error occured while evaluating the calculation string:\n%1" ).arg( error ) ); + mVectorLayer->destroyEditCommand(); + return; + } - if ( !calculationSuccess ) - { - QMessageBox::critical( 0, tr( "Error" ), tr( "An error occured while evaluating the calculation string:\n%1" ).arg( error ) ); - mVectorLayer->destroyEditCommand(); - return; + mVectorLayer->endEditCommand(); } - - mVectorLayer->endEditCommand(); QDialog::accept(); } @@ -275,12 +304,53 @@ void QgsFieldCalculator::populateOutputFieldTypes() void QgsFieldCalculator::on_mNewFieldGroupBox_toggled( bool on ) { mUpdateExistingGroupBox->setChecked( !on ); + if ( on && ! ( mVectorLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes ) ) + { + mOnlyVirtualFieldsInfoLabel->setVisible( true ); + } + else + { + mOnlyVirtualFieldsInfoLabel->setVisible( false ); + } + + if ( ( mNewFieldGroupBox->isChecked() && mCreateVirtualFieldCheckbox->isChecked() ) || mVectorLayer->isEditable() ) + { + mEditModeAutoTurnOnLabel->setVisible( false ); + } + else + { + mEditModeAutoTurnOnLabel->setVisible( true ); + } } void QgsFieldCalculator::on_mUpdateExistingGroupBox_toggled( bool on ) { mNewFieldGroupBox->setChecked( !on ); setOkButtonState(); + + if ( on ) + { + mOnlyUpdateSelectedCheckBox->setEnabled( mVectorLayer->selectedFeatureCount() > 0 ); + } + else + { + on_mCreateVirtualFieldCheckbox_stateChanged( mCreateVirtualFieldCheckbox->checkState() ); + } +} + +void QgsFieldCalculator::on_mCreateVirtualFieldCheckbox_stateChanged( int state ) +{ + mOnlyUpdateSelectedCheckBox->setChecked( false ); + mOnlyUpdateSelectedCheckBox->setEnabled( state != Qt::Checked && mVectorLayer->selectedFeatureCount() > 0 ); + + if ( ( mNewFieldGroupBox->isChecked() && mCreateVirtualFieldCheckbox->isChecked() ) || mVectorLayer->isEditable() ) + { + mEditModeAutoTurnOnLabel->setVisible( false ); + } + else + { + mEditModeAutoTurnOnLabel->setVisible( true ); + } } diff --git a/src/app/qgsfieldcalculator.h b/src/app/qgsfieldcalculator.h index df910e29545c..c12c644376da 100644 --- a/src/app/qgsfieldcalculator.h +++ b/src/app/qgsfieldcalculator.h @@ -36,27 +36,38 @@ class APP_EXPORT QgsFieldCalculator: public QDialog, private Ui::QgsFieldCalcula void on_mNewFieldGroupBox_toggled( bool on ); void on_mUpdateExistingGroupBox_toggled( bool on ); + void on_mCreateVirtualFieldCheckbox_stateChanged( int state ); void on_mOutputFieldNameLineEdit_textChanged( const QString& text ); void on_mOutputFieldTypeComboBox_activated( int index ); void on_mButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } private slots: - /**Sets the ok button enabled / disabled*/ + /** Sets the ok button enabled / disabled*/ void setOkButtonState(); private: - //default constructor forbidden + //! default constructor forbidden QgsFieldCalculator(); - /**Inserts existing fields into the combo box*/ + /** Inserts existing fields into the combo box*/ void populateFields(); - /**Inserts the types supported by the provider into the combo box*/ + /** Inserts the types supported by the provider into the combo box*/ void populateOutputFieldTypes(); QgsVectorLayer* mVectorLayer; - /**Key: field name, Value: field index*/ + /** Key: field name, Value: field index*/ QMap mFieldMap; + /** Create a field based on the definitions */ + inline QgsField fieldDefinition() + { + return QgsField( mOutputFieldNameLineEdit->text(), + ( QVariant::Type ) mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole ).toInt(), + mOutputFieldTypeComboBox->itemData( mOutputFieldTypeComboBox->currentIndex(), Qt::UserRole + 1 ).toString(), + mOutputFieldWidthSpinBox->value(), + mOutputFieldPrecisionSpinBox->value() ); + } + /**idx of changed attribute*/ int mAttributeId; diff --git a/src/app/qgsfieldsproperties.cpp b/src/app/qgsfieldsproperties.cpp index e38969914bbe..ad451d00a2e3 100644 --- a/src/app/qgsfieldsproperties.cpp +++ b/src/app/qgsfieldsproperties.cpp @@ -533,14 +533,8 @@ void QgsFieldsProperties::on_mAddAttributeButton_clicked() QgsAddAttrDialog dialog( mLayer, this ); if ( dialog.exec() == QDialog::Accepted ) { - if ( dialog.mode() == QgsAddAttrDialog::VirtualField ) - { - mLayer->addExpressionField( dialog.expression(), dialog.field() ); - } - else - { - addAttribute( dialog.field() ); - } + addAttribute( dialog.field() ); + } } @@ -582,13 +576,13 @@ void QgsFieldsProperties::updateButtons() if ( mLayer->isEditable() ) { mDeleteAttributeButton->setEnabled( cap & QgsVectorDataProvider::DeleteAttributes ); - mCalculateFieldButton->setEnabled( cap & ( QgsVectorDataProvider::ChangeAttributeValues | QgsVectorDataProvider::AddAttributes ) ); + mAddAttributeButton->setEnabled( cap & QgsVectorDataProvider::AddAttributes ); mToggleEditingButton->setChecked( true ); } else { mToggleEditingButton->setChecked( false ); - mCalculateFieldButton->setEnabled( false ); + mAddAttributeButton->setEnabled( false ); // Enable delete button if items are selected mDeleteAttributeButton->setEnabled( mFieldsList->selectedItems().count() > 0 ); diff --git a/src/ui/qgsaddattrdialogbase.ui b/src/ui/qgsaddattrdialogbase.ui index 110e812fe8ab..32d2d0626779 100644 --- a/src/ui/qgsaddattrdialogbase.ui +++ b/src/ui/qgsaddattrdialogbase.ui @@ -6,8 +6,8 @@ 0 0 - 487 - 416 + 225 + 190 @@ -17,196 +17,97 @@ true + + + + N&ame + + + mNameEdit + + + - - - <i>Virtual fields</i> are calculated on the fly and cannot be directly modified and will not be saved to the data. + + + + + + Comment + + mCommentEdit + + + + + + + + - Virtual Field + Type + + + mTypeBox - - mFieldModeButtonGroup - - - - - <i>Permanent fields</i> are saved in the data provider and it is possible to directly modify them. + + + + + + + Type + + + mTypeBox + + + + - Permanent Field + Width - - true + + mLength - - mFieldModeButtonGroup - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - 0 - - - - - Define an expression which will be used to calculate this field. - - - Expression - - - - - - - N&ame - - - mNameEdit - - - - - - - - - - Comment - - - mCommentEdit - - - - - - - - - - Type - - - mTypeBox - - - - - - - - - - Type - - - mTypeBox - - - - - - - Width - - - mLength - - - - - - - - - - Precision - - - mPrec - - - - - - - - - - + + + + + + + Precision + + + mPrec + - + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - - - - - 0 - 0 - - - - Layer is currently not in edit mode. To add a permanent field, editing mode will automatically be turned on. - - - true - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - QgsFieldExpressionWidget - QWidget -
qgsfieldexpressionwidget.h
- 1 -
-
+ mNameEdit + mCommentEdit + mTypeBox + mLength + mPrec buttonBox @@ -244,7 +145,4 @@ - - - diff --git a/src/ui/qgsfieldcalculatorbase.ui b/src/ui/qgsfieldcalculatorbase.ui index 917e2e57b954..620fbe7ad8fe 100644 --- a/src/ui/qgsfieldcalculatorbase.ui +++ b/src/ui/qgsfieldcalculatorbase.ui @@ -14,13 +14,6 @@ Field calculator - - - - Only update selected features - - - @@ -49,7 +42,7 @@ 3 - 3 + 9 3 @@ -60,7 +53,7 @@ 3 - + Output field name @@ -70,10 +63,10 @@ - + - + Output field type @@ -83,10 +76,10 @@ - + - + Output field width @@ -96,7 +89,7 @@ - + Width of complete output. For example 123,456 means 6 as field width. @@ -109,7 +102,7 @@ - + Precision @@ -119,16 +112,66 @@ - + 2 + + + + A virtual field will be recalculated every time it is used and will not be saved in the data provider but in the project. + + + Create virtual field + + + + + + + + 3 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + + + + + + This layer does not support adding new provider fields. You can only add virtual fields. + + + true + + + + + + + false + + + + + + + Only update selected features + + + @@ -144,32 +187,31 @@ false + + 3 + + + 9 + + + 3 + + + 0 + - - - - false - - - - - - - 3 - 0 - - - - Qt::Horizontal + + + You are editing information on this layer but the layer is currently not in edit mode. If you click Ok, edit mode will automatically be turned on. - - QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + true