Skip to content

Commit 34ccc34

Browse files
committed
Merge pull request #2580 from nirvn/projection_selector_dbl_click_v5
[projection selector] apply selected projection on double click
2 parents 576875e + 8a40dda commit 34ccc34

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

python/gui/qgsprojectionselector.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ class QgsProjectionSelector : QWidget
105105
//! Notify others that the widget is now fully initialized, including deferred selection of projection
106106
//! @note added in 2.4
107107
void initialized();
108+
//! Apply projection on double click
109+
//! @note added in 2.14
110+
void projectionDoubleClicked();
108111
};

src/gui/qgsgenericprojectionselector.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ QgsGenericProjectionSelector::QgsGenericProjectionSelector( QWidget *parent,
3636

3737
//we will show this only when a message is set
3838
textEdit->hide();
39+
40+
//apply selected projection upon double click on item
41+
connect( projectionSelector, SIGNAL( projectionDoubleClicked() ), this, SLOT( accept() ) );
3942
}
4043

4144
void QgsGenericProjectionSelector::setMessage( QString theMessage )

src/gui/qgsprojectionselector.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsapplication.h"
1919
#include "qgslogger.h"
2020
#include "qgscoordinatereferencesystem.h"
21+
#include "qgsmessagelog.h"
2122

2223
//qt includes
2324
#include <QFileInfo>
@@ -718,6 +719,24 @@ void QgsProjectionSelector::on_lstCoordinateSystems_currentItemChanged( QTreeWid
718719
}
719720
}
720721

722+
void QgsProjectionSelector::on_lstCoordinateSystems_itemDoubleClicked( QTreeWidgetItem *current, int column )
723+
{
724+
Q_UNUSED( column );
725+
726+
QgsDebugMsg( "Entered." );
727+
728+
if ( !current )
729+
{
730+
QgsDebugMsg( "no current item" );
731+
return;
732+
}
733+
734+
// If the item has children, it's not an end node in the tree, and
735+
// hence is just a grouping thingy, not an actual CRS.
736+
if ( current->childCount() == 0 )
737+
emit projectionDoubleClicked();
738+
}
739+
721740
void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * )
722741
{
723742
QgsDebugMsg( "Entered." );
@@ -735,6 +754,23 @@ void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *cu
735754
lstCoordinateSystems->setCurrentItem( nodes.first() );
736755
}
737756

757+
void QgsProjectionSelector::on_lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column )
758+
{
759+
Q_UNUSED( column );
760+
761+
QgsDebugMsg( "Entered." );
762+
763+
if ( !current )
764+
{
765+
QgsDebugMsg( "no current item" );
766+
return;
767+
}
768+
769+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( current->text( QGIS_CRS_ID_COLUMN ), Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
770+
if ( !nodes.isEmpty() )
771+
emit projectionDoubleClicked();
772+
}
773+
738774
void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item )
739775
{
740776
if ( item->data( 0, Qt::UserRole ).toBool() )

src/gui/qgsprojectionselector.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjecti
192192
//! Most recently used projections (trimmed at 25 entries)
193193
QStringList mRecentProjections;
194194

195-
//! hide deprecated CRSes
195+
//! Hide deprecated CRSes
196196
void hideDeprecated( QTreeWidgetItem *item );
197197

198+
//! Apply projection on double click
199+
void on_lstCoordinateSystems_itemDoubleClicked( QTreeWidgetItem *current, int column );
200+
void on_lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column );
201+
198202
private slots:
199203
//! get list of authorities
200204
QStringList authorities();
@@ -208,6 +212,9 @@ class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjecti
208212
//! Notify others that the widget is now fully initialized, including deferred selection of projection
209213
//! @note added in 2.4
210214
void initialized();
215+
//! Apply projection on double click
216+
//! @note added in 2.14
217+
void projectionDoubleClicked();
211218
};
212219

213220
#endif

0 commit comments

Comments
 (0)