Skip to content

Commit

Permalink
Update auxiliary storage tab and data defined buttons according to au…
Browse files Browse the repository at this point in the history
…xiliary fields
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent 6b81286 commit 8826a8a
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 4 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsauxiliarystorage.sip
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class QgsAuxiliaryField : QgsField

};

typedef QList<QgsAuxiliaryField> QgsAuxiliaryFields;

class QgsAuxiliaryLayer : QgsVectorLayer
{
%Docstring
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions python/gui/qgspropertyoverridebutton.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,4 +1079,6 @@ void QgsDiagramProperties::createAuxiliaryField()
button->updateFieldLists();
button->setToProperty( property );
mDataDefinedProperties.setProperty( key, button->toProperty() );

emit auxiliaryFieldCreated();
}
4 changes: 4 additions & 0 deletions src/app/qgsdiagramproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -640,4 +649,6 @@ void QgsLabelingGui::createAuxiliaryField()
button->updateFieldLists();
button->setToProperty( property );
mDataDefinedProperties.setProperty( key, button->toProperty() );

emit auxiliaryFieldCreated();
}
4 changes: 4 additions & 0 deletions src/app/qgslabelinggui.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress

void setLayer( QgsMapLayer *layer );

signals:

void auxiliaryFieldCreated();

public slots:

void updateUi();
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgslabelingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ void QgsLabelingWidget::adaptToLayer()
{
mLabelModeComboBox->setCurrentIndex( 0 );
}

QgsLabelingGui *lg = qobject_cast<QgsLabelingGui *>( mWidget );
if ( lg )
{
lg->updateUi();
}
}

void QgsLabelingWidget::writeSettingsToLayer()
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgslabelingwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class QgsLabelingWidget : public QgsMapLayerConfigWidget, private Ui::QgsLabelin

void resetSettings();

signals:

void auxiliaryFieldCreated();

protected slots:
void labelModeChanged( int index );
void showEngineConfigDialog();
Expand Down
38 changes: 36 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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();

Expand All @@ -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
{
Expand All @@ -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()
Expand All @@ -1512,6 +1546,6 @@ void QgsVectorLayerProperties::onAuxiliaryLayerNew()
QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
if ( dlg.exec() == QDialog::Accepted )
{
updateAuxiliaryStoragePage();
updateAuxiliaryStoragePage( true );
}
}
2 changes: 1 addition & 1 deletion src/app/qgsvectorlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsauxiliarystorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,32 @@ 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;
}

setType( type );
setName( name( def ) );
setTypeName( typeName );
setLength( len );
setPrecision( precision );
}
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsauxiliarystorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class CORE_EXPORT QgsAuxiliaryField : public QgsField
friend class QgsAuxiliaryLayer;
};

typedef QList<QgsAuxiliaryField> QgsAuxiliaryFields;

/**
* \class QgsAuxiliaryLayer
*
Expand Down Expand Up @@ -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.
*
Expand Down
8 changes: 7 additions & 1 deletion src/gui/qgspropertyoverridebutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!).
Expand Down

0 comments on commit 8826a8a

Please sign in to comment.