QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgslegendpatchshapebutton.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendpatchshapebutton.h
3  -----------------
4  Date : April 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSLEGENDPATCHSHAPEBUTTON_H
16 #define QGSLEGENDPATCHSHAPEBUTTON_H
17 
18 #include "qgis_gui.h"
19 #include "qgis_sip.h"
20 #include "qgssymbol.h"
21 #include "qgslegendpatchshape.h"
22 #include <QToolButton>
23 #include <QPointer>
24 #include <memory>
25 
26 class QgsPanelWidget;
27 class QgsMessageBar;
28 
36 class GUI_EXPORT QgsLegendPatchShapeButton : public QToolButton
37 {
38  Q_OBJECT
39 
40  public:
41 
46  QgsLegendPatchShapeButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
47 
48  QSize minimumSizeHint() const override;
49  QSize sizeHint() const override;
50 
57  void setSymbolType( QgsSymbol::SymbolType type );
58 
63  QgsSymbol::SymbolType symbolType() const { return mType; }
64 
71  void setPreviewSymbol( QgsSymbol *symbol SIP_TRANSFER );
72 
77  void setDialogTitle( const QString &title );
78 
83  QString dialogTitle() const;
84 
90  QgsLegendPatchShape shape();
91 
98  void setMessageBar( QgsMessageBar *bar );
99 
105  QgsMessageBar *messageBar() const;
106 
107  public slots:
108 
114  void setShape( const QgsLegendPatchShape &shape );
115 
119  void setToDefault();
120 
121  signals:
122 
128  void changed();
129 
130  protected:
131 
132  void changeEvent( QEvent *e ) override;
133  void showEvent( QShowEvent *e ) override;
134  void resizeEvent( QResizeEvent *event ) override;
135 
136  // Reimplemented to detect right mouse button clicks on the button
137  void mousePressEvent( QMouseEvent *e ) override;
138 
139  private slots:
140 
141  void showSettingsDialog();
142 
146  void prepareMenu();
147 
148  void loadPatchFromStyle( const QString &name );
149 
150  private:
151 
152  QgsLegendPatchShape mShape;
153 
154  QSize mSizeHint;
155 
156  QString mDialogTitle;
157 
159 
160  std::unique_ptr< QgsSymbol > mPreviewSymbol;
161 
162  QgsMessageBar *mMessageBar = nullptr;
163 
164  QMenu *mMenu = nullptr;
165 
166  QSize mIconSize;
167 
168  bool mIsDefault = true;
169 
173  void updatePreview();
174 
175 };
176 
177 #endif // QGSLEGENDPATCHSHAPEBUTTON_H
A button for creating and modifying QgsLegendPatchShape settings.
QgsSymbol::SymbolType symbolType() const
Returns the symbol type which the button requires.
void changed()
Emitted when the shape's settings are changed.
Represents a patch shape for use in map legends.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Base class for any widget that can be shown as a inline panel.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
SymbolType
Type of the symbol.
Definition: qgssymbol.h:87
@ Fill
Fill symbol.
Definition: qgssymbol.h:90
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36