Skip to content

Commit b5465e0

Browse files
author
jef
committedApr 5, 2010
use list instead of buttons for popular/recent projections
git-svn-id: http://svn.osgeo.org/qgis/trunk@13253 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f82574f commit b5465e0

File tree

3 files changed

+159
-147
lines changed

3 files changed

+159
-147
lines changed
 

‎src/gui/qgsprojectionselector.cpp

Lines changed: 25 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
const int NAME_COLUMN = 0;
3535
const int AUTHID_COLUMN = 1;
3636
const int QGIS_CRS_ID_COLUMN = 2;
37-
const int POPULAR_CRSES = 3;
3837

3938
QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name, Qt::WFlags fl )
4039
: QWidget( parent, fl )
@@ -47,21 +46,24 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char * name
4746
setupUi( this );
4847
connect( lstCoordinateSystems, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
4948
this, SLOT( coordinateSystemSelected( QTreeWidgetItem* ) ) );
50-
connect( leSearch, SIGNAL( returnPressed() ), pbnFind, SLOT( animateClick() ) );
5149

5250
// Get the full path name to the sqlite3 spatial reference database.
5351
mSrsDatabaseFileName = QgsApplication::srsDbFilePath();
5452
lstCoordinateSystems->header()->setResizeMode( AUTHID_COLUMN, QHeaderView::Stretch );
5553
lstCoordinateSystems->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
5654
lstCoordinateSystems->header()->setResizeMode( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
5755

56+
lstRecent->header()->setResizeMode( AUTHID_COLUMN, QHeaderView::Stretch );
57+
lstRecent->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
58+
lstRecent->header()->setResizeMode( QGIS_CRS_ID_COLUMN, QHeaderView::Fixed );
59+
5860
cbxAuthority->addItem( tr( "All" ) );
5961
cbxAuthority->addItems( authorities() );
6062

6163
// Read settings from persistent storage
6264
QSettings settings;
6365
mRecentProjections = settings.value( "/UI/recentProjections" ).toStringList();
64-
/*** The reading (above) of internal id from persistent storage should be removed sometims in the future */
66+
/*** The reading (above) of internal id from persistent storage should be removed sometime in the future */
6567
/*** This is kept now for backwards compatibility */
6668

6769
QStringList projectionsEpsg = settings.value( "/UI/recentProjectionsEpsg" ).toStringList();
@@ -135,10 +137,13 @@ QgsProjectionSelector::~QgsProjectionSelector()
135137

136138
void QgsProjectionSelector::resizeEvent( QResizeEvent * theEvent )
137139
{
138-
139140
lstCoordinateSystems->header()->resizeSection( NAME_COLUMN, theEvent->size().width() - 240 );
140141
lstCoordinateSystems->header()->resizeSection( AUTHID_COLUMN, 240 );
141142
lstCoordinateSystems->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
143+
144+
lstRecent->header()->resizeSection( NAME_COLUMN, theEvent->size().width() - 240 );
145+
lstRecent->header()->resizeSection( AUTHID_COLUMN, 240 );
146+
lstRecent->header()->resizeSection( QGIS_CRS_ID_COLUMN, 0 );
142147
}
143148

144149
void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
@@ -171,43 +176,8 @@ void QgsProjectionSelector::showEvent( QShowEvent * theEvent )
171176
applyAuthIDSelection();
172177
}
173178

174-
// Update buttons
175-
pbnPopular1->setDisabled( true );
176-
pbnPopular2->setDisabled( true );
177-
pbnPopular3->setDisabled( true );
178-
pbnPopular4->setDisabled( true );
179-
pbnPopular1->hide();
180-
pbnPopular2->hide();
181-
pbnPopular3->hide();
182-
pbnPopular4->hide();
183-
184-
if ( mRecentProjections.size() > 0 )
185-
{
186-
pbnPopular1->setText( getCrsIdName( mRecentProjections.at( 0 ).toLong() ) );
187-
pbnPopular1->setDisabled( false );
188-
pbnPopular1->show();
189-
}
190-
191-
if ( mRecentProjections.size() > 1 )
192-
{
193-
pbnPopular2->setText( getCrsIdName( mRecentProjections.at( 1 ).toLong() ) );
194-
pbnPopular2->setDisabled( false );
195-
pbnPopular2->show();
196-
}
197-
198-
if ( mRecentProjections.size() > 2 )
199-
{
200-
pbnPopular3->setText( getCrsIdName( mRecentProjections.at( 2 ).toLong() ) );
201-
pbnPopular3->setDisabled( false );
202-
pbnPopular3->show();
203-
}
204-
205-
if ( mRecentProjections.size() > 3 )
206-
{
207-
pbnPopular4->setText( getCrsIdName( mRecentProjections.at( 3 ).toLong() ) );
208-
pbnPopular4->setDisabled( false );
209-
pbnPopular4->show();
210-
}
179+
for ( int i = mRecentProjections.size() - 1; i >= 0; i-- )
180+
insertRecent( mRecentProjections.at( i ).toLong() );
211181

212182
// Pass up the inheritance hierarchy
213183
QWidget::showEvent( theEvent );
@@ -347,26 +317,20 @@ void QgsProjectionSelector::applyCRSNameSelection()
347317
}
348318
}
349319

350-
QString QgsProjectionSelector::getCrsIdName( long theCrsId )
320+
void QgsProjectionSelector::insertRecent( long theCrsId )
351321
{
352-
QString retvalue( "" );
353-
if ( mProjListDone && mUserProjListDone )
354-
{
355-
QString myCRSIDString = QString::number( theCrsId );
322+
if ( !mProjListDone || !mUserProjListDone )
323+
return;
356324

357-
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( myCRSIDString, Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
325+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems( QString::number( theCrsId ), Qt::MatchExactly | Qt::MatchRecursive, QGIS_CRS_ID_COLUMN );
358326

359-
if ( nodes.count() > 0 )
360-
{
361-
retvalue = nodes.first()->text( NAME_COLUMN );
362-
if ( nodes.first()->text( AUTHID_COLUMN ) != "" )
363-
{
364-
retvalue += " " + nodes.first()->text( AUTHID_COLUMN );
365-
}
366-
}
367-
}
368-
return retvalue;
327+
if ( nodes.count() == 0 )
328+
return;
369329

330+
lstRecent->insertTopLevelItem( 0, new QTreeWidgetItem( lstRecent, QStringList()
331+
<< nodes.first()->text( NAME_COLUMN )
332+
<< nodes.first()->text( AUTHID_COLUMN )
333+
<< nodes.first()->text( QGIS_CRS_ID_COLUMN ) ) );
370334
}
371335

372336
void QgsProjectionSelector::applyAuthIDSelection()
@@ -889,6 +853,8 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem
889853
QString myProjString = selectedProj4String();
890854
lstCoordinateSystems->scrollToItem( theItem );
891855
teProjection->setText( myProjString );
856+
857+
lstRecent->clearSelection();
892858
}
893859
else
894860
{
@@ -920,24 +886,9 @@ void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged()
920886
hideDeprecated( lstCoordinateSystems->topLevelItem( i ) );
921887
}
922888

923-
void QgsProjectionSelector::on_pbnPopular1_clicked()
924-
{
925-
setSelectedCrsId( mRecentProjections.at( 0 ).toLong() );
926-
}
927-
928-
void QgsProjectionSelector::on_pbnPopular2_clicked()
929-
{
930-
setSelectedCrsId( mRecentProjections.at( 1 ).toLong() );
931-
}
932-
933-
void QgsProjectionSelector::on_pbnPopular3_clicked()
934-
{
935-
setSelectedCrsId( mRecentProjections.at( 2 ).toLong() );
936-
}
937-
938-
void QgsProjectionSelector::on_pbnPopular4_clicked()
889+
void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous )
939890
{
940-
setSelectedCrsId( mRecentProjections.at( 3 ).toLong() );
891+
setSelectedCrsId( current->text( QGIS_CRS_ID_COLUMN ).toLong() );
941892
}
942893

943894
void QgsProjectionSelector::on_pbnFind_clicked()

‎src/gui/qgsprojectionselector.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,9 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
110110
void setOgcWmsCrsFilter( QSet<QString> crsFilter );
111111

112112
void on_pbnFind_clicked();
113+
void on_lstRecent_currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * );
113114
void on_cbxHideDeprecated_stateChanged();
114115

115-
void on_pbnPopular1_clicked();
116-
void on_pbnPopular2_clicked();
117-
void on_pbnPopular3_clicked();
118-
void on_pbnPopular4_clicked();
119-
120116
protected:
121117
/** Used to ensure the projection list view is actually populated */
122118
void showEvent( QShowEvent * theEvent );
@@ -201,8 +197,8 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
201197
*/
202198
long getLargestCRSIDMatch( QString theSql );
203199

204-
//! Returns name from CRS Id
205-
QString getCrsIdName( long theCrsId );
200+
//! add recently used CRS
201+
void insertRecent( long theCrsId );
206202

207203
//! Has the Projection List been populated?
208204
bool mProjListDone;

‎src/ui/qgsprojectionselectorbase.ui

Lines changed: 131 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>374</width>
10-
<height>464</height>
9+
<width>590</width>
10+
<height>358</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -65,18 +65,6 @@
6565
</property>
6666
</widget>
6767
</item>
68-
<item row="3" column="0">
69-
<widget class="QPushButton" name="pbnPopular1"/>
70-
</item>
71-
<item row="4" column="0">
72-
<widget class="QPushButton" name="pbnPopular2"/>
73-
</item>
74-
<item row="5" column="0">
75-
<widget class="QPushButton" name="pbnPopular3"/>
76-
</item>
77-
<item row="6" column="0">
78-
<widget class="QPushButton" name="pbnPopular4"/>
79-
</item>
8068
<item row="0" column="0">
8169
<widget class="QTreeWidget" name="lstCoordinateSystems">
8270
<property name="alternatingRowColors">
@@ -116,67 +104,144 @@
116104
<property name="title">
117105
<string>Search</string>
118106
</property>
119-
<layout class="QGridLayout">
120-
<item row="1" column="1">
121-
<widget class="QComboBox" name="cbxMode">
107+
<layout class="QVBoxLayout" name="verticalLayout">
108+
<item>
109+
<layout class="QHBoxLayout" name="horizontalLayout_2">
122110
<item>
123-
<property name="text">
124-
<string>ID</string>
125-
</property>
111+
<widget class="QLabel" name="label">
112+
<property name="text">
113+
<string>Authority</string>
114+
</property>
115+
</widget>
126116
</item>
127117
<item>
128-
<property name="text">
129-
<string>Name</string>
130-
</property>
118+
<widget class="QComboBox" name="cbxAuthority"/>
131119
</item>
132-
</widget>
133-
</item>
134-
<item row="0" column="0">
135-
<widget class="QLabel" name="label">
136-
<property name="text">
137-
<string>Authority</string>
138-
</property>
139-
</widget>
140-
</item>
141-
<item row="0" column="1">
142-
<widget class="QComboBox" name="cbxAuthority"/>
143-
</item>
144-
<item row="1" column="0">
145-
<widget class="QLabel" name="label_2">
146-
<property name="text">
147-
<string>Search for</string>
148-
</property>
149-
</widget>
150-
</item>
151-
<item row="0" column="2">
152-
<widget class="QLineEdit" name="leSearch"/>
153-
</item>
154-
<item row="0" column="3">
155-
<widget class="QPushButton" name="pbnFind">
156-
<property name="maximumSize">
157-
<size>
158-
<width>100</width>
159-
<height>16777215</height>
160-
</size>
161-
</property>
162-
<property name="text">
163-
<string>Find</string>
164-
</property>
165-
<property name="default">
166-
<bool>true</bool>
167-
</property>
168-
</widget>
120+
<item>
121+
<widget class="QLabel" name="label_2">
122+
<property name="text">
123+
<string>Search for</string>
124+
</property>
125+
</widget>
126+
</item>
127+
<item>
128+
<widget class="QComboBox" name="cbxMode">
129+
<item>
130+
<property name="text">
131+
<string>ID</string>
132+
</property>
133+
</item>
134+
<item>
135+
<property name="text">
136+
<string>Name</string>
137+
</property>
138+
</item>
139+
</widget>
140+
</item>
141+
<item>
142+
<spacer name="horizontalSpacer">
143+
<property name="orientation">
144+
<enum>Qt::Horizontal</enum>
145+
</property>
146+
<property name="sizeHint" stdset="0">
147+
<size>
148+
<width>40</width>
149+
<height>20</height>
150+
</size>
151+
</property>
152+
</spacer>
153+
</item>
154+
<item>
155+
<widget class="QCheckBox" name="cbxHideDeprecated">
156+
<property name="text">
157+
<string>Hide deprecated CRSs</string>
158+
</property>
159+
</widget>
160+
</item>
161+
</layout>
169162
</item>
170-
<item row="1" column="2" colspan="2">
171-
<widget class="QCheckBox" name="cbxHideDeprecated">
172-
<property name="text">
173-
<string>Hide deprecated CRSs</string>
174-
</property>
175-
</widget>
163+
<item>
164+
<layout class="QHBoxLayout" name="horizontalLayout">
165+
<item>
166+
<widget class="QLineEdit" name="leSearch"/>
167+
</item>
168+
<item>
169+
<widget class="QPushButton" name="pbnFind">
170+
<property name="maximumSize">
171+
<size>
172+
<width>100</width>
173+
<height>16777215</height>
174+
</size>
175+
</property>
176+
<property name="text">
177+
<string>Find</string>
178+
</property>
179+
<property name="default">
180+
<bool>true</bool>
181+
</property>
182+
</widget>
183+
</item>
184+
</layout>
176185
</item>
177186
</layout>
178187
</widget>
179188
</item>
189+
<item row="3" column="0">
190+
<widget class="QLabel" name="label_3">
191+
<property name="text">
192+
<string>Recently used coordinate references systems</string>
193+
</property>
194+
</widget>
195+
</item>
196+
<item row="4" column="0">
197+
<widget class="QTreeWidget" name="lstRecent">
198+
<property name="sizePolicy">
199+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
200+
<horstretch>0</horstretch>
201+
<verstretch>0</verstretch>
202+
</sizepolicy>
203+
</property>
204+
<property name="minimumSize">
205+
<size>
206+
<width>0</width>
207+
<height>105</height>
208+
</size>
209+
</property>
210+
<property name="maximumSize">
211+
<size>
212+
<width>16777215</width>
213+
<height>105</height>
214+
</size>
215+
</property>
216+
<property name="alternatingRowColors">
217+
<bool>true</bool>
218+
</property>
219+
<property name="rootIsDecorated">
220+
<bool>false</bool>
221+
</property>
222+
<property name="uniformRowHeights">
223+
<bool>true</bool>
224+
</property>
225+
<property name="columnCount">
226+
<number>3</number>
227+
</property>
228+
<column>
229+
<property name="text">
230+
<string>Coordinate Reference System</string>
231+
</property>
232+
</column>
233+
<column>
234+
<property name="text">
235+
<string>Authority ID</string>
236+
</property>
237+
</column>
238+
<column>
239+
<property name="text">
240+
<string>ID</string>
241+
</property>
242+
</column>
243+
</widget>
244+
</item>
180245
</layout>
181246
</widget>
182247
<layoutdefault spacing="6" margin="11"/>

0 commit comments

Comments
 (0)
Please sign in to comment.