mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Add a custom name for symbol layers in property definition
This commit is contained in:
parent
4fa3400981
commit
4e10a11a47
@ -211,7 +211,7 @@ class QgsAuxiliaryLayer : QgsVectorLayer
|
|||||||
:rtype: int
|
:rtype: int
|
||||||
%End
|
%End
|
||||||
|
|
||||||
int propertyFromField( int index ) const;
|
int propertyFromIndex( int index ) const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns the underlying property key for the field index. The key may be
|
Returns the underlying property key for the field index. The key may be
|
||||||
a PAL, diagram or symbology property according to the underlying
|
a PAL, diagram or symbology property according to the underlying
|
||||||
@ -224,6 +224,16 @@ class QgsAuxiliaryLayer : QgsVectorLayer
|
|||||||
:rtype: int
|
:rtype: int
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
QgsPropertyDefinition propertyDefinitionFromIndex( int index ) const;
|
||||||
|
%Docstring
|
||||||
|
Returns the property definition fir the underlying field index.
|
||||||
|
|
||||||
|
\param index The index of the field
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
:rtype: QgsPropertyDefinition
|
||||||
|
%End
|
||||||
|
|
||||||
static int createProperty( QgsPalLayerSettings::Property property, const QString &providerId, QgsVectorLayer *vlayer );
|
static int createProperty( QgsPalLayerSettings::Property property, const QString &providerId, QgsVectorLayer *vlayer );
|
||||||
%Docstring
|
%Docstring
|
||||||
Create if necessary a new auxiliary field for a PAL property and
|
Create if necessary a new auxiliary field for a PAL property and
|
||||||
|
@ -72,16 +72,17 @@ class QgsPropertyDefinition
|
|||||||
Constructs an empty property.
|
Constructs an empty property.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsPropertyDefinition( const QString &name, const QString &description, StandardPropertyTemplate type, const QString &origin = QString() );
|
QgsPropertyDefinition( const QString &name, const QString &description, StandardPropertyTemplate type, const QString &origin = QString(), const QString &comment = QString() );
|
||||||
%Docstring
|
%Docstring
|
||||||
Constructor for QgsPropertyDefinition, using a standard property template.
|
Constructor for QgsPropertyDefinition, using a standard property template.
|
||||||
\param name is used internally and should be a unique, alphanumeric string.
|
\param name is used internally and should be a unique, alphanumeric string.
|
||||||
\param description can be any localised string describing what the property is used for.
|
\param description can be any localised string describing what the property is used for.
|
||||||
\param type one of the predefined standard property template
|
\param type one of the predefined standard property template
|
||||||
\param origin The origin of the property
|
\param origin The origin of the property
|
||||||
|
\param comment A free comment for the property
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin = QString() );
|
QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin = QString(), const QString &comment = QString() );
|
||||||
%Docstring
|
%Docstring
|
||||||
Constructor for custom QgsPropertyDefinitions.
|
Constructor for custom QgsPropertyDefinitions.
|
||||||
\param name is used internally and should be a unique, alphanumeric string.
|
\param name is used internally and should be a unique, alphanumeric string.
|
||||||
@ -90,6 +91,7 @@ class QgsPropertyDefinition
|
|||||||
\param helpText parameter should specify a descriptive string for users outlining the types
|
\param helpText parameter should specify a descriptive string for users outlining the types
|
||||||
of value acceptable by the property (eg 'dashed' or 'solid' for a line style property).
|
of value acceptable by the property (eg 'dashed' or 'solid' for a line style property).
|
||||||
\param origin The origin of the property
|
\param origin The origin of the property
|
||||||
|
\param comment A free comment for the property
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
@ -120,6 +122,17 @@ class QgsPropertyDefinition
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
QString comment() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the comment of the property
|
||||||
|
:rtype: str
|
||||||
|
%End
|
||||||
|
|
||||||
|
void setComment( const QString &comment );
|
||||||
|
%Docstring
|
||||||
|
Sets comment of the property
|
||||||
|
%End
|
||||||
|
|
||||||
QString helpText() const;
|
QString helpText() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Helper text for using the property, including a description of the valid values for the property.
|
Helper text for using the property, including a description of the valid values for the property.
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
#include "qgsauxiliarystorage.h"
|
#include "qgsauxiliarystorage.h"
|
||||||
#include "qgsnewauxiliarylayerdialog.h"
|
#include "qgsnewauxiliarylayerdialog.h"
|
||||||
#include "qgslabelinggui.h"
|
#include "qgslabelinggui.h"
|
||||||
|
#include "qgssymbollayer.h"
|
||||||
|
|
||||||
#include "layertree/qgslayertreelayer.h"
|
#include "layertree/qgslayertreelayer.h"
|
||||||
#include "qgslayertree.h"
|
#include "qgslayertree.h"
|
||||||
@ -1532,7 +1533,9 @@ void QgsVectorLayerProperties::updateAuxiliaryStoragePage( bool reset )
|
|||||||
|
|
||||||
item->setText( 0, prop.origin() );
|
item->setText( 0, prop.origin() );
|
||||||
item->setText( 1, prop.name() );
|
item->setText( 1, prop.name() );
|
||||||
item->setText( 2, field.typeName() );
|
item->setText( 2, prop.comment() );
|
||||||
|
item->setText( 3, field.typeName() );
|
||||||
|
item->setText( 4, field.name() );
|
||||||
|
|
||||||
mAuxiliaryStorageFieldsTree->addTopLevelItem( item );
|
mAuxiliaryStorageFieldsTree->addTopLevelItem( item );
|
||||||
}
|
}
|
||||||
@ -1653,6 +1656,7 @@ void QgsVectorLayerProperties::onAuxiliaryLayerDeleteField()
|
|||||||
QgsPropertyDefinition def;
|
QgsPropertyDefinition def;
|
||||||
def.setOrigin( item->text( 0 ) );
|
def.setOrigin( item->text( 0 ) );
|
||||||
def.setName( item->text( 1 ) );
|
def.setName( item->text( 1 ) );
|
||||||
|
def.setComment( item->text( 2 ) );
|
||||||
|
|
||||||
const QString fieldName = QgsAuxiliaryField::nameFromProperty( def );
|
const QString fieldName = QgsAuxiliaryField::nameFromProperty( def );
|
||||||
|
|
||||||
@ -1680,14 +1684,20 @@ void QgsVectorLayerProperties::deleteAuxiliaryField( int index )
|
|||||||
if ( !mLayer->auxiliaryLayer() )
|
if ( !mLayer->auxiliaryLayer() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int key = mLayer->auxiliaryLayer()->propertyFromField( index );
|
int key = mLayer->auxiliaryLayer()->propertyFromIndex( index );
|
||||||
|
QgsPropertyDefinition def = mLayer->auxiliaryLayer()->propertyDefinitionFromIndex( index );
|
||||||
|
|
||||||
if ( mLayer->auxiliaryLayer()->deleteAttribute( index ) )
|
if ( mLayer->auxiliaryLayer()->deleteAttribute( index ) )
|
||||||
{
|
{
|
||||||
mLayer->updateFields();
|
mLayer->updateFields();
|
||||||
|
|
||||||
// immediately deactivate data defined button
|
// immediately deactivate data defined button
|
||||||
if ( labelingDialog && labelingDialog->labelingGui() )
|
if ( key >= 0 && def.origin().compare( "labeling", Qt::CaseInsensitive ) == 0
|
||||||
|
&& labelingDialog
|
||||||
|
&& labelingDialog->labelingGui() )
|
||||||
|
{
|
||||||
labelingDialog->labelingGui()->deactivateField( ( QgsPalLayerSettings::Property ) key );
|
labelingDialog->labelingGui()->deactivateField( ( QgsPalLayerSettings::Property ) key );
|
||||||
|
}
|
||||||
|
|
||||||
updateAuxiliaryStoragePage( true );
|
updateAuxiliaryStoragePage( true );
|
||||||
mFieldsPropertiesDialog->init();
|
mFieldsPropertiesDialog->init();
|
||||||
|
@ -110,6 +110,11 @@ QgsAuxiliaryField::QgsAuxiliaryField( const QgsField &f )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( parts.size() == 3 )
|
||||||
|
{
|
||||||
|
def.setComment( parts[2] );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !def.name().isEmpty() )
|
if ( !def.name().isEmpty() )
|
||||||
{
|
{
|
||||||
init( def );
|
init( def );
|
||||||
@ -162,7 +167,10 @@ bool QgsAuxiliaryLayer::clear()
|
|||||||
|
|
||||||
QString QgsAuxiliaryField::nameFromProperty( const QgsPropertyDefinition &def, bool joined )
|
QString QgsAuxiliaryField::nameFromProperty( const QgsPropertyDefinition &def, bool joined )
|
||||||
{
|
{
|
||||||
QString fieldName = QString( "%2_%3" ).arg( def.origin(), def.name().toLower() );
|
QString fieldName = QString( "%1_%2" ).arg( def.origin(), def.name().toLower() );
|
||||||
|
|
||||||
|
if ( !def.comment().isEmpty() )
|
||||||
|
fieldName = QString( "%1_%2" ).arg( fieldName ).arg( def.comment() );
|
||||||
|
|
||||||
if ( joined )
|
if ( joined )
|
||||||
fieldName = QString( "%1%2" ).arg( AS_JOINPREFIX, fieldName );
|
fieldName = QString( "%1%2" ).arg( AS_JOINPREFIX, fieldName );
|
||||||
@ -405,7 +413,7 @@ bool QgsAuxiliaryLayer::isHiddenProperty( int index ) const
|
|||||||
return hidden;
|
return hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsAuxiliaryLayer::propertyFromField( int index ) const
|
int QgsAuxiliaryLayer::propertyFromIndex( int index ) const
|
||||||
{
|
{
|
||||||
int p = -1;
|
int p = -1;
|
||||||
QgsAuxiliaryField aField( fields().field( index ) );
|
QgsAuxiliaryField aField( fields().field( index ) );
|
||||||
@ -424,10 +432,28 @@ int QgsAuxiliaryLayer::propertyFromField( int index ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( aDef.origin().compare( "symbol" ) == 0 )
|
||||||
|
{
|
||||||
|
const QgsPropertiesDefinition defs = QgsSymbolLayer::propertyDefinitions();
|
||||||
|
QgsPropertiesDefinition::const_iterator it = defs.constBegin();
|
||||||
|
for ( ; it != defs.constEnd(); ++it )
|
||||||
|
{
|
||||||
|
if ( it->name().compare( aDef.name(), Qt::CaseInsensitive ) == 0 )
|
||||||
|
{
|
||||||
|
p = it.key();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsPropertyDefinition QgsAuxiliaryLayer::propertyDefinitionFromIndex( int index ) const
|
||||||
|
{
|
||||||
|
return QgsAuxiliaryField( fields().field( index ) ).propertyDefinition();
|
||||||
|
}
|
||||||
|
|
||||||
int QgsAuxiliaryLayer::indexOfProperty( const QgsPropertyDefinition &def ) const
|
int QgsAuxiliaryLayer::indexOfProperty( const QgsPropertyDefinition &def ) const
|
||||||
{
|
{
|
||||||
return fields().indexOf( QgsAuxiliaryField::nameFromProperty( def ) );
|
return fields().indexOf( QgsAuxiliaryField::nameFromProperty( def ) );
|
||||||
|
@ -238,7 +238,16 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
|
|||||||
*
|
*
|
||||||
* \since QGIS 3.0
|
* \since QGIS 3.0
|
||||||
*/
|
*/
|
||||||
int propertyFromField( int index ) const;
|
int propertyFromIndex( int index ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the property definition fir the underlying field index.
|
||||||
|
*
|
||||||
|
* \param index The index of the field
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
QgsPropertyDefinition propertyDefinitionFromIndex( int index ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create if necessary a new auxiliary field for a PAL property and
|
* Create if necessary a new auxiliary field for a PAL property and
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
#include "qgssymbollayerutils.h"
|
#include "qgssymbollayerutils.h"
|
||||||
#include "qgscolorramp.h"
|
#include "qgscolorramp.h"
|
||||||
|
|
||||||
QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, const QString &description, QgsPropertyDefinition::StandardPropertyTemplate type, const QString &origin )
|
QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, const QString &description, QgsPropertyDefinition::StandardPropertyTemplate type, const QString &origin, const QString &comment )
|
||||||
: mName( name )
|
: mName( name )
|
||||||
, mDescription( description )
|
, mDescription( description )
|
||||||
, mStandardType( type )
|
, mStandardType( type )
|
||||||
, mOrigin( origin )
|
, mOrigin( origin )
|
||||||
|
, mComment( comment )
|
||||||
{
|
{
|
||||||
switch ( mStandardType )
|
switch ( mStandardType )
|
||||||
{
|
{
|
||||||
@ -170,12 +171,13 @@ QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, const QString
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin )
|
QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin, const QString &comment )
|
||||||
: mName( name )
|
: mName( name )
|
||||||
, mDescription( description )
|
, mDescription( description )
|
||||||
, mTypes( dataType )
|
, mTypes( dataType )
|
||||||
, mHelpText( helpText )
|
, mHelpText( helpText )
|
||||||
, mOrigin( origin )
|
, mOrigin( origin )
|
||||||
|
, mComment( comment )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool QgsPropertyDefinition::supportsAssistant() const
|
bool QgsPropertyDefinition::supportsAssistant() const
|
||||||
|
@ -116,8 +116,9 @@ class CORE_EXPORT QgsPropertyDefinition
|
|||||||
* \param description can be any localised string describing what the property is used for.
|
* \param description can be any localised string describing what the property is used for.
|
||||||
* \param type one of the predefined standard property template
|
* \param type one of the predefined standard property template
|
||||||
* \param origin The origin of the property
|
* \param origin The origin of the property
|
||||||
|
* \param comment A free comment for the property
|
||||||
*/
|
*/
|
||||||
QgsPropertyDefinition( const QString &name, const QString &description, StandardPropertyTemplate type, const QString &origin = QString() );
|
QgsPropertyDefinition( const QString &name, const QString &description, StandardPropertyTemplate type, const QString &origin = QString(), const QString &comment = QString() );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for custom QgsPropertyDefinitions.
|
* Constructor for custom QgsPropertyDefinitions.
|
||||||
@ -127,8 +128,9 @@ class CORE_EXPORT QgsPropertyDefinition
|
|||||||
* \param helpText parameter should specify a descriptive string for users outlining the types
|
* \param helpText parameter should specify a descriptive string for users outlining the types
|
||||||
* of value acceptable by the property (eg 'dashed' or 'solid' for a line style property).
|
* of value acceptable by the property (eg 'dashed' or 'solid' for a line style property).
|
||||||
* \param origin The origin of the property
|
* \param origin The origin of the property
|
||||||
|
* \param comment A free comment for the property
|
||||||
*/
|
*/
|
||||||
QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin = QString() );
|
QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin = QString(), const QString &comment = QString() );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the property. This is used internally and should be a unique, alphanumeric string.
|
* Returns the name of the property. This is used internally and should be a unique, alphanumeric string.
|
||||||
@ -155,6 +157,16 @@ class CORE_EXPORT QgsPropertyDefinition
|
|||||||
*/
|
*/
|
||||||
QString description() const { return mDescription; }
|
QString description() const { return mDescription; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the comment of the property
|
||||||
|
*/
|
||||||
|
QString comment() const { return mComment; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets comment of the property
|
||||||
|
*/
|
||||||
|
void setComment( const QString &comment ) { mComment = comment; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper text for using the property, including a description of the valid values for the property.
|
* Helper text for using the property, including a description of the valid values for the property.
|
||||||
*/
|
*/
|
||||||
@ -185,6 +197,7 @@ class CORE_EXPORT QgsPropertyDefinition
|
|||||||
QString mHelpText;
|
QString mHelpText;
|
||||||
StandardPropertyTemplate mStandardType = Custom;
|
StandardPropertyTemplate mStandardType = Custom;
|
||||||
QString mOrigin;
|
QString mOrigin;
|
||||||
|
QString mComment;
|
||||||
|
|
||||||
static QString trString();
|
static QString trString();
|
||||||
};
|
};
|
||||||
|
@ -297,6 +297,7 @@ SET(QGIS_GUI_SRCS
|
|||||||
qgsmessageviewer.cpp
|
qgsmessageviewer.cpp
|
||||||
qgsmetadatawidget.cpp
|
qgsmetadatawidget.cpp
|
||||||
qgsnewauxiliarylayerdialog.cpp
|
qgsnewauxiliarylayerdialog.cpp
|
||||||
|
qgsnewauxiliaryfielddialog.cpp
|
||||||
qgsnewhttpconnection.cpp
|
qgsnewhttpconnection.cpp
|
||||||
qgsnewmemorylayerdialog.cpp
|
qgsnewmemorylayerdialog.cpp
|
||||||
qgsnewnamedialog.cpp
|
qgsnewnamedialog.cpp
|
||||||
@ -458,6 +459,7 @@ SET(QGIS_GUI_MOC_HDRS
|
|||||||
qgsmessageviewer.h
|
qgsmessageviewer.h
|
||||||
qgsmetadatawidget.h
|
qgsmetadatawidget.h
|
||||||
qgsnewauxiliarylayerdialog.h
|
qgsnewauxiliarylayerdialog.h
|
||||||
|
qgsnewauxiliaryfielddialog.h
|
||||||
qgsnewhttpconnection.h
|
qgsnewhttpconnection.h
|
||||||
qgsnewmemorylayerdialog.h
|
qgsnewmemorylayerdialog.h
|
||||||
qgsnewnamedialog.h
|
qgsnewnamedialog.h
|
||||||
|
82
src/gui/qgsnewauxiliaryfielddialog.cpp
Normal file
82
src/gui/qgsnewauxiliaryfielddialog.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsnewauxiliaryfielddialog.cpp - description
|
||||||
|
-------------------
|
||||||
|
begin : Sept 05, 2017
|
||||||
|
copyright : (C) 2017 by Paul Blottiere
|
||||||
|
email : paul.blottiere@oslandia.com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "qgsnewauxiliaryfielddialog.h"
|
||||||
|
#include "qgsauxiliarystorage.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
QgsNewAuxiliaryFieldDialog::QgsNewAuxiliaryFieldDialog( const QgsPropertyDefinition &def, QgsVectorLayer *layer, bool nameOnly, QWidget *parent )
|
||||||
|
: QDialog( parent )
|
||||||
|
, mLayer( layer )
|
||||||
|
, mNameOnly( nameOnly )
|
||||||
|
, mPropertyDefinition( def )
|
||||||
|
{
|
||||||
|
setupUi( this );
|
||||||
|
|
||||||
|
mType->addItem( tr( "String" ) );
|
||||||
|
mType->addItem( tr( "Numeric" ) );
|
||||||
|
mType->addItem( tr( "Boolean" ) );
|
||||||
|
|
||||||
|
switch ( def.dataType() )
|
||||||
|
{
|
||||||
|
case QgsPropertyDefinition::DataTypeString:
|
||||||
|
mType->setCurrentIndex( mType->findText( tr( "String" ) ) );
|
||||||
|
break;
|
||||||
|
case QgsPropertyDefinition::DataTypeNumeric:
|
||||||
|
mType->setCurrentIndex( mType->findText( tr( "Numeric" ) ) );
|
||||||
|
break;
|
||||||
|
case QgsPropertyDefinition::DataTypeBoolean:
|
||||||
|
mType->setCurrentIndex( mType->findText( tr( "Boolean" ) ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mNameOnly )
|
||||||
|
mType->setEnabled( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsNewAuxiliaryFieldDialog::accept()
|
||||||
|
{
|
||||||
|
QgsPropertyDefinition def = mPropertyDefinition;
|
||||||
|
def.setComment( mName->text() );
|
||||||
|
|
||||||
|
QString fieldName = QgsAuxiliaryField::nameFromProperty( def, true );
|
||||||
|
const int idx = mLayer->fields().lookupField( fieldName );
|
||||||
|
if ( idx >= 0 )
|
||||||
|
{
|
||||||
|
const QString title = tr( "Invalid name" );
|
||||||
|
const QString msg = tr( "Auxiliary field '%1' already exists" ).arg( fieldName );
|
||||||
|
QMessageBox::critical( this, title, msg, QMessageBox::Ok );
|
||||||
|
}
|
||||||
|
else if ( def.comment().isEmpty() )
|
||||||
|
{
|
||||||
|
const QString title = tr( "Invalid name" );
|
||||||
|
const QString msg = tr( "Name is a mandatory parameter" );
|
||||||
|
QMessageBox::critical( this, title, msg, QMessageBox::Ok );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( mLayer->auxiliaryLayer()->addAuxiliaryField( def ) )
|
||||||
|
mPropertyDefinition = def;
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsPropertyDefinition QgsNewAuxiliaryFieldDialog::propertyDefinition() const
|
||||||
|
{
|
||||||
|
return mPropertyDefinition;
|
||||||
|
}
|
63
src/gui/qgsnewauxiliaryfielddialog.h
Normal file
63
src/gui/qgsnewauxiliaryfielddialog.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsnewauxiliaryfielddialog.h - description
|
||||||
|
-------------------
|
||||||
|
begin : Sept 05, 2017
|
||||||
|
copyright : (C) 2017 by Paul Blottiere
|
||||||
|
email : paul.blottiere@oslandia.com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QGSNEWAUXILIARYFIELDDIALOG_H
|
||||||
|
#define QGSNEWAUXILIARYFIELDDIALOG_H
|
||||||
|
|
||||||
|
#include "ui_qgsnewauxiliaryfielddialogbase.h"
|
||||||
|
#include "qgsguiutils.h"
|
||||||
|
#include "qgis_gui.h"
|
||||||
|
#include "qgsvectorlayer.h"
|
||||||
|
#include "qgsproperty.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \ingroup gui
|
||||||
|
*
|
||||||
|
* \brief A dialog to create a new auxiliary field
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
class GUI_EXPORT QgsNewAuxiliaryFieldDialog: public QDialog, private Ui::QgsNewAuxiliaryFieldDialogBase
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* \param def The property definition to use to create the auxiliary field
|
||||||
|
* \param layer The vector layer for which the auxiliary layer has to be created
|
||||||
|
* \param customOnly True to indicate that only the name widget is enabled
|
||||||
|
* \param parent Parent window
|
||||||
|
*/
|
||||||
|
QgsNewAuxiliaryFieldDialog( const QgsPropertyDefinition &def, QgsVectorLayer *layer, bool nameOnly = true, QWidget *parent = nullptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the underlying property definition.
|
||||||
|
*/
|
||||||
|
QgsPropertyDefinition propertyDefinition() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void accept() override;
|
||||||
|
|
||||||
|
QgsVectorLayer *mLayer = nullptr;
|
||||||
|
bool mNameOnly = true;
|
||||||
|
QgsPropertyDefinition mPropertyDefinition;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -39,6 +39,7 @@
|
|||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgssettings.h"
|
#include "qgssettings.h"
|
||||||
#include "qgsnewauxiliarylayerdialog.h"
|
#include "qgsnewauxiliarylayerdialog.h"
|
||||||
|
#include "qgsnewauxiliaryfielddialog.h"
|
||||||
#include "qgsauxiliarystorage.h"
|
#include "qgsauxiliarystorage.h"
|
||||||
|
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
@ -133,11 +134,19 @@ void QgsSymbolLayerWidget::createAuxiliaryField()
|
|||||||
|
|
||||||
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
|
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
|
||||||
QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
|
QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
|
||||||
const QgsPropertyDefinition def = QgsSymbolLayer::propertyDefinitions()[key];
|
QgsPropertyDefinition def = QgsSymbolLayer::propertyDefinitions()[key];
|
||||||
|
|
||||||
// create property in auxiliary storage if necessary
|
// create property in auxiliary storage if necessary
|
||||||
if ( !mVectorLayer->auxiliaryLayer()->exists( def ) )
|
if ( !mVectorLayer->auxiliaryLayer()->exists( def ) )
|
||||||
mVectorLayer->auxiliaryLayer()->addAuxiliaryField( def );
|
{
|
||||||
|
QgsNewAuxiliaryFieldDialog dlg( def, mVectorLayer, true, this );
|
||||||
|
if ( dlg.exec() == QDialog::Accepted )
|
||||||
|
def = dlg.propertyDefinition();
|
||||||
|
}
|
||||||
|
|
||||||
|
// return if still not exist
|
||||||
|
if ( !mVectorLayer->auxiliaryLayer()->exists( def ) )
|
||||||
|
return;
|
||||||
|
|
||||||
// update property with join field name from auxiliary storage
|
// update property with join field name from auxiliary storage
|
||||||
QgsProperty property = button->toProperty();
|
QgsProperty property = button->toProperty();
|
||||||
|
111
src/ui/qgsnewauxiliaryfielddialogbase.ui
Normal file
111
src/ui/qgsnewauxiliaryfielddialogbase.ui
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QgsNewAuxiliaryFieldDialogBase</class>
|
||||||
|
<widget class="QDialog" name="QgsNewAuxiliaryFieldDialogBase">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>397</width>
|
||||||
|
<height>159</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Auxiliary storage : new auxiliary field</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>50</x>
|
||||||
|
<y>120</y>
|
||||||
|
<width>341</width>
|
||||||
|
<height>32</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="verticalLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>381</width>
|
||||||
|
<height>101</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>New auxiliary field parameters</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Type</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QComboBox" name="mType"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QLineEdit" name="mName"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>QgsNewAuxiliaryFieldDialogBase</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>QgsNewAuxiliaryFieldDialogBase</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -2191,11 +2191,21 @@ border-radius: 2px;</string>
|
|||||||
<string>Property</string>
|
<string>Property</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Type</string>
|
<string>Type</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Full Name</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user