QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsprojectionselectionwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprojectionselectionwidget.h
3  --------------------------------------
4  Date : 05.01.2015
5  Copyright : (C) 2015 Denis Rouzaud
6  Email : [email protected]
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 #include <QComboBox>
24 
26 
28 
35 class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
36 {
37  Q_OBJECT
38  public:
39 
42  enum CrsOption
43  {
44  LayerCrs, /*< optional layer CRS */
45  ProjectCrs, /*< current project CRS (if OTF reprojection enabled) */
46  CurrentCrs, /*< current user selected CRS */
47  DefaultCrs, /*< global default QGIS CRS */
48  RecentCrs /*< recently used CRS */
49  };
50 
51  explicit QgsProjectionSelectionWidget( QWidget *parent = 0 );
52 
53  /* Returns a pointer to the projection selector dialog used by the widget.
54  * Can be used to modify how the projection selector dialog behaves.
55  * @returns projection selector dialog
56  */
57  QgsGenericProjectionSelector* dialog() { return mDialog; }
58 
59  /* Returns the currently selected CRS for the widget
60  * @returns current CRS
61  */
62  QgsCoordinateReferenceSystem crs() const;
63 
64  /* Sets whether a predefined CRS option should be shown in the widget.
65  * @param option CRS option to show/hide
66  * @param visible whether the option should be shown
67  */
68  void setOptionVisible( const CrsOption option, const bool visible );
69 
70  signals:
71 
72  /* Emitted when the selected CRS is changed
73  */
74  void crsChanged( QgsCoordinateReferenceSystem );
75 
76  public slots:
77 
78  /* Sets the current CRS for the widget
79  * @param crs new CRS
80  */
81  void setCrs( const QgsCoordinateReferenceSystem& crs );
82 
83  /* Sets the layer CRS for the widget. If set, this will be added as an option
84  * to the preset CRSes shown in the widget.
85  * @param crs layer CRS
86  */
87  void setLayerCrs( const QgsCoordinateReferenceSystem& crs );
88 
89  /* Opens the dialog for selecting a new CRS
90  */
91  void selectCrs();
92 
93  private:
94 
97  QgsCoordinateReferenceSystem mProjectCrs;
98  QgsCoordinateReferenceSystem mDefaultCrs;
99  QComboBox* mCrsComboBox;
100  QToolButton* mButton;
102 
103  void addProjectCrsOption();
104  void addDefaultCrsOption();
105  void addRecentCrs();
106  bool crsIsShown( const long srsid ) const;
107 
108  int firstRecentCrsIndex() const;
109 
110  private slots:
111 
112  void comboIndexChanged( int idx );
113 
114 };
115 
116 #endif // QGSPROJECTIONSELECTIONWIDGET_H