@@ -41,6 +41,7 @@ extern "C"
41
41
#include < proj_api.h>
42
42
}
43
43
44
+
44
45
QgsCustomProjectionDialog::QgsCustomProjectionDialog ( QWidget *parent, Qt::WFlags fl )
45
46
: QDialog( parent, fl )
46
47
{
@@ -68,8 +69,7 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WFlag
68
69
leNameList->setCurrentItem ( leNameList->topLevelItem ( 0 ) );
69
70
}
70
71
71
- // leNameList->hideColumn(QGIS_CRS_ID_COLUMN);
72
- leNameList->header ()->setResizeMode ( QGIS_CRS_NAME_COLUMN, QHeaderView::Stretch );
72
+ leNameList->hideColumn (QGIS_CRS_ID_COLUMN);
73
73
74
74
}
75
75
@@ -111,7 +111,7 @@ void QgsCustomProjectionDialog::populateList()
111
111
name= QString::fromUtf8 ( ( char * ) sqlite3_column_text ( myPreparedStatement, 1 ) );
112
112
parameters= QString::fromUtf8 ( ( char * ) sqlite3_column_text ( myPreparedStatement, 2 ) );
113
113
114
- crs.createFromProj4 ( parameters, false );
114
+ crs.createFromProj4 ( parameters );
115
115
existingCRSnames[id] = name;
116
116
existingCRSparameters[id] = crs;
117
117
@@ -141,7 +141,8 @@ void QgsCustomProjectionDialog::populateList()
141
141
}
142
142
}
143
143
144
- bool QgsCustomProjectionDialog::deleteCRS ( QString id ){
144
+ bool QgsCustomProjectionDialog::deleteCRS ( QString id )
145
+ {
145
146
sqlite3 *myDatabase;
146
147
const char *myTail;
147
148
sqlite3_stmt *myPreparedStatement;
@@ -234,94 +235,67 @@ void QgsCustomProjectionDialog::insertProjection(QString myProjectionAcronym)
234
235
sqlite3_close ( myDatabase );
235
236
}
236
237
237
- bool QgsCustomProjectionDialog::saveCRS (QgsCoordinateReferenceSystem myParameters , QString myName, QString myId, bool newEntry)
238
+ bool QgsCustomProjectionDialog::saveCRS (QgsCoordinateReferenceSystem myCRS , QString myName, QString myId, bool newEntry)
238
239
{
239
-
240
- if ( ! myParameters.isValid () )
241
- {
242
- QMessageBox::information ( this , tr ( " QGIS Custom Projection" ),
243
- tr ( " The proj4 projection definition for the CRS \" %1\" is not valid." ).arg ( myName ) );
244
- // + tr( " Please add a proj= clause before pressing save." ) );
245
- return false ;
246
- }
247
-
248
- QString myProjectionAcronym = myParameters.projectionAcronym ();
249
- QString myEllipsoidAcronym = myParameters.ellipsoidAcronym ();
250
-
251
240
QString mySql;
241
+ int return_id;
242
+ QString myProjectionAcronym = myCRS.projectionAcronym ();
243
+ QString myEllipsoidAcronym = myCRS.ellipsoidAcronym ();
252
244
if ( newEntry )
253
245
{
254
- if ( existingCRSnames.size ()==0 )
255
- {
256
- mySql = " insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
257
- + QString::number ( USER_CRS_START_ID )
258
- + " ," + quotedValue ( myName )
259
- + " ," + quotedValue ( myProjectionAcronym )
260
- + " ," + quotedValue ( myEllipsoidAcronym )
261
- + " ," + quotedValue ( myParameters.toProj4 () )
262
- + " ,0)" ; // <-- is_geo shamelessly hard coded for now
263
- }
246
+ return_id=myCRS.saveAsUserCRS (myName);
247
+ if (return_id==-1 )
248
+ return false ;
264
249
else
265
- {
266
- mySql = " insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
267
- + quotedValue ( myName )
268
- + " ," + quotedValue ( myProjectionAcronym )
269
- + " ," + quotedValue ( myEllipsoidAcronym )
270
- + " ," + quotedValue ( myParameters.toProj4 () )
271
- + " ,0)" ; // <-- is_geo shamelessly hard coded for now
272
- }
250
+ myId = QString::number (return_id);
273
251
}
274
252
else
275
253
{
276
254
mySql = " update tbl_srs set description="
277
255
+ quotedValue ( myName )
278
256
+ " ,projection_acronym=" + quotedValue ( myProjectionAcronym )
279
257
+ " ,ellipsoid_acronym=" + quotedValue ( myEllipsoidAcronym )
280
- + " ,parameters=" + quotedValue ( myParameters .toProj4 () )
258
+ + " ,parameters=" + quotedValue ( myCRS .toProj4 () )
281
259
+ " ,is_geo=0" // <--shamelessly hard coded for now
282
260
+ " where srs_id=" + quotedValue ( myId )
283
261
;
284
- }
285
- QgsDebugMsg ( mySql );
286
- sqlite3 *myDatabase;
287
- const char *myTail;
288
- sqlite3_stmt *myPreparedStatement;
289
- int myResult;
290
- // check if the db is available
291
- myResult = sqlite3_open ( QgsApplication::qgisUserDbFilePath ().toUtf8 (), &myDatabase );
292
- if ( myResult != SQLITE_OK )
293
- {
294
- QgsDebugMsg ( QString ( " Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg ( sqlite3_errmsg ( myDatabase ) ).arg ( QgsApplication::qgisUserDbFilePath () ) );
295
- // XXX This will likely never happen since on open, sqlite creates the
296
- // database if it does not exist.
297
- Q_ASSERT ( myResult == SQLITE_OK );
298
- }
299
- myResult = sqlite3_prepare ( myDatabase, mySql.toUtf8 (), mySql.toUtf8 ().length (), &myPreparedStatement, &myTail );
300
- sqlite3_step ( myPreparedStatement );
301
- // XXX Need to free memory from the error msg if one is set
302
- if ( myResult != SQLITE_OK )
303
- {
304
- QgsDebugMsg ( QString ( " failed to write to database in custom projection dialog: %1 [%2]" ).arg ( mySql ).arg ( sqlite3_errmsg ( myDatabase ) ) );
305
- }
262
+ QgsDebugMsg ( mySql );
263
+ sqlite3 *myDatabase;
264
+ const char *myTail;
265
+ sqlite3_stmt *myPreparedStatement;
266
+ int myResult;
267
+ // check if the db is available
268
+ myResult = sqlite3_open ( QgsApplication::qgisUserDbFilePath ().toUtf8 (), &myDatabase );
269
+ if ( myResult != SQLITE_OK )
270
+ {
271
+ QgsDebugMsg ( QString ( " Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg ( sqlite3_errmsg ( myDatabase ) ).arg ( QgsApplication::qgisUserDbFilePath () ) );
272
+ // XXX This will likely never happen since on open, sqlite creates the
273
+ // database if it does not exist.
274
+ Q_ASSERT ( myResult == SQLITE_OK );
275
+ }
276
+ myResult = sqlite3_prepare ( myDatabase, mySql.toUtf8 (), mySql.toUtf8 ().length (), &myPreparedStatement, &myTail );
277
+ sqlite3_step ( myPreparedStatement );
278
+ // XXX Need to free memory from the error msg if one is set
279
+ if ( myResult != SQLITE_OK )
280
+ {
281
+ QgsDebugMsg ( QString ( " failed to write to database in custom projection dialog: %1 [%2]" ).arg ( mySql ).arg ( sqlite3_errmsg ( myDatabase ) ) );
282
+ }
306
283
307
- sqlite3_finalize ( myPreparedStatement );
308
- if ( newEntry )
309
- {
310
- int return_id = sqlite3_last_insert_rowid ( myDatabase );
311
- myId = QString::number ( return_id ) ;
284
+ sqlite3_finalize ( myPreparedStatement );
285
+ // close sqlite3 db
286
+ sqlite3_close ( myDatabase );
287
+ if (myResult != SQLITE_OK)
288
+ return false ;
312
289
}
313
- // close sqlite3 db
314
- sqlite3_close ( myDatabase );
315
-
316
- existingCRSparameters[myId] = myParameters;
290
+ existingCRSparameters[myId] = myCRS;
317
291
existingCRSnames[myId] = myName;
318
292
319
293
// If we have a projection acronym not in the user db previously, add it.
320
294
// This is a must, or else we can't select it from the vw_srs table.
321
295
// Actually, add it always and let the SQL PRIMARY KEY remove duplicates.
322
296
insertProjection ( myProjectionAcronym );
323
297
324
- return myResult == SQLITE_OK ;
298
+ return true ;
325
299
}
326
300
327
301
@@ -360,7 +334,6 @@ void QgsCustomProjectionDialog::on_pbnRemove_clicked()
360
334
customCRSparameters.erase ( customCRSparameters.begin () + i );
361
335
}
362
336
363
-
364
337
void QgsCustomProjectionDialog::on_leNameList_currentItemChanged ( QTreeWidgetItem *current, QTreeWidgetItem * previous )
365
338
{
366
339
// Store the modifications made to the current element before moving on
@@ -369,7 +342,7 @@ void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetIte
369
342
{
370
343
previousIndex = leNameList->indexOfTopLevelItem ( previous );
371
344
customCRSnames[previousIndex] = leName->text ();
372
- customCRSparameters[previousIndex].createFromProj4 ( teParameters->toPlainText (), false );
345
+ customCRSparameters[previousIndex].createFromProj4 ( teParameters->toPlainText () );
373
346
previous->setText ( QGIS_CRS_NAME_COLUMN, leName->text () );
374
347
previous->setText ( QGIS_CRS_PARAMETERS_COLUMN, teParameters->toPlainText () );
375
348
}
@@ -418,7 +391,7 @@ void QgsCustomProjectionDialog::on_buttonBox_accepted()
418
391
if (i != -1 )
419
392
{
420
393
customCRSnames[i] = leName->text ();
421
- customCRSparameters[i].createFromProj4 ( teParameters->toPlainText (), false );
394
+ customCRSparameters[i].createFromProj4 ( teParameters->toPlainText () );
422
395
}
423
396
424
397
QgsDebugMsg ( " We save the modified CRS." );
0 commit comments