mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
set layer scale visibility for several layers
This commit is contained in:
parent
0e7955146a
commit
8485b9ce6f
@ -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
|
||||
|
30
python/gui/qgsscalevisibilitydialog.sip
Normal file
30
python/gui/qgsscalevisibilitydialog.sip
Normal file
@ -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"
|
||||
@ -1109,6 +1110,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() ) );
|
||||
@ -6697,6 +6699,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() ) )
|
||||
@ -8483,6 +8518,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
|
||||
|
86
src/gui/qgsscalevisibilitydialog.cpp
Normal file
86
src/gui/qgsscalevisibilitydialog.cpp
Normal file
@ -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();
|
||||
}
|
58
src/gui/qgsscalevisibilitydialog.h
Normal file
58
src/gui/qgsscalevisibilitydialog.h
Normal file
@ -0,0 +1,58 @@
|
||||
/***************************************************************************
|
||||
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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSSCALEVISIBILITYDIALOG_H
|
||||
#define QGSSCALEVISIBILITYDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QGroupBox>
|
||||
|
||||
#include "qgsscalerangewidget.h"
|
||||
|
||||
class GUI_EXPORT QgsScaleVisibilityDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
private:
|
||||
QGroupBox* mGroupBox;
|
||||
QgsScaleRangeWidget* mScaleWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSSCALEVISIBILITYDIALOG_H
|
@ -17,7 +17,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1050</width>
|
||||
<height>21</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="mProjectMenu">
|
||||
@ -148,6 +148,7 @@
|
||||
<addaction name="mActionSaveLayerDefinition"/>
|
||||
<addaction name="mActionRemoveLayer"/>
|
||||
<addaction name="mActionDuplicateLayer"/>
|
||||
<addaction name="mActionSetLayerScaleVisibility"/>
|
||||
<addaction name="mActionSetLayerCRS"/>
|
||||
<addaction name="mActionSetProjectCRSFromLayer"/>
|
||||
<addaction name="mActionLayerProperties"/>
|
||||
@ -2168,6 +2169,11 @@ Acts on currently active editable layer</string>
|
||||
<string>Save As Layer Definition File...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="mActionSetLayerScaleVisibility">
|
||||
<property name="text">
|
||||
<string>Set Scale Visibility of Layer(s)</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../images/images.qrc"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user