Skip to content
Permalink
Browse files
[feature][ui][processing] Add a calculate from layout map function to…
… the extent parameter widget
  • Loading branch information
nirvn committed Jan 6, 2022
1 parent 0e150e8 commit 9c75ae7e5f4d2fff33b1c451afec56cebfe8ac00
Showing with 132 additions and 72 deletions.
  1. +52 −8 src/gui/qgsextentwidget.cpp
  2. +2 −0 src/gui/qgsextentwidget.h
  3. +78 −64 src/ui/qgsextentgroupboxwidget.ui
@@ -23,6 +23,9 @@
#include "qgsexception.h"
#include "qgsproject.h"
#include "qgsdoublevalidator.h"
#include "qgslayoutmanager.h"
#include "qgslayoutitemmap.h"
#include "qgsprintlayout.h"

#include <QMenu>
#include <QAction>
@@ -48,17 +51,30 @@ QgsExtentWidget::QgsExtentWidget( QWidget *parent, WidgetStyle style )
connect( mLayerMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layerMenuAboutToShow );
mMapLayerModel = new QgsMapLayerModel( this );

mLayoutMenu = new QMenu( tr( "Calculate from Layout Map" ), this );
mButtonCalcFromLayout->setMenu( mLayoutMenu );
connect( mLayoutMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layoutMenuAboutToShow );

mMenu = new QMenu( this );
mUseCanvasExtentAction = new QAction( tr( "Use Map Canvas Extent" ), this );
mUseCanvasExtentAction = new QAction( tr( "Use Current Map Canvas Extent" ), this );
mUseCanvasExtentAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
mUseCanvasExtentAction->setVisible( false );
connect( mUseCanvasExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );

mUseCurrentExtentAction = new QAction( tr( "Use Current Layer Extent" ), this );
mUseCurrentExtentAction = new QAction( tr( "Use Current Layer/Default Extent" ), this );
mUseCurrentExtentAction->setVisible( false );
connect( mUseCurrentExtentAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromCurrent );

mDrawOnCanvasAction = new QAction( tr( "Draw on Canvas" ), this );
mDrawOnCanvasAction = new QAction( tr( "Draw on Map Canvas" ), this );
mDrawOnCanvasAction->setVisible( false );
connect( mDrawOnCanvasAction, &QAction::triggered, this, &QgsExtentWidget::setOutputExtentFromDrawOnCanvas );

mMenu->addMenu( mLayerMenu );
mMenu->addMenu( mLayoutMenu );
mMenu->addSeparator();
mMenu->addAction( mUseCanvasExtentAction );
mMenu->addAction( mDrawOnCanvasAction );
mMenu->addAction( mUseCurrentExtentAction );

mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
@@ -120,7 +136,7 @@ void QgsExtentWidget::setCurrentExtent( const QgsRectangle &currentExtent, const
mCurrentCrs = currentCrs;

mCurrentExtentButton->setVisible( true );
mMenu->addAction( mUseCurrentExtentAction );
mUseCurrentExtentAction->setVisible( true );
}

void QgsExtentWidget::setOutputCrs( const QgsCoordinateReferenceSystem &outputCrs )
@@ -341,6 +357,34 @@ void QgsExtentWidget::layerMenuAboutToShow()
}
}

void QgsExtentWidget::layoutMenuAboutToShow()
{
mLayoutMenu->clear();

if ( QgsLayoutManager *manager = QgsProject::instance()->layoutManager() )
{
const QList<QgsPrintLayout *> layouts = manager->printLayouts();
for ( const QgsPrintLayout *layout : layouts )
{
QList< QgsLayoutItemMap * > maps;
layout->layoutItems( maps );
if ( maps.empty() )
continue;

QMenu *layoutMenu = new QMenu( layout->name(), mMenu );
for ( const QgsLayoutItemMap *map : std::as_const( maps ) )
{
QgsRectangle extent = map->extent();
QgsCoordinateReferenceSystem crs = map->crs();
QAction *mapExtentAction = new QAction( tr( "%1" ).arg( map->displayName() ), mLayoutMenu );
connect( mapExtentAction, &QAction::triggered, this, [this, extent, crs] { setOutputExtentFromUser( extent, crs ); } );
layoutMenu->addAction( mapExtentAction );
}
mLayoutMenu->addMenu( layoutMenu );
}
}
}

void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
{
QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
@@ -447,16 +491,16 @@ void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOptio
mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
mCurrentExtentButton->setVisible( true );

mMenu->addAction( mUseCanvasExtentAction );
mUseCanvasExtentAction->setVisible( true );
if ( drawOnCanvasOption )
mMenu->addAction( mDrawOnCanvasAction );
mDrawOnCanvasAction->setVisible( true );
}
else
{
mButtonDrawOnCanvas->setVisible( false );
mCurrentExtentButton->setVisible( false );
mMenu->removeAction( mUseCanvasExtentAction );
mMenu->removeAction( mDrawOnCanvasAction );
mUseCanvasExtentAction->setVisible( false );
mUseCanvasExtentAction->setVisible( false );
}
}

@@ -244,6 +244,7 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
private slots:

void layerMenuAboutToShow();
void layoutMenuAboutToShow();

void extentDrawn( const QgsRectangle &extent );
void mapToolDeactivated();
@@ -265,6 +266,7 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox

QMenu *mMenu = nullptr;
QMenu *mLayerMenu = nullptr;
QMenu *mLayoutMenu = nullptr;
QgsMapLayerModel *mMapLayerModel = nullptr;
QList< QAction * > mLayerMenuActions;
QAction *mUseCanvasExtentAction = nullptr;
@@ -114,46 +114,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="11">
<widget class="QPushButton" name="mButtonDrawOnCanvas">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Draw on Canvas</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="mOriginalExtentButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Current Layer Extent</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="mCurrentExtentButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Map Canvas Extent</string>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -166,19 +127,6 @@
</property>
</spacer>
</item>
<item row="2" column="5">
<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 row="2" column="10">
<spacer name="horizontalSpacer_2">
<property name="orientation">
@@ -192,18 +140,84 @@
</property>
</spacer>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="mButtonCalcFromLayer">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Calculate from Layer</string>
</property>
</widget>
<item row="2" column="1" colspan="7">
<layout class="QHBoxLayout" name="horizontalLayout1">
<item>
<widget class="QLabel" name="calculateLabel">
<property name="text">
<string>Calculate from</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonCalcFromLayer">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Layer</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonCalcFromLayout">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Layout Map</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mOriginalExtentButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Current Layer Extent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mCurrentExtentButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Map Canvas Extent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonDrawOnCanvas">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Draw on Canvas</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

0 comments on commit 9c75ae7

Please sign in to comment.