88 changes: 88 additions & 0 deletions src/gui/qgsextentgroupbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef QGSEXTENTGROUPBOX_H
#define QGSEXTENTGROUPBOX_H

#include "qgscollapsiblegroupbox.h"

#include "ui_qgsextentgroupboxwidget.h"

#include "qgscoordinatereferencesystem.h"
#include "qgsrectangle.h"

class QgsCoordinateReferenceSystem;

/**
* Collapsible group box for configuration of extent, typically for a save operation.
*
* Besides allowing the user to enter the extent manually, it comes with options to use
* original extent or extent defined by the current view in map canvas.
*
* When using the widget, make sure to call setOriginalExtent(), setCurrentExtent() and setOutputCrs() during initialization.
*
* @note added in 2.4
*/
class QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::QgsExtentGroupBoxWidget
{
Q_OBJECT
public:
explicit QgsExtentGroupBox( QWidget* parent = 0 );

enum ExtentState
{
OriginalExtent, //!< layer's extent
CurrentExtent, //!< map canvas extent
UserExtent, //!< extent manually entered/modified by the user
};

//! Setup original extent - should be called as part of initialization
void setOriginalExtent( const QgsRectangle& originalExtent, const QgsCoordinateReferenceSystem& originalCrs );

QgsRectangle originalExtent() const { return mOriginalExtent; }
const QgsCoordinateReferenceSystem& originalCrs() const { return mOriginalCrs; }

//! Setup current extent - should be called as part of initialization (or whenever current extent changes)
void setCurrentExtent( const QgsRectangle& currentExtent, const QgsCoordinateReferenceSystem& currentCrs );

QgsRectangle currentExtent() const { return mCurrentExtent; }
const QgsCoordinateReferenceSystem& currentCrs() const { return mCurrentCrs; }

//! Set the output CRS - may need to be used for transformation from original/current extent.
//! Should be called as part of initialization and whenever the the output CRS is changed
void setOutputCrs( const QgsCoordinateReferenceSystem& outputCrs );

//! Get the resulting extent - in output CRS coordinates
QgsRectangle outputExtent() const;

public slots:
//! set output extent to be the same as original extent (may be transformed to output CRS)
void setOutputExtentFromOriginal();

//! set output extent to be the same as current extent (may be transformed to output CRS)
void setOutputExtentFromCurrent();

signals:
//! emitted when extent is changed
void extentChanged( const QgsRectangle& r );

protected slots:

void on_mXMinLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mXMaxLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mYMinLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mYMaxLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }

protected:
void setOutputExtent( const QgsRectangle& r, const QgsCoordinateReferenceSystem& srcCrs, ExtentState state );
void updateExtentStateMsg();

ExtentState mExtentState;

QgsCoordinateReferenceSystem mOutputCrs;

QgsRectangle mCurrentExtent;
QgsCoordinateReferenceSystem mCurrentCrs;

QgsRectangle mOriginalExtent;
QgsCoordinateReferenceSystem mOriginalCrs;
};

#endif // QGSEXTENTGROUPBOX_H
155 changes: 155 additions & 0 deletions src/ui/qgsextentgroupboxwidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsExtentGroupBoxWidget</class>
<widget class="QWidget" name="QgsExtentGroupBoxWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>388</width>
<height>159</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<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">
<string>North</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="mYMaxLineEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="mYMinLabel">
<property name="text">
<string>South</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="mYMinLineEdit"/>
</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>
<widget class="QPushButton" name="mCurrentExtentButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Map view extent</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
11 changes: 10 additions & 1 deletion src/ui/qgsvectorlayersaveasdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<x>0</x>
<y>0</y>
<width>562</width>
<height>458</height>
<height>483</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -183,6 +183,9 @@
</item>
</layout>
</item>
<item>
<widget class="QgsExtentGroupBox" name="mExtentGroupBox"/>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mDatasourceOptionsGroupBox">
<property name="title">
Expand Down Expand Up @@ -328,6 +331,12 @@
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsExtentGroupBox</class>
<extends>QGroupBox</extends>
<header>qgsextentgroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down