Skip to content
Permalink
Browse files

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
  • Loading branch information
wonder
wonder committed Mar 11, 2006
1 parent b26de88 commit a21911b8f3bc2bf7100ef604df58c6e4a9b65f4a
@@ -59,7 +59,6 @@ libqgis_coreHEADERS = \
qgsfeature.h \
qgsfeatureattribute.h \
qgsfield.h \
qgsfile.h \
qgsgeometry.h \
qgsgeometryvertexindex.h \
qgslabelattributes.h \
@@ -113,7 +112,6 @@ libqgis_core_la_SOURCES =\
qgsfeature.cpp \
qgsfeatureattribute.cpp \
qgsfield.cpp \
qgsfile.cpp \
qgsgeometry.cpp \
qgsgeometryvertexindex.cpp \
qgslabelattributes.cpp \
@@ -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");
}

/*!
@@ -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();

@@ -26,6 +26,7 @@
#include "qgsspatialrefsys.h"
#include "qgsgeometry.h"
#include "qgsdistancearea.h"
#include "qgsapplication.h"

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

@@ -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;

This file was deleted.

This file was deleted.

@@ -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"
@@ -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
@@ -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
@@ -412,7 +412,7 @@ public slots:
void createLegend();
void createOverview();
void createCanvas();
void createDB();
bool createDB();
//toolbars ----------------------------------------
QToolBar *mFileToolBar;
QToolBar *mLayerToolBar;

0 comments on commit a21911b

Please sign in to comment.
You can’t perform that action at this time.