Skip to content

Commit 07355d8

Browse files
author
g_j_m
committedJan 10, 2006
qt3 to qt4 changes for projection selector dialog
Partially complete - effective use of dialog space needs more work (to come) Moved to the QtreeWidget - caused a moderate number of changes in code Loading the srs into the tree widget is _much_ faster git-svn-id: http://svn.osgeo.org/qgis/trunk@4641 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c039f78 commit 07355d8

File tree

3 files changed

+140
-112
lines changed

3 files changed

+140
-112
lines changed
 

‎src/widgets/projectionselector/qgsprojectionselector.cpp

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
#include <Q3ProgressDialog>
2626
#include <QTextStream>
2727

28+
#define QGISDEBUG
2829

2930
QgsProjectionSelector::QgsProjectionSelector( QWidget* parent , const char* name , Qt::WFlags fl )
3031
: QWidget(parent, fl)
3132
{
3233
setupUi(this);
33-
connect(lstCoordinateSystems, SIGNAL(currentChanged(Q3ListViewItem*)),
34-
this, SLOT(coordinateSystemSelected(Q3ListViewItem*)));
34+
connect(lstCoordinateSystems, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
35+
this, SLOT(coordinateSystemSelected(QTreeWidgetItem*)));
3536
connect(leSearch, SIGNAL(returnPressed()), pbnFind, SLOT(animateClick()));
3637

3738
// Get the full path name to the sqlite3 spatial reference database.
@@ -49,42 +50,39 @@ void QgsProjectionSelector::setSelectedSRSName(QString theSRSNAme)
4950
#ifdef QGISDEBUG
5051
std::cout << "QgsProjectionSelector::setSelectedSRSName called with \n" << theSRSNAme.toLocal8Bit().data() << std::endl;
5152
#endif
52-
//now delegate off to the rest of the work
53-
Q3ListViewItemIterator myIterator (lstCoordinateSystems);
54-
while (myIterator.current())
55-
{
56-
if (myIterator.current()->text(0)==theSRSNAme)
57-
{
58-
lstCoordinateSystems->setCurrentItem(myIterator.current());
59-
lstCoordinateSystems->ensureItemVisible(myIterator.current());
60-
return;
61-
}
62-
++myIterator;
53+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems(theSRSNAme, Qt::MatchExactly|Qt::MatchRecursive, 0);
54+
55+
if (nodes.count() == 1)
56+
lstCoordinateSystems->setCurrentItem(nodes.first());
57+
else // unselect the selected item to avoid confusing the user
58+
{
59+
if (lstCoordinateSystems->currentItem() != NULL)
60+
lstCoordinateSystems->setItemSelected(lstCoordinateSystems->currentItem(), false);
61+
teProjection->setText("");
6362
}
6463
}
6564

6665
void QgsProjectionSelector::setSelectedSRSID(long theSRSID)
6766
{
6867
QString mySRSIDString=QString::number(theSRSID);
69-
Q3ListViewItemIterator myIterator (lstCoordinateSystems);
70-
while (myIterator.current())
71-
{
72-
if (myIterator.current()->text(1)==mySRSIDString)
73-
{
74-
lstCoordinateSystems->setCurrentItem(myIterator.current());
75-
lstCoordinateSystems->ensureItemVisible(myIterator.current());
76-
return;
77-
}
78-
++myIterator;
79-
}
8068

69+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems(mySRSIDString, Qt::MatchExactly|Qt::MatchRecursive, 1);
70+
71+
if (nodes.count() == 1)
72+
lstCoordinateSystems->setCurrentItem(nodes.first());
73+
else // unselect the selected item to avoid confusing the user
74+
{
75+
if (lstCoordinateSystems->currentItem() != NULL)
76+
lstCoordinateSystems->setItemSelected(lstCoordinateSystems->currentItem(), false);
77+
teProjection->setText("");
78+
}
8179
}
8280

8381
//note this line just returns the projection name!
8482
QString QgsProjectionSelector::getSelectedName()
8583
{
8684
// return the selected wkt name from the list view
87-
Q3ListViewItem *lvi = lstCoordinateSystems->currentItem();
85+
QTreeWidgetItem *lvi = lstCoordinateSystems->currentItem();
8886
if(lvi)
8987
{
9088
return lvi->text(0);
@@ -103,7 +101,7 @@ QString QgsProjectionSelector::getCurrentProj4String()
103101
// system
104102
//
105103
// Get the selected node
106-
Q3ListViewItem *myItem = lstCoordinateSystems->currentItem();
104+
QTreeWidgetItem *myItem = lstCoordinateSystems->currentItem();
107105
if(myItem)
108106
{
109107

@@ -198,7 +196,7 @@ long QgsProjectionSelector::getCurrentSRID()
198196
// system
199197
//
200198
// Get the selected node
201-
Q3ListViewItem *lvi = lstCoordinateSystems->currentItem();
199+
QTreeWidgetItem *lvi = lstCoordinateSystems->currentItem();
202200
if(lvi)
203201
{
204202
// Make sure the selected node is a srs and not a top-level projection node
@@ -295,7 +293,7 @@ void QgsProjectionSelector::getUserProjList()
295293
std::cout << "Fetching user projection list..." << std::endl;
296294
#endif
297295
// User defined coordinate system node
298-
mUserProjList = new Q3ListViewItem(lstCoordinateSystems,"User Defined Coordinate System");
296+
mUserProjList = new QTreeWidgetItem(lstCoordinateSystems,QStringList("User Defined Coordinate System"));
299297
//determine where the user proj database lives for this user. If none is found an empty
300298
//now only will be shown
301299
QString myQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
@@ -337,10 +335,10 @@ void QgsProjectionSelector::getUserProjList()
337335
// XXX Need to free memory from the error msg if one is set
338336
if(myResult == SQLITE_OK)
339337
{
340-
Q3ListViewItem *newItem;
338+
QTreeWidgetItem *newItem;
341339
while(sqlite3_step(myPreparedStatement) == SQLITE_ROW)
342340
{
343-
newItem = new Q3ListViewItem(mUserProjList, QString::fromUtf8((char *)sqlite3_column_text(myPreparedStatement,0)));
341+
newItem = new QTreeWidgetItem(mUserProjList, QStringList(QString::fromUtf8((char *)sqlite3_column_text(myPreparedStatement,0))));
344342
// display the qgis srs_id in the second column of the list view
345343
newItem->setText(1,QString::fromUtf8((char *)sqlite3_column_text(myPreparedStatement, 1)));
346344
}
@@ -355,9 +353,9 @@ void QgsProjectionSelector::getProjList()
355353
// Create the top-level nodes for the list view of projections
356354
//
357355
// Geographic coordinate system node
358-
mGeoList = new Q3ListViewItem(lstCoordinateSystems,"Geographic Coordinate System");
356+
mGeoList = new QTreeWidgetItem(lstCoordinateSystems,QStringList("Geographic Coordinate System"));
359357
// Projected coordinate system node
360-
mProjList = new Q3ListViewItem(lstCoordinateSystems,"Projected Coordinate System");
358+
mProjList = new QTreeWidgetItem(lstCoordinateSystems,QStringList("Projected Coordinate System"));
361359

362360
//bail out in case the projections db does not exist
363361
//this is neccessary in case the pc is running linux with a
@@ -413,11 +411,16 @@ void QgsProjectionSelector::getProjList()
413411
std::cout << "SQL for projection list executed ok..." << std::endl;
414412
#endif
415413

416-
Q3ListViewItem *newItem;
414+
QTreeWidgetItem *newItem;
417415
// set up the progress dialog
418416
int myProgress = 1;
419417
Q3ProgressDialog myProgressBar( tr("Building Projections List..."), 0, myEntriesCount,
420418
this, "progress", TRUE );
419+
// Cache some stuff to speed up creating of the list of projected
420+
// spatial reference systems
421+
QString previousSrsType("");
422+
QTreeWidgetItem* previousSrsTypeNode = NULL;
423+
421424
// set initial value to 1
422425
myProgressBar.setProgress(myProgress);
423426
while(sqlite3_step(ppStmt) == SQLITE_ROW)
@@ -433,7 +436,7 @@ void QgsProjectionSelector::getProjList()
433436
{
434437
// this is a geographic coordinate system
435438
// Add it to the tree
436-
newItem = new Q3ListViewItem(mGeoList, QString::fromUtf8((char *)sqlite3_column_text(ppStmt,0)));
439+
newItem = new QTreeWidgetItem(mGeoList, QStringList(QString::fromUtf8((char *)sqlite3_column_text(ppStmt,0))));
437440

438441
// display the qgis srs_id in the second column of the list view
439442
newItem->setText(1,QString::fromUtf8((char *)sqlite3_column_text(ppStmt, 1)));
@@ -442,18 +445,32 @@ void QgsProjectionSelector::getProjList()
442445
{
443446
// This is a projected srs
444447

445-
Q3ListViewItem *node;
446-
// Fine the node for this type and add the projection to it
448+
QTreeWidgetItem *node;
449+
QString srsType = QString::fromUtf8((char*)sqlite3_column_text(ppStmt, 3));
450+
// Find the node for this type and add the projection to it
447451
// If the node doesn't exist, create it
448-
node = lstCoordinateSystems->findItem(QString::fromUtf8((char *)sqlite3_column_text(ppStmt, 3)),0);
449-
if(node == 0)
450-
{
451-
// the node doesn't exist -- create it
452-
node = new Q3ListViewItem(mProjList, QString::fromUtf8((char *)sqlite3_column_text(ppStmt, 3)));
453-
}
454-
452+
if (srsType == previousSrsType)
453+
{
454+
node = previousSrsTypeNode;
455+
}
456+
else
457+
{ // Different from last one, need to search
458+
QList<QTreeWidgetItem*> nodes = lstCoordinateSystems->findItems(srsType,Qt::MatchExactly|Qt::MatchRecursive,0);
459+
if(nodes.count() == 0)
460+
{
461+
// the node doesn't exist -- create it
462+
node = new QTreeWidgetItem(mProjList, QStringList(srsType));
463+
}
464+
else
465+
{
466+
node = nodes.first();
467+
}
468+
// Update the cache.
469+
previousSrsType = srsType;
470+
previousSrsTypeNode = node;
471+
}
455472
// add the item, setting the projection name in the first column of the list view
456-
newItem = new Q3ListViewItem(node, QString::fromUtf8((char *)sqlite3_column_text(ppStmt,0)));
473+
newItem = new QTreeWidgetItem(node, QStringList(QString::fromUtf8((char *)sqlite3_column_text(ppStmt,0))));
457474
// set the srs_id in the second column on the list view
458475
newItem->setText(1,QString::fromUtf8((char *)sqlite3_column_text(ppStmt, 1)));
459476
}
@@ -466,7 +483,9 @@ void QgsProjectionSelector::getProjList()
466483
// see a progress dialog end at 99%)
467484
myProgressBar.setProgress(myEntriesCount);
468485
}
486+
#ifdef QGISDEBUG
469487
std::cout << "Size of projection list widget : " << sizeof(*lstCoordinateSystems) << std::endl;
488+
#endif
470489
// close the sqlite3 statement
471490
sqlite3_finalize(ppStmt);
472491
// close the database
@@ -537,17 +556,24 @@ void QgsProjectionSelector::updateProjAndEllipsoidAcronyms(int theSrsid,QString
537556
}
538557

539558
// New coordinate system selected from the list
540-
void QgsProjectionSelector::coordinateSystemSelected( Q3ListViewItem * theItem )
559+
void QgsProjectionSelector::coordinateSystemSelected( QTreeWidgetItem * theItem)
541560
{
542-
QString myDescription = tr("QGIS SRSID: ") + QString::number(getCurrentSRSID()) +"\n";
543-
myDescription += tr("PostGIS SRID: ") + QString::number(getCurrentSRID()) +"\n";
544-
emit sridSelected(QString::number(getCurrentSRSID()));
545-
QString myProjString = getCurrentProj4String();
546-
if (!myProjString.isNull())
547-
{
548-
myDescription+=(myProjString);
561+
// If the item has children, it's not an end node in the tree, and
562+
// hence is just a grouping thingy, not an actual SRS.
563+
if (theItem->childCount() == 0)
564+
{
565+
QString myDescription = tr("QGIS SRSID: ") + QString::number(getCurrentSRSID()) +"\n";
566+
myDescription += tr("PostGIS SRID: ") + QString::number(getCurrentSRID()) +"\n";
567+
emit sridSelected(QString::number(getCurrentSRSID()));
568+
QString myProjString = getCurrentProj4String();
569+
if (!myProjString.isNull())
570+
{
571+
myDescription+=(myProjString);
572+
}
573+
teProjection->setText(myDescription);
549574
}
550-
teProjection->setText(myDescription);
575+
else
576+
teProjection->setText("");
551577
}
552578

553579
void QgsProjectionSelector::on_pbnFind_clicked()
@@ -600,7 +626,7 @@ void QgsProjectionSelector::on_pbnFind_clicked()
600626
return;
601627
}
602628
#ifdef QGISDEBUG
603-
std::cout << " Search sql" << mySql.toLocal8Bit().data() << std::endl;
629+
std::cout << " Search sql: " << mySql.toLocal8Bit().data() << std::endl;
604630
#endif
605631

606632
//

‎src/widgets/projectionselector/qgsprojectionselector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class QgsProjectionSelector: public QWidget, private Ui::QgsProjectionSelectorBa
5151

5252
// List view nodes for the tree view of projections
5353
//! User defined projections node
54-
Q3ListViewItem *mUserProjList;
54+
QTreeWidgetItem *mUserProjList;
5555
//! GEOGCS node
56-
Q3ListViewItem *mGeoList;
56+
QTreeWidgetItem *mGeoList;
5757
//! PROJCS node
58-
Q3ListViewItem *mProjList;
58+
QTreeWidgetItem *mProjList;
5959
//! Users custom coordinate system file
6060
QString mCustomCsFile;
6161
//! File name of the sqlite3 database
@@ -70,7 +70,7 @@ class QgsProjectionSelector: public QWidget, private Ui::QgsProjectionSelectorBa
7070
/**private handler for when user selects a cs
7171
*it will cause wktSelected and sridSelected events to be spawned
7272
*/
73-
void coordinateSystemSelected(Q3ListViewItem*);
73+
void coordinateSystemSelected(QTreeWidgetItem*);
7474

7575
signals:
7676
void sridSelected(QString theSRID);

‎src/widgets/projectionselector/qgsprojectionselectorbase.ui

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<x>0</x>
1010
<y>0</y>
1111
<width>600</width>
12-
<height>478</height>
12+
<height>498</height>
1313
</rect>
1414
</property>
1515
<property name="windowTitle" >
@@ -20,34 +20,36 @@
2020
</property>
2121
<layout class="QGridLayout" >
2222
<property name="margin" >
23-
<number>10</number>
23+
<number>9</number>
2424
</property>
2525
<property name="spacing" >
2626
<number>6</number>
2727
</property>
2828
<item row="0" column="0" >
29-
<widget class="Q3ButtonGroup" name="buttonGroup2" >
29+
<widget class="QGroupBox" name="groupBox_2" >
30+
<property name="sizePolicy" >
31+
<sizepolicy>
32+
<hsizetype>5</hsizetype>
33+
<vsizetype>1</vsizetype>
34+
<horstretch>0</horstretch>
35+
<verstretch>0</verstretch>
36+
</sizepolicy>
37+
</property>
3038
<property name="title" >
3139
<string>Projection</string>
3240
</property>
33-
<layout class="QGridLayout" >
41+
<layout class="QVBoxLayout" >
3442
<property name="margin" >
35-
<number>10</number>
43+
<number>9</number>
3644
</property>
3745
<property name="spacing" >
3846
<number>6</number>
3947
</property>
40-
<item row="0" column="0" >
41-
<widget class="Q3ListView" name="lstCoordinateSystems" >
42-
<property name="showSortIndicator" >
43-
<bool>true</bool>
44-
</property>
45-
<property name="rootIsDecorated" >
46-
<bool>true</bool>
47-
</property>
48+
<item>
49+
<widget class="QTreeWidget" name="lstCoordinateSystems" >
4850
<column>
4951
<property name="text" >
50-
<string>Coordinate Systems</string>
52+
<string>Coordinate System</string>
5153
</property>
5254
</column>
5355
<column>
@@ -57,43 +59,50 @@
5759
</column>
5860
</widget>
5961
</item>
60-
<item row="1" column="0" >
61-
<widget class="Q3TextEdit" name="teProjection" >
62+
<item>
63+
<widget class="QTextEdit" name="teProjection" >
6264
<property name="sizePolicy" >
6365
<sizepolicy>
64-
<hsizetype>7</hsizetype>
65-
<vsizetype>7</vsizetype>
66+
<hsizetype>5</hsizetype>
67+
<vsizetype>1</vsizetype>
6668
<horstretch>0</horstretch>
6769
<verstretch>0</verstretch>
6870
</sizepolicy>
6971
</property>
70-
<property name="maximumSize" >
71-
<size>
72-
<width>32767</width>
73-
<height>76</height>
74-
</size>
72+
<property name="autoFormatting" >
73+
<set>QTextEdit::AutoBulletList</set>
7574
</property>
7675
<property name="readOnly" >
7776
<bool>true</bool>
7877
</property>
7978
</widget>
8079
</item>
81-
<item row="2" column="0" >
82-
<widget class="Q3ButtonGroup" name="buttonGroup2_2" >
80+
<item>
81+
<widget class="QGroupBox" name="groupBox" >
8382
<property name="title" >
8483
<string>Search</string>
8584
</property>
8685
<layout class="QGridLayout" >
8786
<property name="margin" >
88-
<number>10</number>
87+
<number>9</number>
8988
</property>
9089
<property name="spacing" >
9190
<number>6</number>
9291
</property>
93-
<item row="0" column="4" >
94-
<widget class="QLineEdit" name="leSearch" />
92+
<item row="1" column="5" >
93+
<spacer>
94+
<property name="orientation" >
95+
<enum>Qt::Horizontal</enum>
96+
</property>
97+
<property name="sizeHint" >
98+
<size>
99+
<width>40</width>
100+
<height>20</height>
101+
</size>
102+
</property>
103+
</spacer>
95104
</item>
96-
<item row="0" column="5" >
105+
<item row="1" column="3" colspan="2" >
97106
<widget class="QPushButton" name="pbnFind" >
98107
<property name="text" >
99108
<string>Find</string>
@@ -103,6 +112,9 @@
103112
</property>
104113
</widget>
105114
</item>
115+
<item row="1" column="0" colspan="3" >
116+
<widget class="QLineEdit" name="leSearch" />
117+
</item>
106118
<item row="0" column="0" >
107119
<widget class="QRadioButton" name="radSRID" >
108120
<property name="text" >
@@ -120,20 +132,33 @@
120132
</property>
121133
</widget>
122134
</item>
123-
<item row="0" column="2" >
135+
<item row="0" column="2" colspan="2" >
124136
<widget class="QRadioButton" name="radSRSID" >
125137
<property name="text" >
126138
<string>QGIS SRSID</string>
127139
</property>
128140
</widget>
129141
</item>
130-
<item row="0" column="3" >
142+
<item row="0" column="4" >
131143
<widget class="QRadioButton" name="radName" >
132144
<property name="text" >
133145
<string>Name</string>
134146
</property>
135147
</widget>
136148
</item>
149+
<item row="0" column="5" >
150+
<spacer>
151+
<property name="orientation" >
152+
<enum>Qt::Horizontal</enum>
153+
</property>
154+
<property name="sizeHint" >
155+
<size>
156+
<width>40</width>
157+
<height>20</height>
158+
</size>
159+
</property>
160+
</spacer>
161+
</item>
137162
</layout>
138163
</widget>
139164
</item>
@@ -144,29 +169,6 @@
144169
</widget>
145170
<layoutdefault spacing="6" margin="11" />
146171
<pixmapfunction></pixmapfunction>
147-
<customwidgets>
148-
<customwidget>
149-
<class>Q3ListView</class>
150-
<extends></extends>
151-
<header>q3listview.h</header>
152-
<container>0</container>
153-
<pixmap></pixmap>
154-
</customwidget>
155-
<customwidget>
156-
<class>Q3TextEdit</class>
157-
<extends></extends>
158-
<header>q3textedit.h</header>
159-
<container>0</container>
160-
<pixmap></pixmap>
161-
</customwidget>
162-
<customwidget>
163-
<class>Q3ButtonGroup</class>
164-
<extends></extends>
165-
<header>Qt3Support/Q3ButtonGroup</header>
166-
<container>1</container>
167-
<pixmap></pixmap>
168-
</customwidget>
169-
</customwidgets>
170172
<resources/>
171173
<connections/>
172174
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.