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 ( !mNotSetText.isEmpty() )
180 if (
optionVisible( QgsProjectionSelectionWidget::CrsOption::CrsNotSet ) )
187 mCrsComboBox->blockSignals(
true );
189 mCrsComboBox->blockSignals(
false );
196 QApplication::restoreOverrideCursor();
202 if ( !( event->possibleActions() & Qt::CopyAction ) )
208 if ( mapLayerFromMimeData( event->mimeData() ) )
211 event->setDropAction( Qt::CopyAction );
238 if ( !( event->possibleActions() & Qt::CopyAction ) )
244 if (
QgsMapLayer *layer = mapLayerFromMimeData( event->mimeData() ) )
247 setFocus( Qt::MouseFocusReason );
248 event->setDropAction( Qt::CopyAction );
251 if ( layer->crs().isValid() )
262 void QgsProjectionSelectionWidget::addNotSetOption()
269 void QgsProjectionSelectionWidget::comboIndexChanged(
int idx )
271 switch (
static_cast< CrsOption >( mCrsComboBox->itemData( idx ).toInt() ) )
287 long srsid = mCrsComboBox->itemData( idx, Qt::UserRole + 1 ).toLongLong();
308 mCrsComboBox->blockSignals(
true );
310 mCrsComboBox->blockSignals(
false );
315 if ( crsNotSetIndex >= 0 )
317 mCrsComboBox->blockSignals(
true );
318 mCrsComboBox->setCurrentIndex( crsNotSetIndex );
319 mCrsComboBox->blockSignals(
false );
340 if ( layerItemIndex > -1 )
351 if ( layerItemIndex > -1 )
353 mCrsComboBox->removeItem( layerItemIndex );
359 void QgsProjectionSelectionWidget::addProjectCrsOption()
367 void QgsProjectionSelectionWidget::addDefaultCrsOption()
372 void QgsProjectionSelectionWidget::addCurrentCrsOption()
384 return tr(
"invalid projection" );
387 void QgsProjectionSelectionWidget::addRecentCrs()
395 if ( crsIsShown( srsid ) )
403 mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( (
long long )srsid ), Qt::UserRole + 1 );
408 bool QgsProjectionSelectionWidget::crsIsShown(
const long srsid )
const
410 return srsid == mLayerCrs.
srsid() || srsid == mDefaultCrs.
srsid() || srsid == mProjectCrs.
srsid();
413 int QgsProjectionSelectionWidget::firstRecentCrsIndex()
const
415 for (
int i = 0; i < mCrsComboBox->count(); ++i )
425 void QgsProjectionSelectionWidget::updateTooltip()
431 setToolTip( QString() );
434 QgsMapLayer *QgsProjectionSelectionWidget::mapLayerFromMimeData(
const QMimeData *data )
const