Skip to content

Commit

Permalink
[FEATURE][layouts] Allow configuring legend patch shapes by
Browse files Browse the repository at this point in the history
double-clicking on legend items

Allows users to set custom legend patch shapes for items by
entering a WKT string representing the patch geometry
  • Loading branch information
nyalldawson committed Apr 21, 2020
1 parent 3d7e5d6 commit ddbcb1f
Show file tree
Hide file tree
Showing 17 changed files with 1,139 additions and 64 deletions.
Expand Up @@ -40,6 +40,7 @@ Alternative constructor.
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;



signals:

void refreshLegend();
Expand Down
148 changes: 148 additions & 0 deletions python/gui/auto_generated/qgslegendpatchshapebutton.sip.in
@@ -0,0 +1,148 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgslegendpatchshapebutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLegendPatchShapeButton : QToolButton
{
%Docstring
A button for creating and modifying QgsLegendPatchShape settings.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgslegendpatchshapebutton.h"
%End
public:

QgsLegendPatchShapeButton( QWidget *parent /TransferThis/ = 0, const QString &dialogTitle = QString() );
%Docstring
Construct a new patch shape button with the specified ``parent`` widget.
Use ``dialogTitle`` string to define the title to show in the legend patch shape widget.
%End

virtual QSize minimumSizeHint() const;

virtual QSize sizeHint() const;


void setSymbolType( QgsSymbol::SymbolType type );
%Docstring
Sets the symbol ``type`` which the button requires.
If the type differs from the current symbol type, the symbol will be reset
to a default symbol style of the new type.

.. seealso:: :py:func:`symbolType`
%End

QgsSymbol::SymbolType symbolType() const;
%Docstring
Returns the symbol type which the button requires.

.. seealso:: :py:func:`setSymbolType`
%End

void setPreviewSymbol( QgsSymbol *symbol /Transfer/ );
%Docstring
Sets the symbol to use for previewing the legend patch shape.

Ownership is transferred to the button. It is the caller's responsiblity
to ensure that the symbol type matches the button's symbolType()
%End

void setDialogTitle( const QString &title );
%Docstring
Sets the ``title`` for the symbol settings dialog window.

.. seealso:: :py:func:`dialogTitle`
%End

QString dialogTitle() const;
%Docstring
Returns the title for the symbol settings dialog window.

.. seealso:: :py:func:`setDialogTitle`
%End

QgsLegendPatchShape shape();
%Docstring
Returns the current shape defined by the button.

.. seealso:: :py:func:`setShape`

.. seealso:: :py:func:`changed`
%End

void setMessageBar( QgsMessageBar *bar );
%Docstring
Sets the message ``bar`` associated with the widget. This allows the widget to push feedback messages
to the appropriate message bar.

.. seealso:: :py:func:`messageBar`

.. versionadded:: 3.6
%End

QgsMessageBar *messageBar() const;
%Docstring
Returns the message bar associated with the widget.

.. seealso:: :py:func:`setMessageBar`

.. versionadded:: 3.6
%End

public slots:

void setShape( const QgsLegendPatchShape &shape );
%Docstring
Sets the ``shape`` for the button.

.. seealso:: :py:func:`shape`

.. seealso:: :py:func:`changed`
%End

void setToDefault();
%Docstring
Resets the shape to the default shape.
%End

signals:

void changed();
%Docstring
Emitted when the shape's settings are changed.

.. seealso:: :py:func:`shape`

.. seealso:: :py:func:`setShape`
%End

protected:

virtual void changeEvent( QEvent *e );

virtual void showEvent( QShowEvent *e );

virtual void resizeEvent( QResizeEvent *event );


virtual void mousePressEvent( QMouseEvent *e );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgslegendpatchshapebutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
58 changes: 58 additions & 0 deletions python/gui/auto_generated/qgslegendpatchshapewidget.sip.in
@@ -0,0 +1,58 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgslegendpatchshapewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLegendPatchShapeWidget : QgsPanelWidget
{
%Docstring
Widget for configuring a custom legend patch shape.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgslegendpatchshapewidget.h"
%End
public:

QgsLegendPatchShapeWidget( QWidget *parent /TransferThis/ = 0, const QgsLegendPatchShape &shape = QgsLegendPatchShape() );
%Docstring
Constructor for QgsLegendPatchShapeWidget, with the specified ``parent`` widget.
%End

QgsLegendPatchShape shape() const;
%Docstring
Returns the legend patch shape as currently defined by the widget.

.. seealso:: :py:func:`setShape`
%End

void setShape( const QgsLegendPatchShape &shape );
%Docstring
Sets the shape to show in the widget.

.. seealso:: :py:func:`shape`
%End

signals:

void changed();
%Docstring
Emitted whenever the patch shape defined by the widget is changed.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgslegendpatchshapewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -108,6 +108,8 @@
%Include auto_generated/qgsidentifymenu.sip
%Include auto_generated/qgskeyvaluewidget.sip
%Include auto_generated/qgslegendfilterbutton.sip
%Include auto_generated/qgslegendpatchshapebutton.sip
%Include auto_generated/qgslegendpatchshapewidget.sip
%Include auto_generated/qgslimitedrandomcolorrampdialog.sip
%Include auto_generated/qgslistwidget.sip
%Include auto_generated/qgslonglongvalidator.sip
Expand Down
19 changes: 10 additions & 9 deletions src/core/layout/qgslayoutitemlegend.h
Expand Up @@ -55,6 +55,16 @@ class CORE_EXPORT QgsLegendModel : public QgsLayerTreeModel

Qt::ItemFlags flags( const QModelIndex &index ) const override;

/**
* Returns filtered list of active legend nodes attached to a particular layer node
* (by default it returns also legend node embedded in parent layer node (if any) unless skipNodeEmbeddedInParent is true)
* \note Parameter skipNodeEmbeddedInParent added in QGIS 2.18
* \note Not available in Python bindings
* \see layerOriginalLegendNodes()
* \since QGIS 3.10
*/
QList<QgsLayerTreeModelLegendNode *> layerLegendNodes( QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent = false ) const SIP_SKIP;

signals:

/**
Expand All @@ -73,15 +83,6 @@ class CORE_EXPORT QgsLegendModel : public QgsLayerTreeModel

private:

/**
* Returns filtered list of active legend nodes attached to a particular layer node
* (by default it returns also legend node embedded in parent layer node (if any) unless skipNodeEmbeddedInParent is true)
* \note Parameter skipNodeEmbeddedInParent added in QGIS 2.18
* \see layerOriginalLegendNodes()
* \since QGIS 3.10
*/
QList<QgsLayerTreeModelLegendNode *> layerLegendNodes( QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent = false ) const;

/**
* Pointer to the QgsLayoutItemLegend class that made the model.
* \since QGIS 3.10
Expand Down
4 changes: 4 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -432,6 +432,8 @@ SET(QGIS_GUI_SRCS
qgskeyvaluewidget.cpp
qgslistwidget.cpp
qgslegendfilterbutton.cpp
qgslegendpatchshapebutton.cpp
qgslegendpatchshapewidget.cpp
qgslimitedrandomcolorrampdialog.cpp
qgsratiolockbutton.cpp
qgsludialog.cpp
Expand Down Expand Up @@ -656,6 +658,8 @@ SET(QGIS_GUI_HDRS
qgsinstallgridshiftdialog.h
qgskeyvaluewidget.h
qgslegendfilterbutton.h
qgslegendpatchshapebutton.h
qgslegendpatchshapewidget.h
qgslimitedrandomcolorrampdialog.h
qgslistwidget.h
qgslonglongvalidator.h
Expand Down

0 comments on commit ddbcb1f

Please sign in to comment.