QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
layout
qgslayoutcombobox.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutcombobox.cpp
3
--------------------------------------
4
Date : March 2019
5
Copyright : (C) 2019 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
16
17
#include "
qgslayoutcombobox.h
"
18
19
#include "
qgslayoutmodel.h
"
20
21
#include "moc_qgslayoutcombobox.cpp"
22
23
QgsLayoutComboBox::QgsLayoutComboBox
( QWidget *parent,
QgsLayoutManager
*manager )
24
: QComboBox( parent )
25
{
26
setLayoutManager
( manager );
27
28
connect(
this
,
static_cast<
void
( QComboBox::* )(
int
)
>
( &QComboBox::currentIndexChanged ),
this
, &QgsLayoutComboBox::indexChanged );
29
}
30
31
void
QgsLayoutComboBox::setLayoutManager
(
QgsLayoutManager
*manager )
32
{
33
if
( mModel )
34
mModel->deleteLater();
35
if
( mProxyModel )
36
mProxyModel->deleteLater();
37
38
mModel =
new
QgsLayoutManagerModel
( manager,
this
);
39
mProxyModel =
new
QgsLayoutManagerProxyModel
(
this
);
40
mProxyModel->setSourceModel( mModel );
41
42
connect( mProxyModel, &QAbstractItemModel::rowsInserted,
this
, &QgsLayoutComboBox::rowsChanged );
43
connect( mProxyModel, &QAbstractItemModel::rowsRemoved,
this
, &QgsLayoutComboBox::rowsChanged );
44
setModel( mProxyModel );
45
mProxyModel->sort( 0, Qt::AscendingOrder );
46
}
47
48
QgsLayoutManagerProxyModel::Filters
QgsLayoutComboBox::filters
()
const
49
{
50
return
mProxyModel->filters();
51
}
52
53
void
QgsLayoutComboBox::setFilters
(
QgsLayoutManagerProxyModel::Filters
filters
)
54
{
55
mProxyModel->setFilters(
filters
);
56
}
57
58
void
QgsLayoutComboBox::setAllowEmptyLayout
(
bool
allowEmpty )
59
{
60
mModel->setAllowEmptyLayout( allowEmpty );
61
}
62
63
bool
QgsLayoutComboBox::allowEmptyLayout
()
const
64
{
65
return
mModel->allowEmptyLayout();
66
}
67
68
void
QgsLayoutComboBox::setCurrentLayout
(
QgsMasterLayoutInterface
*
layout
)
69
{
70
if
( !mModel )
71
return
;
72
73
const
QModelIndex idx = mModel->indexFromLayout(
layout
);
74
if
( idx.isValid() )
75
{
76
const
QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
77
if
( proxyIdx.isValid() )
78
{
79
setCurrentIndex( proxyIdx.row() );
80
return
;
81
}
82
}
83
setCurrentIndex(
allowEmptyLayout
() ? 0 : -1 );
84
}
85
86
QgsMasterLayoutInterface
*
QgsLayoutComboBox::currentLayout
()
const
87
{
88
return
layout
( currentIndex() );
89
}
90
91
void
QgsLayoutComboBox::indexChanged(
int
i )
92
{
93
Q_UNUSED( i )
94
emit
layoutChanged
(
currentLayout
() );
95
}
96
97
void
QgsLayoutComboBox::rowsChanged()
98
{
99
if
( count() == 1 )
100
{
101
//currently selected item has changed
102
emit
layoutChanged
(
currentLayout
() );
103
}
104
else
if
( count() == 0 )
105
{
106
emit
layoutChanged
(
nullptr
);
107
}
108
}
109
110
QgsMasterLayoutInterface
*
QgsLayoutComboBox::layout
(
int
index )
const
111
{
112
const
QModelIndex proxyIndex = mProxyModel->index( index, 0 );
113
if
( !proxyIndex.isValid() )
114
{
115
return
nullptr
;
116
}
117
118
const
QModelIndex sourceIndex = mProxyModel->mapToSource( proxyIndex );
119
if
( !sourceIndex.isValid() )
120
{
121
return
nullptr
;
122
}
123
124
return
mModel->layoutFromIndex( sourceIndex );
125
}
QgsLayoutComboBox::allowEmptyLayout
bool allowEmptyLayout() const
Returns true if the combobox includes the empty layout ("not set") choice.
Definition
qgslayoutcombobox.cpp:63
QgsLayoutComboBox::setLayoutManager
void setLayoutManager(QgsLayoutManager *manager)
Sets the layout manager containing the layouts to list in the combo box.
Definition
qgslayoutcombobox.cpp:31
QgsLayoutComboBox::layoutChanged
void layoutChanged(QgsMasterLayoutInterface *layout)
Emitted whenever the currently selected layout changes.
QgsLayoutComboBox::currentLayout
QgsMasterLayoutInterface * currentLayout() const
Returns the layout currently selected in the combo box.
Definition
qgslayoutcombobox.cpp:86
QgsLayoutComboBox::QgsLayoutComboBox
QgsLayoutComboBox(QWidget *parent=nullptr, QgsLayoutManager *manager=nullptr)
QgsLayoutComboBox creates a combo box to display a list of items in a layout manager.
Definition
qgslayoutcombobox.cpp:23
QgsLayoutComboBox::setCurrentLayout
void setCurrentLayout(QgsMasterLayoutInterface *layout)
Sets the currently selected layout in the combo box.
Definition
qgslayoutcombobox.cpp:68
QgsLayoutComboBox::setAllowEmptyLayout
void setAllowEmptyLayout(bool allowEmpty)
Sets whether an optional empty layout ("not set") option is present in the combobox.
Definition
qgslayoutcombobox.cpp:58
QgsLayoutComboBox::filters
QgsLayoutManagerProxyModel::Filters filters() const
Returns the current filters used for filtering available layouts.
Definition
qgslayoutcombobox.cpp:48
QgsLayoutComboBox::setFilters
void setFilters(QgsLayoutManagerProxyModel::Filters filters)
Sets the current filters used for filtering available layouts.
Definition
qgslayoutcombobox.cpp:53
QgsLayoutComboBox::layout
QgsMasterLayoutInterface * layout(int index) const
Returns the layout at the specified index.
Definition
qgslayoutcombobox.cpp:110
QgsLayoutManagerModel
List model representing the print layouts and reports available in a layout manager.
Definition
qgslayoutmanagermodel.h:48
QgsLayoutManagerProxyModel
QSortFilterProxyModel subclass for QgsLayoutManagerModel.
Definition
qgslayoutmanagermodel.h:112
QgsLayoutManagerProxyModel::Filters
QFlags< Filter > Filters
Definition
qgslayoutmanagermodel.h:122
QgsLayoutManager
Manages storage of a set of layouts.
Definition
qgslayoutmanager.h:50
QgsMasterLayoutInterface
Interface for master layout type objects, such as print layouts and reports.
Definition
qgsmasterlayoutinterface.h:45
qgslayoutcombobox.h
qgslayoutmodel.h
Generated on
for QGIS API Documentation by
1.17.0