16 #include <QHBoxLayout> 28 QHBoxLayout *layout =
new QHBoxLayout();
29 layout->setContentsMargins( 0, 0, 0, 0 );
30 layout->setSpacing( 6 );
35 mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
38 addProjectCrsOption();
46 addDefaultCrsOption();
51 layout->addWidget( mCrsComboBox );
53 mButton =
new QToolButton(
this );
55 mButton->setToolTip( tr(
"Select CRS" ) );
56 layout->addWidget( mButton );
58 setFocusPolicy( Qt::StrongFocus );
59 setFocusProxy( mButton );
60 setAcceptDrops(
true );
63 connect( mCrsComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsProjectionSelectionWidget::comboIndexChanged );
68 switch ( static_cast< CrsOption >( mCrsComboBox->currentData().toInt() ) )
80 long srsid = mCrsComboBox->currentData( Qt::UserRole + 1 ).toLongLong();
92 int optionIndex = mCrsComboBox->findData( option );
94 if ( visible && optionIndex < 0 )
106 addProjectCrsOption();
111 addDefaultCrsOption();
116 addCurrentCrsOption();
136 else if ( !visible && optionIndex >= 0 )
139 mCrsComboBox->removeItem( optionIndex );
151 int optionIndex = mCrsComboBox->findData(
CrsNotSet );
152 if ( optionIndex >= 0 )
154 mCrsComboBox->setItemText( optionIndex, mNotSetText );
165 int optionIndex = mCrsComboBox->findData( option );
166 return optionIndex >= 0;
173 if ( !mMessage.isEmpty() )
177 if (
optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
184 mCrsComboBox->blockSignals(
true );
186 mCrsComboBox->blockSignals(
false );
193 QApplication::restoreOverrideCursor();
199 if ( !( event->possibleActions() & Qt::CopyAction ) )
205 if ( mapLayerFromMimeData( event->mimeData() ) )
208 event->setDropAction( Qt::CopyAction );
235 if ( !( event->possibleActions() & Qt::CopyAction ) )
241 if (
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
244 setFocus( Qt::MouseFocusReason );
245 event->setDropAction( Qt::CopyAction );
248 if ( layer->crs().isValid() )
259 void QgsProjectionSelectionWidget::addNotSetOption()
266 void QgsProjectionSelectionWidget::comboIndexChanged(
int idx )
268 switch ( static_cast< CrsOption >( mCrsComboBox->itemData( idx ).toInt() ) )
284 long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
305 mCrsComboBox->blockSignals(
true );
307 mCrsComboBox->blockSignals(
false );
312 if ( crsNotSetIndex >= 0 )
314 mCrsComboBox->blockSignals(
true );
315 mCrsComboBox->setCurrentIndex( crsNotSetIndex );
316 mCrsComboBox->blockSignals(
false );
337 if ( layerItemIndex > -1 )
348 if ( layerItemIndex > -1 )
350 mCrsComboBox->removeItem( layerItemIndex );
356 void QgsProjectionSelectionWidget::addProjectCrsOption()
364 void QgsProjectionSelectionWidget::addDefaultCrsOption()
369 void QgsProjectionSelectionWidget::addCurrentCrsOption()
381 return tr(
"invalid projection" );
384 void QgsProjectionSelectionWidget::addRecentCrs()
392 if ( crsIsShown( srsid ) )
400 mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( (
long long )srsid ), Qt::UserRole + 1 );
405 bool QgsProjectionSelectionWidget::crsIsShown(
const long srsid )
const 407 return srsid == mLayerCrs.
srsid() || srsid == mDefaultCrs.
srsid() || srsid == mProjectCrs.
srsid();
410 int QgsProjectionSelectionWidget::firstRecentCrsIndex()
const 412 for (
int i = 0; i < mCrsComboBox->count(); ++i )
414 if ( static_cast< CrsOption >( mCrsComboBox->itemData( i ).toInt() ) ==
RecentCrs )
422 void QgsProjectionSelectionWidget::updateTooltip()
428 setToolTip( QString() );
431 QgsMapLayer *QgsProjectionSelectionWidget::mapLayerFromMimeData(
const QMimeData *data )
const Base class for all map layer types.
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.
static UriList decodeUriList(const QMimeData *data)
void setMessage(const QString &message)
Sets a message to show in the dialog.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setShowNoProjection(bool show)
Sets whether a "no/invalid" projection option should be shown.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
A generic dialog to prompt the user for a Coordinate Reference System.
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
static QList< QgsCoordinateReferenceSystem > recentCoordinateReferenceSystems()
Returns a list of recently used CRS.
QgsCoordinateReferenceSystem crs
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
Full WKT2 string, conforming to ISO 19162:2018 / OGC 18-010, with all possible nodes and new keyword ...
bool isHighlighted() const
Returns true if the combo box is currently highlighted.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
QList< QgsMimeDataUtils::Uri > UriList
A QComboBox subclass with the ability to "highlight" the edges of the widget.
long srsid() const
Returns the internal CRS ID, if available.
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
QString authid() const
Returns the authority identifier for the CRS.
static QgsCoordinateReferenceSystem fromSrsId(long srsId)
Creates a CRS from a specified QGIS SRS ID.
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
void setHighlighted(bool highlighted)
Sets whether the combo box is currently highlighted.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.