Skip to content

Commit 2261999

Browse files
committed
switch DB Manager's SQL editor to QgsCodeEditorSQL
1 parent 9a2327c commit 2261999

File tree

3 files changed

+25
-205
lines changed

3 files changed

+25
-205
lines changed

python/plugins/db_manager/dlg_sql_window.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from PyQt4.QtCore import *
2626
from PyQt4.QtGui import *
27+
from PyQt4.Qsci import *
2728
from qgis.core import *
2829

2930
from .db_plugins.plugin import BaseError
@@ -49,7 +50,7 @@ def __init__(self, iface, db, parent=None):
4950

5051
self.editSql.setFocus()
5152
self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
52-
self.editSql.initCompleter(self.db)
53+
self.initCompleter()
5354

5455
# allow to copy results
5556
copyAction = QAction("copy", self)
@@ -284,3 +285,23 @@ def copySelectedResults(self):
284285
QApplication.clipboard().setText( text, QClipboard.Selection )
285286
QApplication.clipboard().setText( text, QClipboard.Clipboard )
286287

288+
def initCompleter(self):
289+
dictionary = None
290+
if self.db:
291+
dictionary = self.db.connector.getSqlDictionary()
292+
if not dictionary:
293+
# use the generic sql dictionary
294+
from .sql_dictionary import getSqlDictionary
295+
dictionary = getSqlDictionary()
296+
297+
wordlist = []
298+
for name, value in dictionary.iteritems():
299+
wordlist += value # concat lists
300+
wordlist = list(set(wordlist)) # remove duplicates
301+
302+
api = QsciAPIs(self.editSql.lexer())
303+
for word in wordlist:
304+
api.add(word)
305+
306+
api.prepare()
307+
self.editSql.lexer().setAPIs(api)

python/plugins/db_manager/sqledit.py

Lines changed: 0 additions & 201 deletions
This file was deleted.

python/plugins/db_manager/ui/DlgSqlWindow.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</layout>
7171
</item>
7272
<item>
73-
<widget class="SqlEdit" name="editSql"/>
73+
<widget class="QgsCodeEditorSQL" name="editSql"/>
7474
</item>
7575
<item>
7676
<layout class="QHBoxLayout">
@@ -356,9 +356,9 @@ columns</string>
356356
</widget>
357357
<customwidgets>
358358
<customwidget>
359-
<class>SqlEdit</class>
359+
<class>QgsCodeEditorSQL</class>
360360
<extends>QTextEdit</extends>
361-
<header>..sqledit</header>
361+
<header>qgscodeeditorsql.h</header>
362362
</customwidget>
363363
</customwidgets>
364364
<tabstops>

0 commit comments

Comments
 (0)