mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Allow user to create its own auxiliary field
This commit is contained in:
parent
4e10a11a47
commit
fc0ebb783d
@ -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.
|
||||
|
@ -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() )
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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 )
|
||||
|
@ -2153,6 +2153,17 @@ border-radius: 2px;</string>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mAuxiliaryStorageFieldsAddBtn">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mAuxiliaryStorageFieldsDeleteBtn">
|
||||
<property name="text">
|
||||
|
Loading…
x
Reference in New Issue
Block a user