QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgssymbolbutton.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgssymbolbutton.h
3
-----------------
4
Date : July 2017
5
Copyright : (C) 2017 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 QGSSYMBOLBUTTON_H
16
#define QGSSYMBOLBUTTON_H
17
18
#include <memory>
19
20
#include "
qgis.h
"
21
#include "qgis_gui.h"
22
#include "
qgis_sip.h
"
23
24
#include <QPointer>
25
#include <QToolButton>
26
27
class
QgsMapCanvas
;
28
class
QgsVectorLayer
;
29
class
QgsExpressionContextGenerator
;
30
class
QgsPanelWidget
;
31
class
QgsMessageBar
;
32
class
QMimeData;
33
class
QgsSymbol
;
34
class
QgsSymbolSelectorWidget
;
35
45
class
GUI_EXPORT
QgsSymbolButton
:
public
QToolButton
46
{
47
Q_OBJECT
48
49
Q_PROPERTY( QString
dialogTitle
READ
dialogTitle
WRITE
setDialogTitle
)
50
51
public
:
56
QgsSymbolButton
( QWidget *parent
SIP_TRANSFERTHIS
=
nullptr
,
const
QString &
dialogTitle
= QString() );
57
~QgsSymbolButton
()
override
;
58
59
QSize
minimumSizeHint
()
const override
;
60
QSize
sizeHint
()
const override
;
61
68
void
setSymbolType
(
Qgis::SymbolType
type );
69
74
Qgis::SymbolType
symbolType
()
const
{
return
mType; }
75
80
void
setDialogTitle(
const
QString &title );
81
86
QString dialogTitle()
const
;
87
93
QgsSymbol
*symbol();
94
101
template
<
class
SymbolType> SymbolType *
clonedSymbol
()
SIP_SKIP
102
{
103
QgsSymbol
*tmpSymbol = mSymbol.get();
104
SymbolType *symbolCastToType =
dynamic_cast<
SymbolType *
>
( tmpSymbol );
105
106
if
( symbolCastToType )
107
{
108
return
symbolCastToType->clone();
109
}
110
else
111
{
112
//could not cast
113
return
nullptr
;
114
}
115
}
116
121
QgsMapCanvas
*mapCanvas()
const
;
122
128
void
setMapCanvas(
QgsMapCanvas
*canvas );
129
136
void
setMessageBar(
QgsMessageBar
*bar );
137
143
QgsMessageBar
*messageBar()
const
;
144
149
QgsVectorLayer
*layer()
const
;
150
157
void
setLayer(
QgsVectorLayer
*layer );
158
163
void
registerExpressionContextGenerator(
QgsExpressionContextGenerator
*generator );
164
173
void
setDefaultSymbol(
QgsSymbol
*symbol
SIP_TRANSFER
);
174
183
const
QgsSymbol
*defaultSymbol()
const
;
184
191
bool
showNull()
const
;
192
199
bool
isNull()
const
;
200
206
bool
fixedSizeConstraints()
const
;
207
208
public
slots:
209
216
void
setSymbol(
QgsSymbol
*symbol
SIP_TRANSFER
);
217
222
void
setColor(
const
QColor &color );
223
228
void
copySymbol();
229
235
void
pasteSymbol();
236
241
void
copyColor();
242
248
void
pasteColor();
249
257
void
setShowNull(
bool
showNull );
258
266
void
setToNull();
267
277
void
setToDefaultSymbol();
278
284
void
setFixedSizeConstraints(
bool
fixedSizeConstraints );
285
286
signals:
287
293
void
changed
();
294
295
protected
:
296
void
changeEvent
( QEvent *e )
override
;
297
void
showEvent
( QShowEvent *e )
override
;
298
void
resizeEvent
( QResizeEvent *event )
override
;
299
300
// Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
301
void
mousePressEvent
( QMouseEvent *e )
override
;
302
// Reimplemented to allow dragging colors/symbols from button
303
void
mouseMoveEvent
( QMouseEvent *e )
override
;
304
void
mouseReleaseEvent
( QMouseEvent *e )
override
;
305
void
keyPressEvent
( QKeyEvent *e )
override
;
306
// Reimplemented to accept dragged colors
307
void
dragEnterEvent
( QDragEnterEvent *e )
override
;
308
309
// Reimplemented to reset button appearance after drag leave
310
void
dragLeaveEvent
( QDragLeaveEvent *e )
override
;
311
312
// Reimplemented to accept dropped colors
313
void
dropEvent
( QDropEvent *e )
override
;
314
315
void
wheelEvent
( QWheelEvent *event )
override
;
316
317
private
slots:
318
319
void
showSettingsDialog();
320
void
updateSymbolFromWidget(
QgsSymbolSelectorWidget
*widget );
321
325
void
prepareMenu();
326
327
void
addRecentColor(
const
QColor &color );
328
332
void
activatePicker();
333
334
private
:
335
QSize mSizeHint;
336
337
QString mDialogTitle;
338
339
Qgis::SymbolType
mType =
Qgis::SymbolType::Fill
;
340
341
QgsMapCanvas
*mMapCanvas =
nullptr
;
342
QgsMessageBar
*mMessageBar =
nullptr
;
343
344
QPoint mDragStartPosition;
345
346
QMenu *mMenu =
nullptr
;
347
348
QPointer<QgsVectorLayer> mLayer;
349
350
QSize mIconSize;
351
352
std::unique_ptr<QgsSymbol> mSymbol;
353
354
QgsExpressionContextGenerator
*mExpressionContextGenerator =
nullptr
;
355
356
bool
mPickingColor =
false
;
357
358
bool
mShowNull =
false
;
359
360
bool
mFixedSizeConstraints =
true
;
361
362
std::unique_ptr<QgsSymbol> mDefaultSymbol;
363
368
void
updatePreview(
const
QColor &color = QColor(),
QgsSymbol
*tempSymbol =
nullptr
);
369
379
bool
colorFromMimeData(
const
QMimeData *mimeData, QColor &resultColor,
bool
&hasAlpha );
380
384
QPixmap createColorIcon(
const
QColor &color )
const
;
385
392
void
stopPicking( QPoint eventPos,
bool
samplingColor =
true
);
393
394
void
showColorDialog();
395
396
void
updateSizeHint();
397
};
398
399
#endif
// QGSSYMBOLBUTTON_H
Qgis::SymbolType
SymbolType
Symbol types.
Definition
qgis.h:671
Qgis::SymbolType::Fill
@ Fill
Fill symbol.
Definition
qgis.h:674
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition
qgsexpressioncontextgenerator.h:36
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition
qgsmapcanvas.h:96
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition
qgsmessagebar.h:61
QgsPanelWidget
Base class for any widget that can be shown as an inline panel.
Definition
qgspanelwidget.h:32
QgsSymbolButton::wheelEvent
void wheelEvent(QWheelEvent *event) override
Definition
qgssymbolbutton.cpp:433
QgsSymbolButton::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *e) override
Definition
qgssymbolbutton.cpp:366
QgsSymbolButton::sizeHint
QSize sizeHint() const override
Definition
qgssymbolbutton.cpp:115
QgsSymbolButton::changeEvent
void changeEvent(QEvent *e) override
Definition
qgssymbolbutton.cpp:621
QgsSymbolButton::QgsSymbolButton
QgsSymbolButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new symbol button.
Definition
qgssymbolbutton.cpp:48
QgsSymbolButton::~QgsSymbolButton
~QgsSymbolButton() override
QgsSymbolButton::mousePressEvent
void mousePressEvent(QMouseEvent *e) override
Definition
qgssymbolbutton.cpp:312
QgsSymbolButton::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *e) override
Definition
qgssymbolbutton.cpp:392
QgsSymbolButton::showEvent
void showEvent(QShowEvent *e) override
Definition
qgssymbolbutton.cpp:630
QgsSymbolButton::setSymbolType
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type which the button requires.
Definition
qgssymbolbutton.cpp:120
QgsSymbolButton::setDialogTitle
void setDialogTitle(const QString &title)
Sets the title for the symbol settings dialog window.
Definition
qgssymbolbutton.cpp:815
QgsSymbolButton::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
Definition
qgssymbolbutton.cpp:379
QgsSymbolButton::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition
qgssymbolbutton.cpp:636
QgsSymbolButton::minimumSizeHint
QSize minimumSizeHint() const override
Definition
qgssymbolbutton.cpp:110
QgsSymbolButton::dropEvent
void dropEvent(QDropEvent *e) override
Definition
qgssymbolbutton.cpp:415
QgsSymbolButton::dialogTitle
QString dialogTitle
Definition
qgssymbolbutton.h:49
QgsSymbolButton::changed
void changed()
Emitted when the symbol's settings are changed.
QgsSymbolButton::dragLeaveEvent
void dragLeaveEvent(QDragLeaveEvent *e) override
Definition
qgssymbolbutton.cpp:408
QgsSymbolButton::symbolType
Qgis::SymbolType symbolType() const
Returns the symbol type which the button requires.
Definition
qgssymbolbutton.h:74
QgsSymbolButton::clonedSymbol
SymbolType * clonedSymbol()
Returns a clone of the current symbol (as the specified template type) defined by the button.
Definition
qgssymbolbutton.h:101
QgsSymbolButton::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e) override
Definition
qgssymbolbutton.cpp:333
QgsSymbolSelectorWidget
Symbol selector widget that can be used to select and build a symbol.
Definition
qgssymbolselectordialog.h:89
QgsSymbol
Abstract base class for all rendered symbols.
Definition
qgssymbol.h:227
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
qgis.h
qgis_sip.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition
qgis_sip.h:52
SIP_SKIP
#define SIP_SKIP
Definition
qgis_sip.h:138
SIP_TRANSFER
#define SIP_TRANSFER
Definition
qgis_sip.h:35
Generated on
for QGIS API Documentation by
1.17.0