Skip to content

Commit

Permalink
[FEATURE] New standard widget for symbol buttons
Browse files Browse the repository at this point in the history
Button widgets for configuring symbol properties were reimplemented
multiple times throughout the codebase. This commit creates a new
standard QgsSymbolButton widget which should be used whenever
a button for configuring symbol properties is required.

Features include:
- automatic use of inline panels whenever possible
- dropdown menu with shortcuts to color settings, copy/pasting colors
- accepts drag and dropped colors to set symbol color
  • Loading branch information
nyalldawson committed Jul 24, 2017
1 parent 9a12249 commit 22c4740
Show file tree
Hide file tree
Showing 7 changed files with 904 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
%Include qgsstatusbar.sip
%Include qgssublayersdialog.sip
%Include qgssubstitutionlistwidget.sip
%Include qgssymbolbutton.sip
%Include qgstablewidgetbase.sip
%Include qgstabwidget.sip
%Include qgstaskmanagerwidget.sip
Expand Down
159 changes: 159 additions & 0 deletions python/gui/qgssymbolbutton.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssymbolbutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsSymbolButton : QToolButton
{
%Docstring
A button for creating and modifying QgsSymbol settings.

The button shows a preview icon for the current symbol, and will open a detailed symbol editor dialog (or
panel widget) when clicked.

.. versionadded:: 3.0
%End

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

QgsSymbolButton( QWidget *parent /TransferThis/ = 0, const QString &dialogTitle = QString() );
%Docstring
Construct a new symbol button.
Use ``dialogTitle`` string to define the title to show in the symbol settings dialog.
%End

virtual QSize minimumSizeHint() const;

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

QString dialogTitle() const;
%Docstring
Returns the title for the symbol settings dialog window.
.. seealso:: setDialogTitle()
:rtype: str
%End

QgsSymbol *symbol();
%Docstring
Returns the current symbol defined by the button.
.. seealso:: setSymbol()
.. seealso:: changed()
:rtype: QgsSymbol
%End

QgsMapCanvas *mapCanvas() const;
%Docstring
Returns the map canvas associated with the widget.
.. seealso:: setMapCanvas()
:rtype: QgsMapCanvas
%End

void setMapCanvas( QgsMapCanvas *canvas );
%Docstring
Sets a map ``canvas`` to associate with the widget. This allows the
widget to fetch current settings from the map canvas, such as current scale.
.. seealso:: mapCanvas()
%End

QgsVectorLayer *layer() const;
%Docstring
Returns the layer associated with the widget.
.. seealso:: setLayer()
:rtype: QgsVectorLayer
%End

void setLayer( QgsVectorLayer *layer );
%Docstring
Sets a ``layer`` to associate with the widget. This allows the
widget to setup layer related settings within the symbol settings dialog,
such as correctly populating data defined override buttons.
.. seealso:: layer()
%End

void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
%Docstring
Register an expression context generator class that will be used to retrieve
an expression context for the button when required.
%End

public slots:

void setSymbol( QgsSymbol *symbol /Transfer/ );
%Docstring
Sets the ``symbol`` for the button. Ownership of ``symbol`` is transferred to the
button.
.. seealso:: symbol()
.. seealso:: changed()
%End

void setColor( const QColor &color );
%Docstring
Sets the current ``color`` for the symbol. Will emit a changed() signal if the color is different
to the previous symbol color.
%End

void copyColor();
%Docstring
Copies the current symbol color to the clipboard.
.. seealso:: pasteColor()
%End

void pasteColor();
%Docstring
Pastes a color from the clipboard to the symbol. If clipboard does not contain a valid
color or string representation of a color, then no change is applied.
.. seealso:: copyColor()
%End

signals:

void changed();
%Docstring
Emitted when the symbol's settings are changed.
.. seealso:: symbol()
.. seealso:: setSymbol()
%End

protected:

virtual void changeEvent( QEvent *e );

virtual void showEvent( QShowEvent *e );

virtual void resizeEvent( QResizeEvent *event );


virtual void mousePressEvent( QMouseEvent *e );

virtual void mouseMoveEvent( QMouseEvent *e );

virtual void dragEnterEvent( QDragEnterEvent *e );


virtual void dragLeaveEvent( QDragLeaveEvent *e );


virtual void dropEvent( QDropEvent *e );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssymbolbutton.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ SET(QGIS_GUI_SRCS
qgssubstitutionlistwidget.cpp
qgssqlcomposerdialog.cpp
qgsstatusbar.cpp
qgssymbolbutton.cpp
qgstablewidgetbase.cpp
qgstabwidget.cpp
qgstablewidgetitem.cpp
Expand Down Expand Up @@ -492,6 +493,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsstatusbar.h
qgssublayersdialog.h
qgssubstitutionlistwidget.h
qgssymbolbutton.h
qgstablewidgetbase.h
qgstabwidget.h
qgstaskmanagerwidget.h
Expand Down
Loading

0 comments on commit 22c4740

Please sign in to comment.