Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'denis/scalevisiblayers_newlegend' into …
…legend-refactoring
  • Loading branch information
wonder-sk committed May 21, 2014
2 parents 3180dee + 8485b9c commit 0d761bf
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 29 deletions.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions python/gui/qgsscalevisibilitydialog.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 );

};
36 changes: 36 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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() ) )
Expand Down Expand Up @@ -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 );

Expand Down
10 changes: 7 additions & 3 deletions src/app/qgisapp.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
53 changes: 28 additions & 25 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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 )
{
}

Expand All @@ -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 )
{
Expand All @@ -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() ) );

Expand Down Expand Up @@ -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();
}
Expand All @@ -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 )
{
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -146,6 +146,7 @@ qgsrelationmanagerdialog.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgsscalerangewidget.cpp
qgsscalevisibilitydialog.cpp
qgssearchquerybuilder.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
Expand Down Expand Up @@ -292,6 +293,7 @@ qgsrelationeditor.h
qgsrelationmanagerdialog.h
qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgssublayersdialog.h
qgsunitselectionwidget.h
Expand Down Expand Up @@ -359,6 +361,7 @@ qgsrelationeditor.h
qgsrubberband.h
qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgssublayersdialog.h
qgsvectorlayertools.h
Expand Down
86 changes: 86 additions & 0 deletions src/gui/qgsscalevisibilitydialog.cpp
@@ -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.