16 #include <QHBoxLayout> 29 QHBoxLayout *layout =
new QHBoxLayout();
30 layout->setContentsMargins( 0, 0, 0, 0 );
31 layout->setSpacing( 6 );
34 mCrsComboBox =
new QComboBox(
this );
36 mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
39 addProjectCrsOption();
42 QString defCrsString = settings.
value( QStringLiteral(
"Projections/projectDefaultCrs" ),
GEO_EPSG_CRS_AUTHID ).toString();
48 addDefaultCrsOption();
53 layout->addWidget( mCrsComboBox );
55 mButton =
new QToolButton(
this );
57 mButton->setToolTip( tr(
"Select CRS" ) );
58 layout->addWidget( mButton );
60 setFocusPolicy( Qt::StrongFocus );
61 setFocusProxy( mButton );
64 connect( mCrsComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsProjectionSelectionWidget::comboIndexChanged );
69 switch ( (
CrsOption )mCrsComboBox->currentData().toInt() )
81 long srsid = mCrsComboBox->currentData( Qt::UserRole + 1 ).toLongLong();
93 int optionIndex = mCrsComboBox->findData( option );
95 if ( visible && optionIndex < 0 )
107 addProjectCrsOption();
112 addDefaultCrsOption();
117 addCurrentCrsOption();
137 else if ( !visible && optionIndex >= 0 )
140 mCrsComboBox->removeItem( optionIndex );
152 int optionIndex = mCrsComboBox->findData(
CrsNotSet );
153 if ( optionIndex >= 0 )
155 mCrsComboBox->setItemText( optionIndex, mNotSetText );
166 int optionIndex = mCrsComboBox->findData( option );
167 return optionIndex >= 0;
182 mCrsComboBox->blockSignals(
true );
184 mCrsComboBox->blockSignals(
false );
191 QApplication::restoreOverrideCursor();
195 void QgsProjectionSelectionWidget::addNotSetOption()
202 void QgsProjectionSelectionWidget::comboIndexChanged(
int idx )
204 switch ( (
CrsOption )mCrsComboBox->itemData( idx ).toInt() )
220 long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
239 currentCrsOptionText( crs ) );
240 mCrsComboBox->blockSignals(
true );
242 mCrsComboBox->blockSignals(
false );
247 if ( crsNotSetIndex >= 0 )
249 mCrsComboBox->blockSignals(
true );
250 mCrsComboBox->setCurrentIndex( crsNotSetIndex );
251 mCrsComboBox->blockSignals(
false );
256 currentCrsOptionText( crs ) );
267 if ( layerItemIndex > -1 )
269 mCrsComboBox->setItemText( layerItemIndex, tr(
"Layer CRS: %1 - %2" ).arg( crs.
authid(), crs.
description() ) );
278 if ( layerItemIndex > -1 )
280 mCrsComboBox->removeItem( layerItemIndex );
286 void QgsProjectionSelectionWidget::addProjectCrsOption()
294 void QgsProjectionSelectionWidget::addDefaultCrsOption()
299 void QgsProjectionSelectionWidget::addCurrentCrsOption()
311 return tr(
"invalid projection" );
314 void QgsProjectionSelectionWidget::addRecentCrs()
318 Q_FOREACH (
const QString &projection, recentProjections )
320 long srsid = projection.toLong();
323 if ( crsIsShown( srsid ) )
333 mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( (
long long )srsid ), Qt::UserRole + 1 );
343 bool QgsProjectionSelectionWidget::crsIsShown(
const long srsid )
const 345 return srsid == mLayerCrs.
srsid() || srsid == mDefaultCrs.
srsid() || srsid == mProjectCrs.
srsid();
348 int QgsProjectionSelectionWidget::firstRecentCrsIndex()
const 350 for (
int i = 0; i < mCrsComboBox->count(); ++i )
This class is a composition of two QSettings instances:
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.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
A generic dialog to prompt the user for a Coordinate Reference System.
static QStringList recentProjections()
Returns a list of recently used projections.
QgsCoordinateReferenceSystem crs
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
long srsid() const
Returns the internal CRS ID, if available.
QString authid() const
Returns the authority identifier for the CRS.
static QgsCoordinateReferenceSystem fromSrsId(long srsId)
Creates a CRS from a specified QGIS SRS ID.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.