Skip to content

Commit

Permalink
[layouts] Sort layers by name in 'add layer' to legend dialog
Browse files Browse the repository at this point in the history
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 5582a57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/app/layout/qgslayoutlegendlayersdialog.cpp
Expand Up @@ -17,6 +17,7 @@
#include <QStandardItem>
#include "qgsmaplayer.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayerproxymodel.h"
#include "qgssettings.h"

QgsLayoutLegendLayersDialog::QgsLayoutLegendLayersDialog( QWidget *parent )
Expand All @@ -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 );
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/layout/qgslayoutlegendlayersdialog.h
Expand Up @@ -18,7 +18,7 @@
#include "ui_qgslayoutlegendlayersdialogbase.h"

class QgsMapLayer;
class QgsMapLayerModel;
class QgsMapLayerProxyModel;

/**
* \ingroup app
Expand All @@ -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.