16 #include <QHBoxLayout> 
   32   mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
 
   34   const int labelMargin = 
static_cast< int >( std::round( mCrsComboBox->fontMetrics().horizontalAdvance( 
'X' ) ) );
 
   35   QHBoxLayout *layout = 
new QHBoxLayout();
 
   36   layout->setContentsMargins( 0, 0, 0, 0 );
 
   37   layout->setSpacing( 0 );
 
   41   addProjectCrsOption();
 
   49     addDefaultCrsOption();
 
   54   layout->addWidget( mCrsComboBox, 1 );
 
   59   mWarningLabelContainer = 
new QWidget();
 
   60   QHBoxLayout *warningLayout = 
new QHBoxLayout();
 
   61   warningLayout->setContentsMargins( 0, 0, 0, 0 );
 
   62   mWarningLabel = 
new QLabel();
 
   64   const int size = 
static_cast< int >( std::max( 24.0, mCrsComboBox->minimumSize().height() * 0.5 ) );
 
   65   mWarningLabel->setPixmap( icon.pixmap( icon.actualSize( QSize( size, size ) ) ) );
 
   66   warningLayout->insertSpacing( 0, labelMargin / 2 );
 
   67   warningLayout->insertWidget( 1, mWarningLabel );
 
   68   mWarningLabelContainer->setLayout( warningLayout );
 
   69   layout->addWidget( mWarningLabelContainer );
 
   70   mWarningLabelContainer->hide();
 
   72   layout->addSpacing( labelMargin / 2 );
 
   74   mButton = 
new QToolButton( 
this );
 
   76   mButton->setToolTip( tr( 
"Select CRS" ) );
 
   77   layout->addWidget( mButton );
 
   79   setFocusPolicy( Qt::StrongFocus );
 
   80   setFocusProxy( mButton );
 
   81   setAcceptDrops( 
true );
 
   84   connect( mCrsComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsProjectionSelectionWidget::comboIndexChanged );
 
   97   switch ( 
static_cast< CrsOption >( mCrsComboBox->currentData().toInt() ) )
 
  109       const long srsid = mCrsComboBox->currentData( Qt::UserRole + 1 ).toLongLong();
 
  121   const int optionIndex = mCrsComboBox->findData( option );
 
  123   if ( visible && optionIndex < 0 )
 
  135         addProjectCrsOption();
 
  140         addDefaultCrsOption();
 
  145         addCurrentCrsOption();
 
  165   else if ( !visible && optionIndex >= 0 )
 
  168     mCrsComboBox->removeItem( optionIndex );
 
  180   const int optionIndex = mCrsComboBox->findData( 
CrsNotSet );
 
  181   if ( optionIndex >= 0 )
 
  183     mCrsComboBox->setItemText( optionIndex, mNotSetText );
 
  194   const int optionIndex = mCrsComboBox->findData( option );
 
  195   return optionIndex >= 0;
 
  202   if ( !mMessage.isEmpty() )
 
  206   if ( !mNotSetText.isEmpty() )
 
  209   if ( 
optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
 
  217     mCrsComboBox->blockSignals( 
true );
 
  219     mCrsComboBox->blockSignals( 
false );
 
  226     QApplication::restoreOverrideCursor();
 
  232   if ( !( event->possibleActions() & Qt::CopyAction ) )
 
  238   if ( mapLayerFromMimeData( event->mimeData() ) )
 
  241     event->setDropAction( Qt::CopyAction );
 
  268   if ( !( event->possibleActions() & Qt::CopyAction ) )
 
  274   if ( 
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
 
  277     setFocus( Qt::MouseFocusReason );
 
  278     event->setDropAction( Qt::CopyAction );
 
  281     if ( layer->crs().isValid() )
 
  294   return mSourceEnsemble;
 
  299   if ( mSourceEnsemble == ensemble )
 
  302   mSourceEnsemble = ensemble;
 
  308   return mShowAccuracyWarnings;
 
  313   mShowAccuracyWarnings = show;
 
  314   if ( !mShowAccuracyWarnings )
 
  315     mWarningLabelContainer->hide();
 
  320 void QgsProjectionSelectionWidget::addNotSetOption()
 
  327 void QgsProjectionSelectionWidget::comboIndexChanged( 
int idx )
 
  329   switch ( 
static_cast< CrsOption >( mCrsComboBox->itemData( idx ).toInt() ) )
 
  345       const long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
 
  358 void QgsProjectionSelectionWidget::updateWarning()
 
  360   if ( !mShowAccuracyWarnings )
 
  362     if ( mWarningLabelContainer->isVisible() )
 
  363       mWarningLabelContainer->hide();
 
  369     const double crsAccuracyWarningThreshold = 
QgsSettings().
value( QStringLiteral( 
"/projections/crsAccuracyWarningThreshold" ), 0.0, 
QgsSettings::App ).toDouble();
 
  372     if ( !ensemble.
isValid() || ensemble.
name() == mSourceEnsemble || ( ensemble.
accuracy() > 0 && ensemble.
accuracy() < crsAccuracyWarningThreshold ) )
 
  374       mWarningLabelContainer->hide();
 
  378       mWarningLabelContainer->show();
 
  380       QString warning = QStringLiteral( 
"<p>" );
 
  383       if ( !ensemble.
code().isEmpty() )
 
  384         id = QStringLiteral( 
"<i>%1</i> (%2:%3)" ).arg( ensemble.
name(), ensemble.
authority(), ensemble.
code() );
 
  386         id = QStringLiteral( 
"<i>%</i>”" ).arg( ensemble.
name() );
 
  390         warning = tr( 
"The selected CRS is based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg( 
id ).arg( ensemble.
accuracy() );
 
  394         warning = tr( 
"The selected CRS is based on %1, which has a limited accuracy." ).arg( 
id );
 
  396       warning += QStringLiteral( 
"</p><p>" ) + tr( 
"Use an alternative CRS if accurate positioning is required." ) + QStringLiteral( 
"</p>" );
 
  398       const QList< QgsDatumEnsembleMember > members = ensemble.
members();
 
  399       if ( !members.isEmpty() )
 
  401         warning += QStringLiteral( 
"<p>" ) + tr( 
"%1 consists of the datums:" ).arg( ensemble.
name() ) + QStringLiteral( 
"</p><ul>" );
 
  405           if ( !member.code().isEmpty() )
 
  406             id = QStringLiteral( 
"%1 (%2:%3)" ).arg( member.name(), member.authority(), member.code() );
 
  409           warning += QStringLiteral( 
"<li>%1</li>" ).arg( 
id );
 
  412         warning += QLatin1String( 
"</ul>" );
 
  415       mWarningLabel->setToolTip( warning );
 
  420     mWarningLabelContainer->hide();
 
  432     mCrsComboBox->blockSignals( 
true );
 
  434     mCrsComboBox->blockSignals( 
false );
 
  439     if ( crsNotSetIndex >= 0 )
 
  441       mCrsComboBox->blockSignals( 
true );
 
  442       mCrsComboBox->setCurrentIndex( crsNotSetIndex );
 
  443       mCrsComboBox->blockSignals( 
false );
 
  464     if ( layerItemIndex > -1 )
 
  475     if ( layerItemIndex > -1 )
 
  477       mCrsComboBox->removeItem( layerItemIndex );
 
  483 void QgsProjectionSelectionWidget::addProjectCrsOption()
 
  491 void QgsProjectionSelectionWidget::addDefaultCrsOption()
 
  496 void QgsProjectionSelectionWidget::addCurrentCrsOption()
 
  508     return tr( 
"invalid projection" );
 
  511 void QgsProjectionSelectionWidget::addRecentCrs()
 
  519     if ( crsIsShown( srsid ) )
 
  527       mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( ( 
long long )srsid ), Qt::UserRole + 1 );
 
  532 bool QgsProjectionSelectionWidget::crsIsShown( 
const long srsid )
 const 
  534   return srsid == mLayerCrs.
srsid() || srsid == mDefaultCrs.
srsid() || srsid == mProjectCrs.
srsid();
 
  537 int QgsProjectionSelectionWidget::firstRecentCrsIndex()
 const 
  539   for ( 
int i = 0; i < mCrsComboBox->count(); ++i )
 
  549 void QgsProjectionSelectionWidget::updateTooltip()
 
  555     setToolTip( QString() );
 
  559 QgsMapLayer *QgsProjectionSelectionWidget::mapLayerFromMimeData( 
const QMimeData *data )
 const 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsCoordinateReferenceSystemRegistry * coordinateReferenceSystemRegistry()
Returns the application's coordinate reference system (CRS) registry, which handles known CRS definit...
void userCrsChanged(const QString &id)
Emitted whenever an existing user CRS definition is changed.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsDatumEnsemble datumEnsemble() const SIP_THROW(QgsNotSupportedException)
Attempts to retrieve datum ensemble details from the CRS.
void updateDefinition()
Updates the definition and parameters of the coordinate reference system to their latest values.
static QList< QgsCoordinateReferenceSystem > recentCoordinateReferenceSystems()
Returns a list of recently used CRS.
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
QString authid() const
Returns the authority identifier for the CRS.
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
static QgsCoordinateReferenceSystem fromSrsId(long srsId)
Creates a CRS from a specified QGIS SRS ID.
long srsid() const
Returns the internal CRS ID, if available.
Contains information about a member of a datum ensemble.
Contains information about a datum ensemble.
QString code() const
Identification code, e.g.
QString authority() const
Authority name, e.g.
bool isValid() const
Returns true if the datum ensemble is a valid object, or false if it is a null/invalid object.
QList< QgsDatumEnsembleMember > members() const
Contains a list of members of the ensemble.
QString name() const
Display name of datum ensemble.
double accuracy() const
Positional accuracy (in meters).
A QComboBox subclass with the ability to "highlight" the edges of the widget.
void setHighlighted(bool highlighted)
Sets whether the combo box is currently highlighted.
bool isHighlighted() const
Returns true if the combo box is currently highlighted.
Base class for all map layer types.
QList< QgsMimeDataUtils::Uri > UriList
static UriList decodeUriList(const QMimeData *data)
Custom exception class which is raised when an operation is not supported.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateReferenceSystem crs
A generic dialog to prompt the user for a Coordinate Reference System.
void setNotSetText(const QString &text)
Sets the text to show for the not set option.
void setShowNoProjection(bool show)
Sets whether a "no/invalid" projection option should be 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.
void setRequireValidSelection()
Sets the dialog to require a valid selection only, preventing users from accepting the dialog if no s...
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
const QgsCoordinateReferenceSystem & crs