Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
|
@@ -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 |