QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsaggregatetoolbutton.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsaggregatetoolbutton.cpp
3
--------------------------------------
4
Date : Nov 2017
5
Copyright : (C) 2017 Matthias Kuhn
6
Email : matthias@opengis.ch
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
16
#include "
qgsaggregatetoolbutton.h
"
17
18
#include "
qgis.h
"
19
#include "
qgsaggregatecalculator.h
"
20
21
#include <QMenu>
22
23
#include "moc_qgsaggregatetoolbutton.cpp"
24
25
QgsAggregateToolButton::QgsAggregateToolButton
()
26
{
27
setFocusPolicy( Qt::StrongFocus );
28
setPopupMode( QToolButton::InstantPopup );
29
30
mMenu =
new
QMenu(
this
);
31
connect( mMenu, &QMenu::aboutToShow,
this
, &QgsAggregateToolButton::aboutToShowMenu );
32
setMenu( mMenu );
33
34
setText( tr(
"Exclude"
) );
35
}
36
37
void
QgsAggregateToolButton::setType
( QMetaType::Type
type
)
38
{
39
if
( mType ==
type
)
40
return
;
41
42
mType =
type
;
43
updateAvailableAggregates();
44
}
45
46
void
QgsAggregateToolButton::setType
( QVariant::Type
type
)
47
{
48
setType
(
QgsVariantUtils::variantTypeToMetaType
(
type
) );
49
}
50
51
void
QgsAggregateToolButton::aboutToShowMenu()
52
{
53
mMenu->clear();
54
55
QAction *action = mMenu->addAction( tr(
"Exclude"
) );
56
connect( action, &QAction::triggered,
this
, [
this
] {
setActive
(
false
); } );
57
58
for
(
const
auto
&
aggregate
: std::as_const( mAvailableAggregates ) )
59
{
60
QAction *action = mMenu->addAction(
aggregate
.name );
61
connect( action, &QAction::triggered,
this
, [
this
,
aggregate
] {
62
setText(
aggregate
.name );
63
setAggregate
(
aggregate
.function );
64
} );
65
}
66
}
67
68
void
QgsAggregateToolButton::updateAvailableAggregates()
69
{
70
QList<QgsAggregateCalculator::AggregateInfo> aggregates =
QgsAggregateCalculator::aggregates
();
71
72
for
(
const
auto
&
aggregate
: aggregates )
73
{
74
if
(
aggregate
.supportedTypes.contains( mType ) )
75
{
76
mAvailableAggregates.append(
aggregate
);
77
}
78
}
79
}
80
81
void
QgsAggregateToolButton::setActive
(
bool
active
)
82
{
83
if
(
active
== mActive )
84
return
;
85
86
mActive =
active
;
87
88
if
( !
active
)
89
setText( tr(
"Exclude"
) );
90
emit
activeChanged
();
91
}
92
93
QString
QgsAggregateToolButton::aggregate
()
const
94
{
95
return
mAggregate;
96
}
97
98
void
QgsAggregateToolButton::setAggregate
(
const
QString &
aggregate
)
99
{
100
if
(
aggregate
== mAggregate )
101
return
;
102
103
mAggregate = QString();
104
105
for
(
const
auto
&agg : std::as_const( mAvailableAggregates ) )
106
{
107
if
( agg.function ==
aggregate
)
108
{
109
mAggregate =
aggregate
;
110
setText( agg.name );
111
break
;
112
}
113
}
114
115
setActive
( !mAggregate.isEmpty() );
116
117
emit
aggregateChanged
();
118
}
119
120
bool
QgsAggregateToolButton::active
()
const
121
{
122
return
mActive;
123
}
124
125
QMetaType::Type
QgsAggregateToolButton::type
()
const
126
{
127
return
mType;
128
}
QgsAggregateCalculator::aggregates
static QList< QgsAggregateCalculator::AggregateInfo > aggregates()
Structured information for available aggregates.
Definition
qgsaggregatecalculator.cpp:309
QgsAggregateToolButton::setActive
void setActive(bool active)
When this flag is false, the aggregate will be deactivated.
Definition
qgsaggregatetoolbutton.cpp:81
QgsAggregateToolButton::active
bool active() const
When this flag is false, the aggregate will be deactivated.
Definition
qgsaggregatetoolbutton.cpp:120
QgsAggregateToolButton::setType
void setType(QMetaType::Type type)
Based on the type of underlying data, some aggregates will be available or not.
Definition
qgsaggregatetoolbutton.cpp:37
QgsAggregateToolButton::setAggregate
void setAggregate(const QString &aggregate)
The function name of the selected aggregate or a Null String if none is chosen.
Definition
qgsaggregatetoolbutton.cpp:98
QgsAggregateToolButton::type
QMetaType::Type type() const
Based on the type of underlying data, some aggregates will be available or not.
Definition
qgsaggregatetoolbutton.cpp:125
QgsAggregateToolButton::aggregate
QString aggregate() const
The function name of the selected aggregate or a Null String if none is chosen.
Definition
qgsaggregatetoolbutton.cpp:93
QgsAggregateToolButton::activeChanged
void activeChanged()
A function has been selected or deselected.
QgsAggregateToolButton::aggregateChanged
void aggregateChanged()
The function name of the selected aggregate has changed.
QgsAggregateToolButton::QgsAggregateToolButton
QgsAggregateToolButton()
Constructor.
Definition
qgsaggregatetoolbutton.cpp:25
QgsVariantUtils::variantTypeToMetaType
static QMetaType::Type variantTypeToMetaType(QVariant::Type variantType)
Converts a QVariant::Type to a QMetaType::Type.
Definition
qgsvariantutils.cpp:501
qgis.h
qgsaggregatecalculator.h
qgsaggregatetoolbutton.h
Generated on
for QGIS API Documentation by
1.17.0