Skip to content
Permalink
Browse files
[feature][ui][processing] Add a calculate from bookmark function to t…
…he extent parameter widget
  • Loading branch information
nirvn committed Jan 6, 2022
1 parent 1527025 commit d8ad923a84ac89856afe1d0df0ef951b38b6e99e
Showing with 69 additions and 0 deletions.
  1. +45 −0 src/gui/qgsextentwidget.cpp
  2. +7 −0 src/gui/qgsextentwidget.h
  3. +17 −0 src/ui/qgsextentgroupboxwidget.ui
@@ -26,6 +26,8 @@
#include "qgslayoutmanager.h"
#include "qgslayoutitemmap.h"
#include "qgsprintlayout.h"
#include "qgsbookmarkmodel.h"
#include "qgsreferencedgeometry.h"

#include <QMenu>
#include <QAction>
@@ -55,6 +57,10 @@ QgsExtentWidget::QgsExtentWidget( QWidget *parent, WidgetStyle style )
mButtonCalcFromLayout->setMenu( mLayoutMenu );
connect( mLayoutMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::layoutMenuAboutToShow );

mBookmarkMenu = new QMenu( tr( "Calculate from Bookmark" ), this );
mButtonCalcFromBookmark->setMenu( mBookmarkMenu );
connect( mBookmarkMenu, &QMenu::aboutToShow, this, &QgsExtentWidget::bookmarkMenuAboutToShow );

mMenu = new QMenu( this );
mUseCanvasExtentAction = new QAction( tr( "Use Current Map Canvas Extent" ), this );
mUseCanvasExtentAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
@@ -71,6 +77,7 @@ QgsExtentWidget::QgsExtentWidget( QWidget *parent, WidgetStyle style )

mMenu->addMenu( mLayerMenu );
mMenu->addMenu( mLayoutMenu );
mMenu->addMenu( mBookmarkMenu );
mMenu->addSeparator();
mMenu->addAction( mUseCanvasExtentAction );
mMenu->addAction( mDrawOnCanvasAction );
@@ -385,6 +392,44 @@ void QgsExtentWidget::layoutMenuAboutToShow()
}
}

void QgsExtentWidget::bookmarkMenuAboutToShow()
{
mBookmarkMenu->clear();

if ( !mBookmarkModel )
mBookmarkModel = new QgsBookmarkManagerProxyModel( QgsApplication::bookmarkManager(), QgsProject::instance()->bookmarkManager(), this );

QMap< QString, QMenu * > groupMenus;
for ( int i = 0; i < mBookmarkModel->rowCount(); ++i )
{
const QString group = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleGroup ).toString();
QMenu *destMenu = mBookmarkMenu;
if ( !group.isEmpty() )
{
destMenu = groupMenus.value( group );
if ( !destMenu )
{
destMenu = new QMenu( group, mBookmarkMenu );
groupMenus[ group ] = destMenu;
}
}
QAction *action = new QAction( mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleName ).toString(), mBookmarkMenu );
const QgsReferencedRectangle extent = mBookmarkModel->data( mBookmarkModel->index( i, 0 ), QgsBookmarkManagerModel::RoleExtent ).value< QgsReferencedRectangle >();
connect( action, &QAction::triggered, this, [ = ] { setOutputExtentFromUser( extent, extent.crs() ); } );
destMenu->addAction( action );
}

QStringList groupKeys = groupMenus.keys();
groupKeys.sort( Qt::CaseInsensitive );
for ( int i = 0; i < groupKeys.count(); ++i )
{
if ( mBookmarkMenu->actions().value( i ) )
mBookmarkMenu->insertMenu( mBookmarkMenu->actions().at( i ), groupMenus.value( groupKeys.at( i ) ) );
else
mBookmarkMenu->addMenu( groupMenus.value( groupKeys.at( i ) ) );
}
}

void QgsExtentWidget::setExtentToLayerExtent( const QString &layerId )
{
QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
@@ -30,6 +30,7 @@
#include <memory>
#include <QRegularExpression>

class QgsBookmarkManagerProxyModel;
class QgsCoordinateReferenceSystem;
class QgsMapLayerModel;
class QgsMapLayer;
@@ -245,6 +246,7 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox

void layerMenuAboutToShow();
void layoutMenuAboutToShow();
void bookmarkMenuAboutToShow();

void extentDrawn( const QgsRectangle &extent );
void mapToolDeactivated();
@@ -265,9 +267,14 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
QgsCoordinateReferenceSystem mOriginalCrs;

QMenu *mMenu = nullptr;

QMenu *mLayerMenu = nullptr;
QMenu *mLayoutMenu = nullptr;
QMenu *mBookmarkMenu = nullptr;

QgsMapLayerModel *mMapLayerModel = nullptr;
QgsBookmarkManagerProxyModel *mBookmarkModel = nullptr;

QList< QAction * > mLayerMenuActions;
QAction *mUseCanvasExtentAction = nullptr;
QAction *mUseCurrentExtentAction = nullptr;
@@ -178,6 +178,23 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonCalcFromBookmark">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Bookmark</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1" colspan="7">
<layout class="QHBoxLayout" name="horizontalLayout2">
<item>
<widget class="QPushButton" name="mOriginalExtentButton">
<property name="sizePolicy">

0 comments on commit d8ad923

Please sign in to comment.