QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsprojectionselectiondialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgenericprojectionselector.cpp
3  Set user defined CRS using projection selector widget
4  -------------------
5  begin : May 28, 2004
6  copyright : (C) 2004 by Gary E.Sherman
7  email : sherman at mrcc.com
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 #include "qgsapplication.h"
19 #include "qgssettings.h"
20 
22 #include "qgshelp.h"
23 #include <QApplication>
24 #include "qgsgui.h"
25 
27  Qt::WindowFlags fl )
28  : QDialog( parent, fl )
29 {
30  setupUi( this );
32  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsProjectionSelectionDialog::showHelp );
33 
34  //we will show this only when a message is set
35  textEdit->hide();
36 
37  //apply selected projection upon double-click on item
38  connect( projectionSelector, &QgsProjectionSelectionTreeWidget::projectionDoubleClicked, this, &QgsProjectionSelectionDialog::accept );
39 }
40 
41 void QgsProjectionSelectionDialog::setMessage( const QString &message )
42 {
43  QString m = message;
44  //short term kludge to make the layer selector default to showing
45  //a layer projection selection message. If you want the selector
46  if ( m.isEmpty() )
47  {
48  // Set up text edit pane
49  QString format( QStringLiteral( "<h1>%1</h1>%2 %3" ) );
50  QString header = tr( "Define this layer's coordinate reference system:" );
51  QString sentence1 = tr( "This layer appears to have no projection specification." );
52  QString sentence2 = tr( "By default, this layer will now have its projection set to that of the project, "
53  "but you may override this by selecting a different projection below." );
54  m = format.arg( header, sentence1, sentence2 );
55  }
56 
57  QString myStyle = QgsApplication::reportStyleSheet();
58  m = "<head><style>" + myStyle + "</style></head><body>" + m + "</body>";
59  textEdit->setHtml( m );
60  textEdit->show();
61 }
62 
64 {
65  projectionSelector->setShowNoProjection( show );
66 }
67 
69 {
70  return projectionSelector->showNoProjection();
71 }
72 
74 {
75  return projectionSelector->crs();
76 }
77 
79 {
80  projectionSelector->setCrs( crs );
81 }
82 
83 void QgsProjectionSelectionDialog::setOgcWmsCrsFilter( const QSet<QString> &crsFilter )
84 {
85  projectionSelector->setOgcWmsCrsFilter( crsFilter );
86 }
87 
88 void QgsProjectionSelectionDialog::showHelp()
89 {
90  QgsHelp::openHelp( QStringLiteral( "working_with_projections/working_with_projections.html" ) );
91 }
void setMessage(const QString &message)
Sets a message to show in the dialog.
static QString reportStyleSheet()
Returns a standard css style sheet for reports.
void setShowNoProjection(bool show)
Sets whether a "no/invalid" projection option should be shown.
void projectionDoubleClicked()
Emitted when a projection is double clicked in the list.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
QgsProjectionSelectionDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsProjectionSelectionDialog.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
This class represents a coordinate reference system (CRS).
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:82
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:35
bool showNoProjection() const
Returns whether the "no/invalid" projection option is shown.