Skip to content
Permalink
Browse files

[FEATURE] Access to visibility groups in map composer

  • Loading branch information
wonder-sk committed Sep 4, 2014
1 parent e3c2711 commit 1f8659cbb1ac00dbc8901915ac759697d6830001
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include "qgscomposermapgrid.h"
#include "qgscomposermapoverview.h"
@@ -36,6 +37,7 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsgenericprojectionselector.h"
#include "qgsproject.h"
#include "qgsvisibilitygroups.h"
#include <QColorDialog>
#include <QFontDialog>
#include <QMessageBox>
@@ -110,6 +112,14 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
//set initial state of frame style controls
toggleFrameControls( false, false, false );

QMenu* m = new QMenu( this );
m->addAction( "No groups" )->setEnabled( false );
mLayerListFromGroupButton->setMenu( m );
mLayerListFromGroupButton->setIcon( QgsApplication::getThemeIcon( "/mActionShowAllLayers.png" ) );
mLayerListFromGroupButton->setToolTip( tr( "Set layer list from a visibility group" ) );

connect( m, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowVisibilityGroupsMenu() ) );

if ( composerMap )
{
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
@@ -249,6 +259,38 @@ void QgsComposerMapWidget::compositionAtlasToggled( bool atlasEnabled )
}
}

void QgsComposerMapWidget::aboutToShowVisibilityGroupsMenu()
{
QMenu* menu = qobject_cast<QMenu*>( sender() );
if ( !menu )
return;

menu->clear();
foreach ( QString groupName, QgsVisibilityGroups::instance()->groups() )
{
menu->addAction( groupName, this, SLOT( visibilityGroupSelected() ) );
}

if ( menu->actions().isEmpty() )
menu->addAction( tr( "No groups defined" ) )->setEnabled( false );
}

void QgsComposerMapWidget::visibilityGroupSelected()
{
QAction* action = qobject_cast<QAction*>( sender() );
if ( !action )
return;

QStringList lst = QgsVisibilityGroups::instance()->groupVisibleLayers( action->text() );
if ( mComposerMap )
{
mKeepLayerListCheckBox->setChecked( true );
mComposerMap->setLayerSet( lst );
mComposerMap->cache();
mComposerMap->update();
}
}

void QgsComposerMapWidget::on_mAtlasCheckBox_toggled( bool checked )
{
if ( !mComposerMap )
@@ -155,6 +155,10 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
/**Enables or disables the atlas controls when composer atlas is toggled on/off*/
void compositionAtlasToggled( bool atlasEnabled );

void aboutToShowVisibilityGroupsMenu();

void visibilityGroupSelected();

private:
QgsComposerMap* mComposerMap;

@@ -435,6 +435,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! returns pointer to map legend
QgsLayerTreeView* layerTreeView();

QgsLayerTreeMapCanvasBridge* layerTreeCanvasBridge() { return mLayerTreeCanvasBridge; }

//! returns pointer to plugin manager
QgsPluginManager *pluginManager();

@@ -16,6 +16,7 @@
#include "qgsvisibilitygroups.h"

#include "qgslayertree.h"
#include "qgslayertreemapcanvasbridge.h"
#include "qgsproject.h"
#include "qgisapp.h"

@@ -123,6 +124,23 @@ QStringList QgsVisibilityGroups::groups() const
return mGroups.keys();
}

QStringList QgsVisibilityGroups::groupVisibleLayers( const QString& name ) const
{
QSet<QString> visibleIds = mGroups.value( name ).mVisibleLayerIDs;

// also make sure to order the layers according to map canvas order
QgsLayerTreeMapCanvasBridge* bridge = QgisApp::instance()->layerTreeCanvasBridge();
QStringList order = bridge->hasCustomLayerOrder() ? bridge->customLayerOrder() : bridge->defaultLayerOrder();
QStringList order2;
foreach ( QString layerID, order )
{
if ( visibleIds.contains( layerID ) )
order2 << layerID;
}

return order2;
}

QMenu* QgsVisibilityGroups::menu()
{
return mMenu;
@@ -171,7 +189,7 @@ void QgsVisibilityGroups::applyState( const QString& groupName )
return;

const GroupRecord& rec = mGroups[groupName];
applyStateToLayerTreeGroup( QgsProject::instance()->layerTreeRoot(), QSet<QString>::fromList( rec.mVisibleLayerIDs ) );
applyStateToLayerTreeGroup( QgsProject::instance()->layerTreeRoot(), rec.mVisibleLayerIDs );

mMenuDirty = true;
}
@@ -18,7 +18,7 @@

#include <QMap>
#include <QObject>
#include <QStringList>
#include <QSet>

class QAction;
class QDomDocument;
@@ -27,21 +27,34 @@ class QMenu;
class QgsLayerTreeNode;
class QgsLayerTreeGroup;

/**
* Controller class that allows creation of visibility groups consisting of currently visible
* map layers in map canvas.
*/
class QgsVisibilityGroups : public QObject
{
Q_OBJECT
public:

static QgsVisibilityGroups* instance();

//! Add a new group using the current state of project's layer tree
void addGroup( const QString& name );
//! Update existing group using the current state of project's layer tree
void updateGroup( const QString& name );
//! Remove existing group
void removeGroup( const QString& name );

//! Remove all groups
void clear();

//! Return list of existing group names
QStringList groups() const;

//! Return list of layer IDs that should be visible for particular group
QStringList groupVisibleLayers( const QString& name ) const;

//! Convenience menu that lists available groups and actions for management
QMenu* menu();

signals:
@@ -70,7 +83,7 @@ class QgsVisibilityGroups : public QObject
}

//! List of layers that are visible
QStringList mVisibleLayerIDs;
QSet<QString> mVisibleLayerIDs;
//! For layers that have checkable legend symbols and not all symbols are checked - list which ones are
//QMap<QString, QStringList> mPerLayerCheckedLegendSymbols;
} GroupRecord;
@@ -54,9 +54,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-628</y>
<width>444</width>
<height>2231</height>
<y>0</y>
<width>447</width>
<height>2274</height>
</rect>
</property>
<property name="sizePolicy">
@@ -77,7 +77,7 @@
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
@@ -163,17 +163,44 @@
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mKeepLayerListCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Lock layers for map item</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QCheckBox" name="mKeepLayerListCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Lock layers for map item</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="mLayerListFromGroupButton">
<property name="text">
<string>...</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@@ -1268,6 +1295,85 @@
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>mPreviewModeComboBox</tabstop>
<tabstop>mUpdatePreviewButton</tabstop>
<tabstop>mScaleLineEdit</tabstop>
<tabstop>mScaleDDBtn</tabstop>
<tabstop>mMapRotationSpinBox</tabstop>
<tabstop>mMapRotationDDBtn</tabstop>
<tabstop>mDrawCanvasItemsCheckBox</tabstop>
<tabstop>mKeepLayerListCheckBox</tabstop>
<tabstop>mLayerListFromGroupButton</tabstop>
<tabstop>mXMinLineEdit</tabstop>
<tabstop>mXMinDDBtn</tabstop>
<tabstop>mYMinLineEdit</tabstop>
<tabstop>mYMinDDBtn</tabstop>
<tabstop>mXMaxLineEdit</tabstop>
<tabstop>mXMaxDDBtn</tabstop>
<tabstop>mYMaxLineEdit</tabstop>
<tabstop>mYMaxDDBtn</tabstop>
<tabstop>mSetToMapCanvasExtentButton</tabstop>
<tabstop>mViewExtentInCanvasButton</tabstop>
<tabstop>mAtlasCheckBox</tabstop>
<tabstop>mAtlasMarginSpinBox</tabstop>
<tabstop>mAtlasPredefinedScaleRadio</tabstop>
<tabstop>mAtlasFixedScaleRadio</tabstop>
<tabstop>mAtlasMarginRadio</tabstop>
<tabstop>mAddGridPushButton</tabstop>
<tabstop>mRemoveGridPushButton</tabstop>
<tabstop>mGridUpButton</tabstop>
<tabstop>mGridDownButton</tabstop>
<tabstop>mGridListWidget</tabstop>
<tabstop>mGridCheckBox</tabstop>
<tabstop>mGridTypeComboBox</tabstop>
<tabstop>mMapGridCRSButton</tabstop>
<tabstop>mMapGridUnitComboBox</tabstop>
<tabstop>mIntervalXSpinBox</tabstop>
<tabstop>mIntervalYSpinBox</tabstop>
<tabstop>mOffsetXSpinBox</tabstop>
<tabstop>mOffsetYSpinBox</tabstop>
<tabstop>mCrossWidthSpinBox</tabstop>
<tabstop>mGridLineStyleButton</tabstop>
<tabstop>mGridBlendComboBox</tabstop>
<tabstop>mGridFramePenSizeSpinBox</tabstop>
<tabstop>mGridFramePenColorButton</tabstop>
<tabstop>mGridFrameFill1ColorButton</tabstop>
<tabstop>mGridFrameFill2ColorButton</tabstop>
<tabstop>mCheckGridLeftSide</tabstop>
<tabstop>mCheckGridRightSide</tabstop>
<tabstop>mCheckGridTopSide</tabstop>
<tabstop>mCheckGridBottomSide</tabstop>
<tabstop>mFrameStyleComboBox</tabstop>
<tabstop>mFrameWidthSpinBox</tabstop>
<tabstop>mDrawAnnotationGroupBox</tabstop>
<tabstop>mAnnotationFormatComboBox</tabstop>
<tabstop>mAnnotationPositionLeftComboBox</tabstop>
<tabstop>mAnnotationDirectionComboBoxLeft</tabstop>
<tabstop>mAnnotationPositionRightComboBox</tabstop>
<tabstop>mAnnotationDirectionComboBoxRight</tabstop>
<tabstop>mAnnotationPositionTopComboBox</tabstop>
<tabstop>mAnnotationDirectionComboBoxTop</tabstop>
<tabstop>mAnnotationPositionBottomComboBox</tabstop>
<tabstop>mAnnotationDirectionComboBoxBottom</tabstop>
<tabstop>mAnnotationFontButton</tabstop>
<tabstop>mAnnotationFontColorButton</tabstop>
<tabstop>mDistanceToMapFrameSpinBox</tabstop>
<tabstop>mCoordinatePrecisionSpinBox</tabstop>
<tabstop>mGridMarkerStyleButton</tabstop>
<tabstop>mAddOverviewPushButton</tabstop>
<tabstop>mRemoveOverviewPushButton</tabstop>
<tabstop>mOverviewUpButton</tabstop>
<tabstop>mOverviewDownButton</tabstop>
<tabstop>mOverviewListWidget</tabstop>
<tabstop>mOverviewCheckBox</tabstop>
<tabstop>mOverviewFrameMapComboBox</tabstop>
<tabstop>mOverviewFrameStyleButton</tabstop>
<tabstop>mOverviewBlendModeComboBox</tabstop>
<tabstop>mOverviewInvertCheckbox</tabstop>
<tabstop>mOverviewCenterCheckbox</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
</resources>

0 comments on commit 1f8659c

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