mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -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
|
:rtype: str
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
void setDataType( DataType type );
|
||||||
|
%Docstring
|
||||||
|
Sets the data type
|
||||||
|
%End
|
||||||
|
|
||||||
DataType dataType() const;
|
DataType dataType() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns the allowable field/value data type for the property.
|
Returns the allowable field/value data type for the property.
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
#include "qgsstyle.h"
|
#include "qgsstyle.h"
|
||||||
#include "qgsauxiliarystorage.h"
|
#include "qgsauxiliarystorage.h"
|
||||||
#include "qgsnewauxiliarylayerdialog.h"
|
#include "qgsnewauxiliarylayerdialog.h"
|
||||||
|
#include "qgsnewauxiliaryfielddialog.h"
|
||||||
#include "qgslabelinggui.h"
|
#include "qgslabelinggui.h"
|
||||||
#include "qgssymbollayer.h"
|
#include "qgssymbollayer.h"
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
|
|||||||
, mAuxiliaryLayerActionDelete( nullptr )
|
, mAuxiliaryLayerActionDelete( nullptr )
|
||||||
, mAuxiliaryLayerActionExport( nullptr )
|
, mAuxiliaryLayerActionExport( nullptr )
|
||||||
, mAuxiliaryLayerActionDeleteField( nullptr )
|
, mAuxiliaryLayerActionDeleteField( nullptr )
|
||||||
|
, mAuxiliaryLayerActionAddField( nullptr )
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
|
connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
|
||||||
@ -382,6 +384,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
|
|||||||
mAuxiliaryStorageActions->setMenu( menu );
|
mAuxiliaryStorageActions->setMenu( menu );
|
||||||
|
|
||||||
connect( mAuxiliaryStorageFieldsDeleteBtn, &QPushButton::clicked, this, &QgsVectorLayerProperties::onAuxiliaryLayerDeleteField );
|
connect( mAuxiliaryStorageFieldsDeleteBtn, &QPushButton::clicked, this, &QgsVectorLayerProperties::onAuxiliaryLayerDeleteField );
|
||||||
|
connect( mAuxiliaryStorageFieldsAddBtn, &QPushButton::clicked, this, &QgsVectorLayerProperties::onAuxiliaryLayerAddField );
|
||||||
|
|
||||||
updateAuxiliaryStoragePage();
|
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 )
|
void QgsVectorLayerProperties::deleteAuxiliaryField( int index )
|
||||||
{
|
{
|
||||||
if ( !mLayer->auxiliaryLayer() )
|
if ( !mLayer->auxiliaryLayer() )
|
||||||
|
@ -164,6 +164,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
|
|||||||
|
|
||||||
void onAuxiliaryLayerDeleteField();
|
void onAuxiliaryLayerDeleteField();
|
||||||
|
|
||||||
|
void onAuxiliaryLayerAddField();
|
||||||
|
|
||||||
void onAuxiliaryLayerExport();
|
void onAuxiliaryLayerExport();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -235,6 +237,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
|
|||||||
QAction *mAuxiliaryLayerActionDelete = nullptr;
|
QAction *mAuxiliaryLayerActionDelete = nullptr;
|
||||||
QAction *mAuxiliaryLayerActionExport = nullptr;
|
QAction *mAuxiliaryLayerActionExport = nullptr;
|
||||||
QAction *mAuxiliaryLayerActionDeleteField = nullptr;
|
QAction *mAuxiliaryLayerActionDeleteField = nullptr;
|
||||||
|
QAction *mAuxiliaryLayerActionAddField = nullptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openPanel( QgsPanelWidget *panel );
|
void openPanel( QgsPanelWidget *panel );
|
||||||
|
@ -81,6 +81,8 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f )
|
|||||||
if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 )
|
if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 )
|
||||||
{
|
{
|
||||||
def = p;
|
def = p;
|
||||||
|
if ( parts.size() == 3 )
|
||||||
|
def.setComment( parts[2] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +95,8 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f )
|
|||||||
if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 )
|
if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 )
|
||||||
{
|
{
|
||||||
def = p;
|
def = p;
|
||||||
|
if ( parts.size() == 3 )
|
||||||
|
def.setComment( parts[2] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,17 +109,19 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f )
|
|||||||
if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 )
|
if ( p.name().compare( propertyName, Qt::CaseInsensitive ) == 0 )
|
||||||
{
|
{
|
||||||
def = p;
|
def = p;
|
||||||
|
if ( parts.size() == 3 )
|
||||||
|
def.setComment( parts[2] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( origin.compare( "user", Qt::CaseInsensitive ) == 0 )
|
||||||
if ( parts.size() == 3 )
|
|
||||||
{
|
{
|
||||||
def.setComment( parts[2] );
|
def.setOrigin( "user" );
|
||||||
|
def.setComment( propertyName );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !def.name().isEmpty() )
|
if ( !def.name().isEmpty() || !def.comment().isEmpty() )
|
||||||
{
|
{
|
||||||
init( def );
|
init( def );
|
||||||
setTypeName( f.typeName() );
|
setTypeName( f.typeName() );
|
||||||
@ -125,7 +131,7 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f )
|
|||||||
|
|
||||||
void QgsAuxiliaryField::init( const QgsPropertyDefinition &def )
|
void QgsAuxiliaryField::init( const QgsPropertyDefinition &def )
|
||||||
{
|
{
|
||||||
if ( !def.name().isEmpty() )
|
if ( !def.name().isEmpty() || !def.comment().isEmpty() )
|
||||||
{
|
{
|
||||||
QVariant::Type type;
|
QVariant::Type type;
|
||||||
QString typeName;
|
QString typeName;
|
||||||
@ -167,7 +173,10 @@ bool QgsAuxiliaryLayer::clear()
|
|||||||
|
|
||||||
QString QgsAuxiliaryField::nameFromProperty( const QgsPropertyDefinition &def, bool joined )
|
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() )
|
if ( !def.comment().isEmpty() )
|
||||||
fieldName = QString( "%1_%2" ).arg( fieldName ).arg( def.comment() );
|
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 )
|
bool QgsAuxiliaryLayer::addAuxiliaryField( const QgsPropertyDefinition &definition )
|
||||||
{
|
{
|
||||||
if ( definition.name().isEmpty() || exists( definition ) )
|
if ( ( definition.name().isEmpty() && definition.comment().isEmpty() ) || exists( definition ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QgsAuxiliaryField af( definition );
|
const QgsAuxiliaryField af( definition );
|
||||||
|
@ -172,6 +172,11 @@ class CORE_EXPORT QgsPropertyDefinition
|
|||||||
*/
|
*/
|
||||||
QString helpText() const { return mHelpText; }
|
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.
|
* Returns the allowable field/value data type for the property.
|
||||||
*/
|
*/
|
||||||
|
@ -47,6 +47,8 @@ QgsNewAuxiliaryFieldDialog::QgsNewAuxiliaryFieldDialog( const QgsPropertyDefinit
|
|||||||
|
|
||||||
if ( mNameOnly )
|
if ( mNameOnly )
|
||||||
mType->setEnabled( false );
|
mType->setEnabled( false );
|
||||||
|
else
|
||||||
|
mType->setEnabled( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsNewAuxiliaryFieldDialog::accept()
|
void QgsNewAuxiliaryFieldDialog::accept()
|
||||||
@ -54,6 +56,24 @@ void QgsNewAuxiliaryFieldDialog::accept()
|
|||||||
QgsPropertyDefinition def = mPropertyDefinition;
|
QgsPropertyDefinition def = mPropertyDefinition;
|
||||||
def.setComment( mName->text() );
|
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 );
|
QString fieldName = QgsAuxiliaryField::nameFromProperty( def, true );
|
||||||
const int idx = mLayer->fields().lookupField( fieldName );
|
const int idx = mLayer->fields().lookupField( fieldName );
|
||||||
if ( idx >= 0 )
|
if ( idx >= 0 )
|
||||||
|
@ -2153,6 +2153,17 @@ border-radius: 2px;</string>
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<widget class="QPushButton" name="mAuxiliaryStorageFieldsDeleteBtn">
|
<widget class="QPushButton" name="mAuxiliaryStorageFieldsDeleteBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user