QGIS API Documentation  3.15.0-Master (c0197371fe)
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 sentence1 = tr( "This layer appears to have no projection specification." );
50  QString sentence2 = tr( "By default, this layer will now have its projection set to that of the project, "
51  "but you may override this by selecting a different projection below." );
52  m = QStringLiteral( "%1 %2" ).arg( sentence1, sentence2 );
53  }
54 
55  QString myStyle = QgsApplication::reportStyleSheet();
56  m = "<head><style>" + myStyle + "</style></head><body>" + m + "</body>";
57  textEdit->setHtml( m );
58  textEdit->show();
59 }
60 
62 {
63  projectionSelector->setShowNoProjection( show );
64 }
65 
67 {
68  return projectionSelector->showNoProjection();
69 }
70 
72 {
73  return projectionSelector->crs();
74 }
75 
77 {
78  projectionSelector->setCrs( crs );
79 }
80 
81 void QgsProjectionSelectionDialog::setOgcWmsCrsFilter( const QSet<QString> &crsFilter )
82 {
83  projectionSelector->setOgcWmsCrsFilter( crsFilter );
84 }
85 
86 void QgsProjectionSelectionDialog::showHelp()
87 {
88  QgsHelp::openHelp( QStringLiteral( "working_with_projections/working_with_projections.html" ) );
89 }
void setMessage(const QString &message)
Sets a message to show in the dialog.
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
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:133
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
bool showNoProjection() const
Returns whether the "no/invalid" projection option is shown.