Skip to content

Commit

Permalink
Extent group box improvements: custom title base, checkable group box
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 29, 2015
1 parent b452bc0 commit 9e16952
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
9 changes: 9 additions & 0 deletions python/gui/qgsextentgroupbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class QgsExtentGroupBox : QgsCollapsibleGroupBox

QgsExtentGroupBox::ExtentState extentState() const;

//! Set base part of title of the group box (will be appended with extent state)
//! @note added in 2.12
void setTitleBase( const QString& title );
//! Set base part of title of the group box (will be appended with extent state)
//! @note added in 2.12
QString titleBase() const;

public slots:
//! set output extent to be the same as original extent (may be transformed to output CRS)
void setOutputExtentFromOriginal();
Expand All @@ -65,6 +72,8 @@ class QgsExtentGroupBox : QgsCollapsibleGroupBox
void on_mYMinLineEdit_textEdited( const QString & );
void on_mYMaxLineEdit_textEdited( const QString & );

void groupBoxClicked();

protected:
void setOutputExtent( const QgsRectangle& r, const QgsCoordinateReferenceSystem& srcCrs, QgsExtentGroupBox::ExtentState state );
void setOutputExtentFromLineEdit();
Expand Down
34 changes: 33 additions & 1 deletion src/gui/qgsextentgroupbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

QgsExtentGroupBox::QgsExtentGroupBox( QWidget* parent )
: QgsCollapsibleGroupBox( parent )
, mTitleBase( tr( "Extent" ) )
, mExtentState( OriginalExtent )
{
setupUi( this );
Expand All @@ -16,6 +17,7 @@ QgsExtentGroupBox::QgsExtentGroupBox( QWidget* parent )

connect( mCurrentExtentButton, SIGNAL( clicked() ), this, SLOT( setOutputExtentFromCurrent() ) );
connect( mOriginalExtentButton, SIGNAL( clicked() ), this, SLOT( setOutputExtentFromOriginal() ) );
connect( this, SIGNAL( clicked( bool ) ), this, SLOT( groupBoxClicked() ) );
}


Expand Down Expand Up @@ -58,6 +60,9 @@ void QgsExtentGroupBox::setOutputExtent( const QgsRectangle& r, const QgsCoordin

mExtentState = state;

if ( isCheckable() && !isChecked() )
setChecked( true );

updateTitle();

emit extentChanged( extent );
Expand Down Expand Up @@ -91,7 +96,9 @@ void QgsExtentGroupBox::updateTitle()
default:
break;
}
msg = tr( "Extent (current: %1)" ).arg( msg );
if ( isCheckable() && !isChecked() )
msg = tr( "none" );
msg = tr( "%1 (current: %2)" ).arg( mTitleBase ).arg( msg );

setTitle( msg );
}
Expand All @@ -114,9 +121,34 @@ void QgsExtentGroupBox::setOutputExtentFromUser( const QgsRectangle& extent, con
setOutputExtent( extent, crs, UserExtent );
}

void QgsExtentGroupBox::groupBoxClicked()
{
if ( !isCheckable() )
return;

updateTitle();

// output extent just went from null to something (or vice versa)
emit extentChanged( outputExtent() );
}


QgsRectangle QgsExtentGroupBox::outputExtent() const
{
if ( isCheckable() && !isChecked() )
return QgsRectangle();

return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
}

void QgsExtentGroupBox::setTitleBase(const QString& title)
{
mTitleBase = title;
updateTitle();
}

QString QgsExtentGroupBox::titleBase() const
{
return mTitleBase;
}
12 changes: 12 additions & 0 deletions src/gui/qgsextentgroupbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::

ExtentState extentState() const { return mExtentState; }

//! Set base part of title of the group box (will be appended with extent state)
//! @note added in 2.12
void setTitleBase( const QString& title );
//! Set base part of title of the group box (will be appended with extent state)
//! @note added in 2.12
QString titleBase() const;

public slots:
//! set output extent to be the same as original extent (may be transformed to output CRS)
void setOutputExtentFromOriginal();
Expand All @@ -75,11 +82,16 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::
void on_mYMinLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
void on_mYMaxLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }

void groupBoxClicked();

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

//! Base part of the title used for the extent
QString mTitleBase;

ExtentState mExtentState;

QgsCoordinateReferenceSystem mOutputCrs;
Expand Down

0 comments on commit 9e16952

Please sign in to comment.