QGIS API Documentation
4.3.0-Master (91d4a333d5d)
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
class
QgsColorPickerHelper
;
36
37
47
class
GUI_EXPORT
QgsSymbolButton
:
public
QToolButton
48
{
49
Q_OBJECT
50
51
Q_PROPERTY( QString
dialogTitle
READ
dialogTitle
WRITE
setDialogTitle
)
52
53
public
:
58
QgsSymbolButton
( QWidget *parent
SIP_TRANSFERTHIS
=
nullptr
,
const
QString &
dialogTitle
= QString() );
59
~QgsSymbolButton
()
override
;
60
61
QSize
minimumSizeHint
()
const override
;
62
QSize
sizeHint
()
const override
;
63
70
void
setSymbolType
(
Qgis::SymbolType
type );
71
76
Qgis::SymbolType
symbolType
()
const
{
return
mType; }
77
82
void
setDialogTitle(
const
QString &title );
83
88
QString dialogTitle()
const
;
89
95
QgsSymbol
*symbol();
96
103
template
<
class
SymbolType> SymbolType *
clonedSymbol
()
SIP_SKIP
104
{
105
QgsSymbol
*tmpSymbol = mSymbol.get();
106
SymbolType *symbolCastToType =
dynamic_cast<
SymbolType *
>
( tmpSymbol );
107
108
if
( symbolCastToType )
109
{
110
return
symbolCastToType->clone();
111
}
112
else
113
{
114
//could not cast
115
return
nullptr
;
116
}
117
}
118
123
QgsMapCanvas
*mapCanvas()
const
;
124
130
void
setMapCanvas(
QgsMapCanvas
*canvas );
131
138
void
setMessageBar(
QgsMessageBar
*bar );
139
145
QgsMessageBar
*messageBar()
const
;
146
151
QgsVectorLayer
*layer()
const
;
152
159
void
setLayer(
QgsVectorLayer
*layer );
160
165
void
registerExpressionContextGenerator(
QgsExpressionContextGenerator
*generator );
166
175
void
setDefaultSymbol(
QgsSymbol
*symbol
SIP_TRANSFER
);
176
185
const
QgsSymbol
*defaultSymbol()
const
;
186
193
bool
showNull()
const
;
194
201
bool
isNull()
const
;
202
208
bool
fixedSizeConstraints()
const
;
209
210
public
slots:
211
218
void
setSymbol(
QgsSymbol
*symbol
SIP_TRANSFER
);
219
224
void
setColor(
const
QColor &color );
225
230
void
copySymbol();
231
237
void
pasteSymbol();
238
243
void
copyColor();
244
250
void
pasteColor();
251
259
void
setShowNull(
bool
showNull );
260
268
void
setToNull();
269
279
void
setToDefaultSymbol();
280
286
void
setFixedSizeConstraints(
bool
fixedSizeConstraints );
287
288
signals:
289
295
void
changed
();
296
297
protected
:
298
void
changeEvent
( QEvent *e )
override
;
299
void
showEvent
( QShowEvent *e )
override
;
300
void
resizeEvent
( QResizeEvent *event )
override
;
301
302
// Reimplemented to allow dragging colors
303
void
mousePressEvent
( QMouseEvent *e )
override
;
304
void
contextMenuEvent
( QContextMenuEvent *e )
override
;
305
// Reimplemented to allow dragging colors/symbols from button
306
void
mouseMoveEvent
( QMouseEvent *e )
override
;
307
// Reimplemented to accept dragged colors
308
void
dragEnterEvent
( QDragEnterEvent *e )
override
;
309
310
// Reimplemented to reset button appearance after drag leave
311
void
dragLeaveEvent
( QDragLeaveEvent *e )
override
;
312
313
// Reimplemented to accept dropped colors
314
void
dropEvent
( QDropEvent *e )
override
;
315
316
void
wheelEvent
( QWheelEvent *event )
override
;
317
318
private
slots:
319
320
void
showSettingsDialog();
321
void
updateSymbolFromWidget(
QgsSymbolSelectorWidget
*widget );
322
326
void
prepareMenu();
327
328
void
addRecentColor(
const
QColor &color );
329
333
void
activatePicker();
334
335
void
onColorPicked(
const
QColor &color );
336
void
onColorHovered(
const
QColor &color );
337
void
colorPickingCanceled();
338
339
private
:
340
QSize mSizeHint;
341
342
QString mDialogTitle;
343
344
Qgis::SymbolType
mType =
Qgis::SymbolType::Fill
;
345
346
QgsMapCanvas
*mMapCanvas =
nullptr
;
347
QgsMessageBar
*mMessageBar =
nullptr
;
348
349
QPoint mDragStartPosition;
350
351
QMenu *mMenu =
nullptr
;
352
353
QPointer<QgsVectorLayer> mLayer;
354
355
QSize mIconSize;
356
357
std::unique_ptr<QgsSymbol> mSymbol;
358
359
QgsExpressionContextGenerator
*mExpressionContextGenerator =
nullptr
;
360
361
bool
mShowNull =
false
;
362
363
bool
mFixedSizeConstraints =
true
;
364
365
std::unique_ptr<QgsSymbol> mDefaultSymbol;
366
367
QgsColorPickerHelper
*mPickerHelper =
nullptr
;
368
373
void
updatePreview(
const
QColor &color = QColor(),
QgsSymbol
*tempSymbol =
nullptr
);
374
384
bool
colorFromMimeData(
const
QMimeData *mimeData, QColor &resultColor,
bool
&hasAlpha );
385
389
QPixmap createColorIcon(
const
QColor &color )
const
;
390
391
void
showColorDialog();
392
393
void
updateSizeHint();
394
};
395
396
#endif
// QGSSYMBOLBUTTON_H
Qgis::SymbolType
SymbolType
Symbol types.
Definition
qgis.h:671
Qgis::SymbolType::Fill
@ Fill
Fill symbol.
Definition
qgis.h:674
QgsColorPickerHelper
A utility class for sampling colors from the screen.
Definition
qgscolorpickerhelper.h:44
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:405
QgsSymbolButton::sizeHint
QSize sizeHint() const override
Definition
qgssymbolbutton.cpp:121
QgsSymbolButton::changeEvent
void changeEvent(QEvent *e) override
Definition
qgssymbolbutton.cpp:587
QgsSymbolButton::QgsSymbolButton
QgsSymbolButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new symbol button.
Definition
qgssymbolbutton.cpp:49
QgsSymbolButton::~QgsSymbolButton
~QgsSymbolButton() override
QgsSymbolButton::mousePressEvent
void mousePressEvent(QMouseEvent *e) override
Definition
qgssymbolbutton.cpp:318
QgsSymbolButton::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *e) override
Definition
qgssymbolbutton.cpp:364
QgsSymbolButton::showEvent
void showEvent(QShowEvent *e) override
Definition
qgssymbolbutton.cpp:596
QgsSymbolButton::setSymbolType
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type which the button requires.
Definition
qgssymbolbutton.cpp:126
QgsSymbolButton::setDialogTitle
void setDialogTitle(const QString &title)
Sets the title for the symbol settings dialog window.
Definition
qgssymbolbutton.cpp:772
QgsSymbolButton::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition
qgssymbolbutton.cpp:602
QgsSymbolButton::minimumSizeHint
QSize minimumSizeHint() const override
Definition
qgssymbolbutton.cpp:116
QgsSymbolButton::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *e) override
Definition
qgssymbolbutton.cpp:327
QgsSymbolButton::dropEvent
void dropEvent(QDropEvent *e) override
Definition
qgssymbolbutton.cpp:387
QgsSymbolButton::dialogTitle
QString dialogTitle
Definition
qgssymbolbutton.h:51
QgsSymbolButton::changed
void changed()
Emitted when the symbol's settings are changed.
QgsSymbolButton::dragLeaveEvent
void dragLeaveEvent(QDragLeaveEvent *e) override
Definition
qgssymbolbutton.cpp:380
QgsSymbolButton::symbolType
Qgis::SymbolType symbolType() const
Returns the symbol type which the button requires.
Definition
qgssymbolbutton.h:76
QgsSymbolButton::clonedSymbol
SymbolType * clonedSymbol()
Returns a clone of the current symbol (as the specified template type) defined by the button.
Definition
qgssymbolbutton.h:103
QgsSymbolButton::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e) override
Definition
qgssymbolbutton.cpp:338
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