mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Update auxiliary storage tab and data defined buttons according to auxiliary fields
This commit is contained in:
parent
6b81286a8f
commit
8826a8abaa
@ -58,6 +58,8 @@ class QgsAuxiliaryField : QgsField
|
||||
|
||||
};
|
||||
|
||||
typedef QList<QgsAuxiliaryField> QgsAuxiliaryFields;
|
||||
|
||||
class QgsAuxiliaryLayer : QgsVectorLayer
|
||||
{
|
||||
%Docstring
|
||||
@ -117,6 +119,12 @@ class QgsAuxiliaryLayer : QgsVectorLayer
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
QgsAuxiliaryFields auxiliaryFields() const;
|
||||
%Docstring
|
||||
Returns a list of all auxiliary fields currently managed by the layer.
|
||||
:rtype: QgsAuxiliaryFields
|
||||
%End
|
||||
|
||||
bool save();
|
||||
%Docstring
|
||||
Commit changes and starts editing then.
|
||||
|
@ -176,6 +176,13 @@ class QgsPropertyOverrideButton: QToolButton
|
||||
%Docstring
|
||||
Updates list of fields.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
void updateGui();
|
||||
%Docstring
|
||||
Updates data defined button icon.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
|
@ -1079,4 +1079,6 @@ void QgsDiagramProperties::createAuxiliaryField()
|
||||
button->updateFieldLists();
|
||||
button->setToProperty( property );
|
||||
mDataDefinedProperties.setProperty( key, button->toProperty() );
|
||||
|
||||
emit auxiliaryFieldCreated();
|
||||
}
|
||||
|
@ -39,6 +39,10 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
|
||||
//! Adds an attribute from the list of available attributes to the assigned attributes with a random color.
|
||||
void addAttribute( QTreeWidgetItem *item );
|
||||
|
||||
signals:
|
||||
|
||||
void auxiliaryFieldCreated();
|
||||
|
||||
public slots:
|
||||
void apply();
|
||||
void mDiagramTypeComboBox_currentIndexChanged( int index );
|
||||
|
@ -611,6 +611,15 @@ void QgsLabelingGui::updateUi()
|
||||
{
|
||||
chkMergeLines->setToolTip( QString() );
|
||||
}
|
||||
|
||||
mCoordXDDBtn->updateFieldLists();
|
||||
mCoordXDDBtn->updateGui();
|
||||
|
||||
mCoordYDDBtn->updateFieldLists();
|
||||
mCoordYDDBtn->updateGui();
|
||||
|
||||
mCoordRotationDDBtn->updateFieldLists();
|
||||
mCoordRotationDDBtn->updateGui();
|
||||
}
|
||||
|
||||
void QgsLabelingGui::createAuxiliaryField()
|
||||
@ -640,4 +649,6 @@ void QgsLabelingGui::createAuxiliaryField()
|
||||
button->updateFieldLists();
|
||||
button->setToProperty( property );
|
||||
mDataDefinedProperties.setProperty( key, button->toProperty() );
|
||||
|
||||
emit auxiliaryFieldCreated();
|
||||
}
|
||||
|
@ -43,6 +43,10 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress
|
||||
|
||||
void setLayer( QgsMapLayer *layer );
|
||||
|
||||
signals:
|
||||
|
||||
void auxiliaryFieldCreated();
|
||||
|
||||
public slots:
|
||||
|
||||
void updateUi();
|
||||
|
@ -96,6 +96,12 @@ void QgsLabelingWidget::adaptToLayer()
|
||||
{
|
||||
mLabelModeComboBox->setCurrentIndex( 0 );
|
||||
}
|
||||
|
||||
QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget );
|
||||
if ( lg )
|
||||
{
|
||||
lg->updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLabelingWidget::writeSettingsToLayer()
|
||||
@ -156,6 +162,7 @@ void QgsLabelingWidget::labelModeChanged( int index )
|
||||
QgsLabelingGui *simpleWidget = new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings, this );
|
||||
simpleWidget->setDockMode( dockMode() );
|
||||
connect( simpleWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
|
||||
connect( simpleWidget, &QgsLabelingGui::auxiliaryFieldCreated, this, &QgsLabelingWidget::auxiliaryFieldCreated );
|
||||
|
||||
if ( index == 3 )
|
||||
simpleWidget->setLabelMode( QgsLabelingGui::ObstaclesOnly );
|
||||
|
@ -51,6 +51,10 @@ class QgsLabelingWidget : public QgsMapLayerConfigWidget, private Ui::QgsLabelin
|
||||
|
||||
void resetSettings();
|
||||
|
||||
signals:
|
||||
|
||||
void auxiliaryFieldCreated();
|
||||
|
||||
protected slots:
|
||||
void labelModeChanged( int index );
|
||||
void showEngineConfigDialog();
|
||||
|
@ -147,6 +147,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
|
||||
layout->setMargin( 0 );
|
||||
labelingDialog = new QgsLabelingWidget( mLayer, QgisApp::instance()->mapCanvas(), labelingFrame );
|
||||
labelingDialog->layout()->setContentsMargins( -1, 0, -1, 0 );
|
||||
connect( labelingDialog, &QgsLabelingWidget::auxiliaryFieldCreated, this, [ = ] { updateAuxiliaryStoragePage(); } );
|
||||
layout->addWidget( labelingDialog );
|
||||
labelingFrame->setLayout( layout );
|
||||
}
|
||||
@ -256,6 +257,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
|
||||
diagLayout->setMargin( 0 );
|
||||
diagramPropertiesDialog = new QgsDiagramProperties( mLayer, mDiagramFrame, QgisApp::instance()->mapCanvas() );
|
||||
diagramPropertiesDialog->layout()->setContentsMargins( -1, 0, -1, 0 );
|
||||
connect( diagramPropertiesDialog, &QgsDiagramProperties::auxiliaryFieldCreated, this, [ = ] { updateAuxiliaryStoragePage(); } );
|
||||
diagLayout->addWidget( diagramPropertiesDialog );
|
||||
mDiagramFrame->setLayout( diagLayout );
|
||||
|
||||
@ -1467,7 +1469,7 @@ void QgsVectorLayerProperties::showHelp()
|
||||
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html" ) );
|
||||
}
|
||||
|
||||
void QgsVectorLayerProperties::updateAuxiliaryStoragePage()
|
||||
void QgsVectorLayerProperties::updateAuxiliaryStoragePage( bool reset )
|
||||
{
|
||||
const QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();
|
||||
|
||||
@ -1486,6 +1488,33 @@ void QgsVectorLayerProperties::updateAuxiliaryStoragePage()
|
||||
|
||||
// update actions
|
||||
mAuxiliaryLayerActionNew->setEnabled( false );
|
||||
|
||||
const QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();
|
||||
if ( alayer )
|
||||
{
|
||||
const int fields = alayer->auxiliaryFields().count();
|
||||
mAuxiliaryStorageFieldsLineEdit->setText( QString::number( fields ) );
|
||||
|
||||
// add fields
|
||||
mAuxiliaryStorageFieldsTree->clear();
|
||||
Q_FOREACH ( const QgsAuxiliaryField &field, alayer->auxiliaryFields() )
|
||||
{
|
||||
const QgsPropertyDefinition prop = field.propertyDefinition();
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
|
||||
if ( prop.origin() == QgsPropertyDefinition::Pal )
|
||||
item->setText( 0, "Pal" );
|
||||
else if ( prop.origin() == QgsPropertyDefinition::Diagram )
|
||||
item->setText( 0, "Diagram" );
|
||||
else
|
||||
item->setText( 0, "Unknown" );
|
||||
|
||||
item->setText( 1, prop.name() );
|
||||
item->setText( 2, field.typeName() );
|
||||
|
||||
mAuxiliaryStorageFieldsTree->addTopLevelItem( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1500,6 +1529,11 @@ void QgsVectorLayerProperties::updateAuxiliaryStoragePage()
|
||||
mAuxiliaryStorageFieldsLineEdit->setText( QString() );
|
||||
mAuxiliaryStorageFeaturesLineEdit->setText( QString() );
|
||||
}
|
||||
|
||||
if ( reset && labelingDialog )
|
||||
{
|
||||
labelingDialog->resetSettings(); // update data defined buttons
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorLayerProperties::onAuxiliaryLayerNew()
|
||||
@ -1512,6 +1546,6 @@ void QgsVectorLayerProperties::onAuxiliaryLayerNew()
|
||||
QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
|
||||
if ( dlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
updateAuxiliaryStoragePage();
|
||||
updateAuxiliaryStoragePage( true );
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
|
||||
//! Adds a new join to mJoinTreeWidget
|
||||
void addJoinToTreeWidget( const QgsVectorLayerJoinInfo &join, const int insertIndex = -1 );
|
||||
|
||||
void updateAuxiliaryStoragePage();
|
||||
void updateAuxiliaryStoragePage( bool reset = false );
|
||||
|
||||
QgsExpressionContext mContext;
|
||||
|
||||
|
@ -84,20 +84,24 @@ void QgsAuxiliaryField::init( const QgsPropertyDefinition &def )
|
||||
if ( !def.name().isEmpty() )
|
||||
{
|
||||
QVariant::Type type;
|
||||
QString typeName;
|
||||
int len( 0 ), precision( 0 );
|
||||
switch ( def.dataType() )
|
||||
{
|
||||
case QgsPropertyDefinition::DataTypeString:
|
||||
type = QVariant::String;
|
||||
len = 50;
|
||||
typeName = "String";
|
||||
break;
|
||||
case QgsPropertyDefinition::DataTypeNumeric:
|
||||
type = QVariant::Double;
|
||||
len = 0;
|
||||
precision = 0;
|
||||
typeName = "Real";
|
||||
break;
|
||||
case QgsPropertyDefinition::DataTypeBoolean:
|
||||
type = QVariant::Int; // sqlite does not have a bool type
|
||||
typeName = "Integer";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -105,6 +109,7 @@ void QgsAuxiliaryField::init( const QgsPropertyDefinition &def )
|
||||
|
||||
setType( type );
|
||||
setName( name( def ) );
|
||||
setTypeName( typeName );
|
||||
setLength( len );
|
||||
setPrecision( precision );
|
||||
}
|
||||
@ -178,6 +183,16 @@ bool QgsAuxiliaryLayer::addAuxiliaryField( const QgsPropertyDefinition &definiti
|
||||
return rc;
|
||||
}
|
||||
|
||||
QgsAuxiliaryFields QgsAuxiliaryLayer::auxiliaryFields() const
|
||||
{
|
||||
QgsAuxiliaryFields afields;
|
||||
|
||||
for ( int i = 2; i < fields().count(); i++ ) // ignore rowid and PK field
|
||||
afields.append( QgsAuxiliaryField( fields().field( i ) ) );
|
||||
|
||||
return afields;
|
||||
}
|
||||
|
||||
bool QgsAuxiliaryLayer::save()
|
||||
{
|
||||
bool rc = false;
|
||||
|
@ -83,6 +83,8 @@ class CORE_EXPORT QgsAuxiliaryField : public QgsField
|
||||
friend class QgsAuxiliaryLayer;
|
||||
};
|
||||
|
||||
typedef QList<QgsAuxiliaryField> QgsAuxiliaryFields;
|
||||
|
||||
/**
|
||||
* \class QgsAuxiliaryLayer
|
||||
*
|
||||
@ -144,6 +146,11 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
|
||||
*/
|
||||
bool addAuxiliaryField( const QgsPropertyDefinition &definition );
|
||||
|
||||
/**
|
||||
* Returns a list of all auxiliary fields currently managed by the layer.
|
||||
*/
|
||||
QgsAuxiliaryFields auxiliaryFields() const;
|
||||
|
||||
/**
|
||||
* Commit changes and starts editing then.
|
||||
*
|
||||
|
@ -188,6 +188,13 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
|
||||
*/
|
||||
void updateFieldLists();
|
||||
|
||||
/**
|
||||
* Updates data defined button icon.
|
||||
*
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
void updateGui();
|
||||
|
||||
/**
|
||||
* Sets a symbol which can be used for previews inside the widget or in any dialog created
|
||||
* by the widget. If not specified, a default created symbol will be used instead.
|
||||
@ -221,7 +228,6 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
|
||||
void showDescriptionDialog();
|
||||
void showExpressionDialog();
|
||||
void showAssistant();
|
||||
void updateGui();
|
||||
|
||||
/**
|
||||
* Sets the active status, emitting the activated signal where necessary (but never emitting the changed signal!).
|
||||
|
Loading…
x
Reference in New Issue
Block a user