Skip to content

Commit b134c2d

Browse files
author
morb_au
committed
Better fix for the issues raised in r5618 and r5626 - the selected item is now scrolled into view, even when the projection selector is being opened.
There still seems to be a slight issue when showing the Project Properties for the first time on a blank project (i.e. it scrolls *near* the WGS 84 entry, but not quite on top of it), but I'll leave that for another time. Other situations now seem to work OK. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5642 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6dc7628 commit b134c2d

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

src/widgets/projectionselector/qgsprojectionselector.cpp

+27-40
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ void QgsProjectionSelector::showEvent ( QShowEvent * theEvent )
7373
applyUserProjList(&mCrsFilter);
7474
}
7575

76+
// check if a paricular projection is waiting
77+
// to be pre-selected, and if so, to select it now.
78+
if (mSRSNameSelectionPending)
79+
{
80+
applySRSNameSelection();
81+
}
82+
if (mSRSIDSelectionPending)
83+
{
84+
applySRSIDSelection();
85+
}
86+
7687
// Pass up the inheritance heirarchy
7788
QWidget::showEvent(theEvent);
7889
}
@@ -146,43 +157,33 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression(QSet<QString> * cr
146157

147158
void QgsProjectionSelector::setSelectedSRSName(QString theSRSName)
148159
{
149-
// ensure the projection list view is actually populated
150-
// before we select from its contents
151-
152-
if (!mProjListDone)
153-
{
154-
applyProjList(&mCrsFilter);
155-
}
160+
mSRSNameSelection = theSRSName;
161+
mSRSNameSelectionPending = TRUE;
162+
mSRSIDSelectionPending = FALSE; // only one type can be pending at a time
156163

157-
if (!mUserProjListDone)
164+
if (isVisible())
158165
{
159-
applyUserProjList(&mCrsFilter);
166+
applySRSNameSelection();
160167
}
161-
162-
mSRSNameSelection = theSRSName;
163-
mSRSNameSelectionPending = TRUE;
164-
applySRSNameSelection();
168+
// else we will wait for the projection selector to
169+
// become visible (with the showEvent()) and set the
170+
// selection there
165171
}
166172

167173

168174
void QgsProjectionSelector::setSelectedSRSID(long theSRSID)
169175
{
170-
// ensure the projection list view is actually populated
171-
// before we select from its contents
172-
173-
if (!mProjListDone)
174-
{
175-
applyProjList(&mCrsFilter);
176-
}
176+
mSRSIDSelection = theSRSID;
177+
mSRSIDSelectionPending = TRUE;
178+
mSRSNameSelectionPending = FALSE; // only one type can be pending at a time
177179

178-
if (!mUserProjListDone)
180+
if (isVisible())
179181
{
180-
applyUserProjList(&mCrsFilter);
182+
applySRSIDSelection();
181183
}
182-
183-
mSRSIDSelection = theSRSID;
184-
mSRSIDSelectionPending = TRUE;
185-
applySRSIDSelection();
184+
// else we will wait for the projection selector to
185+
// become visible (with the showEvent()) and set the
186+
// selection there
186187
}
187188

188189

@@ -203,11 +204,6 @@ void QgsProjectionSelector::applySRSNameSelection()
203204
if (nodes.count() > 0)
204205
{
205206
lstCoordinateSystems->setCurrentItem(nodes.first());
206-
207-
// The following seems to be broken in Qt 4.1.0:
208-
// It only works if the widget is already visible.
209-
// (Which makes it really hard to scroll to an
210-
// item before you exec() the widget)
211207
lstCoordinateSystems->scrollToItem(nodes.first());
212208
}
213209
else // unselect the selected item to avoid confusing the user
@@ -235,11 +231,6 @@ void QgsProjectionSelector::applySRSIDSelection()
235231
if (nodes.count() > 0)
236232
{
237233
lstCoordinateSystems->setCurrentItem(nodes.first());
238-
239-
// The following seems to be broken in Qt 4.1.0:
240-
// It only works if the widget is already visible.
241-
// (Which makes it really hard to scroll to an
242-
// item before you exec() the widget)
243234
lstCoordinateSystems->scrollToItem(nodes.first());
244235
}
245236
else // unselect the selected item to avoid confusing the user
@@ -795,10 +786,6 @@ void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem)
795786
myDescription+=(myProjString);
796787
}
797788

798-
// The following seems to be broken in Qt 4.1.0:
799-
// It only works if the widget is already visible.
800-
// (Which makes it really hard to scroll to an
801-
// item before you exec() the widget)
802789
lstCoordinateSystems->scrollToItem(theItem);
803790
teProjection->setText(myDescription);
804791
}

src/widgets/projectionselector/qgsprojectionselector.h

+8
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class QgsProjectionSelector: public QWidget, private Ui::QgsProjectionSelectorBa
127127
*
128128
* \warning This function does nothing unless getUserList() and getUserProjList()
129129
* Have already been called
130+
*
131+
* \warning This function only expands the parents of the selection and
132+
* does not scroll the list to the selection if the widget is not visible.
133+
* Therefore you will typically want to use this in a showEvent().
130134
*/
131135
void applySRSNameSelection();
132136

@@ -135,6 +139,10 @@ class QgsProjectionSelector: public QWidget, private Ui::QgsProjectionSelectorBa
135139
*
136140
* \warning This function does nothing unless getUserList() and getUserProjList()
137141
* Have already been called
142+
*
143+
* \warning This function only expands the parents of the selection and
144+
* does not scroll the list to the selection if the widget is not visible.
145+
* Therefore you will typically want to use this in a showEvent().
138146
*/
139147
void applySRSIDSelection();
140148

0 commit comments

Comments
 (0)