Skip to content

Commit e70e53d

Browse files
author
mhugent
committed
Commit postgis dialog extension to trunk
git-svn-id: http://svn.osgeo.org/qgis/trunk@7920 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent db0ca5b commit e70e53d

9 files changed

+875
-359
lines changed

src/app/qgsdbsourceselect.cpp

+327-259
Large diffs are not rendered by default.

src/app/qgsdbsourceselect.h

+17-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#define QGSDBSOURCESELECT_H
2020
#include "ui_qgsdbsourceselectbase.h"
2121
#include "qgisgui.h"
22+
#include "qgsdbfilterproxymodel.h"
23+
#include "qgsdbtablemodel.h"
24+
2225
extern "C"
2326
{
2427
#include <libpq-fe.h>
@@ -68,8 +71,6 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
6871
QStringList selectedTables();
6972
//! Connection info (database, host, user, password)
7073
QString connInfo();
71-
//! Return the name of the selected encoding (e.g. UTf-8, ISO-8559-1, etc/)
72-
QString encoding();
7374
// Store the selected database
7475
void dbChanged();
7576
// Utility function to construct the query for finding out the
@@ -85,12 +86,18 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
8586
void on_btnNew_clicked();
8687
void on_btnEdit_clicked();
8788
void on_btnDelete_clicked();
88-
void on_lstTables_itemDoubleClicked(QTableWidgetItem *);
89-
void setSql(QTableWidgetItem *);
89+
void on_mSearchOptionsButton_clicked();
90+
void on_mSearchTableEdit_textChanged(const QString & text);
91+
void on_mSearchColumnComboBox_currentIndexChanged(const QString & text);
92+
void on_mSearchModeComboBox_currentIndexChanged(const QString & text);
93+
void setSql(const QModelIndex& index);
9094
void on_btnHelp_clicked();
9195
void on_cmbConnections_activated(int);
9296
void setLayerType(QString schema, QString table, QString column,
9397
QString type);
98+
//!Sets a new regular expression to the model
99+
void setSearchExpression(const QString& regexp);
100+
94101
private:
95102
enum columns {
96103
dbssType=0,
@@ -107,6 +114,9 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
107114
bool searchGeometryColumnsOnly,
108115
bool searchPublicOnly);
109116

117+
/**Inserts information about the spatial tables into mTableModel*/
118+
bool getTableInfo(PGconn *pg, bool searchGeometryColumnsOnly, bool searchPublicOnly);
119+
110120
// queue another query for the thread
111121
void addSearchGeometryColumn(const QString &schema, const QString &table, const QString &column);
112122

@@ -115,10 +125,6 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
115125
void setConnectionListPosition();
116126
// Show the context help for the dialog
117127
void showHelp();
118-
// initialize row
119-
void initRow(int row);
120-
// update the row
121-
void updateRow(int row, QString detail, QString type);
122128
// Combine the schema, table and column data into a single string
123129
// useful for display to the user
124130
QString fullDescription(QString schema, QString table, QString column, QString type);
@@ -130,14 +136,13 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
130136
QStringList m_selectedTables;
131137
// Storage for the range of layer type icons
132138
QMap<QString, QPair<QString, QIcon> > mLayerIcons;
133-
#if 0
134-
// minlength of layer type combobox
135-
int mCbMinLength;
136-
#endif
137139
//! Pointer to the qgis application mainwindow
138140
QgisApp *qgisApp;
139141
PGconn *pd;
140142
static const int context_id = 939347163;
143+
//! Model that acts as datasource for mTableTreeWidget
144+
QgsDbTableModel mTableModel;
145+
QgsDbFilterProxyModel mProxyModel;
141146
};
142147

143148

src/core/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ qgsclipper.cpp
1111
qgscontexthelp.cpp
1212
qgscoordinatetransform.cpp
1313
qgsdatasourceuri.cpp
14+
qgsdbfilterproxymodel.cpp
15+
qgsdbtablemodel.cpp
1416
qgsdistancearea.cpp
1517
qgsexception.cpp
1618
qgsfeature.cpp

src/core/qgsdbfilterproxymodel.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/***************************************************************************
2+
qgsdbfilterproxymodel.cpp - description
3+
-------------------------
4+
begin : Dec 2007
5+
copyright : (C) 2007 by Marco Hugentobler
6+
email : marco dot hugentobler at karto dot baug dot ethz dot ch
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+
18+
#include "qgsdbfilterproxymodel.h"
19+
20+
QgsDbFilterProxyModel::QgsDbFilterProxyModel(QObject* parent): QSortFilterProxyModel(parent)
21+
{
22+
23+
}
24+
25+
QgsDbFilterProxyModel::~QgsDbFilterProxyModel()
26+
{
27+
28+
}
29+
30+
bool QgsDbFilterProxyModel::filterAcceptsRow(int row, const QModelIndex & source_parent ) const
31+
{
32+
//if parent is valid, we have a toplevel item that should be always shown
33+
if(!source_parent.isValid())
34+
{
35+
return true;
36+
}
37+
38+
//else we have a row that describes a table and that
39+
//should be tested using the given wildcard/regexp
40+
return QSortFilterProxyModel::filterAcceptsRow(row, source_parent);
41+
}
42+
43+
void QgsDbFilterProxyModel::_setFilterWildcard(const QString& pattern)
44+
{
45+
QSortFilterProxyModel::setFilterWildcard(pattern);
46+
emit layoutChanged();
47+
}
48+
49+
void QgsDbFilterProxyModel::_setFilterRegExp(const QString& pattern)
50+
{
51+
QSortFilterProxyModel::setFilterRegExp(pattern);
52+
emit layoutChanged();
53+
}

src/core/qgsdbfilterproxymodel.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************
2+
qgsdbfilterproxymodel.h - description
3+
-----------------------
4+
begin : Dec 2007
5+
copyright : (C) 2007 by Marco Hugentobler
6+
email : marco dot hugentobler at karto dot baug dot ethz dot ch
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+
18+
#ifndef QGSDBFILTERPROXYMODEL_H
19+
#define QGSDBFILTERPROXYMODEL_H
20+
21+
#include <QSortFilterProxyModel>
22+
23+
/**A class that implements a custom filter and can be used
24+
as a proxy for QgsDbTableModel*/
25+
class CORE_EXPORT QgsDbFilterProxyModel: public QSortFilterProxyModel
26+
{
27+
public:
28+
QgsDbFilterProxyModel(QObject* parent = 0);
29+
~QgsDbFilterProxyModel();
30+
/**Calls QSortFilterProxyModel::setFilterWildcard and triggers update*/
31+
void _setFilterWildcard(const QString& pattern);
32+
/**Calls QSortFilterProxyModel::setFilterRegExp and triggers update*/
33+
void _setFilterRegExp(const QString& pattern);
34+
35+
protected:
36+
virtual bool filterAcceptsRow(int row, const QModelIndex & source_parent ) const;
37+
};
38+
39+
#endif

0 commit comments

Comments
 (0)