16 #include <QHBoxLayout> 
   29   QHBoxLayout *layout = 
new QHBoxLayout();
 
   30   layout->setContentsMargins( 0, 0, 0, 0 );
 
   31   layout->setSpacing( 6 );
 
   36   mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
 
   39   addProjectCrsOption();
 
   47     addDefaultCrsOption();
 
   52   layout->addWidget( mCrsComboBox );
 
   54   mButton = 
new QToolButton( 
this );
 
   56   mButton->setToolTip( tr( 
"Select CRS" ) );
 
   57   layout->addWidget( mButton );
 
   59   setFocusPolicy( Qt::StrongFocus );
 
   60   setFocusProxy( mButton );
 
   61   setAcceptDrops( 
true );
 
   64   connect( mCrsComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsProjectionSelectionWidget::comboIndexChanged );
 
   77   switch ( 
static_cast< CrsOption >( mCrsComboBox->currentData().toInt() ) )
 
   89       long srsid = mCrsComboBox->currentData( Qt::UserRole + 1 ).toLongLong();
 
  101   int optionIndex = mCrsComboBox->findData( option );
 
  103   if ( visible && optionIndex < 0 )
 
  115         addProjectCrsOption();
 
  120         addDefaultCrsOption();
 
  125         addCurrentCrsOption();
 
  145   else if ( !visible && optionIndex >= 0 )
 
  148     mCrsComboBox->removeItem( optionIndex );
 
  160   int optionIndex = mCrsComboBox->findData( 
CrsNotSet );
 
  161   if ( optionIndex >= 0 )
 
  163     mCrsComboBox->setItemText( optionIndex, mNotSetText );
 
  174   int optionIndex = mCrsComboBox->findData( option );
 
  175   return optionIndex >= 0;
 
  182   if ( !mMessage.isEmpty() )
 
  186   if ( !mNotSetText.isEmpty() )
 
  189   if ( 
optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
 
  197     mCrsComboBox->blockSignals( 
true );
 
  199     mCrsComboBox->blockSignals( 
false );
 
  206     QApplication::restoreOverrideCursor();
 
  212   if ( !( event->possibleActions() & Qt::CopyAction ) )
 
  218   if ( mapLayerFromMimeData( event->mimeData() ) )
 
  221     event->setDropAction( Qt::CopyAction );
 
  248   if ( !( event->possibleActions() & Qt::CopyAction ) )
 
  254   if ( 
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
 
  257     setFocus( Qt::MouseFocusReason );
 
  258     event->setDropAction( Qt::CopyAction );
 
  261     if ( layer->crs().isValid() )
 
  272 void QgsProjectionSelectionWidget::addNotSetOption()
 
  279 void QgsProjectionSelectionWidget::comboIndexChanged( 
int idx )
 
  281   switch ( 
static_cast< CrsOption >( mCrsComboBox->itemData( idx ).toInt() ) )
 
  297       long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
 
  318     mCrsComboBox->blockSignals( 
true );
 
  320     mCrsComboBox->blockSignals( 
false );
 
  325     if ( crsNotSetIndex >= 0 )
 
  327       mCrsComboBox->blockSignals( 
true );
 
  328       mCrsComboBox->setCurrentIndex( crsNotSetIndex );
 
  329       mCrsComboBox->blockSignals( 
false );
 
  350     if ( layerItemIndex > -1 )
 
  361     if ( layerItemIndex > -1 )
 
  363       mCrsComboBox->removeItem( layerItemIndex );
 
  369 void QgsProjectionSelectionWidget::addProjectCrsOption()
 
  377 void QgsProjectionSelectionWidget::addDefaultCrsOption()
 
  382 void QgsProjectionSelectionWidget::addCurrentCrsOption()
 
  394     return tr( 
"invalid projection" );
 
  397 void QgsProjectionSelectionWidget::addRecentCrs()
 
  405     if ( crsIsShown( srsid ) )
 
  413       mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( ( 
long long )srsid ), Qt::UserRole + 1 );
 
  418 bool QgsProjectionSelectionWidget::crsIsShown( 
const long srsid )
 const 
  420   return srsid == mLayerCrs.
srsid() || srsid == mDefaultCrs.
srsid() || srsid == mProjectCrs.
srsid();
 
  423 int QgsProjectionSelectionWidget::firstRecentCrsIndex()
 const 
  425   for ( 
int i = 0; i < mCrsComboBox->count(); ++i )
 
  435 void QgsProjectionSelectionWidget::updateTooltip()
 
  441     setToolTip( QString() );
 
  444 QgsMapLayer *QgsProjectionSelectionWidget::mapLayerFromMimeData( 
const QMimeData *data )
 const 
static QgsCoordinateReferenceSystemRegistry * coordinateReferenceSystemRegistry()
Returns the application's coordinate reference system (CRS) registry, which handles known CRS definit...
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
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.
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.
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)
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