Skip to content

Commit 3c5b3bb

Browse files
committed
[FEATURE] add DB Manager plugin
1 parent c5c4c7e commit 3c5b3bb

File tree

101 files changed

+12723
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+12723
-0
lines changed

python/plugins/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ ADD_SUBDIRECTORY(mapserver_export)
33
ADD_SUBDIRECTORY(fTools)
44
ADD_SUBDIRECTORY(GdalTools)
55
ADD_SUBDIRECTORY(osm)
6+
ADD_SUBDIRECTORY(db_manager)

python/plugins/db_manager/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
*~
3+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SET (DB_MANAGER_PLUGIN_DIR ${QGIS_DATA_DIR}/python/plugins/db_manager)
2+
3+
FILE(GLOB OTHER_FILES LICENCE README TODO)
4+
FILE(GLOB PY_FILES *.py)
5+
6+
FILE(GLOB UI_FILES ui/*.ui)
7+
PYQT4_WRAP_UI(PYUI_FILES ${UI_FILES})
8+
PYQT4_ADD_RESOURCES(PYRC_FILES resources.qrc)
9+
ADD_CUSTOM_TARGET(db_manager ALL DEPENDS ${PYUI_FILES} ${PYRC_FILES})
10+
11+
INSTALL(FILES ${OTHER_FILES} DESTINATION ${DB_MANAGER_PLUGIN_DIR})
12+
INSTALL(FILES ${PY_FILES} DESTINATION ${DB_MANAGER_PLUGIN_DIR})
13+
INSTALL(FILES ui/__init__.py ${PYUI_FILES} DESTINATION ${DB_MANAGER_PLUGIN_DIR}/ui)
14+
INSTALL(FILES ${PYRC_FILES} DESTINATION ${DB_MANAGER_PLUGIN_DIR})
15+
16+
ADD_SUBDIRECTORY(db_plugins)
17+
ADD_SUBDIRECTORY(icons)

python/plugins/db_manager/CREDITS

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREDITS: 2011/10/13
2+
3+
DB Manager plugin for QuantumGIS
4+
5+
Author and maintainer:
6+
Giuseppe Sucameli <brush.tyler@gmail.com>
7+
8+
9+
The following is a list of contributors who have participated in the project:
10+
11+
Version 0.1.18 includes:
12+
- autocompletion based on "QTextEdit with autocompletion using pyqt" by rowinggolfer (see http://rowinggolfer.blogspot.com/2010/08/qtextedit-with-autocompletion-using.html)
13+
14+
Version 0.1.5 includes patches from:
15+
- Sandro Santilli <strk@keybit.net> for plugin icon.
16+
17+
Version 0.1.2 includes:
18+
- syntax highlighting based on "Python Syntax Highlighting Example" by Carson J. Q. Farmer (see http://www.carsonfarmer.com/?p=333)
19+
- TopoViewer plugin based on qgis_pgis_topoview by Sandro Santilli <strk@keybit.net> (see at https://github.com/strk/qgis_pgis_topoview/)
20+
21+
Version 0.1.0 includes patches from:
22+
- Mauricio de Paulo <mauricio.dev@gmail.com> for PostGIS Rasters support.
23+

python/plugins/db_manager/LICENSE

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
DB Manager * Copyright (c) 2011 Giuseppe Sucameli
2+
3+
Licensed under the terms of GNU GPL v2 (or any layer)
4+
http://www.gnu.org/copyleft/gpl.html
5+
6+
7+
Code:
8+
- some code is derived from PG_Manager by Martin Dobias (GPLv2 license)
9+
- highlighter is based on "Python Syntax Highlighting Example" by Carson J. Q. Farmer (GPLv2 license)
10+
- autocompletion based on "QTextEdit with autocompletion using pyqt" by rowinggolfer (GPLv2 license)
11+
12+
Icons:
13+
- toolbar icons are derived from gis-0.1 iconset by Robert Szczepanek (Creative Commons Attribution-Share Alike 3.0 Unported license)
14+
- refresh toolbar icon is from Tango project (public domain)
15+
- table, view and namespace icons in database view are from pgAdmin3 (BSD license)
16+
- other icons are from QGIS project (GPLv2 license)
17+
- plugin icon by Sandro Santilli, using qgis icon and database icon by Dracos - http://commons.wikimedia.org/wiki/File:Applications-database.svg (Creative Commons Attribution-Share Alike 3.0 Unported license)

python/plugins/db_manager/README

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
DB Manager * Copyright (c) 2011 Giuseppe Sucameli
2+
3+
DB Manager is a database manager plugin for QuantumGIS.
4+
It allows to you to show the DBs contents and run query on them.
5+
6+
In this moment DB Manager supports the following DBMS backends:
7+
- PostgreSQL/PostGIS through the psycopg2 pymodule
8+
- SQLite/SpatiaLite using the pyspatialite pymodule
9+
10+
11+
For more info about the project, see at the wiki page:
12+
http://www.qgis.org/wiki/DB_Manager_plugin_GSoC_2011
13+
14+
or visit my GitHub repository:
15+
https://github.com/brushtyler/db_manager
16+

python/plugins/db_manager/TODO

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
DB Manager TODO and DONE list.
2+
3+
4+
DONE:
5+
* run only the selected part of a query (v0.1.20)
6+
* add versioning support to PostgreSQL dbs (v0.1.19)
7+
* completer for sql keywords/functions (v0.1.18)
8+
* highlights PG and SL functions, fix slow connection to PG db (v0.1.17)
9+
* add contestual menu to db tree, use service param when available to connect to PG dbs (v0.1.16)
10+
* close transactions before doing changes to tables (v0.1.15)
11+
* improve error handling running a query in sql window (v0.1.14)
12+
* fix error dialog (v0.1.13)
13+
* improve error handling, add Re-connect button (v0.1.12)
14+
* add "Run Vacuum" and "Move to schema" to menu (v0.1.11)
15+
* fix encoding support and import layer on Win (v0.1.10)
16+
* allow to copy contents from views (v0.1.9)
17+
* GUI to import data by drag'n'drop (v0.1.8)
18+
* edit table (v0.1.8)
19+
* create table (v0.1.7)
20+
* display schemas and tables comments (v0.1.6)
21+
* SQL syntax highlighting (v0.1.5)
22+
* load a query as layer into canvas (v0.1.4)
23+
* import/export OGR layers and non-spatial data using Import Vector Layer feature (v.0.1.0)
24+
25+
26+
TODO:
27+
- PGManager
28+
* GUI to import/export data (from shapefiles)
29+
- RT_Sql_Layer
30+
* query builder
31+
* query manager
32+
- QSpatialite
33+
* GUI to import QGis layer
34+
- SPIT
35+
* mass import of shapefiles

python/plugins/db_manager/__init__.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
/***************************************************************************
5+
Name : DB Manager
6+
Description : Database manager plugin for QuantumGIS
7+
Date : May 23, 2011
8+
copyright : (C) 2011 by Giuseppe Sucameli
9+
email : brush.tyler@gmail.com
10+
11+
***************************************************************************/
12+
13+
/***************************************************************************
14+
* *
15+
* This program is free software; you can redistribute it and/or modify *
16+
* it under the terms of the GNU General Public License as published by *
17+
* the Free Software Foundation; either version 2 of the License, or *
18+
* (at your option) any later version. *
19+
* *
20+
***************************************************************************/
21+
"""
22+
23+
def name():
24+
return "DB Manager"
25+
26+
def description():
27+
return "Manage your databases within QGis"
28+
29+
def version():
30+
return "0.1.19"
31+
32+
def qgisMinimumVersion():
33+
return "1.5.0"
34+
35+
def icon():
36+
return "icons/dbmanager.png"
37+
38+
def authorName():
39+
return "Giuseppe Sucameli"
40+
41+
def classFactory(iface):
42+
from .db_manager_plugin import DBManagerPlugin
43+
return DBManagerPlugin(iface)
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
/***************************************************************************
5+
Name : DB Manager
6+
Description : Database manager plugin for QuantumGIS
7+
Date : May 23, 2011
8+
copyright : (C) 2011 by Giuseppe Sucameli
9+
email : brush.tyler@gmail.com
10+
11+
The content of this file is based on
12+
- QTextEdit with autocompletion using pyqt by rowinggolfer (GPLv2 license)
13+
see http://rowinggolfer.blogspot.com/2010/08/qtextedit-with-autocompletion-using.html
14+
***************************************************************************/
15+
16+
/***************************************************************************
17+
* *
18+
* This program is free software; you can redistribute it and/or modify *
19+
* it under the terms of the GNU General Public License as published by *
20+
* the Free Software Foundation; either version 2 of the License, or *
21+
* (at your option) any later version. *
22+
* *
23+
***************************************************************************/
24+
"""
25+
26+
from PyQt4.QtGui import *
27+
from PyQt4.QtCore import *
28+
29+
class SqlCompleter(QCompleter):
30+
def __init__(self, editor, db=None):
31+
# get the wordlist
32+
dictionary = None
33+
if db:
34+
dictionary = db.connector.getSqlDictionary()
35+
if not dictionary:
36+
# use the generic sql dictionary
37+
from .sql_dictionary import getSqlDictionary
38+
dictionary = getSqlDictionary()
39+
40+
wordlist = QStringList()
41+
for name, value in dictionary.iteritems():
42+
wordlist << value
43+
44+
# setup the completer
45+
QCompleter.__init__(self, sorted(wordlist), editor)
46+
self.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
47+
self.setWrapAround(False)
48+
49+
if isinstance(editor, CompletionTextEdit):
50+
editor.setCompleter(self)
51+
52+
53+
class CompletionTextEdit(QTextEdit):
54+
def __init__(self, *args, **kwargs):
55+
QTextEdit.__init__(self, *args, **kwargs)
56+
self.completer = None
57+
58+
def setCompleter(self, completer):
59+
if self.completer:
60+
self.disconnect(self.completer, 0, self, 0)
61+
if not completer:
62+
return
63+
64+
completer.setWidget(self)
65+
completer.setCompletionMode(QCompleter.PopupCompletion)
66+
completer.setCaseSensitivity(Qt.CaseInsensitive)
67+
self.completer = completer
68+
self.connect(self.completer, SIGNAL("activated(const QString&)"), self.insertCompletion)
69+
70+
def insertCompletion(self, completion):
71+
tc = self.textCursor()
72+
extra = completion.length() - self.completer.completionPrefix().length()
73+
tc.movePosition(QTextCursor.Left)
74+
tc.movePosition(QTextCursor.EndOfWord)
75+
tc.insertText(completion.right(extra))
76+
self.setTextCursor(tc)
77+
78+
def textUnderCursor(self):
79+
tc = self.textCursor()
80+
tc.select(QTextCursor.WordUnderCursor)
81+
return tc.selectedText()
82+
83+
def focusInEvent(self, event):
84+
if self.completer:
85+
self.completer.setWidget(self)
86+
QTextEdit.focusInEvent(self, event)
87+
88+
def keyPressEvent(self, event):
89+
if self.completer and self.completer.popup().isVisible():
90+
if event.key() in (Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab, Qt.Key_Backtab):
91+
event.ignore()
92+
return
93+
94+
# has ctrl-E or ctrl-space been pressed??
95+
isShortcut = event.modifiers() == Qt.ControlModifier and event.key() in (Qt.Key_E, Qt.Key_Space)
96+
if not self.completer or not isShortcut:
97+
QTextEdit.keyPressEvent(self, event)
98+
99+
# ctrl or shift key on it's own??
100+
ctrlOrShift = event.modifiers() in (Qt.ControlModifier, Qt.ShiftModifier)
101+
if ctrlOrShift and event.text().isEmpty():
102+
# ctrl or shift key on it's own
103+
return
104+
105+
eow = QString("~!@#$%^&*()+{}|:\"<>?,./;'[]\\-=") # end of word
106+
107+
hasModifier = event.modifiers() != Qt.NoModifier and not ctrlOrShift
108+
109+
completionPrefix = self.textUnderCursor()
110+
111+
if not isShortcut and (hasModifier or event.text().isEmpty() or
112+
completionPrefix.length() < 3 or eow.contains(event.text().right(1))):
113+
self.completer.popup().hide()
114+
return
115+
116+
if completionPrefix != self.completer.completionPrefix():
117+
self.completer.setCompletionPrefix(completionPrefix)
118+
popup = self.completer.popup()
119+
popup.setCurrentIndex(self.completer.completionModel().index(0,0))
120+
121+
cr = self.cursorRect()
122+
cr.setWidth(self.completer.popup().sizeHintForColumn(0)
123+
+ self.completer.popup().verticalScrollBar().sizeHint().width())
124+
self.completer.complete(cr) # popup it up!
125+
126+
#if __name__ == "__main__":
127+
# app = QApplication([])
128+
# te = CompletionTextEdit()
129+
# SqlCompleter( te )
130+
# te.show()
131+
# app.exec_()

0 commit comments

Comments
 (0)