-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable editing extent buffer in the GUI
- Loading branch information
1 parent
984a947
commit 1db7781
Showing
6 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
/*************************************************************************** | ||
qgsextentbufferdialog.cpp | ||
--------------------- | ||
begin : December 2024 | ||
copyright : (C) 2024 by Juho Ervasti | ||
email : juho dot ervasti at gispo dot fi | ||
*************************************************************************** | ||
* * | ||
* 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 "qgsextentbufferdialog.h" | ||
#include "qdialogbuttonbox.h" | ||
#include "qgsexpressioncontext.h" | ||
#include "qgshelp.h" | ||
#include "qgspanelwidget.h" | ||
#include "qgssymbol.h" | ||
#include "qgssymbolwidgetcontext.h" | ||
#include "qgsvectorlayer.h" | ||
|
||
QgsExtentBufferWidget::QgsExtentBufferWidget( QgsSymbol *symbol, QgsVectorLayer *layer, QWidget *parent ) | ||
: QgsPanelWidget( parent ), mSymbol( symbol ), mLayer( layer ) | ||
{ | ||
setupUi( this ); | ||
|
||
mExtentBufferSpinBox->setValue( mSymbol-> extentBuffer() ); | ||
|
||
connect( mExtentBufferSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), [ = ]() | ||
{ | ||
emit widgetChanged(); | ||
} ); | ||
|
||
registerDataDefinedButton( mExtentBufferDDButton, QgsSymbol::Property::ExtentBuffer ); | ||
} | ||
|
||
QgsSymbolWidgetContext QgsExtentBufferWidget::context() const | ||
{ | ||
return mContext; | ||
} | ||
|
||
void QgsExtentBufferWidget::setContext( const QgsSymbolWidgetContext &context ) | ||
{ | ||
mContext = context; | ||
} | ||
|
||
void QgsExtentBufferWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key ) | ||
{ | ||
// pass in nullptr to avoid id, feature and geometry variables being added | ||
// since the buffer is not evaluated per-feature | ||
button->init( static_cast< int >( key ), mSymbol->dataDefinedProperties(), QgsSymbol::propertyDefinitions(), nullptr ); | ||
connect( button, &QgsPropertyOverrideButton::changed, [ = ]() | ||
{ | ||
emit widgetChanged(); | ||
} ); | ||
|
||
button->registerExpressionContextGenerator( this ); | ||
} | ||
|
||
QgsExpressionContext QgsExtentBufferWidget::createExpressionContext() const | ||
{ | ||
QList<QgsExpressionContextScope *> scopes = mContext.globalProjectAtlasMapLayerScopes( mLayer ); | ||
QgsExpressionContext expContext( scopes ); | ||
|
||
return expContext; | ||
} | ||
|
||
double QgsExtentBufferWidget::extentBuffer() const | ||
{ | ||
return mExtentBufferSpinBox->value(); | ||
} | ||
|
||
QgsProperty QgsExtentBufferWidget::dataDefinedProperty() const | ||
{ | ||
return mExtentBufferDDButton->toProperty(); | ||
} | ||
|
||
|
||
/// QgsExtentBufferDialog | ||
|
||
QgsExtentBufferDialog::QgsExtentBufferDialog( QgsSymbol *symbol, QgsVectorLayer *layer, QWidget *parent ) | ||
: QDialog( parent ) | ||
{ | ||
QVBoxLayout *vLayout = new QVBoxLayout(); | ||
mWidget = new QgsExtentBufferWidget( symbol, layer ); | ||
vLayout->addWidget( mWidget ); | ||
|
||
QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal ); | ||
connect( bbox, &QDialogButtonBox::accepted, this, &QgsExtentBufferDialog::accept ); | ||
connect( bbox, &QDialogButtonBox::rejected, this, &QgsExtentBufferDialog::reject ); | ||
connect( bbox, &QDialogButtonBox::helpRequested, this, &QgsExtentBufferDialog::showHelp ); | ||
|
||
vLayout->addWidget( bbox ); | ||
setLayout( vLayout ); | ||
|
||
setWindowTitle( tr( "Extent buffer" ) ); | ||
} | ||
|
||
double QgsExtentBufferDialog::extentBuffer() const | ||
{ | ||
if ( !mWidget ) | ||
return 0; | ||
|
||
return mWidget->extentBuffer(); | ||
} | ||
|
||
QgsProperty QgsExtentBufferDialog::dataDefinedProperty() const | ||
{ | ||
if ( !mWidget ) | ||
return QgsProperty(); | ||
|
||
return mWidget->dataDefinedProperty(); | ||
} | ||
|
||
QgsExtentBufferWidget *QgsExtentBufferDialog::widget() const | ||
{ | ||
return mWidget; | ||
} | ||
|
||
void QgsExtentBufferDialog::showHelp() | ||
{ | ||
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#extent-buffer" ) ); | ||
} | ||
|
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,131 @@ | ||
/*************************************************************************** | ||
qgsextentbufferdialog.h | ||
--------------------- | ||
begin : December 2024 | ||
copyright : (C) 2024 by Juho Ervasti | ||
email : juho dot ervasti at gispo dot fi | ||
*************************************************************************** | ||
* * | ||
* 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 QGSEXTENTBUFFERDIALOG_H | ||
#define QGSEXTENTBUFFERDIALOG_H | ||
|
||
#include <QDialog> | ||
#include "qgis_sip.h" | ||
|
||
#include "qgssymbol.h" | ||
#include "qgssymbolwidgetcontext.h" | ||
#include "ui_qgsextentbufferdialogbase.h" | ||
#include "qgis_gui.h" | ||
|
||
class QgsVectorLayer; | ||
|
||
/** | ||
* \class QgsExtentBufferWidget | ||
* \ingroup gui | ||
* \brief A widget which allows the user to modify the rendering order of extent buffers. | ||
* \see QgsExtentBufferDialog | ||
*/ | ||
class GUI_EXPORT QgsExtentBufferWidget : public QgsPanelWidget, public QgsExpressionContextGenerator, private Ui::QgsExtentBufferDialogBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
|
||
/** | ||
* Constructor for QgsExtentBufferWidget | ||
*/ | ||
QgsExtentBufferWidget( QgsSymbol *symbol, QgsVectorLayer *layer, QWidget *parent SIP_TRANSFERTHIS = nullptr ); | ||
|
||
/** | ||
* Returns the extent buffer value currently set in the widget. | ||
* | ||
* \returns extent buffer value | ||
*/ | ||
double extentBuffer() const; | ||
|
||
/** | ||
* Returns the data defined property currently set in the widget. | ||
* | ||
* \returns property | ||
*/ | ||
QgsProperty dataDefinedProperty() const; | ||
|
||
/** | ||
* Sets the context in which widget is shown, e.g., the associated map canvas and expression contexts. | ||
* \param context symbol widget context | ||
* \see context() | ||
*/ | ||
void setContext( const QgsSymbolWidgetContext &context ); | ||
|
||
/** | ||
* Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts. | ||
* \see setContext() | ||
*/ | ||
QgsSymbolWidgetContext context() const; | ||
|
||
private: | ||
QgsSymbol *mSymbol = nullptr; | ||
QgsVectorLayer *mLayer = nullptr; | ||
QgsSymbolWidgetContext mContext; | ||
|
||
QgsExpressionContext createExpressionContext() const override; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key ); | ||
}; | ||
|
||
/** | ||
* \class QgsExtentBufferDialog | ||
* \ingroup gui | ||
* \brief A dialog which allows the user to modify the extent buffer of a symbol. | ||
*/ | ||
class GUI_EXPORT QgsExtentBufferDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
public: | ||
|
||
//! Constructor for QgsExtentBufferDialog. | ||
QgsExtentBufferDialog( QgsSymbol *symbol, QgsVectorLayer *layer, QWidget *parent SIP_TRANSFERTHIS = nullptr ); | ||
|
||
/** | ||
* Returns the extent buffer value currently set in the widget. | ||
*/ | ||
double extentBuffer() const; | ||
|
||
/** | ||
* Returns the extent buffer value currently set in the widget. | ||
* | ||
* \note returns 0 if widget does not exist | ||
* | ||
* \returns extent buffer value | ||
*/ | ||
QgsProperty dataDefinedProperty() const; | ||
|
||
/** | ||
* Returns the data defined property currently set in the widget. | ||
* | ||
* \note returns empty property if widget does not exist | ||
* | ||
* \returns property | ||
*/ | ||
QgsExtentBufferWidget *widget() const; | ||
|
||
private: | ||
QgsExtentBufferWidget *mWidget; | ||
|
||
private slots: | ||
|
||
void showHelp(); | ||
|
||
}; | ||
|
||
#endif // QGSEXTENTBUFFERDIALOG_H |
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
Oops, something went wrong.