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

« back to all changes in this revision

Viewing changes to src/app/qgsspatialitesourceselect.h

  • 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
                          qgspatialitesourceselect.h  -  description
 
3
                             -------------------
 
4
    begin                : Dec 2008
 
5
    copyright            : (C) 2008 by Sandro Furieri
 
6
    email                : a.furieri@lqt.it
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
#ifndef QGSSPATIALITESOURCESELECT_H
 
18
#define QGSSPATIALITESOURCESELECT_H
 
19
#include "ui_qgsspatialitesourceselectbase.h"
 
20
 
 
21
#include "qgisgui.h"
 
22
#include "qgsspatialitefilterproxymodel.h"
 
23
#include "qgsspatialitetablemodel.h"
 
24
#include "qgscontexthelp.h"
 
25
 
 
26
extern "C"
 
27
{
 
28
#include <spatialite/sqlite3.h>
 
29
}
 
30
 
 
31
#include <QThread>
 
32
 
 
33
#include <vector>
 
34
#include <list>
 
35
#include <utility>
 
36
 
 
37
#include <QMap>
 
38
#include <QPair>
 
39
#include <QIcon>
 
40
#include <QFileDialog>
 
41
 
 
42
class QStringList;
 
43
class QTableWidgetItem;
 
44
class QgisApp;
 
45
class QPushButton;
 
46
 
 
47
/*! \class QgsSpatiaLiteSourceSelect
 
48
 * \brief Dialog to create connections and add tables from SpatiaLite.
 
49
 *
 
50
 * This dialog allows the user to define and save connection information
 
51
 * for SpatiaLite/SQLite databases. The user can then connect and add
 
52
 * tables from the database to the map canvas.
 
53
 */
 
54
class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSourceSelectBase
 
55
{
 
56
    Q_OBJECT
 
57
 
 
58
  public:
 
59
 
 
60
    //! Constructor
 
61
    QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags fl = QgisGui::ModalDialogFlags );
 
62
    //! Destructor
 
63
    ~QgsSpatiaLiteSourceSelect() {}
 
64
    //! Populate the connection list combo box
 
65
    void populateConnectionList();
 
66
    //! Determines the tables the user selected and closes the dialog
 
67
    void addTables();
 
68
    //! String list containing the selected tables
 
69
    QStringList selectedTables();
 
70
    //! Connection info (DB-path)
 
71
    QString connectionInfo();
 
72
    // Store the selected database
 
73
    void dbChanged();
 
74
 
 
75
  public slots:
 
76
    /*! Connects to the database using the stored connection parameters.
 
77
     * Once connected, available layers are displayed.
 
78
     */
 
79
    void on_btnConnect_clicked();
 
80
    void addClicked();
 
81
    //! Opens the create connection dialog to build a new connection
 
82
    void on_btnNew_clicked();
 
83
    //! Deletes the selected connection
 
84
    void on_btnDelete_clicked();
 
85
    void on_mSearchOptionsButton_clicked();
 
86
    void on_mSearchTableEdit_textChanged( const QString & text );
 
87
    void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );
 
88
    void on_mSearchModeComboBox_currentIndexChanged( const QString & text );
 
89
    void on_cmbConnections_activated( int );
 
90
    void setLayerType( QString table, QString column, QString type );
 
91
    //!Sets a new regular expression to the model
 
92
    void setSearchExpression( const QString & regexp );
 
93
 
 
94
    void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
 
95
 
 
96
  private:
 
97
    enum columns
 
98
    {
 
99
      dbssType = 0,
 
100
      dbssDetail,
 
101
      dbssSql,
 
102
      dbssColumns,
 
103
    };
 
104
 
 
105
    typedef std::pair < QString, QString > geomPair;
 
106
    typedef std::list < geomPair > geomCol;
 
107
 
 
108
    /**Checks if geometry_columns_auth table exists*/
 
109
    bool checkGeometryColumnsAuth( sqlite3 * handle );
 
110
 
 
111
    /**Checks if views_geometry_columns table exists*/
 
112
    bool checkViewsGeometryColumns( sqlite3 * handle );
 
113
 
 
114
    /**Checks if virts_geometry_columns table exists*/
 
115
    bool checkVirtsGeometryColumns( sqlite3 * handle );
 
116
 
 
117
    /**Checks if this layer has been declared HIDDEN*/
 
118
    bool isDeclaredHidden( sqlite3 * handle, QString table, QString geom );
 
119
 
 
120
    /**cleaning well-formatted SQL strings*/
 
121
    QString quotedValue( QString value ) const;
 
122
 
 
123
    /**Inserts information about the spatial tables into mTableModel*/
 
124
    bool getTableInfo( sqlite3 * handle );
 
125
 
 
126
    // SpatiaLite DB open / close
 
127
    sqlite3 *openSpatiaLiteDb( QString path );
 
128
    void closeSpatiaLiteDb( sqlite3 * handle );
 
129
 
 
130
    // Set the position of the database connection list to the last
 
131
    // used one.
 
132
    void setConnectionListPosition();
 
133
    // Combine the table and column data into a single string
 
134
    // useful for display to the user
 
135
    QString fullDescription( QString table, QString column, QString type );
 
136
    // The column labels
 
137
    QStringList mColumnLabels;
 
138
    QString mSqlitePath;
 
139
    QStringList m_selectedTables;
 
140
    // Storage for the range of layer type icons
 
141
    QMap < QString, QPair < QString, QIcon > >mLayerIcons;
 
142
    //! Pointer to the qgis application mainwindow
 
143
    QgisApp *qgisApp;
 
144
    //! Model that acts as datasource for mTableTreeWidget
 
145
    QgsSpatiaLiteTableModel mTableModel;
 
146
    QgsSpatiaLiteFilterProxyModel mProxyModel;
 
147
 
 
148
    QPushButton *mAddButton;
 
149
};
 
150
 
 
151
#endif // QGSSPATIALITESOURCESELECT_H