diff --git a/python/core/qgsproperty.sip b/python/core/qgsproperty.sip index 322e9d6fb06..7a21d0754ad 100644 --- a/python/core/qgsproperty.sip +++ b/python/core/qgsproperty.sip @@ -139,6 +139,11 @@ class QgsPropertyDefinition :rtype: str %End + void setDataType( DataType type ); +%Docstring + Sets the data type +%End + DataType dataType() const; %Docstring Returns the allowable field/value data type for the property. diff --git a/src/app/qgsvectorlayerproperties.cpp b/src/app/qgsvectorlayerproperties.cpp index 585dd9b23fd..982d50d537a 100644 --- a/src/app/qgsvectorlayerproperties.cpp +++ b/src/app/qgsvectorlayerproperties.cpp @@ -57,6 +57,7 @@ #include "qgsstyle.h" #include "qgsauxiliarystorage.h" #include "qgsnewauxiliarylayerdialog.h" +#include "qgsnewauxiliaryfielddialog.h" #include "qgslabelinggui.h" #include "qgssymbollayer.h" @@ -90,6 +91,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties( , mAuxiliaryLayerActionDelete( nullptr ) , mAuxiliaryLayerActionExport( nullptr ) , mAuxiliaryLayerActionDeleteField( nullptr ) + , mAuxiliaryLayerActionAddField( nullptr ) { setupUi( this ); connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited ); @@ -382,6 +384,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties( mAuxiliaryStorageActions->setMenu( menu ); connect( mAuxiliaryStorageFieldsDeleteBtn, &QPushButton::clicked, this, &QgsVectorLayerProperties::onAuxiliaryLayerDeleteField ); + connect( mAuxiliaryStorageFieldsAddBtn, &QPushButton::clicked, this, &QgsVectorLayerProperties::onAuxiliaryLayerAddField ); updateAuxiliaryStoragePage(); } @@ -1679,6 +1682,19 @@ void QgsVectorLayerProperties::onAuxiliaryLayerDeleteField() } } +void QgsVectorLayerProperties::onAuxiliaryLayerAddField() +{ + QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer(); + if ( !alayer ) + return; + + QgsNewAuxiliaryFieldDialog dlg( QgsPropertyDefinition(), mLayer, false ); + if ( dlg.exec() == QDialog::Accepted ) + { + updateAuxiliaryStoragePage(); + } +} + void QgsVectorLayerProperties::deleteAuxiliaryField( int index ) { if ( !mLayer->auxiliaryLayer() ) diff --git a/src/app/qgsvectorlayerproperties.h b/src/app/qgsvectorlayerproperties.h index def889d4919..fe39d633b03 100644 --- a/src/app/qgsvectorlayerproperties.h +++ b/src/app/qgsvectorlayerproperties.h @@ -164,6 +164,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private void onAuxiliaryLayerDeleteField(); + void onAuxiliaryLayerAddField(); + void onAuxiliaryLayerExport(); private: @@ -235,6 +237,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private QAction *mAuxiliaryLayerActionDelete = nullptr; QAction *mAuxiliaryLayerActionExport = nullptr; QAction *mAuxiliaryLayerActionDeleteField = nullptr; + QAction *mAuxiliaryLayerActionAddField = nullptr; private slots: void openPanel( QgsPanelWidget *panel ); diff --git a/src/core/qgsauxiliarystorage.cpp b/src/core/qgsauxiliarystorage.cpp index 9e1ec120a9c..7cc90b97f91 100644 --- a/src/core/qgsauxiliarystorage.cpp +++ b/src/core/qgsauxiliarystorage.cpp @@ -81,6 +81,8 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f ) if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 ) { def = p; + if ( parts.size() == 3 ) + def.setComment( parts[2] ); break; } } @@ -93,6 +95,8 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f ) if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 ) { def = p; + if ( parts.size() == 3 ) + def.setComment( parts[2] ); break; } } @@ -105,17 +109,19 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f ) if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 ) { def = p; + if ( parts.size() == 3 ) + def.setComment( parts[2] ); break; } } } - - if ( parts.size() == 3 ) + else if ( origin.compare( "user", Qt::CaseInsensitive ) == 0 ) { - def.setComment( parts[2] ); + def.setOrigin( "user" ); + def.setComment( propertyName ); } - if ( !def.name().isEmpty() ) + if ( !def.name().isEmpty() || !def.comment().isEmpty() ) { init( def ); setTypeName( f.typeName() ); @@ -125,7 +131,7 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f ) void QgsAuxiliaryField::init( const QgsPropertyDefinition &def ) { - if ( !def.name().isEmpty() ) + if ( !def.name().isEmpty() || !def.comment().isEmpty() ) { QVariant::Type type; QString typeName; @@ -167,7 +173,10 @@ bool QgsAuxiliaryLayer::clear() QString QgsAuxiliaryField::nameFromProperty( const QgsPropertyDefinition &def, bool joined ) { - QString fieldName = QString( "%1_%2" ).arg( def.origin(), def.name().toLower() ); + QString fieldName = def.origin(); + + if ( !def.name().isEmpty() ) + fieldName = QString( "%1_%2" ).arg( fieldName, def.name().toLower() ); if ( !def.comment().isEmpty() ) fieldName = QString( "%1_%2" ).arg( fieldName ).arg( def.comment() ); @@ -253,7 +262,7 @@ bool QgsAuxiliaryLayer::exists( const QgsPropertyDefinition &definition ) const bool QgsAuxiliaryLayer::addAuxiliaryField( const QgsPropertyDefinition &definition ) { - if ( definition.name().isEmpty() || exists( definition ) ) + if ( ( definition.name().isEmpty() && definition.comment().isEmpty() ) || exists( definition ) ) return false; const QgsAuxiliaryField af( definition ); diff --git a/src/core/qgsproperty.h b/src/core/qgsproperty.h index dc115cc404f..d90c980a0b8 100644 --- a/src/core/qgsproperty.h +++ b/src/core/qgsproperty.h @@ -172,6 +172,11 @@ class CORE_EXPORT QgsPropertyDefinition */ QString helpText() const { return mHelpText; } + /** + * Sets the data type + */ + void setDataType( DataType type ) { mTypes = type; } + /** * Returns the allowable field/value data type for the property. */ diff --git a/src/gui/qgsnewauxiliaryfielddialog.cpp b/src/gui/qgsnewauxiliaryfielddialog.cpp index 8b63f7534b6..4161df2cf57 100644 --- a/src/gui/qgsnewauxiliaryfielddialog.cpp +++ b/src/gui/qgsnewauxiliaryfielddialog.cpp @@ -47,6 +47,8 @@ QgsNewAuxiliaryFieldDialog::QgsNewAuxiliaryFieldDialog( const QgsPropertyDefinit if ( mNameOnly ) mType->setEnabled( false ); + else + mType->setEnabled( true ); } void QgsNewAuxiliaryFieldDialog::accept() @@ -54,6 +56,24 @@ void QgsNewAuxiliaryFieldDialog::accept() QgsPropertyDefinition def = mPropertyDefinition; def.setComment( mName->text() ); + if ( !mNameOnly ) + { + if ( mType->currentText().compare( tr( "String" ) ) == 0 ) + { + def.setDataType( QgsPropertyDefinition::DataTypeString ); + } + else if ( mType->currentText().compare( tr( "Numeric" ) ) == 0 ) + { + def.setDataType( QgsPropertyDefinition::DataTypeNumeric ); + } + else + { + def.setDataType( QgsPropertyDefinition::DataTypeBoolean ); + } + + def.setOrigin( "user" ); + } + QString fieldName = QgsAuxiliaryField::nameFromProperty( def, true ); const int idx = mLayer->fields().lookupField( fieldName ); if ( idx >= 0 ) diff --git a/src/ui/qgsvectorlayerpropertiesbase.ui b/src/ui/qgsvectorlayerpropertiesbase.ui index 886ecb30e16..fc3ccdde966 100644 --- a/src/ui/qgsvectorlayerpropertiesbase.ui +++ b/src/ui/qgsvectorlayerpropertiesbase.ui @@ -2153,6 +2153,17 @@ border-radius: 2px; + + + + + + + + :/images/themes/default/symbologyAdd.svg:/images/themes/default/symbologyAdd.svg + + +