Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Allow adding multiple layers to legend at once
- Loading branch information
1 parent
27c3eb9
commit 057a20c
Showing
9 changed files
with
209 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*************************************************************************** | ||
qgslayoutlegendlayersdialog.cpp | ||
------------------------------- | ||
begin : October 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgslayoutlegendlayersdialog.h" | ||
|
||
#include <QStandardItem> | ||
#include "qgsmaplayer.h" | ||
#include "qgsmaplayermodel.h" | ||
#include "qgssettings.h" | ||
|
||
QgsLayoutLegendLayersDialog::QgsLayoutLegendLayersDialog( QWidget *parent ) | ||
: QDialog( parent ) | ||
{ | ||
setupUi( this ); | ||
QgsSettings settings; | ||
restoreGeometry( settings.value( QStringLiteral( "Windows/LayoutLegendLayers/geometry" ) ).toByteArray() ); | ||
|
||
mModel = new QgsMapLayerModel( listMapLayers ); | ||
listMapLayers->setModel( mModel ); | ||
QModelIndex firstLayer = mModel->index( 0, 0 ); | ||
listMapLayers->selectionModel()->select( firstLayer, QItemSelectionModel::Select ); | ||
} | ||
|
||
QgsLayoutLegendLayersDialog::~QgsLayoutLegendLayersDialog() | ||
{ | ||
QgsSettings settings; | ||
settings.setValue( QStringLiteral( "Windows/LayoutLegendLayers/geometry" ), saveGeometry() ); | ||
} | ||
|
||
QList< QgsMapLayer *> QgsLayoutLegendLayersDialog::selectedLayers() const | ||
{ | ||
QList< QgsMapLayer * > layers; | ||
|
||
const QModelIndexList selection = listMapLayers->selectionModel()->selectedIndexes(); | ||
for ( const QModelIndex &index : selection ) | ||
{ | ||
QgsMapLayer *layer = mModel->layerFromIndex( index ); | ||
if ( layer ) | ||
layers << layer; | ||
} | ||
return layers; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*************************************************************************** | ||
qgslayoutlegendlayersdialog.h | ||
----------------------------- | ||
begin : October 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSLAYOUTLEGENDLAYERSDIALOG_H | ||
#define QGSLAYOUTLEGENDLAYERSDIALOG_H | ||
|
||
#include "ui_qgslayoutlegendlayersdialogbase.h" | ||
|
||
class QgsMapLayer; | ||
class QgsMapLayerModel; | ||
|
||
/** | ||
* \ingroup app | ||
* A dialog to add new layers to the legend. | ||
* */ | ||
class QgsLayoutLegendLayersDialog: public QDialog, private Ui::QgsLayoutLegendLayersDialogBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsLayoutLegendLayersDialog( QWidget *parent = nullptr ); | ||
~QgsLayoutLegendLayersDialog(); | ||
|
||
QList< QgsMapLayer * > selectedLayers() const; | ||
|
||
private: | ||
QgsLayoutLegendLayersDialog() = delete; | ||
|
||
QgsMapLayerModel *mModel = nullptr; | ||
}; | ||
|
||
#endif //QGSLAYOUTLEGENDLAYERSDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>QgsLayoutLegendLayersDialogBase</class> | ||
<widget class="QDialog" name="QgsLayoutLegendLayersDialogBase"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>252</width> | ||
<height>194</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Add Layer to Legend</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="1" column="0"> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0"> | ||
<widget class="QListView" name="listMapLayers"> | ||
<property name="selectionMode"> | ||
<enum>QAbstractItemView::ExtendedSelection</enum> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>QgsLayoutLegendLayersDialogBase</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>QgsLayoutLegendLayersDialogBase</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters