QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsprojectionselectiontreewidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * qgsprojectionselector.cpp *
3 * Copyright (C) 2005 by Tim Sutton *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
12
13//standard includes
14#include <sqlite3.h>
15
16//qgis includes
17#include "qgis.h" //magic numbers here
18#include "qgsapplication.h"
19#include "qgslogger.h"
21#include "qgssettings.h"
22#include "qgsrectangle.h"
23#include "qgsdatums.h"
24#include "qgsprojoperation.h"
25#include "qgsstringutils.h"
26#include "qgsunittypes.h"
28
29//qt includes
30#include <QAction>
31#include <QToolButton>
32#include <QMenu>
33#include <QFileInfo>
34#include <QHeaderView>
35#include <QResizeEvent>
36#include <QMessageBox>
37#include <QRegularExpression>
38
39QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *parent, QgsCoordinateReferenceSystemProxyModel::Filters filters )
40 : QWidget( parent )
41{
42 setupUi( this );
43
44 mCrsModel = new QgsCoordinateReferenceSystemProxyModel( this );
45 mCrsModel->setFilters( filters );
46
47 lstCoordinateSystems->setModel( mCrsModel );
48 lstCoordinateSystems->setSelectionBehavior( QAbstractItemView::SelectRows );
49
50 QFont f = teProjection->font();
51 f.setPointSize( f.pointSize() - 2 );
52 teProjection->setFont( f );
53
54 leSearch->setShowSearchIcon( true );
55
56 connect( lstCoordinateSystems, &QTreeView::doubleClicked, this, &QgsProjectionSelectionTreeWidget::lstCoordinateSystemsDoubleClicked );
57 connect( lstRecent, &QTreeWidget::itemDoubleClicked, this, &QgsProjectionSelectionTreeWidget::lstRecent_itemDoubleClicked );
58 connect( lstCoordinateSystems->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsProjectionSelectionTreeWidget::lstCoordinateSystemsSelectionChanged );
59 connect( lstRecent, &QTreeWidget::currentItemChanged, this, &QgsProjectionSelectionTreeWidget::lstRecent_currentItemChanged );
60 connect( cbxHideDeprecated, &QCheckBox::toggled, this, [ = ]( bool selected )
61 {
62 mCrsModel->setFilterDeprecated( selected );
63 filterRecentCrsList();
64 } );
65 connect( leSearch, &QgsFilterLineEdit::textChanged, this, [ = ]( const QString & filter )
66 {
67 mCrsModel->setFilterString( filter );
68 filterRecentCrsList();
69 } );
70
71 mAreaCanvas->setVisible( mShowMap );
72
73 lstCoordinateSystems->header()->setSectionResizeMode( AuthidColumn, QHeaderView::Stretch );
74
75 // Hide (internal) ID column
76 lstRecent->header()->setSectionResizeMode( AuthidColumn, QHeaderView::Stretch );
77 lstRecent->header()->resizeSection( QgisCrsIdColumn, 0 );
78 lstRecent->header()->setSectionResizeMode( QgisCrsIdColumn, QHeaderView::Fixed );
79 lstRecent->setColumnHidden( QgisCrsIdColumn, true );
80
81 // Clear Crs Column
82 lstRecent->header()->setMinimumSectionSize( 10 );
83 lstRecent->header()->setStretchLastSection( false );
84 lstRecent->header()->resizeSection( ClearColumn, 20 );
85
86 // Clear recent crs context menu
87 lstRecent->setContextMenuPolicy( Qt::CustomContextMenu );
88 connect( lstRecent, &QTreeWidget::customContextMenuRequested, this, [this]( const QPoint & pos )
89 {
90 // If list is empty, do nothing
91 if ( lstRecent->topLevelItemCount() == 0 )
92 return;
93 QMenu menu;
94 // Clear selected
95 QTreeWidgetItem *currentItem = lstRecent->itemAt( pos );
96 if ( currentItem )
97 {
98 QAction *clearSelected = menu.addAction( QgsApplication::getThemeIcon( "/mIconClearItem.svg" ), tr( "Remove Selected CRS from Recently Used CRS" ) );
99 connect( clearSelected, &QAction::triggered, this, [this, currentItem ] { removeRecentCrsItem( currentItem ); } );
100 menu.addSeparator();
101 }
102 // Clear all
103 QAction *clearAll = menu.addAction( QgsApplication::getThemeIcon( "/console/iconClearConsole.svg" ), tr( "Clear All Recently Used CRS" ) );
104 connect( clearAll, &QAction::triggered, this, &QgsProjectionSelectionTreeWidget::clearRecentCrs );
105 menu.exec( lstRecent->viewport()->mapToGlobal( pos ) );
106 } );
107
108 // Install event fiter to catch delete key press on the recent crs list
109 lstRecent->installEventFilter( this );
110
112 for ( const QgsCoordinateReferenceSystem &crs : std::as_const( mRecentProjections ) )
113 {
114 insertRecent( crs );
115 }
116
117 mCheckBoxNoProjection->setHidden( true );
118 mCheckBoxNoProjection->setEnabled( false );
119 connect( mCheckBoxNoProjection, &QCheckBox::toggled, this, [ = ]
120 {
121 if ( !mBlockSignals )
122 {
123 emit crsSelected();
125 }
126 } );
127 connect( mCheckBoxNoProjection, &QCheckBox::toggled, this, [ = ]( bool checked )
128 {
129 if ( mCheckBoxNoProjection->isEnabled() )
130 {
131 mFrameProjections->setDisabled( checked );
132 }
133 } );
134
135 QgsSettings settings;
136 mSplitter->restoreState( settings.value( QStringLiteral( "Windows/ProjectionSelector/splitterState" ) ).toByteArray() );
137}
138
140{
141 QgsSettings settings;
142 settings.setValue( QStringLiteral( "Windows/ProjectionSelector/splitterState" ), mSplitter->saveState() );
143
144 // Push current projection to front, only if set
145 const QgsCoordinateReferenceSystem selectedCrs = crs();
146 if ( selectedCrs.isValid() )
148}
149
151{
152 lstCoordinateSystems->header()->resizeSection( NameColumn, event->size().width() - 240 );
153 lstCoordinateSystems->header()->resizeSection( AuthidColumn, 240 );
154 lstCoordinateSystems->header()->resizeSection( QgisCrsIdColumn, 0 );
155
156 lstRecent->header()->resizeSection( NameColumn, event->size().width() - 260 );
157 lstRecent->header()->resizeSection( AuthidColumn, 240 );
158 lstRecent->header()->resizeSection( QgisCrsIdColumn, 0 );
159 lstRecent->header()->resizeSection( ClearColumn, 20 );
160}
161
162bool QgsProjectionSelectionTreeWidget::eventFilter( QObject *obj, QEvent *ev )
163{
164 if ( obj != lstRecent )
165 return false;
166
167 if ( ev->type() != QEvent::KeyPress )
168 return false;
169
170 QKeyEvent *keyEvent = static_cast<QKeyEvent *>( ev );
171 if ( keyEvent->matches( QKeySequence::Delete ) )
172 {
173 removeRecentCrsItem( lstRecent->currentItem() );
174 return true;
175 }
176
177 return false;
178}
179
180void QgsProjectionSelectionTreeWidget::selectCrsByAuthId( const QString &authid )
181{
182 const QModelIndex sourceIndex = mCrsModel->coordinateReferenceSystemModel()->authIdToIndex( authid );
183 if ( !sourceIndex.isValid() )
184 return;
185
186 const QModelIndex proxyIndex = mCrsModel->mapFromSource( sourceIndex );
187 if ( proxyIndex.isValid() )
188 {
189 lstCoordinateSystems->selectionModel()->select( proxyIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
190 lstCoordinateSystems->scrollTo( proxyIndex );
191 }
192 else
193 {
194 // deselect the selected item to avoid confusing the user
195 lstCoordinateSystems->clearSelection();
196 lstRecent->clearSelection();
197 teProjection->clear();
198 }
199}
200
201void QgsProjectionSelectionTreeWidget::insertRecent( const QgsCoordinateReferenceSystem &crs )
202{
203 const QModelIndex sourceIndex = mCrsModel->coordinateReferenceSystemModel()->authIdToIndex( crs.authid() );
204 if ( !sourceIndex.isValid() )
205 return;
206
207 QTreeWidgetItem *item = new QTreeWidgetItem( lstRecent, QStringList()
208 << sourceIndex.data( QgsCoordinateReferenceSystemModel::RoleName ).toString()
209 << sourceIndex.data( QgsCoordinateReferenceSystemModel::RoleAuthId ).toString() );
210
211 // Insert clear button in the last column
212 QToolButton *clearButton = new QToolButton();
213 clearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClearItem.svg" ) );
214 clearButton->setAutoRaise( true );
215 clearButton->setToolTip( tr( "Remove from recently used CRS" ) );
216 connect( clearButton, &QToolButton::clicked, this, [this, item] { removeRecentCrsItem( item ); } );
217 lstRecent->setItemWidget( item, ClearColumn, clearButton );
218
219 lstRecent->insertTopLevelItem( 0, item );
220}
221
223{
224 if ( !crs.isValid() )
225 {
226 mCheckBoxNoProjection->setChecked( true );
227 }
228 else
229 {
230 mBlockSignals = true;
231 mCheckBoxNoProjection->setChecked( false );
232 mBlockSignals = false;
233
234 if ( !crs.authid().isEmpty() )
235 selectCrsByAuthId( crs.authid() );
236 else
237 loadUnknownCrs( crs );
238
239 const bool changed = crs != QgsProjectionSelectionTreeWidget::crs();
240 if ( changed )
241 {
242 emit crsSelected();
244 }
245 }
246}
247
249{
250 mAreaCanvas->setCanvasRect( rect );
251}
252
254{
255 return mAreaCanvas->canvasRect();
256}
257
258QgsCoordinateReferenceSystemProxyModel::Filters QgsProjectionSelectionTreeWidget::filters() const
259{
260 return mCrsModel->filters();
261}
262
263void QgsProjectionSelectionTreeWidget::setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters )
264{
265 mCrsModel->setFilters( filters );
266}
267
269{
270 if ( mCheckBoxNoProjection->isEnabled() && mCheckBoxNoProjection->isChecked() )
272
273 const QModelIndex currentIndex = lstCoordinateSystems->selectionModel()->selectedRows( 0 ).value( 0 );
274 const QString authid = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleAuthId ).toString();
275 if ( !authid.isEmpty() )
276 {
278 }
279 else
280 {
281 // custom CRS
282 const QString wkt = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleWkt ).toString();
283 const QString proj = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleProj ).toString();
284
285 if ( !wkt.isEmpty() )
287 else if ( !proj.isEmpty() )
289 else
291 }
292}
293
295{
296 mCheckBoxNoProjection->setVisible( show );
297 mCheckBoxNoProjection->setEnabled( show );
298 if ( show )
299 {
300 mFrameProjections->setDisabled( mCheckBoxNoProjection->isChecked() );
301 }
302}
303
305{
306 mShowMap = show;
307 mAreaCanvas->setVisible( show );
308}
309
311{
312 return !mCheckBoxNoProjection->isHidden();
313}
314
316{
317 mCheckBoxNoProjection->setText( text );
318}
319
321{
322 return mShowMap;
323}
324
326{
327 if ( mCheckBoxNoProjection->isChecked() )
328 {
329 return true;
330 }
331 else
332 {
333 const QModelIndex currentIndex = lstCoordinateSystems->selectionModel()->selectedRows( 0 ).value( 0 );
334 const QString authid = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleAuthId ).toString();
335 const QString wkt = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleWkt ).toString();
336 const QString proj = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleProj ).toString();
337 return !authid.isEmpty() || !wkt.isEmpty() || !proj.isEmpty();
338 }
339}
340
341void QgsProjectionSelectionTreeWidget::setOgcWmsCrsFilter( const QSet<QString> &crsFilter )
342{
343 mCrsModel->setFilterAuthIds( crsFilter );
344}
345
346void QgsProjectionSelectionTreeWidget::loadUnknownCrs( const QgsCoordinateReferenceSystem &crs )
347{
348 const QModelIndex sourceIndex = mCrsModel->coordinateReferenceSystemModel()->addCustomCrs( crs );
349 lstCoordinateSystems->selectionModel()->select( mCrsModel->mapFromSource( sourceIndex ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
350 lstCoordinateSystems->scrollTo( mCrsModel->mapFromSource( sourceIndex ) );
351}
352
353// New coordinate system selected from the list
354void QgsProjectionSelectionTreeWidget::lstCoordinateSystemsSelectionChanged( const QItemSelection &selected, const QItemSelection & )
355{
356 if ( selected.isEmpty() )
357 {
358 QgsDebugMsgLevel( QStringLiteral( "no current item" ), 4 );
359 return;
360 }
361
362 const QModelIndex selectedProxyIndex = lstCoordinateSystems->selectionModel()->selectedRows( 0 ).value( 0 );
363 if ( !selectedProxyIndex.isValid() )
364 return;
365
366 lstCoordinateSystems->scrollTo( selectedProxyIndex );
367 const QModelIndex sourceIndex = mCrsModel->mapToSource( selectedProxyIndex );
368
369 // If the item has children, it's not an end node in the tree, and
370 // hence is just a grouping thingy, not an actual CRS.
371 if ( mCrsModel->coordinateReferenceSystemModel()->rowCount( sourceIndex ) == 0 )
372 {
373 // Found a real CRS
374 if ( !mBlockSignals )
375 {
376 emit crsSelected();
377 emit hasValidSelectionChanged( true );
378 }
379
380 updateBoundsPreview();
381
382 const QString crsAuthId = mCrsModel->coordinateReferenceSystemModel()->data( sourceIndex, QgsCoordinateReferenceSystemModel::RoleAuthId ).toString();
383 if ( !crsAuthId.isEmpty() )
384 {
385 QList<QTreeWidgetItem *> nodes = lstRecent->findItems( crsAuthId, Qt::MatchExactly, AuthidColumn );
386 if ( !nodes.isEmpty() )
387 {
388 QgsDebugMsgLevel( QStringLiteral( "found srs %1 in recent" ).arg( crsAuthId ), 4 );
389 lstRecent->setCurrentItem( nodes.first() );
390 }
391 else
392 {
393 QgsDebugMsgLevel( QStringLiteral( "srs %1 not recent" ).arg( crsAuthId ), 4 );
394 lstRecent->clearSelection();
395 lstCoordinateSystems->setFocus( Qt::OtherFocusReason );
396 }
397 }
398 else
399 {
400 lstRecent->clearSelection();
401 lstCoordinateSystems->setFocus( Qt::OtherFocusReason );
402 }
403 }
404 else
405 {
406 // Not a CRS
407 teProjection->clear();
408 lstRecent->clearSelection();
409 emit hasValidSelectionChanged( false );
410 }
411}
412
413void QgsProjectionSelectionTreeWidget::lstCoordinateSystemsDoubleClicked( const QModelIndex &index )
414{
415 if ( !index.isValid() )
416 {
417 QgsDebugMsgLevel( QStringLiteral( "no current item" ), 4 );
418 return;
419 }
420
421 // If the item has children, it's not an end node in the tree, and
422 // hence is just a grouping thingy, not an actual CRS.
423 if ( !mCrsModel->coordinateReferenceSystemModel()->hasChildren( mCrsModel->mapToSource( index ) ) )
425}
426
427void QgsProjectionSelectionTreeWidget::lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * )
428{
429 QgsDebugMsgLevel( QStringLiteral( "Entered." ), 4 );
430
431 if ( !current )
432 {
433 QgsDebugMsgLevel( QStringLiteral( "no current item" ), 4 );
434 return;
435 }
436
437 lstRecent->scrollToItem( current );
438
439 const QString selectedAuthId = current->text( AuthidColumn );
440 const QModelIndex sourceIndex = mCrsModel->coordinateReferenceSystemModel()->authIdToIndex( selectedAuthId );
441 if ( sourceIndex.isValid() )
442 {
443 const QModelIndex proxyIndex = mCrsModel->mapFromSource( sourceIndex );
444 if ( proxyIndex.isValid() )
445 {
446 lstCoordinateSystems->selectionModel()->select( proxyIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
447 lstCoordinateSystems->scrollTo( proxyIndex );
448 }
449 }
450}
451
452void QgsProjectionSelectionTreeWidget::lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column )
453{
454 Q_UNUSED( column )
455
456 QgsDebugMsgLevel( QStringLiteral( "Entered." ), 4 );
457
458 if ( !current )
459 {
460 QgsDebugMsgLevel( QStringLiteral( "no current item" ), 4 );
461 return;
462 }
463
464 const QString selectedAuthId = current->text( AuthidColumn );
465 const QModelIndex sourceIndex = mCrsModel->coordinateReferenceSystemModel()->authIdToIndex( selectedAuthId );
466 if ( sourceIndex.isValid() )
467 {
468 const QModelIndex proxyIndex = mCrsModel->mapFromSource( sourceIndex );
469 if ( proxyIndex.isValid() )
470 {
472 }
473 }
474}
475
476void QgsProjectionSelectionTreeWidget::filterRecentCrsList()
477{
478 QString filterTxtCopy = QgsStringUtils::qRegExpEscape( leSearch->text() );
479 const thread_local QRegularExpression filterRx( QStringLiteral( "\\s+" ) );
480 filterTxtCopy.replace( filterRx, QStringLiteral( ".*" ) );
481 const QRegularExpression re( filterTxtCopy, QRegularExpression::PatternOption::CaseInsensitiveOption );
482
483 const bool hideDeprecated = cbxHideDeprecated->isChecked();
484
485 QTreeWidgetItemIterator itr( lstRecent );
486 while ( *itr )
487 {
488 if ( ( *itr )->childCount() == 0 ) // it's an end node aka a projection
489 {
490 if ( hideDeprecated && ( *itr )->data( 0, RoleDeprecated ).toBool() )
491 {
492 ( *itr )->setHidden( true );
493 if ( ( *itr )->isSelected() )
494 {
495 ( *itr )->setSelected( false );
496 teProjection->clear();
497 }
498 }
499 else if ( ( *itr )->text( NameColumn ).contains( re )
500 || ( *itr )->text( AuthidColumn ).contains( re )
501 )
502 {
503 ( *itr )->setHidden( false );
504 QTreeWidgetItem *parent = ( *itr )->parent();
505 while ( parent )
506 {
507 parent->setExpanded( true );
508 parent->setHidden( false );
509 parent = parent->parent();
510 }
511 }
512 else
513 {
514 ( *itr )->setHidden( true );
515 }
516 }
517 else
518 {
519 ( *itr )->setHidden( true );
520 }
521 ++itr;
522 }
523}
524
528
529void QgsProjectionSelectionTreeWidget::updateBoundsPreview()
530{
531 const QgsCoordinateReferenceSystem currentCrs = crs();
532 if ( !currentCrs.isValid() )
533 return;
534
535 QgsRectangle rect = currentCrs.bounds();
536 QString extentString = tr( "Extent not known" );
537 mAreaCanvas->setPreviewRect( rect );
538 if ( !qgsDoubleNear( rect.area(), 0.0 ) )
539 {
540 extentString = QStringLiteral( "%1, %2, %3, %4" )
541 .arg( rect.xMinimum(), 0, 'f', 2 )
542 .arg( rect.yMinimum(), 0, 'f', 2 )
543 .arg( rect.xMaximum(), 0, 'f', 2 )
544 .arg( rect.yMaximum(), 0, 'f', 2 );
545 }
546
547 QStringList properties;
548 if ( currentCrs.isGeographic() )
549 properties << tr( "Geographic (uses latitude and longitude for coordinates)" );
550 else
551 {
552 properties << tr( "Units: %1" ).arg( QgsUnitTypes::toString( currentCrs.mapUnits() ) );
553 }
554 properties << ( currentCrs.isDynamic() ? tr( "Dynamic (relies on a datum which is not plate-fixed)" ) : tr( "Static (relies on a datum which is plate-fixed)" ) );
555
556 try
557 {
558 const QString celestialBody = currentCrs.celestialBodyName();
559 if ( !celestialBody.isEmpty() )
560 {
561 properties << tr( "Celestial body: %1" ).arg( celestialBody );
562 }
563 }
564 catch ( QgsNotSupportedException & )
565 {
566
567 }
568
569 try
570 {
571 const QgsDatumEnsemble ensemble = currentCrs.datumEnsemble();
572 if ( ensemble.isValid() )
573 {
574 QString id;
575 if ( !ensemble.code().isEmpty() )
576 id = QStringLiteral( "<i>%1</i> (%2:%3)" ).arg( ensemble.name(), ensemble.authority(), ensemble.code() );
577 else
578 id = QStringLiteral( "<i>%</i>”" ).arg( ensemble.name() );
579 if ( ensemble.accuracy() > 0 )
580 {
581 properties << tr( "Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg( id ).arg( ensemble.accuracy() );
582 }
583 else
584 {
585 properties << tr( "Based on %1, which has a limited accuracy." ).arg( id );
586 }
587 }
588 }
589 catch ( QgsNotSupportedException & )
590 {
591
592 }
593
594 const QgsProjOperation operation = currentCrs.operation();
595 properties << tr( "Method: %1" ).arg( operation.description() );
596
597 const QString propertiesString = QStringLiteral( "<dt><b>%1</b></dt><dd><ul><li>%2</li></ul></dd>" ).arg( tr( "Properties" ),
598 properties.join( QLatin1String( "</li><li>" ) ) );
599
600 const QString extentHtml = QStringLiteral( "<dt><b>%1</b></dt><dd>%2</dd>" ).arg( tr( "Extent" ), extentString );
601 const QString wktString = QStringLiteral( "<dt><b>%1</b></dt><dd><code>%2</code></dd>" ).arg( tr( "WKT" ), currentCrs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED, true ).replace( '\n', QLatin1String( "<br>" ) ).replace( ' ', QLatin1String( "&nbsp;" ) ) );
602 const QString proj4String = QStringLiteral( "<dt><b>%1</b></dt><dd><code>%2</code></dd>" ).arg( tr( "Proj4" ), currentCrs.toProj() );
603
604#ifdef Q_OS_WIN
605 const int smallerPointSize = std::max( font().pointSize() - 1, 8 ); // bit less on windows, due to poor rendering of small point sizes
606#else
607 const int smallerPointSize = std::max( font().pointSize() - 2, 6 );
608#endif
609
610 const QModelIndex currentIndex = lstCoordinateSystems->selectionModel()->selectedRows( 0 ).value( 0 );
611 QString selectedName;
612 if ( currentIndex.isValid() )
613 {
614 selectedName = currentIndex.data( QgsCoordinateReferenceSystemModel::RoleName ).toString();
615 }
616 teProjection->setText( QStringLiteral( "<div style=\"font-size: %1pt\"><h3>%2</h3><dl>" ).arg( smallerPointSize ).arg( selectedName ) + propertiesString + wktString + proj4String + extentHtml + QStringLiteral( "</dl></div>" ) );
617}
618
620{
621 // If the list is empty, there is nothing to do
622 if ( lstRecent->topLevelItemCount() == 0 )
623 {
624 return;
625 }
626
627 // Ask for confirmation
628 if ( QMessageBox::question( this, tr( "Clear Recent CRS" ),
629 tr( "Are you sure you want to clear the list of recently used coordinate reference system?" ),
630 QMessageBox::Yes | QMessageBox::No ) != QMessageBox::Yes )
631 {
632 return;
633 }
635 lstRecent->clear();
636}
637
638void QgsProjectionSelectionTreeWidget::removeRecentCrsItem( QTreeWidgetItem *item )
639{
640 if ( !item )
641 return;
642
643 int index = lstRecent->indexOfTopLevelItem( item );
644 if ( index == -1 )
645 return;
646
647 const QString selectedAuthId = item->text( AuthidColumn );
648 if ( !selectedAuthId.isEmpty() )
649 {
650 const QgsCoordinateReferenceSystem crs( selectedAuthId );
652 }
653 lstRecent->takeTopLevelItem( index );
654 delete item;
655}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex addCustomCrs(const QgsCoordinateReferenceSystem &crs)
Adds a custom crs to the model.
@ RoleProj
The coordinate reference system's PROJ representation. This is only used for non-standard CRS (i....
@ RoleName
The coordinate reference system name.
@ RoleWkt
The coordinate reference system's WKT representation. This is only used for non-standard CRS (i....
@ RoleAuthId
The coordinate reference system authority name and id.
QModelIndex authIdToIndex(const QString &authId) const
Retrieves the model index corresponding to a CRS with the specified authId.
QVariant data(const QModelIndex &index, int role) const override
A sort/filter proxy model for coordinate reference systems.
void setFilterDeprecated(bool filter)
Sets whether deprecated CRS should be filtered from the results.
Filters filters() const
Returns any filters that affect how CRS are filtered.
QgsCoordinateReferenceSystemModel * coordinateReferenceSystemModel()
Returns the underlying source model.
void setFilterString(const QString &filter)
Sets a filter string, such that only coordinate reference systems matching the specified string will ...
void setFilterAuthIds(const QSet< QString > &filter)
Sets a filter list of CRS auth ID strings, such that only coordinate reference systems matching the s...
void setFilters(QgsCoordinateReferenceSystemProxyModel::Filters filters)
Set filters that affect how CRS are filtered.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsRectangle bounds() const
Returns the approximate bounds for the region the CRS is usable within.
QString toProj() const
Returns a Proj string representation of this CRS.
static void pushRecentCoordinateReferenceSystem(const QgsCoordinateReferenceSystem &crs)
Pushes a recently used CRS to the top of the recent CRS list.
static void removeRecentCoordinateReferenceSystem(const QgsCoordinateReferenceSystem &crs)
Removes a CRS from the list of recently used CRS.
QgsDatumEnsemble datumEnsemble() const
Attempts to retrieve datum ensemble details from the CRS.
bool isDynamic() const
Returns true if the CRS is a dynamic CRS.
static QgsCoordinateReferenceSystem fromProj(const QString &proj)
Creates a CRS from a proj style formatted string.
static QList< QgsCoordinateReferenceSystem > recentCoordinateReferenceSystems()
Returns a list of recently used CRS.
static void clearRecentCoordinateReferenceSystems()
Cleans the list of recently used CRS.
QString celestialBodyName() const
Attempts to retrieve the name of the celestial body associated with the CRS (e.g.
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
static QgsCoordinateReferenceSystem fromWkt(const QString &wkt)
Creates a CRS from a WKT spatial ref sys definition string.
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
QgsProjOperation operation() const
Returns information about the PROJ operation associated with the coordinate reference system,...
Contains information about a datum ensemble.
Definition qgsdatums.h:95
QString code() const
Identification code, e.g.
Definition qgsdatums.h:122
QString authority() const
Authority name, e.g.
Definition qgsdatums.h:117
bool isValid() const
Returns true if the datum ensemble is a valid object, or false if it is a null/invalid object.
Definition qgsdatums.h:102
QString name() const
Display name of datum ensemble.
Definition qgsdatums.h:107
double accuracy() const
Positional accuracy (in meters).
Definition qgsdatums.h:112
Custom exception class which is raised when an operation is not supported.
Contains information about a PROJ operation.
QString description() const
Description.
void resizeEvent(QResizeEvent *event) override
void setPreviewRect(const QgsRectangle &rect)
Sets the initial "preview" rectangle for the bounds overview map.
void setShowBoundsMap(bool show)
Sets whether to show the bounds preview map.
void crsSelected()
Emitted when a projection is selected in the widget.
Q_DECL_DEPRECATED void pushProjectionToFront()
Marks the current selected projection for push to front of recent projections list.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
bool showNoProjection() const
Returns whether the "no/invalid" projection option is shown.
void setShowNoProjection(bool show)
Sets whether a "no/invalid" projection option should be shown.
bool showBoundsMap() const
Returns whether the bounds preview map is shown.
QgsRectangle previewRect() const
The initial "preview" rectangle for the bounds overview map.
void projectionDoubleClicked()
Emitted when a projection is double clicked in the list.
bool hasValidSelection() const
Returns true if the current selection in the widget is a valid choice.
QgsCoordinateReferenceSystemProxyModel::Filters filters() const
Returns the filters set on the available CRS.
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
Filters this widget by the given CRSs.
void setFilters(QgsCoordinateReferenceSystemProxyModel::Filters filters)
Sets filters for the available CRS.
bool eventFilter(QObject *obj, QEvent *ev) override
void setNotSetText(const QString &text)
Sets the text to show for the not set option.
void clearRecentCrs()
Clear the list of recent projections.
QgsProjectionSelectionTreeWidget(QWidget *parent=nullptr, QgsCoordinateReferenceSystemProxyModel::Filters filters=QgsCoordinateReferenceSystemProxyModel::FilterHorizontal|QgsCoordinateReferenceSystemProxyModel::FilterCompound)
Constructor for QgsProjectionSelectionTreeWidget, with the specified parent widget.
void hasValidSelectionChanged(bool isValid)
Emitted when the selection in the tree is changed from a valid selection to an invalid selection,...
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
A rectangle specified with double values.
double area() const
Returns the area of the rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
This class is a composition of two QSettings instances:
Definition qgssettings.h:63
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QString qRegExpEscape(const QString &string)
Returns an escaped string matching the behavior of QRegExp::escape.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:4332
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
const QgsCoordinateReferenceSystem & crs