mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[FEATURE] Add option to take extent from project map layer
to QgsExtentGroupBox This allows matching another layer's extent in the save vector/ raster layer dialog, among others Fix #16357
This commit is contained in:
parent
6eb3570511
commit
4e4f232ad4
@ -34,6 +34,7 @@ class QgsExtentGroupBox : QgsCollapsibleGroupBox
|
||||
OriginalExtent,
|
||||
CurrentExtent,
|
||||
UserExtent,
|
||||
ProjectLayerExtent,
|
||||
};
|
||||
|
||||
void setOriginalExtent( const QgsRectangle &originalExtent, const QgsCoordinateReferenceSystem &originalCrs );
|
||||
@ -130,6 +131,7 @@ emitted when extent is changed
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
|
@ -16,6 +16,10 @@
|
||||
|
||||
#include "qgscoordinatetransform.h"
|
||||
#include "qgsrasterblock.h"
|
||||
#include "qgsmaplayermodel.h"
|
||||
#include "qgscsexception.h"
|
||||
#include "qgsproject.h"
|
||||
#include <QMenu>
|
||||
|
||||
QgsExtentGroupBox::QgsExtentGroupBox( QWidget *parent )
|
||||
: QgsCollapsibleGroupBox( parent )
|
||||
@ -24,6 +28,11 @@ QgsExtentGroupBox::QgsExtentGroupBox( QWidget *parent )
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
mLayerMenu = new QMenu( this );
|
||||
mButtonCalcFromLayer->setMenu( mLayerMenu );
|
||||
connect( mLayerMenu, &QMenu::aboutToShow, this, &QgsExtentGroupBox::layerMenuAboutToShow );
|
||||
mMapLayerModel = new QgsMapLayerModel( this );
|
||||
|
||||
mXMinLineEdit->setValidator( new QDoubleValidator( this ) );
|
||||
mXMaxLineEdit->setValidator( new QDoubleValidator( this ) );
|
||||
mYMinLineEdit->setValidator( new QDoubleValidator( this ) );
|
||||
@ -67,8 +76,16 @@ void QgsExtentGroupBox::setOutputExtent( const QgsRectangle &r, const QgsCoordin
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsCoordinateTransform ct( srcCrs, mOutputCrs );
|
||||
extent = ct.transformBoundingBox( r );
|
||||
try
|
||||
{
|
||||
QgsCoordinateTransform ct( srcCrs, mOutputCrs );
|
||||
extent = ct.transformBoundingBox( r );
|
||||
}
|
||||
catch ( QgsCsException & )
|
||||
{
|
||||
// can't reproject
|
||||
extent = r;
|
||||
}
|
||||
}
|
||||
|
||||
mXMinLineEdit->setText( QgsRasterBlock::printValue( extent.xMinimum() ) );
|
||||
@ -111,7 +128,8 @@ void QgsExtentGroupBox::updateTitle()
|
||||
case UserExtent:
|
||||
msg = tr( "user defined" );
|
||||
break;
|
||||
default:
|
||||
case ProjectLayerExtent:
|
||||
msg = mExtentLayerName;
|
||||
break;
|
||||
}
|
||||
if ( isCheckable() && !isChecked() )
|
||||
@ -121,6 +139,43 @@ void QgsExtentGroupBox::updateTitle()
|
||||
setTitle( msg );
|
||||
}
|
||||
|
||||
void QgsExtentGroupBox::layerMenuAboutToShow()
|
||||
{
|
||||
qDeleteAll( mMenuActions );
|
||||
mMenuActions.clear();
|
||||
mLayerMenu->clear();
|
||||
for ( int i = 0; i < mMapLayerModel->rowCount(); ++i )
|
||||
{
|
||||
QModelIndex index = mMapLayerModel->index( i, 0 );
|
||||
QAction *act = new QAction( qvariant_cast<QIcon>( mMapLayerModel->data( index, Qt::DecorationRole ) ),
|
||||
mMapLayerModel->data( index, Qt::DisplayRole ).toString() );
|
||||
act->setToolTip( mMapLayerModel->data( index, Qt::ToolTipRole ).toString() );
|
||||
QString layerId = mMapLayerModel->data( index, QgsMapLayerModel::LayerIdRole ).toString();
|
||||
if ( mExtentState == ProjectLayerExtent && mExtentLayerId == layerId )
|
||||
{
|
||||
act->setCheckable( true );
|
||||
act->setChecked( true );
|
||||
}
|
||||
connect( act, &QAction::triggered, this, [this, layerId]
|
||||
{
|
||||
setExtentToLayerExtent( layerId );
|
||||
} );
|
||||
mLayerMenu->addAction( act );
|
||||
mMenuActions << act;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsExtentGroupBox::setExtentToLayerExtent( const QString &layerId )
|
||||
{
|
||||
QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId );
|
||||
if ( !layer )
|
||||
return;
|
||||
|
||||
mExtentLayerId = layerId;
|
||||
mExtentLayerName = layer->name();
|
||||
|
||||
setOutputExtent( layer->extent(), layer->crs(), ProjectLayerExtent );
|
||||
}
|
||||
|
||||
void QgsExtentGroupBox::setOutputExtentFromCurrent()
|
||||
{
|
||||
@ -133,7 +188,6 @@ void QgsExtentGroupBox::setOutputExtentFromOriginal()
|
||||
setOutputExtent( mOriginalExtent, mOriginalCrs, OriginalExtent );
|
||||
}
|
||||
|
||||
|
||||
void QgsExtentGroupBox::setOutputExtentFromUser( const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs )
|
||||
{
|
||||
setOutputExtent( extent, crs, UserExtent );
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "qgis_gui.h"
|
||||
|
||||
class QgsCoordinateReferenceSystem;
|
||||
class QgsMapLayerModel;
|
||||
|
||||
/** \ingroup gui
|
||||
* Collapsible group box for configuration of extent, typically for a save operation.
|
||||
@ -49,6 +50,7 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::
|
||||
OriginalExtent, //!< Layer's extent
|
||||
CurrentExtent, //!< Map canvas extent
|
||||
UserExtent, //!< Extent manually entered/modified by the user
|
||||
ProjectLayerExtent, //!< Extent taken from a layer within the project
|
||||
};
|
||||
|
||||
//! Setup original extent - should be called as part of initialization
|
||||
@ -119,6 +121,21 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::
|
||||
|
||||
QgsRectangle mOriginalExtent;
|
||||
QgsCoordinateReferenceSystem mOriginalCrs;
|
||||
|
||||
private slots:
|
||||
|
||||
void layerMenuAboutToShow();
|
||||
|
||||
private:
|
||||
|
||||
QMenu *mLayerMenu = nullptr;
|
||||
QgsMapLayerModel *mMapLayerModel = nullptr;
|
||||
QList< QAction * > mMenuActions;
|
||||
QString mExtentLayerId;
|
||||
QString mExtentLayerName;
|
||||
|
||||
void setExtentToLayerExtent( const QString &layerId );
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSEXTENTGROUPBOX_H
|
||||
|
155
src/ui/qgsextentgroupboxwidget.ui
Normal file → Executable file
155
src/ui/qgsextentgroupboxwidget.ui
Normal file → Executable file
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>388</width>
|
||||
<width>380</width>
|
||||
<height>164</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -16,32 +16,6 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mXMinLabel">
|
||||
<property name="text">
|
||||
<string>West</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="mXMinLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="mXMaxLabel">
|
||||
<property name="text">
|
||||
<string>East</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="mXMaxLineEdit"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="mYMaxLabel">
|
||||
<property name="text">
|
||||
@ -72,54 +46,38 @@
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="mYMinLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="mXMinLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mXMinLabel">
|
||||
<property name="text">
|
||||
<string>West</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="mXMaxLineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="mXMaxLabel">
|
||||
<property name="text">
|
||||
<string>East</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<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>
|
||||
<widget class="QPushButton" name="mOriginalExtentButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Layer extent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="4">
|
||||
<widget class="QPushButton" name="mCurrentExtentButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
@ -132,7 +90,33 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<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="0" column="3">
|
||||
<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="0" column="5">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -145,6 +129,32 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<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="1" column="2">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -155,7 +165,6 @@
|
||||
<tabstop>mXMinLineEdit</tabstop>
|
||||
<tabstop>mXMaxLineEdit</tabstop>
|
||||
<tabstop>mYMinLineEdit</tabstop>
|
||||
<tabstop>mOriginalExtentButton</tabstop>
|
||||
<tabstop>mCurrentExtentButton</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user