Skip to content

Commit f68cd5e

Browse files
committedJan 5, 2015
dedicated class for projection selection widget
1 parent df2cac7 commit f68cd5e

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
 

‎src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ qgsoptionsdialogbase.cpp
202202
qgsowssourceselect.cpp
203203
qgspluginmanagerinterface.cpp
204204
qgsprojectbadlayerguihandler.cpp
205+
qgsprojectionselectionwidget.cpp
205206
qgsprojectionselector.cpp
206207
qgsquerybuilder.cpp
207208
qgsrasterformatsaveoptionswidget.cpp
@@ -399,6 +400,7 @@ qgsoptionsdialogbase.h
399400
qgsowssourceselect.h
400401
qgspluginmanagerinterface.h
401402
qgsprojectbadlayerguihandler.h
403+
qgsprojectionselectionwidget.h
402404
qgsprojectionselector.h
403405
qgsquerybuilder.h
404406
qgsrasterformatsaveoptionswidget.h
@@ -482,6 +484,7 @@ qgsmessagebar.h
482484
qgsmessageviewer.h
483485
qgsoptionsdialogbase.h
484486
qgsowssourceselect.h
487+
qgsprojectionselectionwidget.h
485488
qgsprojectionselector.h
486489
qgsrelationeditorwidget.h
487490
qgsrubberband.h
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/***************************************************************************
2+
qgsprojectionselectionwidget.cpp
3+
--------------------------------------
4+
Date : 05.01.2015
5+
Copyright : (C) 2015 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include <QHBoxLayout>
17+
18+
19+
#include "qgsprojectionselectionwidget.h"
20+
#include "qgsapplication.h"
21+
#include "qgsgenericprojectionselector.h"
22+
23+
QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) :
24+
QWidget( parent )
25+
{
26+
27+
QHBoxLayout* layout = new QHBoxLayout();
28+
layout->setContentsMargins( 0, 0, 0, 0 );
29+
layout->setSpacing( 0 );
30+
setLayout( layout );
31+
32+
mCrsLineEdit = new QLineEdit( tr( "invalid projection" ), this );
33+
mCrsLineEdit->setReadOnly(true);
34+
layout->addWidget( mCrsLineEdit );
35+
36+
mButton = new QToolButton( this );
37+
mButton->setIcon( QgsApplication::getThemeIcon( "mActionSetProjection.svg" ) );
38+
layout->addWidget( mButton );
39+
40+
connect( mButton, SIGNAL( clicked() ), this, SLOT( selectCrs() ) );
41+
}
42+
43+
void QgsProjectionSelectionWidget::selectCrs()
44+
{
45+
QgsGenericProjectionSelector* mySelector = new QgsGenericProjectionSelector( this );
46+
47+
//find out crs id of current proj4 string
48+
if ( mCrs.isValid() )
49+
{
50+
mySelector->setSelectedCrsId( mCrs.srsid() );
51+
}
52+
53+
if ( mySelector->exec() )
54+
{
55+
QgsCoordinateReferenceSystem crs;
56+
crs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
57+
setCrs( crs );
58+
emit crsChanged( crs );
59+
}
60+
else
61+
{
62+
QApplication::restoreOverrideCursor();
Code has comments. Press enter to view.
63+
}
64+
}
65+
66+
67+
void QgsProjectionSelectionWidget::setCrs( QgsCoordinateReferenceSystem crs )
68+
{
69+
if ( crs.isValid() )
70+
{
71+
mCrsLineEdit->setText( crs.authid() + " - " + crs.description() );
72+
}
73+
else
74+
{
75+
mCrsLineEdit->setText( tr( "invalid projection" ) );
76+
}
77+
mCrs = crs;
78+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/***************************************************************************
2+
qgsprojectionselectionwidget.h
3+
--------------------------------------
4+
Date : 05.01.2015
5+
Copyright : (C) 2015 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
17+
#ifndef QGSPROJECTIONSELECTIONWIDGET_H
18+
#define QGSPROJECTIONSELECTIONWIDGET_H
19+
20+
#include <QWidget>
21+
#include <QLineEdit>
22+
#include <QToolButton>
23+
24+
#include "qgscoordinatereferencesystem.h"
25+
26+
class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
27+
{
28+
Q_OBJECT
29+
public:
30+
explicit QgsProjectionSelectionWidget( QWidget *parent = 0 );
31+
32+
signals:
33+
void crsChanged( QgsCoordinateReferenceSystem );
34+
35+
public slots:
36+
void setCrs( QgsCoordinateReferenceSystem crs );
37+
void selectCrs();
38+
39+
private:
40+
QgsCoordinateReferenceSystem mCrs;
41+
QLineEdit* mCrsLineEdit;
42+
QToolButton* mButton;
43+
};
44+
45+
#endif // QGSPROJECTIONSELECTIONWIDGET_H

0 commit comments

Comments
 (0)
Please sign in to comment.