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 )
422 void QgsProjectionSelectionWidget::updateTooltip()
428 setToolTip( QString() );
431 QgsMapLayer *QgsProjectionSelectionWidget::mapLayerFromMimeData(
const QMimeData *data )
const