Skip to content

Commit a2739f8

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/qgis@4641 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent bd6ff2f commit a2739f8

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);

0 commit comments

Comments
 (0)
Please sign in to comment.