Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] New class QgsLabelSettingsWidgetBase
Base class for widgets which allow customisation of label engine properties, such as label placement settings.
- Loading branch information
1 parent
14c0d2c
commit 060cfb4
Showing
6 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
python/gui/auto_generated/qgslabelsettingswidgetbase.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgslabelsettingswidgetbase.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsLabelSettingsWidgetBase : QgsPanelWidget, protected QgsExpressionContextGenerator | ||
{ | ||
%Docstring | ||
Base class for widgets which allow customisation of label engine properties, such as label placement settings. | ||
|
||
.. versionadded:: 3.12 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslabelsettingswidgetbase.h" | ||
%End | ||
public: | ||
|
||
QgsLabelSettingsWidgetBase( QWidget *parent /TransferThis/ = 0, QgsVectorLayer *vl = 0 ); | ||
%Docstring | ||
Constructor for QgsLabelSettingsWidgetBase. | ||
|
||
:param parent: parent widget | ||
:param vl: associated vector layer | ||
%End | ||
|
||
virtual void setContext( const QgsSymbolWidgetContext &context ); | ||
%Docstring | ||
Sets the ``context`` in which the symbol widget is shown, e.g., the associated map canvas and expression contexts. | ||
|
||
.. seealso:: :py:func:`context` | ||
%End | ||
|
||
QgsSymbolWidgetContext context() const; | ||
%Docstring | ||
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expression contexts. | ||
|
||
.. seealso:: :py:func:`setContext` | ||
%End | ||
|
||
virtual void setGeometryType( QgsWkbTypes::GeometryType type ); | ||
%Docstring | ||
Sets the geometry ``type`` of the features to customize the widget accordingly. | ||
%End | ||
|
||
signals: | ||
|
||
void changed(); | ||
%Docstring | ||
Emitted when any of the settings described by the widget are changed. | ||
%End | ||
|
||
protected: | ||
|
||
virtual QgsExpressionContext createExpressionContext() const; | ||
|
||
|
||
void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key ); | ||
%Docstring | ||
Registers a data defined override ``button``. Handles setting up connections | ||
for the button and initializing the button to show the correct descriptions | ||
and help text for the associated property. | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgslabelsettingswidgetbase.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/*************************************************************************** | ||
qgslabelsettingswidgetbase.h | ||
---------------------- | ||
begin : December 2019 | ||
copyright : (C) 2019 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot 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 "qgslabelsettingswidgetbase.h" | ||
#include "qgsexpressioncontextutils.h" | ||
#include "qgsnewauxiliaryfielddialog.h" | ||
#include "qgsnewauxiliarylayerdialog.h" | ||
#include "qgspropertyoverridebutton.h" | ||
#include "qgsauxiliarystorage.h" | ||
|
||
|
||
QgsLabelSettingsWidgetBase::QgsLabelSettingsWidgetBase( QWidget *parent, QgsVectorLayer *vl ) | ||
: QgsPanelWidget( parent ) | ||
, mVectorLayer( vl ) | ||
{ | ||
} | ||
|
||
void QgsLabelSettingsWidgetBase::setContext( const QgsSymbolWidgetContext &context ) | ||
{ | ||
mContext = context; | ||
} | ||
|
||
QgsSymbolWidgetContext QgsLabelSettingsWidgetBase::context() const | ||
{ | ||
return mContext; | ||
} | ||
|
||
void QgsLabelSettingsWidgetBase::setGeometryType( QgsWkbTypes::GeometryType ) | ||
{ | ||
|
||
} | ||
|
||
QgsExpressionContext QgsLabelSettingsWidgetBase::createExpressionContext() const | ||
{ | ||
if ( mContext.expressionContext() ) | ||
return *mContext.expressionContext(); | ||
|
||
QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( mVectorLayer ) ); | ||
QgsExpressionContextScope *symbolScope = QgsExpressionContextUtils::updateSymbolScope( nullptr, new QgsExpressionContextScope() ); | ||
symbolScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_SYMBOL_COLOR, QColor(), true ) ); | ||
expContext << symbolScope; | ||
|
||
// additional scopes | ||
const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes(); | ||
for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes ) | ||
{ | ||
expContext.appendScope( new QgsExpressionContextScope( scope ) ); | ||
} | ||
|
||
//TODO - show actual value | ||
expContext.setOriginalValueVariable( QVariant() ); | ||
|
||
expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR ); | ||
|
||
return expContext; | ||
} | ||
|
||
void QgsLabelSettingsWidgetBase::createAuxiliaryField() | ||
{ | ||
// try to create an auxiliary layer if not yet created | ||
if ( !mVectorLayer->auxiliaryLayer() ) | ||
{ | ||
QgsNewAuxiliaryLayerDialog dlg( mVectorLayer, this ); | ||
dlg.exec(); | ||
} | ||
|
||
// return if still not exists | ||
if ( !mVectorLayer->auxiliaryLayer() ) | ||
return; | ||
|
||
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() ); | ||
QgsPalLayerSettings::Property key = static_cast< QgsPalLayerSettings::Property >( button->propertyKey() ); | ||
QgsPropertyDefinition def = QgsPalLayerSettings::propertyDefinitions()[key]; | ||
|
||
// create property in auxiliary storage if necessary | ||
if ( !mVectorLayer->auxiliaryLayer()->exists( 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 | ||
QgsProperty property = button->toProperty(); | ||
property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) ); | ||
property.setActive( true ); | ||
button->updateFieldLists(); | ||
button->setToProperty( property ); | ||
|
||
mDataDefinedProperties.setProperty( key, button->toProperty() ); | ||
|
||
emit changed(); | ||
} | ||
|
||
void QgsLabelSettingsWidgetBase::updateDataDefinedProperty() | ||
{ | ||
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() ); | ||
QgsPalLayerSettings::Property key = static_cast< QgsPalLayerSettings::Property >( button->propertyKey() ); | ||
mDataDefinedProperties.setProperty( key, button->toProperty() ); | ||
emit changed(); | ||
} | ||
|
||
void QgsLabelSettingsWidgetBase::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key ) | ||
{ | ||
button->init( key, mDataDefinedProperties, QgsPalLayerSettings::propertyDefinitions(), mVectorLayer, true ); | ||
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsLabelSettingsWidgetBase::updateDataDefinedProperty ); | ||
connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsLabelSettingsWidgetBase::createAuxiliaryField ); | ||
|
||
button->registerExpressionContextGenerator( this ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/*************************************************************************** | ||
qgslabelsettingswidgetbase.h | ||
---------------------- | ||
begin : December 2019 | ||
copyright : (C) 2019 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot 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 QGSLABELSETTINGSWIDGETBASE_H | ||
#define QGSLABELSETTINGSWIDGETBASE_H | ||
|
||
#include "qgssymbolwidgetcontext.h" | ||
#include "qgspallabeling.h" | ||
#include "qgspropertycollection.h" | ||
#include "qgspanelwidget.h" | ||
#include "qgsexpressioncontextgenerator.h" | ||
#include "qgis_gui.h" | ||
#include "qgis_sip.h" | ||
|
||
class QgsPropertyOverrideButton; | ||
|
||
/** | ||
* \ingroup gui | ||
* \class QgsLabelSettingsWidgetBase | ||
* Base class for widgets which allow customisation of label engine properties, such as label placement settings. | ||
* \since QGIS 3.12 | ||
*/ | ||
class GUI_EXPORT QgsLabelSettingsWidgetBase : public QgsPanelWidget, protected QgsExpressionContextGenerator | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsLabelSettingsWidgetBase. | ||
* \param parent parent widget | ||
* \param vl associated vector layer | ||
*/ | ||
QgsLabelSettingsWidgetBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *vl = nullptr ); | ||
|
||
/** | ||
* Sets the \a context in which the symbol widget is shown, e.g., the associated map canvas and expression contexts. | ||
* \see context() | ||
*/ | ||
virtual void setContext( const QgsSymbolWidgetContext &context ); | ||
|
||
/** | ||
* Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expression contexts. | ||
* \see setContext() | ||
*/ | ||
QgsSymbolWidgetContext context() const; | ||
|
||
/** | ||
* Sets the geometry \a type of the features to customize the widget accordingly. | ||
*/ | ||
virtual void setGeometryType( QgsWkbTypes::GeometryType type ); | ||
|
||
signals: | ||
|
||
/** | ||
* Emitted when any of the settings described by the widget are changed. | ||
*/ | ||
void changed(); | ||
|
||
protected: | ||
|
||
QgsExpressionContext createExpressionContext() const override; | ||
|
||
/** | ||
* Registers a data defined override \a button. Handles setting up connections | ||
* for the button and initializing the button to show the correct descriptions | ||
* and help text for the associated property. | ||
*/ | ||
void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key ); | ||
|
||
private slots: | ||
|
||
void createAuxiliaryField(); | ||
void updateDataDefinedProperty(); | ||
|
||
private: | ||
|
||
QgsVectorLayer *mVectorLayer = nullptr; | ||
|
||
bool mBlockSignals = false; | ||
|
||
QgsSymbolWidgetContext mContext; | ||
|
||
QgsPropertyCollection mDataDefinedProperties; | ||
|
||
}; | ||
|
||
#endif // QGSLABELSETTINGSWIDGETBASE_H |
Oops, something went wrong.