~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/core/qgsbookmarkitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/***************************************************************************
3
 
               QgsBookmarkItem.h  - Spatial Bookmark Item
4
 
                             -------------------
5
 
    begin                : 2005-04-23
6
 
    copyright            : (C) 2005 Gary Sherman
7
 
    email                : sherman at mrcc dot com
8
 
 ***************************************************************************/
9
 
 
10
 
/***************************************************************************
11
 
 *                                                                         *
12
 
 *   This program is free software; you can redistribute it and/or modify  *
13
 
 *   it under the terms of the GNU General Public License as published by  *
14
 
 *   the Free Software Foundation; either version 2 of the License, or     *
15
 
 *   (at your option) any later version.                                   *
16
 
 *                                                                         *
17
 
 ***************************************************************************/
18
 
 /* $Id: qgsbookmarkitem.cpp 6827 2007-03-23 19:02:37Z homann $ */
19
 
#include <iostream>
20
 
#include <sqlite3.h>
21
 
#include <qstring.h>
22
 
#include <qtextstream.h>
23
 
 
24
 
#include <cassert>
25
 
 
26
 
#include "qgsrect.h"
27
 
#include "qgsbookmarkitem.h"
28
 
 
29
 
QgsBookmarkItem::QgsBookmarkItem(QString name, QString projectTitle, 
30
 
      QgsRect viewExtent, int srid, QString dbPath)
31
 
      : mName(name), mProjectTitle(projectTitle), mViewExtent(viewExtent),
32
 
      mSrid(srid), mUserDbPath(dbPath)
33
 
{
34
 
}
35
 
QgsBookmarkItem::~QgsBookmarkItem()
36
 
{
37
 
}
38
 
  void QgsBookmarkItem::store()
39
 
{
40
 
  // To store the bookmark we have to open the database and insert
41
 
  // the record using the parameters set in the constructor
42
 
 
43
 
  sqlite3 *db;
44
 
  int rc;
45
 
#ifdef QGISDEBUG 
46
 
  std::cout << "Opening user database: " << mUserDbPath.toLocal8Bit().data() << std::endl; 
47
 
#endif 
48
 
  rc = sqlite3_open(mUserDbPath.toUtf8().data(), &db);
49
 
  if(rc)
50
 
  {
51
 
    std::cout <<  "Can't open database: " <<  sqlite3_errmsg(db) << std::endl;
52
 
 
53
 
    // XXX This will likely never happen since on open, sqlite creates the
54
 
    //     database if it does not exist.
55
 
    assert(rc == 0);
56
 
  }
57
 
  // prepare the sql statement
58
 
  const char *pzTail;
59
 
  sqlite3_stmt *ppStmt;
60
 
  QString sql;
61
 
  QTextOStream sqlStream(&sql);
62
 
  sqlStream << "insert into tbl_bookmarks values(null,'" <<
63
 
    mName << "','" <<
64
 
    mProjectTitle << "'," <<
65
 
    mViewExtent.xMin() << "," <<
66
 
    mViewExtent.yMin() << "," <<
67
 
    mViewExtent.xMax() << "," <<
68
 
    mViewExtent.yMax() << "," <<
69
 
    mSrid << ")";
70
 
 
71
 
#ifdef QGISDEBUG 
72
 
  std::cout << "Storing bookmark using: " << sql.toLocal8Bit().data() << std::endl; 
73
 
#endif 
74
 
  rc = sqlite3_prepare(db, sql.utf8(), sql.length(), &ppStmt, &pzTail);
75
 
  // XXX Need to free memory from the error msg if one is set
76
 
  if(rc == SQLITE_OK)
77
 
  {
78
 
    // get the first row of the result set
79
 
    if(sqlite3_step(ppStmt) != SQLITE_DONE)
80
 
    {
81
 
 
82
 
      // XXX query failed -- warn the user some how
83
 
      std::cout << "Failed to store bookmark: " << sqlite3_errmsg(db) << std::endl; 
84
 
    }
85
 
    // close the statement
86
 
    sqlite3_finalize(ppStmt);
87
 
    // close the database
88
 
    sqlite3_close(db);
89
 
  }
90
 
 
91
 
 
92
 
}