Skip to content

Commit

Permalink
Some code cleanups regarding qgis.db accessing and handling.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wonder committed Mar 11, 2006
1 parent b26de88 commit a21911b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 425 deletions.
2 changes: 0 additions & 2 deletions src/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ libqgis_coreHEADERS = \
qgsfeature.h \
qgsfeatureattribute.h \
qgsfield.h \
qgsfile.h \
qgsgeometry.h \
qgsgeometryvertexindex.h \
qgslabelattributes.h \
Expand Down Expand Up @@ -113,7 +112,6 @@ libqgis_core_la_SOURCES =\
qgsfeature.cpp \
qgsfeatureattribute.cpp \
qgsfield.cpp \
qgsfile.cpp \
qgsgeometry.cpp \
qgsgeometryvertexindex.cpp \
qgslabelattributes.cpp \
Expand Down
10 changes: 9 additions & 1 deletion src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ const QString QgsApplication::qgisMasterDbFilePath()
return mPkgDataPath + QString("/resources/qgis.db");
}

/*!
Returns the path to the settings directory in user's home dir
*/
const QString QgsApplication::qgisSettingsDirPath()
{
return QDir::homeDirPath() + QString("/.qgis/");
}

/*!
Returns the path to the user qgis.db file.
*/
const QString QgsApplication::qgisUserDbFilePath()
{
return QDir::homeDirPath() + QString("/.qgis/qgis.db");
return qgisSettingsDirPath() + QString("qgis.db");
}

/*!
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class QgsApplication: public QApplication
//! Returns the path to the master qgis.db file.
static const QString qgisMasterDbFilePath();

//! Returns the path to the settings directory in user's home dir
static const QString qgisSettingsDirPath();

//! Returns the path to the user qgis.db file.
static const QString qgisUserDbFilePath();

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgsspatialrefsys.h"
#include "qgsgeometry.h"
#include "qgsdistancearea.h"
#include "qgsapplication.h"

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

Expand Down Expand Up @@ -75,13 +76,12 @@ bool QgsDistanceArea::setEllipsoid(const QString& ellipsoid)
//
// SQLITE3 stuff - get parameters for selected ellipsoid
//
QString mQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open(QString(mQGisSettingsDir+"qgis.db").latin1(), &myDatabase);
myResult = sqlite3_open(QString(QgsApplication::qgisUserDbFilePath()).latin1(), &myDatabase);
if(myResult)
{
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
Expand Down
122 changes: 0 additions & 122 deletions src/core/qgsfile.cpp

This file was deleted.

93 changes: 0 additions & 93 deletions src/core/qgsfile.h

This file was deleted.

22 changes: 10 additions & 12 deletions src/gui/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
#include <qgscursors.h>
#include "qgscustomprojectiondialog.h"
#include "qgsencodingfiledialog.h"
#include "qgsfile.h"
#include "qgsgeomtypedialog.h"
#include "qgshelpviewer.h"
#include "qgslegend.h"
Expand Down Expand Up @@ -1134,34 +1133,34 @@ void QgisApp::createLegend()
toolBox->widget(0)->setLayout(myLegendLayout);
return;
}
void QgisApp::createDB()

bool QgisApp::createDB()
{
// Check qgis.db and make private copy if necessary
QString qgisSettingsDirPath(QDir::homeDirPath () + "/.qgis/");
QgsFile qgisPrivateDbFile(qgisSettingsDirPath + "qgis.db");
QFile qgisPrivateDbFile(QgsApplication::qgisUserDbFilePath());

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

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

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

#ifdef QGISDEBUG
if (!isDbFileCopied)
{
std::cout << "[ERROR] Can not make qgis.db private copy" << std::endl;
return FALSE;
}
#endif
}
return TRUE;
}

// Update file menu with the current list of recently accessed projects
Expand Down Expand Up @@ -5384,13 +5383,12 @@ void QgisApp::newBookmark()
QString::null, &ok, this);
if( ok && !bookmarkName.isEmpty())
{
// Make sure the database exists
if(QgsBookmarks::createDatabase())
if (createDB())
{
// create the bookmark
QgsBookmarkItem *bmi = new QgsBookmarkItem(bookmarkName,
QgsProject::instance()->title(), mMapCanvas->extent(), -1,
QDir::homeDirPath () + "/.qgis/qgis.db");
QgsApplication::qgisUserDbFilePath());
bmi->store();
delete bmi;
// emit a signal to indicate that the bookmark was added
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public slots:
void createLegend();
void createOverview();
void createCanvas();
void createDB();
bool createDB();
//toolbars ----------------------------------------
QToolBar *mFileToolBar;
QToolBar *mLayerToolBar;
Expand Down
Loading

0 comments on commit a21911b

Please sign in to comment.