QGIS API Documentation 4.3.0-Master (621ced71bd7)
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 "qgsproject.h"
23#include "qgssettings.h"
24
25#include <QStandardItem>
26#include <QString>
27
28#include "moc_qgslayoutlegendlayersdialog.cpp"
29
30using namespace Qt::StringLiterals;
31
33 : QDialog( parent )
34{
35 setupUi( 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
55void QgsLayoutLegendLayersDialog::setVisibleLayers( const QList<QgsMapLayer *> &layers )
56{
57 mVisibleLayers = layers;
58}
59
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
80void QgsLayoutLegendLayersDialog::filterVisible( bool enabled )
81{
82 if ( enabled )
83 mModel->setLayerAllowlist( mVisibleLayers );
84 else
85 mModel->setLayerAllowlist( QList<QgsMapLayer *>() );
86}
87
88void QgsLayoutLegendLayersDialog::showHelp()
89{
90 QgsHelp::openHelp( u"print_composer/composer_items/composer_legend.html#legend-items"_s );
91}
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:224
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
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, QgsProject *project)
Constructor, taking layers from project.
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:83
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114