Skip to content

Commit a21911b

Browse files
author
wonder
committedMar 11, 2006
Some code cleanups regarding qgis.db accessing and handling.
Removed QgsFile as it's already superseded by Qt4 QFile. Revision 5000 ... WOW :-) git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5000 c8812cc2-4d05-0410-92ff-de0c093fc19c

14 files changed

+70
-425
lines changed
 

‎src/core/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ libqgis_coreHEADERS = \
5959
qgsfeature.h \
6060
qgsfeatureattribute.h \
6161
qgsfield.h \
62-
qgsfile.h \
6362
qgsgeometry.h \
6463
qgsgeometryvertexindex.h \
6564
qgslabelattributes.h \
@@ -113,7 +112,6 @@ libqgis_core_la_SOURCES =\
113112
qgsfeature.cpp \
114113
qgsfeatureattribute.cpp \
115114
qgsfield.cpp \
116-
qgsfile.cpp \
117115
qgsgeometry.cpp \
118116
qgsgeometryvertexindex.cpp \
119117
qgslabelattributes.cpp \

‎src/core/qgsapplication.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ const QString QgsApplication::qgisMasterDbFilePath()
107107
return mPkgDataPath + QString("/resources/qgis.db");
108108
}
109109

110+
/*!
111+
Returns the path to the settings directory in user's home dir
112+
*/
113+
const QString QgsApplication::qgisSettingsDirPath()
114+
{
115+
return QDir::homeDirPath() + QString("/.qgis/");
116+
}
117+
110118
/*!
111119
Returns the path to the user qgis.db file.
112120
*/
113121
const QString QgsApplication::qgisUserDbFilePath()
114122
{
115-
return QDir::homeDirPath() + QString("/.qgis/qgis.db");
123+
return qgisSettingsDirPath() + QString("qgis.db");
116124
}
117125

118126
/*!

‎src/core/qgsapplication.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class QgsApplication: public QApplication
4242
//! Returns the path to the master qgis.db file.
4343
static const QString qgisMasterDbFilePath();
4444

45+
//! Returns the path to the settings directory in user's home dir
46+
static const QString qgisSettingsDirPath();
47+
4548
//! Returns the path to the user qgis.db file.
4649
static const QString qgisUserDbFilePath();
4750

‎src/core/qgsdistancearea.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsspatialrefsys.h"
2727
#include "qgsgeometry.h"
2828
#include "qgsdistancearea.h"
29+
#include "qgsapplication.h"
2930

3031
#define DEG2RAD(x) ((x)*M_PI/180)
3132

@@ -75,13 +76,12 @@ bool QgsDistanceArea::setEllipsoid(const QString& ellipsoid)
7576
//
7677
// SQLITE3 stuff - get parameters for selected ellipsoid
7778
//
78-
QString mQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
7979
sqlite3 *myDatabase;
8080
const char *myTail;
8181
sqlite3_stmt *myPreparedStatement;
8282
int myResult;
8383
//check the db is available
84-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").latin1(), &myDatabase);
84+
myResult = sqlite3_open(QString(QgsApplication::qgisUserDbFilePath()).latin1(), &myDatabase);
8585
if(myResult)
8686
{
8787
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;

‎src/core/qgsfile.cpp

Lines changed: 0 additions & 122 deletions
This file was deleted.

‎src/core/qgsfile.h

Lines changed: 0 additions & 93 deletions
This file was deleted.

‎src/gui/qgisapp.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
#include <qgscursors.h>
7373
#include "qgscustomprojectiondialog.h"
7474
#include "qgsencodingfiledialog.h"
75-
#include "qgsfile.h"
7675
#include "qgsgeomtypedialog.h"
7776
#include "qgshelpviewer.h"
7877
#include "qgslegend.h"
@@ -1134,34 +1133,34 @@ void QgisApp::createLegend()
11341133
toolBox->widget(0)->setLayout(myLegendLayout);
11351134
return;
11361135
}
1137-
void QgisApp::createDB()
1136+
1137+
bool QgisApp::createDB()
11381138
{
11391139
// Check qgis.db and make private copy if necessary
1140-
QString qgisSettingsDirPath(QDir::homeDirPath () + "/.qgis/");
1141-
QgsFile qgisPrivateDbFile(qgisSettingsDirPath + "qgis.db");
1140+
QFile qgisPrivateDbFile(QgsApplication::qgisUserDbFilePath());
11421141

11431142
// first we look for ~/.qgis/qgis.db
11441143
if (!qgisPrivateDbFile.exists())
11451144
{
11461145
// if it doesnt exist we copy it in from the global resources dir
11471146
QString qgisMasterDbFileName = QgsApplication::qgisMasterDbFilePath();
1147+
QFile masterFile(qgisMasterDbFileName);
11481148

11491149
// Must be sure there is destination directory ~/.qgis
1150-
// @todo XXX REPLACE with recursive dir creator, but first define QgsDir class and
1151-
// move i.e. makeDir from QgsBookmarks to QgsDir
1152-
QDir destDir;
1153-
destDir.mkdir(qgisSettingsDirPath, TRUE);
1150+
QDir().mkpath(QgsApplication::qgisSettingsDirPath());
11541151

11551152
//now copy the master file into the users .qgis dir
1156-
bool isDbFileCopied = QgsFile::copy(qgisMasterDbFileName, qgisPrivateDbFile.name());
1153+
bool isDbFileCopied = masterFile.copy(qgisPrivateDbFile.name());
11571154

11581155
#ifdef QGISDEBUG
11591156
if (!isDbFileCopied)
11601157
{
11611158
std::cout << "[ERROR] Can not make qgis.db private copy" << std::endl;
1159+
return FALSE;
11621160
}
11631161
#endif
11641162
}
1163+
return TRUE;
11651164
}
11661165

11671166
// Update file menu with the current list of recently accessed projects
@@ -5384,13 +5383,12 @@ void QgisApp::newBookmark()
53845383
QString::null, &ok, this);
53855384
if( ok && !bookmarkName.isEmpty())
53865385
{
5387-
// Make sure the database exists
5388-
if(QgsBookmarks::createDatabase())
5386+
if (createDB())
53895387
{
53905388
// create the bookmark
53915389
QgsBookmarkItem *bmi = new QgsBookmarkItem(bookmarkName,
53925390
QgsProject::instance()->title(), mMapCanvas->extent(), -1,
5393-
QDir::homeDirPath () + "/.qgis/qgis.db");
5391+
QgsApplication::qgisUserDbFilePath());
53945392
bmi->store();
53955393
delete bmi;
53965394
// emit a signal to indicate that the bookmark was added

‎src/gui/qgisapp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public slots:
412412
void createLegend();
413413
void createOverview();
414414
void createCanvas();
415-
void createDB();
415+
bool createDB();
416416
//toolbars ----------------------------------------
417417
QToolBar *mFileToolBar;
418418
QToolBar *mLayerToolBar;

‎src/gui/qgsbookmarks.cpp

Lines changed: 12 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ QgsBookmarks::QgsBookmarks(QWidget *parent, Qt::WFlags fl)
3838
setupUi(this);
3939
connect(btnClose, SIGNAL(clicked()), this, SLOT(reject()));
4040

41-
// make sure the users database for bookmarks exists
42-
mQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
43-
mUserDbPath = mQGisSettingsDir + "qgis.db";
44-
// create the database (if it exists - no problem)
45-
createDatabase();
41+
// user database is created at QGIS startup in QgisApp::createDB
42+
// we just check whether there is our database [MD]
43+
QFileInfo myFileInfo;
44+
myFileInfo.setFile(QgsApplication::qgisSettingsDirPath());
45+
if ( !myFileInfo.exists( ) )
46+
{
47+
#ifdef QGISDEBUG
48+
std::cout << "The qgis.db does not exist" << std::endl;
49+
#endif
50+
}
51+
4652
// Note proper queens english on next line
4753
initialise();
4854

@@ -109,35 +115,6 @@ void QgsBookmarks::initialise()
109115
}
110116
}
111117

112-
// A recursive function to make a directory and its ancestors
113-
// XXX Note we use this function in two places, one more and we
114-
// XXX should consider making a utility class to contain this and
115-
// XXX other, if any functions that are used across the application.
116-
bool QgsBookmarks::makeDir(QDir &theQDir)
117-
{
118-
if (theQDir.isRoot ())
119-
{
120-
//cannot create a root dir
121-
return (false);
122-
}
123-
124-
QDir myBaseDir;
125-
QFileInfo myTempFileInfo;
126-
127-
myTempFileInfo.setFile(theQDir.path());
128-
myBaseDir = myTempFileInfo.dir();
129-
130-
if(!myBaseDir.exists() && !makeDir(myBaseDir))
131-
{
132-
return FALSE;
133-
}
134-
135-
qDebug("attempting to create directory %s in %s",
136-
(const char *)myTempFileInfo.fileName().toLocal8Bit().data(),
137-
(const char *)myBaseDir.path().toLocal8Bit().data());
138-
139-
return myBaseDir.mkdir(myTempFileInfo.fileName());
140-
}
141118

142119
void QgsBookmarks::on_btnDelete_clicked()
143120
{
@@ -248,7 +225,7 @@ int QgsBookmarks::connectDb()
248225
{
249226

250227
int rc;
251-
rc = sqlite3_open(mUserDbPath.toLocal8Bit().data(), &db);
228+
rc = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &db);
252229
if(rc)
253230
{
254231
std::cout << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
@@ -259,60 +236,6 @@ int QgsBookmarks::connectDb()
259236
}
260237
return rc;
261238
}
262-
bool QgsBookmarks::createDatabase()
263-
{
264-
// make sure the users database for bookmarks exists
265-
QString qgisSettingsDir = QDir::homeDirPath () + "/.qgis/";
266-
// first we look for ~/.qgis/qgis.db
267-
// if it doesnt exist we copy it in from the global resources dir
268-
QFileInfo myFileInfo;
269-
myFileInfo.setFile(qgisSettingsDir + "qgis.db");
270-
if ( !myFileInfo.exists( ) )
271-
{
272-
#ifdef QGISDEBUG
273-
std::cout << "The qgis.db does not exist in $HOME/.qgis" << std::endl;
274-
#endif
275-
// make sure the ~/.qgis dir exists first
276-
QDir myUserQGisDir;
277-
QString myPath = QDir::homeDirPath();
278-
myPath += "/.qgis";
279-
myUserQGisDir.setPath(myPath);
280-
#ifdef QGISDEBUG
281-
std::cout << "Using " << myPath.toLocal8Bit().data() << " as path for qgis.db" << std::endl;
282-
#endif
283-
//now make sure the users .qgis dir exists
284-
makeDir(myUserQGisDir);
285-
// Get the full path name to the sqlite3 spatial reference database.
286-
QString myMasterDatabaseFileName = QgsApplication::qgisMasterDbFilePath();
287-
//now copy the master file into the users .qgis dir
288-
std::ifstream myInputStream(myMasterDatabaseFileName.toLocal8Bit().data() );
289-
290-
if (! myInputStream)
291-
{
292-
std::cerr << "unable to open input file: "
293-
<< myMasterDatabaseFileName.toLocal8Bit().data() << " --bailing out! \n";
294-
//XXX Do better error handling
295-
return false;
296-
}
297-
298-
std::ofstream myOutputStream(QString(qgisSettingsDir+"qgis.db").toLocal8Bit().data());
299-
300-
if (! myOutputStream)
301-
{
302-
std::cerr << "cannot open " << QString(qgisSettingsDir+"qgis.db").toLocal8Bit().data() << " for output\n";
303-
//XXX Do better error handling
304-
return false;
305-
}
306-
307-
char myChar;
308-
while (myInputStream.get(myChar))
309-
{
310-
myOutputStream.put(myChar);
311-
}
312-
313-
}
314-
return true;
315-
}
316239

317240
void QgsBookmarks::on_btnHelp_clicked()
318241
{

‎src/gui/qgsbookmarks.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define QGSBOOKMARKS_H
2020
#include "ui_qgsbookmarksbase.h"
2121
#include <QDialog>
22+
2223
class QString;
23-
class QDir;
2424
class QWidget;
2525
class Q3ListViewItem;
2626
class sqlite3;
@@ -30,7 +30,6 @@ class QgsBookmarks : public QDialog, private Ui::QgsBookmarksBase
3030
public:
3131
QgsBookmarks(QWidget *parent = 0, Qt::WFlags fl = 0);
3232
~QgsBookmarks();
33-
static bool createDatabase();
3433
public slots:
3534
void on_btnDelete_clicked();
3635
void on_btnZoomTo_clicked();
@@ -40,12 +39,9 @@ public slots:
4039

4140
private:
4241
QWidget *mParent;
43-
static bool makeDir(QDir &theQDir);
4442
void initialise();
4543
int connectDb();
4644
void zoomToBookmark();
47-
QString mUserDbPath;
48-
QString mQGisSettingsDir;
4945
sqlite3 *db;
5046
static const int context_id = 85340544;
5147

‎src/gui/qgscustomprojectiondialog.cpp

Lines changed: 21 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,15 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog(QWidget *parent, Qt::WFlags
3737
{
3838
setupUi(this);
3939

40-
mQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
41-
// first we look for ~/.qgis/qgis.db
42-
// if it doesnt exist we copy it in from the global resources dir
40+
// user database is created at QGIS startup in QgisApp::createDB
41+
// we just check whether there is our database [MD]
4342
QFileInfo myFileInfo;
44-
myFileInfo.setFile(mQGisSettingsDir+"qgis.db");
43+
myFileInfo.setFile(QgsApplication::qgisSettingsDirPath());
4544
if ( !myFileInfo.exists( ) )
4645
{
47-
// make sure the ~/.qgis dir exists first
48-
QDir myUserQGisDir;
49-
QString myPath = QDir::homeDirPath();
50-
myPath += "/.qgis";
51-
myUserQGisDir.setPath(myPath);
52-
//now make sure the users .qgis dir exists
53-
makeDir(myUserQGisDir);
54-
// Get the full path name to the sqlite3 spatial reference database.
55-
QString myMasterDatabaseFileName = QgsApplication::qgisMasterDbFilePath();
56-
//now copy the master file into the users .qgis dir
57-
std::ifstream myInputStream(myMasterDatabaseFileName.toLocal8Bit().data() );
58-
59-
if (! myInputStream)
60-
{
61-
std::cerr << "unable to open input file: "
62-
<< myMasterDatabaseFileName.toLocal8Bit().data() << " --bailing out! \n";
63-
//XXX Do better error handling
64-
return ;
65-
}
66-
67-
std::ofstream myOutputStream(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data());
68-
69-
if (! myOutputStream)
70-
{
71-
std::cerr << "cannot open " << QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data() << " for output\n";
72-
//XXX Do better error handling
73-
return ;
74-
}
75-
76-
char myChar;
77-
while (myInputStream.get(myChar))
78-
{
79-
myOutputStream.put(myChar);
80-
}
81-
46+
#ifdef QGISDEBUG
47+
std::cout << "The qgis.db does not exist" << std::endl;
48+
#endif
8249
}
8350

8451
//
@@ -114,7 +81,7 @@ void QgsCustomProjectionDialog::getProjList ()
11481
sqlite3_stmt *myPreparedStatement;
11582
int myResult;
11683
//check the db is available
117-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
84+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
11885
if(myResult)
11986
{
12087
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -149,7 +116,7 @@ void QgsCustomProjectionDialog::getEllipsoidList()
149116
sqlite3_stmt *myPreparedStatement;
150117
int myResult;
151118
//check the db is available
152-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
119+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
153120
if(myResult)
154121
{
155122
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -197,7 +164,7 @@ void QgsCustomProjectionDialog::on_pbnDelete_clicked()
197164
int myResult;
198165
QString myName;
199166
//check the db is available
200-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
167+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
201168
if(myResult)
202169
{
203170
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -257,7 +224,7 @@ long QgsCustomProjectionDialog::getRecordCount()
257224
int myResult;
258225
long myRecordCount=0;
259226
//check the db is available
260-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
227+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
261228
if(myResult)
262229
{
263230
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -290,7 +257,7 @@ QString QgsCustomProjectionDialog::getProjectionFamilyName(QString theProjection
290257
int myResult;
291258
QString myName;
292259
//check the db is available
293-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
260+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
294261
if(myResult)
295262
{
296263
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -321,7 +288,7 @@ QString QgsCustomProjectionDialog::getEllipsoidName(QString theEllipsoidAcronym)
321288
int myResult;
322289
QString myName;
323290
//check the db is available
324-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
291+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
325292
if(myResult)
326293
{
327294
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -352,7 +319,7 @@ QString QgsCustomProjectionDialog::getProjectionFamilyAcronym(QString theProject
352319
int myResult;
353320
QString myName;
354321
//check the db is available
355-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
322+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
356323
if(myResult)
357324
{
358325
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -383,7 +350,7 @@ QString QgsCustomProjectionDialog::getEllipsoidAcronym(QString theEllipsoidName)
383350
int myResult;
384351
QString myName;
385352
//check the db is available
386-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
353+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
387354
if(myResult)
388355
{
389356
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -417,7 +384,7 @@ void QgsCustomProjectionDialog::on_pbnFirst_clicked()
417384
sqlite3_stmt *myPreparedStatement;
418385
int myResult;
419386
//check the db is available
420-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
387+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
421388
if(myResult)
422389
{
423390
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -485,7 +452,7 @@ void QgsCustomProjectionDialog::on_pbnPrevious_clicked()
485452
sqlite3_stmt *myPreparedStatement;
486453
int myResult;
487454
//check the db is available
488-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
455+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
489456
if(myResult)
490457
{
491458
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -562,7 +529,7 @@ void QgsCustomProjectionDialog::on_pbnNext_clicked()
562529
sqlite3_stmt *myPreparedStatement;
563530
int myResult;
564531
//check the db is available
565-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
532+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
566533
if(myResult)
567534
{
568535
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -636,7 +603,7 @@ void QgsCustomProjectionDialog::on_pbnLast_clicked()
636603
sqlite3_stmt *myPreparedStatement;
637604
int myResult;
638605
//check the db is available
639-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
606+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
640607
if(myResult)
641608
{
642609
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -852,12 +819,12 @@ void QgsCustomProjectionDialog::on_pbnSave_clicked()
852819
sqlite3_stmt *myPreparedStatement;
853820
int myResult;
854821
//check the db is available
855-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
822+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
856823
if(myResult!=SQLITE_OK)
857824
{
858825
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) <<
859826
" /n please notify QGIS developers of this error \n " <<
860-
QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data() << " (file name) "
827+
QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << " (file name) "
861828
<< std::endl;
862829
// XXX This will likely never happen since on open, sqlite creates the
863830
// database if it does not exist.
@@ -980,7 +947,7 @@ void QgsCustomProjectionDialog::cboProjectionFamily_highlighted( const QString &
980947
sqlite3_stmt *myPreparedStatement;
981948
int myResult;
982949
//check the db is available
983-
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
950+
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
984951
if(myResult!=SQLITE_OK)
985952
{
986953
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -1012,33 +979,6 @@ void QgsCustomProjectionDialog::cboProjectionFamily_highlighted( const QString &
1012979
}
1013980
*/
1014981

1015-
//a recursive function to make a directory and its ancestors
1016-
bool QgsCustomProjectionDialog::makeDir(QDir &theQDir)
1017-
{
1018-
if (theQDir.isRoot ())
1019-
{
1020-
//cannot create a root dir
1021-
return (false);
1022-
}
1023-
1024-
QDir myBaseDir;
1025-
QFileInfo myTempFileInfo;
1026-
1027-
myTempFileInfo.setFile(theQDir.path());
1028-
myBaseDir = myTempFileInfo.dir();
1029-
1030-
if(!myBaseDir.exists() && !makeDir(myBaseDir))
1031-
{
1032-
return FALSE;
1033-
}
1034-
1035-
qDebug("attempting to create directory %s in %s",
1036-
(const char *)myTempFileInfo.fileName().toLocal8Bit().data(),
1037-
(const char *)myBaseDir.path().toLocal8Bit().data());
1038-
1039-
return myBaseDir.mkdir(myTempFileInfo.fileName());
1040-
}
1041-
1042982

1043983
QString QgsCustomProjectionDialog::getProjFromParameters()
1044984
{
@@ -1111,7 +1051,3 @@ const QString QgsCustomProjectionDialog::stringSQLSafe(const QString theSQL)
11111051
return myRetval;
11121052
}
11131053

1114-
1115-
1116-
1117-

‎src/gui/qgscustomprojectiondialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Q_OBJECT
2727
QgsCustomProjectionDialog(QWidget *parent = 0, Qt::WFlags fl = 0);
2828
~QgsCustomProjectionDialog();
2929
//a recursive function to make a directory and its ancestors
30-
bool makeDir(QDir &theQDir);
3130
public slots:
3231
void on_pbnCalculate_clicked();
3332
void on_pbnHelp_clicked();
@@ -66,7 +65,6 @@ public slots:
6665
//so that we can return to it if the record insert is aborted
6766
long mLastRecordLong;
6867
long mRecordCountLong;
69-
QString mQGisSettingsDir;
7068
const QString stringSQLSafe(const QString theSQL);
7169

7270
};

‎src/gui/qgsspatialrefsys.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ bool QgsSpatialRefSys::createFromSrsId (long theSrsId)
419419
//
420420
if (theSrsId>= USER_PROJECTION_START_ID)
421421
{
422-
myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
422+
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
423423
QFileInfo myFileInfo;
424424
myFileInfo.setFile(myDatabaseFileName);
425425
if ( !myFileInfo.exists( ) )
@@ -663,7 +663,7 @@ QgsSpatialRefSys::RecordMap QgsSpatialRefSys::getRecord(QString theSql)
663663
sqlite3_finalize(myPreparedStatement);
664664
sqlite3_close(myDatabase);
665665

666-
myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
666+
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
667667
QFileInfo myFileInfo;
668668
myFileInfo.setFile(myDatabaseFileName);
669669
if ( !myFileInfo.exists( ) )
@@ -999,7 +999,7 @@ long QgsSpatialRefSys::findMatchingProj()
999999
// Try the users db now
10001000
//
10011001

1002-
myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
1002+
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
10031003
//check the db is available
10041004
myResult = openDb(myDatabaseFileName, &myDatabase);
10051005
if(myResult)
@@ -1261,7 +1261,7 @@ QString QgsSpatialRefSys::getProj4FromSrsId(const int theSrsId)
12611261
//
12621262
if (theSrsId >= USER_PROJECTION_START_ID)
12631263
{
1264-
myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
1264+
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
12651265
QFileInfo myFileInfo;
12661266
myFileInfo.setFile(myDatabaseFileName);
12671267
if ( !myFileInfo.exists( ) ) //its unlikely that this condition will ever be reached

‎src/widgets/projectionselector/qgsprojectionselector.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ QString QgsProjectionSelector::getCurrentProj4String()
255255
//
256256
if (mySrsId.toLong() >= USER_PROJECTION_START_ID)
257257
{
258-
myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
258+
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
259259
QFileInfo myFileInfo;
260260
myFileInfo.setFile(myDatabaseFileName);
261261
if ( !myFileInfo.exists( ) ) //its unlikely that this condition will ever be reached
@@ -346,7 +346,7 @@ long QgsProjectionSelector::getCurrentLongAttribute(QString attributeName)
346346
//
347347
if (lvi->text(1).toLong() >= USER_PROJECTION_START_ID)
348348
{
349-
myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
349+
myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
350350
QFileInfo myFileInfo;
351351
myFileInfo.setFile(myDatabaseFileName);
352352
if ( !myFileInfo.exists( ) )
@@ -466,11 +466,11 @@ void QgsProjectionSelector::applyUserProjList(QSet<QString> * crsFilter)
466466

467467
//determine where the user proj database lives for this user. If none is found an empty
468468
//now only will be shown
469-
QString myQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
469+
QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
470470
// first we look for ~/.qgis/qgis.db
471471
// if it doesnt exist we copy it in from the global resources dir
472472
QFileInfo myFileInfo;
473-
myFileInfo.setFile(myQGisSettingsDir+"qgis.db");
473+
myFileInfo.setFile(myDatabaseFileName);
474474
//return straight away if the user has not created any custom projections
475475
if ( !myFileInfo.exists( ) )
476476
{
@@ -487,7 +487,7 @@ void QgsProjectionSelector::applyUserProjList(QSet<QString> * crsFilter)
487487
sqlite3_stmt *myPreparedStatement;
488488
int myResult;
489489
//check the db is available
490-
myResult = sqlite3_open(QString(myQGisSettingsDir+"qgis.db").toLocal8Bit().data(), &myDatabase);
490+
myResult = sqlite3_open(QString(myDatabaseFileName).toLocal8Bit().data(), &myDatabase);
491491
if(myResult)
492492
{
493493
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
@@ -859,7 +859,7 @@ void QgsProjectionSelector::on_pbnFind_clicked()
859859
}
860860
}
861861
//search the users db
862-
QString myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
862+
QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
863863
QFileInfo myFileInfo;
864864
myFileInfo.setFile(myDatabaseFileName);
865865
if ( !myFileInfo.exists( ) ) //its not critical if this happens
@@ -905,7 +905,7 @@ long QgsProjectionSelector::getLargestSRSIDMatch(QString theSql)
905905
// first we search the users db as any srsid there will be definition be greater than in sys db
906906

907907
//check the db is available
908-
QString myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db";
908+
QString myDatabaseFileName = QgsApplication::qgisUserDbFilePath();
909909
QFileInfo myFileInfo;
910910
myFileInfo.setFile(myDatabaseFileName);
911911
if ( myFileInfo.exists( ) ) //only bother trying to open if the file exists

0 commit comments

Comments
 (0)
Please sign in to comment.