QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 #include <QPushButton>
26 
28  Qt::WindowFlags fl )
29  : QDialog( parent, fl )
30 {
31  setupUi( this );
33  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsProjectionSelectionDialog::showHelp );
34 
35  //we will show this only when a message is set
36  textEdit->hide();
37 
38  //apply selected projection upon double-click on item
39  connect( projectionSelector, &QgsProjectionSelectionTreeWidget::projectionDoubleClicked, this, &QgsProjectionSelectionDialog::accept );
40 
41  const QgsSettings settings;
42  mSplitter->restoreState( settings.value( QStringLiteral( "Windows/ProjectionSelectorDialog/splitterState" ) ).toByteArray() );
43 }
44 
46 {
47  QgsSettings settings;
48  settings.setValue( QStringLiteral( "Windows/ProjectionSelectorDialog/splitterState" ), mSplitter->saveState() );
49 }
50 
51 void QgsProjectionSelectionDialog::setMessage( const QString &message )
52 {
53  textEdit->setHtml( QStringLiteral( "<head><style>%1</style></head><body>%2</body>" ).arg( QgsApplication::reportStyleSheet(),
54  message ) );
55  textEdit->show();
56 }
57 
59 {
60  setMessage( tr( "This layer appears to have no projection specification." )
61  + ' '
62  + tr( "By default, this layer will now have its projection set to that of the project, "
63  "but you may override this by selecting a different projection below." ) );
64 }
65 
67 {
68  projectionSelector->setShowNoProjection( show );
69 }
70 
72 {
73  return projectionSelector->showNoProjection();
74 }
75 
77 {
78  projectionSelector->setNotSetText( text );
79 }
80 
82 {
83  mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( projectionSelector->hasValidSelection() );
84 
85  connect( projectionSelector, &QgsProjectionSelectionTreeWidget::hasValidSelectionChanged, this, [ = ]( bool isValid )
86  {
87  mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
88  } );
89 }
90 
92 {
93  return projectionSelector->crs();
94 }
95 
97 {
98  projectionSelector->setCrs( crs );
99 }
100 
101 void QgsProjectionSelectionDialog::setOgcWmsCrsFilter( const QSet<QString> &crsFilter )
102 {
103  projectionSelector->setOgcWmsCrsFilter( crsFilter );
104 }
105 
106 void QgsProjectionSelectionDialog::showHelp()
107 {
108  QgsHelp::openHelp( QStringLiteral( "working_with_projections/working_with_projections.html" ) );
109 }
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
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:168
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
void setNotSetText(const QString &text)
Sets the text to show for the not set option.
void showNoCrsForLayerMessage()
When called, the dialog will show a default "layer has no CRS set" message above the projection selec...
void setShowNoProjection(bool show)
Sets whether a "no/invalid" projection option should be shown.
bool showNoProjection() const
Returns whether the "no/invalid" projection option is shown.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
void setMessage(const QString &message)
Sets a message to show in the dialog.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
QgsProjectionSelectionDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsProjectionSelectionDialog.
void setRequireValidSelection()
Sets the dialog to require a valid selection only, preventing users from accepting the dialog if no s...
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
void projectionDoubleClicked()
Emitted when a projection is double clicked in the list.
void hasValidSelectionChanged(bool isValid)
Emitted when the selection in the tree is changed from a valid selection to an invalid selection,...
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
const QgsCoordinateReferenceSystem & crs