Skip to content
Permalink
Browse files
Merge remote-tracking branch 'denis/scalevisiblayers_newlegend' into …
…legend-refactoring
  • Loading branch information
wonder-sk committed May 21, 2014
2 parents 3180dee + 8485b9c commit 0d761bfc9bc2018f53449c71525c1d6e6140acb1
@@ -76,6 +76,7 @@
%Include qgsrubberband.sip
%Include qgsscalecombobox.sip
%Include qgsscalerangewidget.sip
%Include qgsscalevisibilitydialog.sip
%Include qgssearchquerybuilder.sip
%Include qgstextannotationitem.sip
%Include qgsvertexmarker.sip
@@ -0,0 +1,30 @@
class QgsScaleVisibilityDialog : QObject
{
%TypeHeaderCode
#include <qgsscalevisibilitydialog.h>
%End

public:
explicit QgsScaleVisibilityDialog( QWidget *parent = 0, QString title = QString(), QgsMapCanvas* mapCanvas = 0 );

//! return if scale visibilty is enabled
bool hasScaleVisibility();

//! return minimum scale (true scale, not scale denominator)
double minimumScale();

//! return maximum scale (true scale, not scale denominator)
double maximumScale();


public slots:
//! set if scale visibility is enabled
void setScaleVisiblity( bool hasScaleVisibility );

//! set minimum scale (true scale, not scale denominator)
void setMinimumScale( double minScale );

//! set maximum scale (true scale, not scale denominator)
void setMaximumScale( double maxScale );

};
@@ -183,6 +183,7 @@
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrectangle.h"
#include "qgsscalecombobox.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsshortcutsmanager.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgssnappingdialog.h"
@@ -1137,6 +1138,7 @@ void QgisApp::createActions()
connect( mActionSaveLayerDefinition, SIGNAL( triggered() ), this, SLOT( saveAsLayerDefinition() ) );
connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
connect( mActionDuplicateLayer, SIGNAL( triggered() ), this, SLOT( duplicateLayers() ) );
connect( mActionSetLayerScaleVisibility, SIGNAL( triggered() ), this, SLOT( setLayerScaleVisibility() ) );
connect( mActionSetLayerCRS, SIGNAL( triggered() ), this, SLOT( setLayerCRS() ) );
connect( mActionSetProjectCRSFromLayer, SIGNAL( triggered() ), this, SLOT( setProjectCRSFromLayer() ) );
connect( mActionLayerProperties, SIGNAL( triggered() ), this, SLOT( layerProperties() ) );
@@ -6725,6 +6727,39 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
}
}

void QgisApp::setLayerScaleVisibility()
{
if ( !mLayerTreeView )
return;

QList<QgsMapLayer*> layers = mLayerTreeView->selectedLayers();

if ( layers.length() < 1 )
return;

QgsScaleVisibilityDialog* dlg = new QgsScaleVisibilityDialog( this, tr( "Set scale visibility for selected layers" ), mMapCanvas );
QgsMapLayer* layer = mLayerTreeView->currentLayer();
if ( layer )
{
dlg->setScaleVisiblity( layer->hasScaleBasedVisibility() );
dlg->setMinimumScale( 1.0 / layer->maximumScale() );
dlg->setMaximumScale( 1.0 / layer->minimumScale() );
}
if ( dlg->exec() )
{
mMapCanvas->freeze();
foreach ( QgsMapLayer* layer, layers )
{
layer->toggleScaleBasedVisibility( dlg->hasScaleVisibility() );
layer->setMinimumScale( 1.0 / dlg->maximumScale() );
layer->setMaximumScale( 1.0 / dlg->minimumScale() );
}
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}
delete dlg;
}

void QgisApp::setLayerCRS()
{
if ( !( mLayerTreeView && mLayerTreeView->currentLayer() ) )
@@ -8511,6 +8546,7 @@ void QgisApp::legendLayerSelectionChanged( void )

mActionRemoveLayer->setEnabled( selectedLayers.count() > 0 );
mActionDuplicateLayer->setEnabled( selectedLayers.count() > 0 );
mActionSetLayerScaleVisibility->setEnabled( selectedLayers.count() > 0 );
mActionSetLayerCRS->setEnabled( selectedLayers.count() > 0 );
mActionSetProjectCRSFromLayer->setEnabled( selectedLayers.count() == 1 );

@@ -349,6 +349,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
/** @note added in 1.9 */
QAction *actionDuplicateLayer() { return mActionDuplicateLayer; }
/** @note added in 2.4 */
QAction *actionSetLayerScaleVisibility() { return mActionSetLayerScaleVisibility; }
QAction *actionSetLayerCRS() { return mActionSetLayerCRS; }
QAction *actionSetProjectCRSFromLayer() { return mActionSetProjectCRSFromLayer; }
QAction *actionLayerProperties() { return mActionLayerProperties; }
@@ -466,9 +468,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
#endif

public slots:
void layerTreeViewDoubleClicked(const QModelIndex& index);
void layerTreeViewCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
void activeLayerChanged(QgsMapLayer* layer);
void layerTreeViewDoubleClicked( const QModelIndex& index );
void layerTreeViewCurrentChanged( const QModelIndex& current, const QModelIndex& previous );
void activeLayerChanged( QgsMapLayer* layer );
//! Zoom to full extent
void zoomFull();
//! Zoom to the previous extent
@@ -710,6 +712,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
/** Duplicate map layer(s) in legend
* @note added in 1.9 */
void duplicateLayers( const QList<QgsMapLayer *> lyrList = QList<QgsMapLayer *>() );
//! Set Scale visibility of selected layers
void setLayerScaleVisibility();
//! Set CRS of a layer
void setLayerCRS();
//! Assign layer CRS to project
@@ -13,9 +13,9 @@
#include "qgsvectorlayer.h"


QgsAppLayerTreeViewMenuProvider::QgsAppLayerTreeViewMenuProvider(QgsLayerTreeView* view, QgsMapCanvas* canvas)
: mView(view)
, mCanvas(canvas)
QgsAppLayerTreeViewMenuProvider::QgsAppLayerTreeViewMenuProvider( QgsLayerTreeView* view, QgsMapCanvas* canvas )
: mView( view )
, mCanvas( canvas )
{
}

@@ -27,38 +27,38 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
QgsLayerTreeViewDefaultActions* actions = mView->defaultActions();

QModelIndex idx = mView->currentIndex();
if (!idx.isValid())
if ( !idx.isValid() )
{
// global menu
menu->addAction( actions->actionAddGroup(menu) );
menu->addAction( actions->actionAddGroup( menu ) );

// TODO: expand all, collapse all
// TODO: update drawing order
}
else if (QgsLayerTreeNode* node = mView->layerTreeModel()->index2node(idx))
else if ( QgsLayerTreeNode* node = mView->layerTreeModel()->index2node( idx ) )
{
// layer or group selected
if (QgsLayerTree::isGroup(node))
if ( QgsLayerTree::isGroup( node ) )
{
menu->addAction( actions->actionZoomToGroup(mCanvas, menu) );
menu->addAction( actions->actionRemoveGroupOrLayer(menu) );
menu->addAction( actions->actionZoomToGroup( mCanvas, menu ) );
menu->addAction( actions->actionRemoveGroupOrLayer( menu ) );

menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ),
tr( "&Set Group CRS" ), QgisApp::instance(), SLOT( legendGroupSetCRS() ) );

menu->addAction( actions->actionRenameGroupOrLayer(menu) );
menu->addAction( actions->actionRenameGroupOrLayer( menu ) );

if (mView->selectedNodes(true).count() >= 2)
menu->addAction( actions->actionGroupSelected(menu) );
if ( mView->selectedNodes( true ).count() >= 2 )
menu->addAction( actions->actionGroupSelected( menu ) );

menu->addAction( actions->actionAddGroup(menu) );
menu->addAction( actions->actionAddGroup( menu ) );
}
else if (QgsLayerTree::isLayer(node))
else if ( QgsLayerTree::isLayer( node ) )
{
QgsMapLayer* layer = QgsLayerTree::toLayer(node)->layer();
QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();

menu->addAction( actions->actionZoomToLayer(mCanvas, menu) );
menu->addAction( actions->actionShowInOverview(menu) );
menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
menu->addAction( actions->actionShowInOverview( menu ) );

if ( layer && layer->type() == QgsMapLayer::RasterLayer )
{
@@ -69,11 +69,14 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( tr( "&Stretch Using Current Extent" ), QgisApp::instance(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
}

menu->addAction( actions->actionRemoveGroupOrLayer(menu) );
menu->addAction( actions->actionRemoveGroupOrLayer( menu ) );

// duplicate layer
QAction* duplicateLayersAction = menu->addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) );

// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );

// set layer crs
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );

@@ -123,7 +126,7 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
if ( !vlayer->isEditable() && vlayer->dataProvider()->supportsSubsetString() && vlayer->vectorJoins().isEmpty() )
menu->addAction( tr( "&Filter..." ), QgisApp::instance(), SLOT( layerSubsetString() ) );

menu->addAction( actions->actionShowFeatureCount(menu) );
menu->addAction( actions->actionShowFeatureCount( menu ) );

menu->addSeparator();
}
@@ -140,16 +143,16 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()

// TODO: custom actions

if (layer && QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() )
if ( layer && QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() )
menu->addAction( tr( "&Properties" ), QgisApp::instance(), SLOT( layerProperties() ) );

if (node->parent() != mView->layerTreeModel()->rootGroup())
menu->addAction( actions->actionMakeTopLevel(menu) );
if ( node->parent() != mView->layerTreeModel()->rootGroup() )
menu->addAction( actions->actionMakeTopLevel( menu ) );

menu->addAction( actions->actionRenameGroupOrLayer(menu) );
menu->addAction( actions->actionRenameGroupOrLayer( menu ) );

if (mView->selectedNodes(true).count() >= 2)
menu->addAction( actions->actionGroupSelected(menu) );
if ( mView->selectedNodes( true ).count() >= 2 )
menu->addAction( actions->actionGroupSelected( menu ) );

if ( mView->selectedLayerNodes().count() == 1 )
{
@@ -146,6 +146,7 @@ qgsrelationmanagerdialog.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgsscalerangewidget.cpp
qgsscalevisibilitydialog.cpp
qgssearchquerybuilder.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
@@ -292,6 +293,7 @@ qgsrelationeditor.h
qgsrelationmanagerdialog.h
qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgssublayersdialog.h
qgsunitselectionwidget.h
@@ -359,6 +361,7 @@ qgsrelationeditor.h
qgsrubberband.h
qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgssublayersdialog.h
qgsvectorlayertools.h
@@ -0,0 +1,86 @@
/***************************************************************************
qgsscalevisibilitydialog.cpp
--------------------------------------
Date : 20.05.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@gmail.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 <QGridLayout>
#include <QDialogButtonBox>


#include "qgsscalevisibilitydialog.h"



QgsScaleVisibilityDialog::QgsScaleVisibilityDialog( QWidget *parent, QString title, QgsMapCanvas* mapCanvas ) :
QDialog( parent )
{
if ( !title.isEmpty() )
{
setWindowTitle( title );
}

QGridLayout* dlgLayout = new QGridLayout( this );
//dlgLayout->setContentsMargins( 0, 0, 0, 0 );

mGroupBox = new QGroupBox( this );
mGroupBox->setCheckable( true );
mGroupBox->setTitle( tr( "Scale visibility " ) );

QGridLayout* gbLayout = new QGridLayout( this );
//gbLayout->setContentsMargins( 0, 0, 0, 0 );

mScaleWidget = new QgsScaleRangeWidget( this );
if ( mapCanvas )
{
mScaleWidget->setMapCanvas( mapCanvas );
}
gbLayout->addWidget( mScaleWidget, 0, 0 );
mGroupBox->setLayout( gbLayout );

QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal, this );
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );

dlgLayout->addWidget( mGroupBox, 0, 0 );
dlgLayout->addWidget( buttonBox, 1, 0 );
}

void QgsScaleVisibilityDialog::setScaleVisiblity( bool hasScaleVisibility )
{
mGroupBox->setChecked( hasScaleVisibility );
}

bool QgsScaleVisibilityDialog::hasScaleVisibility()
{
return mGroupBox->isChecked();
}

void QgsScaleVisibilityDialog::setMinimumScale( double minScale )
{
mScaleWidget->setMinimumScale( minScale );
}

double QgsScaleVisibilityDialog::minimumScale()
{
return mScaleWidget->minimumScale();
}

void QgsScaleVisibilityDialog::setMaximumScale( double maxScale )
{
mScaleWidget->setMaximumScale( maxScale );
}

double QgsScaleVisibilityDialog::maximumScale()
{
return mScaleWidget->maximumScale();
}

0 comments on commit 0d761bf

Please sign in to comment.