Skip to content

Commit

Permalink
dedicated class for projection selection widget
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 5, 2015
1 parent df2cac7 commit f68cd5e
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -202,6 +202,7 @@ qgsoptionsdialogbase.cpp
qgsowssourceselect.cpp
qgspluginmanagerinterface.cpp
qgsprojectbadlayerguihandler.cpp
qgsprojectionselectionwidget.cpp
qgsprojectionselector.cpp
qgsquerybuilder.cpp
qgsrasterformatsaveoptionswidget.cpp
Expand Down Expand Up @@ -399,6 +400,7 @@ qgsoptionsdialogbase.h
qgsowssourceselect.h
qgspluginmanagerinterface.h
qgsprojectbadlayerguihandler.h
qgsprojectionselectionwidget.h
qgsprojectionselector.h
qgsquerybuilder.h
qgsrasterformatsaveoptionswidget.h
Expand Down Expand Up @@ -482,6 +484,7 @@ qgsmessagebar.h
qgsmessageviewer.h
qgsoptionsdialogbase.h
qgsowssourceselect.h
qgsprojectionselectionwidget.h
qgsprojectionselector.h
qgsrelationeditorwidget.h
qgsrubberband.h
Expand Down
78 changes: 78 additions & 0 deletions src/gui/qgsprojectionselectionwidget.cpp
@@ -0,0 +1,78 @@
/***************************************************************************
qgsprojectionselectionwidget.cpp
--------------------------------------
Date : 05.01.2015
Copyright : (C) 2015 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QHBoxLayout>


#include "qgsprojectionselectionwidget.h"
#include "qgsapplication.h"
#include "qgsgenericprojectionselector.h"

QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) :
QWidget( parent )
{

QHBoxLayout* layout = new QHBoxLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
layout->setSpacing( 0 );
setLayout( layout );

mCrsLineEdit = new QLineEdit( tr( "invalid projection" ), this );
mCrsLineEdit->setReadOnly(true);
layout->addWidget( mCrsLineEdit );

mButton = new QToolButton( this );
mButton->setIcon( QgsApplication::getThemeIcon( "mActionSetProjection.svg" ) );
layout->addWidget( mButton );

connect( mButton, SIGNAL( clicked() ), this, SLOT( selectCrs() ) );
}

void QgsProjectionSelectionWidget::selectCrs()
{
QgsGenericProjectionSelector* mySelector = new QgsGenericProjectionSelector( this );

//find out crs id of current proj4 string
if ( mCrs.isValid() )
{
mySelector->setSelectedCrsId( mCrs.srsid() );
}

if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem crs;
crs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
setCrs( crs );
emit crsChanged( crs );
}
else
{
QApplication::restoreOverrideCursor();

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Jan 5, 2015

Collaborator

@3nids this seems a little out of place - is it working around an oddity in QgsGenericProjectionSelector?

This comment has been minimized.

Copy link
@3nids

3nids Jan 6, 2015

Author Member

This used to be in the code in QgsOptions.
I can remove this.

}
}


void QgsProjectionSelectionWidget::setCrs( QgsCoordinateReferenceSystem crs )
{
if ( crs.isValid() )
{
mCrsLineEdit->setText( crs.authid() + " - " + crs.description() );
}
else
{
mCrsLineEdit->setText( tr( "invalid projection" ) );
}
mCrs = crs;
}
45 changes: 45 additions & 0 deletions src/gui/qgsprojectionselectionwidget.h
@@ -0,0 +1,45 @@
/***************************************************************************
qgsprojectionselectionwidget.h
--------------------------------------
Date : 05.01.2015
Copyright : (C) 2015 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


#ifndef QGSPROJECTIONSELECTIONWIDGET_H
#define QGSPROJECTIONSELECTIONWIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QToolButton>

#include "qgscoordinatereferencesystem.h"

class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
{
Q_OBJECT
public:
explicit QgsProjectionSelectionWidget( QWidget *parent = 0 );

signals:
void crsChanged( QgsCoordinateReferenceSystem );

public slots:
void setCrs( QgsCoordinateReferenceSystem crs );
void selectCrs();

private:
QgsCoordinateReferenceSystem mCrs;
QLineEdit* mCrsLineEdit;
QToolButton* mButton;
};

#endif // QGSPROJECTIONSELECTIONWIDGET_H

0 comments on commit f68cd5e

Please sign in to comment.