Skip to content
Permalink
Browse files

[layouts] Sort layers by name in 'add layer' to legend dialog

Because it's hard to find specific layers when the layers are
listed in project order
  • Loading branch information
nyalldawson committed Aug 22, 2018
1 parent ea2ab53 commit 5582a57918a9bffbb48ab0b1f200cff36f7d3241
Showing with 11 additions and 4 deletions.
  1. +9 −2 src/app/layout/qgslayoutlegendlayersdialog.cpp
  2. +2 −2 src/app/layout/qgslayoutlegendlayersdialog.h
@@ -17,6 +17,7 @@
#include <QStandardItem>
#include "qgsmaplayer.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayerproxymodel.h"
#include "qgssettings.h"

QgsLayoutLegendLayersDialog::QgsLayoutLegendLayersDialog( QWidget *parent )
@@ -26,7 +27,7 @@ QgsLayoutLegendLayersDialog::QgsLayoutLegendLayersDialog( QWidget *parent )
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/LayoutLegendLayers/geometry" ) ).toByteArray() );

mModel = new QgsMapLayerModel( listMapLayers );
mModel = new QgsMapLayerProxyModel( listMapLayers );
listMapLayers->setModel( mModel );
QModelIndex firstLayer = mModel->index( 0, 0 );
listMapLayers->selectionModel()->select( firstLayer, QItemSelectionModel::Select );
@@ -47,7 +48,13 @@ QList< QgsMapLayer *> QgsLayoutLegendLayersDialog::selectedLayers() const
const QModelIndexList selection = listMapLayers->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : selection )
{
QgsMapLayer *layer = mModel->layerFromIndex( index );
const QModelIndex sourceIndex = mModel->mapToSource( index );
if ( !sourceIndex.isValid() )
{
continue;
}

QgsMapLayer *layer = mModel->sourceLayerModel()->layerFromIndex( sourceIndex );
if ( layer )
layers << layer;
}
@@ -18,7 +18,7 @@
#include "ui_qgslayoutlegendlayersdialogbase.h"

class QgsMapLayer;
class QgsMapLayerModel;
class QgsMapLayerProxyModel;

/**
* \ingroup app
@@ -37,7 +37,7 @@ class QgsLayoutLegendLayersDialog: public QDialog, private Ui::QgsLayoutLegendLa
private:
QgsLayoutLegendLayersDialog() = delete;

QgsMapLayerModel *mModel = nullptr;
QgsMapLayerProxyModel *mModel = nullptr;
};

#endif //QGSLAYOUTLEGENDLAYERSDIALOG_H

0 comments on commit 5582a57

Please sign in to comment.
You can’t perform that action at this time.