QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
layout
qgslayoutlegendlayersdialog.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutlegendlayersdialog.cpp
3
-------------------------------
4
begin : October 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
#include "
qgslayoutlegendlayersdialog.h
"
16
17
#include "
qgsgui.h
"
18
#include "
qgshelp.h
"
19
#include "
qgsmaplayer.h
"
20
#include "
qgsmaplayermodel.h
"
21
#include "
qgsmaplayerproxymodel.h
"
22
#include "
qgsproject.h
"
23
#include "
qgssettings.h
"
24
25
#include <QStandardItem>
26
#include <QString>
27
28
#include "moc_qgslayoutlegendlayersdialog.cpp"
29
30
using namespace
Qt::StringLiterals;
31
32
QgsLayoutLegendLayersDialog::QgsLayoutLegendLayersDialog
( QWidget *parent,
QgsProject
*project )
33
: QDialog( parent )
34
{
35
setupUi(
this
);
36
QgsGui::enableAutoGeometryRestore
(
this
);
37
38
mFilterLineEdit->setShowClearButton(
true
);
39
mFilterLineEdit->setShowSearchIcon(
true
);
40
41
mModel =
new
QgsMapLayerProxyModel
( project, listMapLayers );
42
listMapLayers->setModel( mModel );
43
const
QModelIndex firstLayer = mModel->index( 0, 0 );
44
listMapLayers->selectionModel()->select( firstLayer, QItemSelectionModel::Select );
45
46
connect( listMapLayers, &QListView::doubleClicked,
this
, &QgsLayoutLegendLayersDialog::accept );
47
48
connect( mFilterLineEdit, &QLineEdit::textChanged, mModel, &
QgsMapLayerProxyModel::setFilterString
);
49
connect( mCheckBoxVisibleLayers, &QCheckBox::toggled,
this
, &QgsLayoutLegendLayersDialog::filterVisible );
50
connect( buttonBox, &QDialogButtonBox::helpRequested,
this
, &QgsLayoutLegendLayersDialog::showHelp );
51
52
mFilterLineEdit->setFocus();
53
}
54
55
void
QgsLayoutLegendLayersDialog::setVisibleLayers
(
const
QList<QgsMapLayer *> &layers )
56
{
57
mVisibleLayers = layers;
58
}
59
60
QList<QgsMapLayer *>
QgsLayoutLegendLayersDialog::selectedLayers
()
const
61
{
62
QList<QgsMapLayer *> layers;
63
64
const
QModelIndexList selection = listMapLayers->selectionModel()->selectedIndexes();
65
for
(
const
QModelIndex &index : selection )
66
{
67
const
QModelIndex sourceIndex = mModel->mapToSource( index );
68
if
( !sourceIndex.isValid() )
69
{
70
continue
;
71
}
72
73
QgsMapLayer
*layer = mModel->sourceLayerModel()->layerFromIndex( sourceIndex );
74
if
( layer )
75
layers << layer;
76
}
77
return
layers;
78
}
79
80
void
QgsLayoutLegendLayersDialog::filterVisible(
bool
enabled )
81
{
82
if
( enabled )
83
mModel->
setLayerAllowlist
( mVisibleLayers );
84
else
85
mModel->
setLayerAllowlist
( QList<QgsMapLayer *>() );
86
}
87
88
void
QgsLayoutLegendLayersDialog::showHelp()
89
{
90
QgsHelp::openHelp
( u
"print_composer/composer_items/composer_legend.html#legend-items"
_s );
91
}
QgsGui::enableAutoGeometryRestore
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition
qgsgui.cpp:225
QgsHelp::openHelp
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition
qgshelp.cpp:41
QgsLayoutLegendLayersDialog::setVisibleLayers
void setVisibleLayers(const QList< QgsMapLayer * > &layers)
Sets a list of visible layers, to use for filtering within the dialog.
Definition
qgslayoutlegendlayersdialog.cpp:55
QgsLayoutLegendLayersDialog::selectedLayers
QList< QgsMapLayer * > selectedLayers() const
Returns the list of selected layers.
Definition
qgslayoutlegendlayersdialog.cpp:60
QgsLayoutLegendLayersDialog::QgsLayoutLegendLayersDialog
QgsLayoutLegendLayersDialog(QWidget *parent, QgsProject *project)
Constructor, taking layers from project.
Definition
qgslayoutlegendlayersdialog.cpp:32
QgsMapLayerProxyModel
A proxy model which provides an easy to use model to display the list of layers in widgets.
Definition
qgsmaplayerproxymodel.h:35
QgsMapLayerProxyModel::setFilterString
void setFilterString(const QString &filter)
Sets a filter string, such that only layers with names matching the specified string will be shown.
Definition
qgsmaplayerproxymodel.cpp:171
QgsMapLayerProxyModel::setLayerAllowlist
void setLayerAllowlist(const QList< QgsMapLayer * > &layers)
Sets an allowlist of layers to include within the model.
Definition
qgsmaplayerproxymodel.cpp:97
QgsMapLayer
Base class for all map layer types.
Definition
qgsmaplayer.h:83
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition
qgsproject.h:114
qgsgui.h
qgshelp.h
qgslayoutlegendlayersdialog.h
qgsmaplayer.h
qgsmaplayermodel.h
qgsmaplayerproxymodel.h
qgsproject.h
qgssettings.h
Generated on
for QGIS API Documentation by
1.17.0