QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
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 ***************************************************************************/
16
17#include "qgsgui.h"
18#include "qgshelp.h"
19#include "qgsmaplayer.h"
20#include "qgsmaplayermodel.h"
22#include "qgssettings.h"
23
24#include <QStandardItem>
25
26#include "moc_qgslayoutlegendlayersdialog.cpp"
27
29 : QDialog( parent )
30{
31 setupUi( this );
33
34 mFilterLineEdit->setShowClearButton( true );
35 mFilterLineEdit->setShowSearchIcon( true );
36
37 mModel = new QgsMapLayerProxyModel( listMapLayers );
38 listMapLayers->setModel( mModel );
39 const QModelIndex firstLayer = mModel->index( 0, 0 );
40 listMapLayers->selectionModel()->select( firstLayer, QItemSelectionModel::Select );
41
42 connect( listMapLayers, &QListView::doubleClicked, this, &QgsLayoutLegendLayersDialog::accept );
43
44 connect( mFilterLineEdit, &QLineEdit::textChanged, mModel, &QgsMapLayerProxyModel::setFilterString );
45 connect( mCheckBoxVisibleLayers, &QCheckBox::toggled, this, &QgsLayoutLegendLayersDialog::filterVisible );
46 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutLegendLayersDialog::showHelp );
47
48 mFilterLineEdit->setFocus();
49}
50
51void QgsLayoutLegendLayersDialog::setVisibleLayers( const QList<QgsMapLayer *> &layers )
52{
53 mVisibleLayers = layers;
54}
55
57{
58 QList<QgsMapLayer *> layers;
59
60 const QModelIndexList selection = listMapLayers->selectionModel()->selectedIndexes();
61 for ( const QModelIndex &index : selection )
62 {
63 const QModelIndex sourceIndex = mModel->mapToSource( index );
64 if ( !sourceIndex.isValid() )
65 {
66 continue;
67 }
68
69 QgsMapLayer *layer = mModel->sourceLayerModel()->layerFromIndex( sourceIndex );
70 if ( layer )
71 layers << layer;
72 }
73 return layers;
74}
75
76void QgsLayoutLegendLayersDialog::filterVisible( bool enabled )
77{
78 if ( enabled )
79 mModel->setLayerAllowlist( mVisibleLayers );
80 else
81 mModel->setLayerAllowlist( QList<QgsMapLayer *>() );
82}
83
84void QgsLayoutLegendLayersDialog::showHelp()
85{
86 QgsHelp::openHelp( QStringLiteral( "print_composer/composer_items/composer_legend.html#legend-items" ) );
87}
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:221
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
void setVisibleLayers(const QList< QgsMapLayer * > &layers)
Sets a list of visible layers, to use for filtering within the dialog.
QList< QgsMapLayer * > selectedLayers() const
Returns the list of selected layers.
QgsLayoutLegendLayersDialog(QWidget *parent=nullptr)
constructor
A proxy model which provides an easy to use model to display the list of layers in widgets.
void setFilterString(const QString &filter)
Sets a filter string, such that only layers with names matching the specified string will be shown.
void setLayerAllowlist(const QList< QgsMapLayer * > &layers)
Sets an allowlist of layers to include within the model.
Base class for all map layer types.
Definition qgsmaplayer.h:80