QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsSymbol
Definition: qgssymbol.h:63
QgsLegendPatchShapeButton
Definition: qgslegendpatchshapebutton.h:36
QgsLegendPatchShape
Definition: qgslegendpatchshape.h:30
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMessageBar
Definition: qgsmessagebar.h:60
qgslegendpatchshape.h
QgsSymbol::Fill
@ Fill
Fill symbol.
Definition: qgssymbol.h:89
QgsLegendPatchShapeButton::symbolType
QgsSymbol::SymbolType symbolType() const
Returns the symbol type which the button requires.
Definition: qgslegendpatchshapebutton.h:63
QgsSymbol::SymbolType
SymbolType
Type of the symbol.
Definition: qgssymbol.h:85
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgssymbol.h