41
41
QgsCustomProjectionDialog::QgsCustomProjectionDialog ( QWidget* parent , const char * name , WFlags fl )
42
42
: QgsCustomProjectionDialogBase( parent, " Projection Designer" , fl )
43
43
{
44
- QString myQGisSettingsDir = QDir::homeDirPath () + " /.qgis/" ;
44
+ mQGisSettingsDir = QDir::homeDirPath () + " /.qgis/" ;
45
45
// first we look for ~/.qgis/user_projections.db
46
46
// if it doesnt exist we copy it in from the global resources dir
47
47
QFileInfo myFileInfo;
48
- myFileInfo.setFile (myQGisSettingsDir +" user_projections.db" );
48
+ myFileInfo.setFile (mQGisSettingsDir +" user_projections.db" );
49
49
if ( !myFileInfo.exists ( ) )
50
50
{
51
51
// make sure the ~/.qgis dir exists first
@@ -73,11 +73,11 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
73
73
return ;
74
74
}
75
75
76
- std::ofstream myOutputStream (QString (myQGisSettingsDir +" user_projections.db" ).latin1 ());
76
+ std::ofstream myOutputStream (QString (mQGisSettingsDir +" user_projections.db" ).latin1 ());
77
77
78
78
if (! myOutputStream)
79
79
{
80
- std::cerr << " cannot open " << QString (myQGisSettingsDir +" user_projections.db" ).latin1 () << " for output\n " ;
80
+ std::cerr << " cannot open " << QString (mQGisSettingsDir +" user_projections.db" ).latin1 () << " for output\n " ;
81
81
// XXX Do better error handling
82
82
return ;
83
83
}
@@ -89,6 +89,27 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
89
89
}
90
90
91
91
}
92
+
93
+ //
94
+ // Setup member vars
95
+ //
96
+ mCurrentRecordId =" " ;
97
+ mCurrentRecordNo =0 ;
98
+
99
+ //
100
+ // Set up databound controls
101
+ //
102
+ getProjList ();
103
+ getEllipsoidList ();
104
+ }
105
+
106
+ QgsCustomProjectionDialog::~QgsCustomProjectionDialog ()
107
+ {
108
+
109
+ }
110
+
111
+ void QgsCustomProjectionDialog::getProjList ()
112
+ {
92
113
//
93
114
// Populate the projection combo
94
115
//
@@ -98,7 +119,7 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
98
119
sqlite3_stmt *myPreparedStatement;
99
120
int myResult;
100
121
// check the db is available
101
- myResult = sqlite3_open (QString (myQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
122
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
102
123
if (myResult)
103
124
{
104
125
std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
@@ -119,8 +140,32 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
119
140
}
120
141
}
121
142
sqlite3_finalize (myPreparedStatement);
143
+ sqlite3_close (myDatabase);
144
+ }
145
+
146
+ void QgsCustomProjectionDialog::getEllipsoidList ()
147
+ {
148
+
149
+ //
150
+ // Populate the ellipsoid combo
151
+ //
152
+ sqlite3 *myDatabase;
153
+ char *myErrorMessage = 0 ;
154
+ const char *myTail;
155
+ sqlite3_stmt *myPreparedStatement;
156
+ int myResult;
157
+ // check the db is available
158
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
159
+ if (myResult)
160
+ {
161
+ std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
162
+ // XXX This will likely never happen since on open, sqlite creates the
163
+ // database if it does not exist.
164
+ assert (myResult == 0 );
165
+ }
166
+
122
167
// Set up the query to retreive the projection information needed to populate the ELLIPSOID list
123
- mySql = " select * from tbl_ellipsoid order by name" ;
168
+ QString mySql = " select * from tbl_ellipsoid order by name" ;
124
169
myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
125
170
// XXX Need to free memory from the error msg if one is set
126
171
if (myResult == SQLITE_OK)
@@ -134,51 +179,271 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
134
179
sqlite3_finalize (myPreparedStatement);
135
180
sqlite3_close (myDatabase);
136
181
}
182
+ void QgsCustomProjectionDialog::pbnHelp_clicked ()
183
+ {
137
184
138
- QgsCustomProjectionDialog::~QgsCustomProjectionDialog ()
185
+ }
186
+
187
+
188
+ void QgsCustomProjectionDialog::pbnOK_clicked ()
139
189
{
190
+
140
191
}
141
192
142
193
143
- void QgsCustomProjectionDialog::pbnHelp_clicked ()
194
+ void QgsCustomProjectionDialog::pbnApply_clicked ()
144
195
{
145
196
146
197
}
147
198
148
199
149
- void QgsCustomProjectionDialog::pbnOK_clicked ()
200
+ void QgsCustomProjectionDialog::pbnCancel_clicked ()
150
201
{
151
202
152
203
}
153
204
154
205
155
- void QgsCustomProjectionDialog::pbnApply_clicked ()
206
+ long QgsCustomProjectionDialog::getRecordCount ()
156
207
{
208
+ sqlite3 *myDatabase;
209
+ char *myErrorMessage = 0 ;
210
+ const char *myTail;
211
+ sqlite3_stmt *myPreparedStatement;
212
+ int myResult;
213
+ long myRecordCount=0 ;
214
+ // check the db is available
215
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
216
+ if (myResult)
217
+ {
218
+ std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
219
+ // XXX This will likely never happen since on open, sqlite creates the
220
+ // database if it does not exist.
221
+ assert (myResult == 0 );
222
+ }
223
+ // Set up the query to retreive the projection information needed to populate the ELLIPSOID list
224
+ QString mySql = " select count(*) from tbl_user_projection" ;
225
+ myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
226
+ // XXX Need to free memory from the error msg if one is set
227
+ if (myResult == SQLITE_OK)
228
+ {
229
+ sqlite3_step (myPreparedStatement) == SQLITE_ROW;
230
+ QString myRecordCountString ((char *)sqlite3_column_text (myPreparedStatement,0 ));
231
+ myRecordCount=myRecordCountString.toLong ();
232
+ }
233
+ // close the sqlite3 statement
234
+ sqlite3_finalize (myPreparedStatement);
235
+ sqlite3_close (myDatabase);
236
+ return myRecordCount;
157
237
158
238
}
159
239
240
+ QString QgsCustomProjectionDialog::getProjectionFamilyName (QString theProjectionFamilyId)
241
+ {
242
+ sqlite3 *myDatabase;
243
+ char *myErrorMessage = 0 ;
244
+ const char *myTail;
245
+ sqlite3_stmt *myPreparedStatement;
246
+ int myResult;
247
+ QString myName;
248
+ // check the db is available
249
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
250
+ if (myResult)
251
+ {
252
+ std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
253
+ // XXX This will likely never happen since on open, sqlite creates the
254
+ // database if it does not exist.
255
+ assert (myResult == 0 );
256
+ }
257
+ // Set up the query to retreive the projection information needed to populate the ELLIPSOID list
258
+ QString mySql = " select name from tbl_projection where acronym='" + theProjectionFamilyId + " '" ;
259
+ myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
260
+ // XXX Need to free memory from the error msg if one is set
261
+ if (myResult == SQLITE_OK)
262
+ {
263
+ sqlite3_step (myPreparedStatement) == SQLITE_ROW;
264
+ myName = QString ((char *)sqlite3_column_text (myPreparedStatement,0 ));
265
+ }
266
+ // close the sqlite3 statement
267
+ sqlite3_finalize (myPreparedStatement);
268
+ sqlite3_close (myDatabase);
269
+ return myName;
160
270
161
- void QgsCustomProjectionDialog::pbnCancel_clicked ()
271
+ }
272
+ QString QgsCustomProjectionDialog::getEllipsoidName (QString theEllipsoidId)
162
273
{
274
+ sqlite3 *myDatabase;
275
+ char *myErrorMessage = 0 ;
276
+ const char *myTail;
277
+ sqlite3_stmt *myPreparedStatement;
278
+ int myResult;
279
+ QString myName;
280
+ // check the db is available
281
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
282
+ if (myResult)
283
+ {
284
+ std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
285
+ // XXX This will likely never happen since on open, sqlite creates the
286
+ // database if it does not exist.
287
+ assert (myResult == 0 );
288
+ }
289
+ // Set up the query to retreive the projection information needed to populate the ELLIPSOID list
290
+ QString mySql = " select name from tbl_ellipsoid where acronym='" + theEllipsoidId + " '" ;
291
+ myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
292
+ // XXX Need to free memory from the error msg if one is set
293
+ if (myResult == SQLITE_OK)
294
+ {
295
+ sqlite3_step (myPreparedStatement) == SQLITE_ROW;
296
+ myName = QString ((char *)sqlite3_column_text (myPreparedStatement,0 ));
297
+ }
298
+ // close the sqlite3 statement
299
+ sqlite3_finalize (myPreparedStatement);
300
+ sqlite3_close (myDatabase);
301
+ return myName;
302
+
303
+ }
304
+
305
+ void QgsCustomProjectionDialog::pbnFirst_clicked ()
306
+ {
307
+ #ifdef QGISDEBUG
308
+ std::cout << " QgsCustomProjectionDialog::pbnFirst_clicked()" << std::endl;
309
+ #endif
310
+ sqlite3 *myDatabase;
311
+ char *myErrorMessage = 0 ;
312
+ const char *myTail;
313
+ sqlite3_stmt *myPreparedStatement;
314
+ int myResult;
315
+ // check the db is available
316
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
317
+ if (myResult)
318
+ {
319
+ std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
320
+ // XXX This will likely never happen since on open, sqlite creates the
321
+ // database if it does not exist.
322
+ assert (myResult == 0 );
323
+ }
324
+
325
+ QString mySql = " select * from tbl_user_projection order by description limit 1" ;
326
+ myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
327
+ // XXX Need to free memory from the error msg if one is set
328
+ if (myResult == SQLITE_OK)
329
+ {
330
+ sqlite3_step (myPreparedStatement) == SQLITE_ROW;
331
+ leName->setText ((char *)sqlite3_column_text (myPreparedStatement,1 ));
332
+ QString myProjectionFamilyId ((char *)sqlite3_column_text (myPreparedStatement,2 ));
333
+ cboProjectionFamily->setCurrentText (getProjectionFamilyName (myProjectionFamilyId));
334
+ QString myEllipsoidId ((char *)sqlite3_column_text (myPreparedStatement,3 ));
335
+ cboEllipsoid->setCurrentText (getEllipsoidName (myEllipsoidId));
336
+ leParameters->setText ((char *)sqlite3_column_text (myPreparedStatement,4 ));
337
+ }
338
+ else
339
+ {
340
+ #ifdef QGISDEBUG
341
+ std::cout << " pbnFirst query failed: " << mySql << std::endl;
342
+ #endif
343
+
344
+ }
345
+ sqlite3_finalize (myPreparedStatement);
346
+ sqlite3_close (myDatabase);
347
+ }
348
+
349
+
350
+ void QgsCustomProjectionDialog::pbnPrevious_clicked ()
351
+ {
352
+ #ifdef QGISDEBUG
353
+ std::cout << " QgsCustomProjectionDialog::pbnPrevious_clicked()" << std::endl;
354
+ #endif
355
+
356
+ }
357
+
358
+
359
+ void QgsCustomProjectionDialog::pbnNext_clicked ()
360
+ {
361
+ #ifdef QGISDEBUG
362
+ std::cout << " QgsCustomProjectionDialog::pbnNext_clicked()" << std::endl;
363
+ #endif
364
+
365
+ }
366
+
367
+
368
+ void QgsCustomProjectionDialog::pbnLast_clicked ()
369
+ {
370
+ #ifdef QGISDEBUG
371
+ std::cout << " QgsCustomProjectionDialog::pbnLast_clicked()" << std::endl;
372
+ #endif
373
+ sqlite3 *myDatabase;
374
+ char *myErrorMessage = 0 ;
375
+ const char *myTail;
376
+ sqlite3_stmt *myPreparedStatement;
377
+ int myResult;
378
+ // check the db is available
379
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
380
+ if (myResult)
381
+ {
382
+ std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
383
+ // XXX This will likely never happen since on open, sqlite creates the
384
+ // database if it does not exist.
385
+ assert (myResult == 0 );
386
+ }
387
+
388
+ QString mySql = " select * from tbl_user_projection order by description desc limit 1" ;
389
+ myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
390
+ // XXX Need to free memory from the error msg if one is set
391
+ if (myResult == SQLITE_OK)
392
+ {
393
+ sqlite3_step (myPreparedStatement) == SQLITE_ROW;
394
+ leName->setText ((char *)sqlite3_column_text (myPreparedStatement,1 ));
395
+ QString myProjectionFamilyId ((char *)sqlite3_column_text (myPreparedStatement,2 ));
396
+ cboProjectionFamily->setCurrentText (getProjectionFamilyName (myProjectionFamilyId));
397
+ QString myEllipsoidId ((char *)sqlite3_column_text (myPreparedStatement,3 ));
398
+ cboEllipsoid->setCurrentText (getProjectionFamilyName (myEllipsoidId));
399
+ leParameters->setText ((char *)sqlite3_column_text (myPreparedStatement,4 ));
400
+ }
401
+ else
402
+ {
403
+ #ifdef QGISDEBUG
404
+ std::cout << " pbnLast query failed: " << mySql << std::endl;
405
+ #endif
406
+
407
+ }
408
+ sqlite3_finalize (myPreparedStatement);
409
+ sqlite3_close (myDatabase);
163
410
164
411
}
165
412
166
413
414
+ void QgsCustomProjectionDialog::pbnNew_clicked ()
415
+ {
416
+ #ifdef QGISDEBUG
417
+ std::cout << " QgsCustomProjectionDialog::pbnNew_clicked()" << std::endl;
418
+ #endif
419
+
420
+ }
421
+
422
+
423
+ void QgsCustomProjectionDialog::pbnSave_clicked ()
424
+ {
425
+ #ifdef QGISDEBUG
426
+ std::cout << " QgsCustomProjectionDialog::pbnSave_clicked()" << std::endl;
427
+ #endif
428
+
429
+ }
430
+
431
+
432
+
167
433
void QgsCustomProjectionDialog::cboProjectionFamily_highlighted ( const QString & theText)
168
434
{
169
435
#ifdef QGISDEBUG
170
436
std::cout << " Projection selected from combo" << std::endl;
171
437
#endif
172
438
// search the sqlite user projections db for the projection entry
173
439
// and display its parameters
174
- QString myQGisSettingsDir = QDir::homeDirPath () + " /.qgis/" ;
175
440
sqlite3 *myDatabase;
176
441
char *myErrorMessage = 0 ;
177
442
const char *myTail;
178
443
sqlite3_stmt *myPreparedStatement;
179
444
int myResult;
180
445
// check the db is available
181
- myResult = sqlite3_open (QString (myQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
446
+ myResult = sqlite3_open (QString (mQGisSettingsDir +" user_projections.db" ).latin1 (), &myDatabase);
182
447
if (myResult)
183
448
{
184
449
std::cout << " Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
0 commit comments