Skip to content
Permalink
Browse files
UI tweaks to the projection UI; Remove old buttons and code etc
  • Loading branch information
NathanW2 committed Nov 23, 2011
1 parent 376adc4 commit 2e208c381c4b0b92db1d584dbae117e55cd8f06a
@@ -89,8 +89,6 @@ class QgsProjectionSelector: QWidget //, private Ui::QgsProjectionSelectorBase
*/
void setOgcWmsCrsFilter(QSet<QString> crsFilter);

void on_pbnFind_clicked();

protected:
/** Used to ensure the projection list view is actually populated */
void showEvent ( QShowEvent * theEvent );
@@ -551,6 +551,16 @@ QString QgsApplication::reportStyleSheet()
" color: black;"
" font-family: arial,sans-serif;"
"}"
"h1{ background-color: #F6F6F6;"
" color: #8FB171; "
" font-size: x-large; "
" font-weight: normal;"
" font-family: luxi serif, georgia, times new roman, times, serif;"
" background: none;"
" padding: 0.75em 0 0;"
" margin: 0;"
" line-height: 3em;"
"}"
"h2{ background-color: #F6F6F6;"
" color: #8FB171; "
" font-size: medium; "
@@ -15,6 +15,8 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsapplication.h"

#include <qgsgenericprojectionselector.h>
#include <QApplication>

@@ -38,20 +40,18 @@ void QgsGenericProjectionSelector::setMessage( QString theMessage )
if ( theMessage.isEmpty() )
{
// Set up text edit pane
QString format( "<h2>%1</h2>%2 %3" );
QString format( "<h1>%1</h1>%2 %3" );
QString header = tr( "Define this layer's coordinate reference system:" );
QString sentence1 = tr( "This layer appears to have no projection specification." );
QString sentence2 = tr( "By default, this layer will now have its projection set to that of the project, "
"but you may override this by selecting a different projection below." );
textEdit->setHtml( format.arg( header ).arg( sentence1 )
.arg( sentence2 ) );
}
else
{
textEdit->setHtml( theMessage );
theMessage = format.arg( header ).arg( sentence1 ).arg( sentence2 );
}
textEdit->show();

QString myStyle = QgsApplication::reportStyleSheet();
theMessage = "<head><style>" + myStyle + "</style></head><body>" + theMessage + "</body>";
textEdit->setHtml( theMessage );
textEdit->show();
}
//! Destructor
QgsGenericProjectionSelector::~QgsGenericProjectionSelector()
@@ -61,16 +61,6 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
// Hide (internal) ID column
lstRecent->setColumnHidden(QGIS_CRS_ID_COLUMN, true);

cbxAuthority->addItem( tr( "All" ) );
cbxAuthority->addItems( authorities() );

// TEMP? hide buttons, we now implemented filter
cbxAuthority->hide();
cbxMode->hide();
label->hide();
label_2->hide();
pbnFind->hide();

// Read settings from persistent storage
QSettings settings;
mRecentProjections = settings.value( "/UI/recentProjections" ).toStringList();
@@ -146,7 +136,6 @@ QgsProjectionSelector::~QgsProjectionSelector()
}
}


void QgsProjectionSelector::resizeEvent( QResizeEvent * theEvent )
{
lstCoordinateSystems->header()->resizeSection( NAME_COLUMN, theEvent->size().width() - 240 );
@@ -877,121 +866,6 @@ void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *cu
setSelectedCrsId( current->text( QGIS_CRS_ID_COLUMN ).toLong() );
}

void QgsProjectionSelector::on_pbnFind_clicked()
{
QgsDebugMsg( "pbnFind..." );

QString mySearchString( sqlSafeString( leSearch->text() ) );

// Set up the query to retrieve the projection information needed to populate the list
QString mySql = "select srs_id from tbl_srs where ";
if ( cbxAuthority->currentIndex() > 0 )
{
mySql += QString( "auth_name='%1' AND " ).arg( cbxAuthority->currentText() );
}

if ( cbxHideDeprecated->isChecked() )
{
mySql += "not deprecated AND ";
}

if ( cbxMode->currentIndex() == 0 )
{
mySql += QString( "auth_id='%1'" ).arg( mySearchString );
}
else
{
mySql += "upper(description) like '%" + mySearchString.toUpper() + "%' ";

long myLargestSrsId = getLargestCRSIDMatch( QString( "%1 order by srs_id desc limit 1" ).arg( mySql ) );
QgsDebugMsg( QString( "Largest CRSID%1" ).arg( myLargestSrsId ) );

//a name search is ambiguous, so we find the first srsid after the current selected srsid
// each time the find button is pressed. This means we can loop through all matches.
if ( myLargestSrsId <= selectedCrsId() )
{
mySql = QString( "%1 order by srs_id limit 1" ).arg( mySql );
}
else
{
// search ahead of the current position
mySql = QString( "%1 and srs_id > %2 order by srs_id limit 1" ).arg( mySql ).arg( selectedCrsId() );
}
}
QgsDebugMsg( QString( " Search sql: %1" ).arg( mySql ) );

//
// Now perform the actual search
//

sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &myDatabase );
if ( myResult )
{
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist. But we checked earlier for its existance
// and aborted in that case. This is because we may be runnig from read only
// media such as live cd and don't want to force trying to create a db.
showDBMissingWarning( mSrsDatabaseFileName );
return;
}

myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
// XXX Need to free memory from the error msg if one is set
if ( myResult == SQLITE_OK )
{
myResult = sqlite3_step( myPreparedStatement );
if ( myResult == SQLITE_ROW )
{
QString mySrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
setSelectedCrsId( mySrsId.toLong() );
// close the sqlite3 statement
sqlite3_finalize( myPreparedStatement );
sqlite3_close( myDatabase );
return;
}
}
//search the users db
QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
QFileInfo myFileInfo;
myFileInfo.setFile( myDatabaseFileName );
if ( !myFileInfo.exists( ) ) //its not critical if this happens
{
QgsDebugMsg( QString( "%1\nUser db does not exist" ).arg( myDatabaseFileName ) );
return ;
}
myResult = sqlite3_open( myDatabaseFileName.toUtf8().data(), &myDatabase );
if ( myResult )
{
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
//no need for assert because user db may not have been created yet
return;
}

myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
// XXX Need to free memory from the error msg if one is set
if ( myResult == SQLITE_OK )
{
myResult = sqlite3_step( myPreparedStatement );
if ( myResult == SQLITE_ROW )
{
QString mySrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
setSelectedCrsId( mySrsId.toLong() );
// close the sqlite3 statement
sqlite3_finalize( myPreparedStatement );
sqlite3_close( myDatabase );
return;
}
}

QMessageBox::information( this, tr( "Find projection" ), tr( "No matching projection found." ) );
lstCoordinateSystems->clearSelection();
teProjection->setText( "" );
}

void QgsProjectionSelector::on_leSearch_textChanged( const QString & theFilterTxt)
{
@@ -113,8 +113,6 @@ class GUI_EXPORT QgsProjectionSelector: public QWidget, private Ui::QgsProjectio
* \warning This function's behaviour is undefined if it is called after the widget is shown.
*/
void setOgcWmsCrsFilter( QSet<QString> crsFilter );

void on_pbnFind_clicked();
void on_lstRecent_currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * );
void on_cbxHideDeprecated_stateChanged();
void on_leSearch_textChanged(const QString &);

0 comments on commit 2e208c3

Please sign in to comment.