16 #include <QHBoxLayout>
30 QHBoxLayout* layout =
new QHBoxLayout();
31 layout->setContentsMargins( 0, 0, 0, 0 );
32 layout->setSpacing( 0 );
35 mCrsComboBox =
new QComboBox(
this );
37 mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
45 addProjectCrsOption();
49 QString defCrsString = settings.value(
"/Projections/projectDefaultCrs",
GEO_EPSG_CRS_AUTHID ).toString();
55 addDefaultCrsOption();
60 layout->addWidget( mCrsComboBox );
62 mButton =
new QToolButton(
this );
64 mButton->setToolTip(
tr(
"Select CRS" ) );
65 layout->addWidget( mButton );
67 setFocusPolicy( Qt::StrongFocus );
68 setFocusProxy( mButton );
70 connect( mButton, SIGNAL( clicked() ),
this, SLOT(
selectCrs() ) );
71 connect( mCrsComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( comboIndexChanged(
int ) ) );
76 switch ((
CrsOption )mCrsComboBox->itemData( mCrsComboBox->currentIndex() ).toInt() )
88 long srsid = mCrsComboBox->itemData( mCrsComboBox->currentIndex(), Qt::UserRole + 1 ).toLongLong();
99 int optionIndex = mCrsComboBox->findData( option );
101 if ( visible && optionIndex < 0 )
113 addProjectCrsOption();
118 addDefaultCrsOption();
127 else if ( !visible && optionIndex >= 0 )
130 mCrsComboBox->removeItem( optionIndex );
142 if ( mDialog->exec() )
144 mCrsComboBox->blockSignals(
true );
146 mCrsComboBox->blockSignals(
false );
154 QApplication::restoreOverrideCursor();
158 void QgsProjectionSelectionWidget::comboIndexChanged(
int idx )
160 switch ((
CrsOption )mCrsComboBox->itemData( idx ).toInt() )
176 long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
191 mCrsComboBox->blockSignals(
true );
193 mCrsComboBox->blockSignals(
false );
198 tr(
"invalid projection" ) );
208 if ( layerItemIndex > -1 )
210 mCrsComboBox->setItemText( layerItemIndex,
tr(
"Layer CRS (%1, %2)" ).arg( crs.
authid() ).arg( crs.
description() ) );
219 if ( layerItemIndex > -1 )
221 mCrsComboBox->removeItem( layerItemIndex );
227 void QgsProjectionSelectionWidget::addProjectCrsOption()
235 void QgsProjectionSelectionWidget::addDefaultCrsOption()
240 void QgsProjectionSelectionWidget::addRecentCrs()
244 foreach ( QString projection, recentProjections )
246 long srsid = projection.toLong();
249 if ( crsIsShown( srsid ) )
260 mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant((
long long )srsid ), Qt::UserRole + 1 );
270 bool QgsProjectionSelectionWidget::crsIsShown(
const long srsid )
const
272 return srsid == mLayerCrs.
srsid() || srsid == mDefaultCrs.
srsid() || srsid == mProjectCrs.
srsid();
275 int QgsProjectionSelectionWidget::firstRecentCrsIndex()
const
277 for (
int i = 0; i < mCrsComboBox->count(); ++i )