Skip to content
Permalink
Browse files

Remove query dialog. Replace with tabs

  • Loading branch information
NathanW2 committed Aug 17, 2015
1 parent bbce092 commit 5fb52fa1edcfe632e2394f0a68709877bff6b14c
@@ -22,6 +22,8 @@
***************************************************************************/
"""

import functools

from PyQt4.QtCore import QObject, Qt, QSettings, QByteArray, SIGNAL, QSize
from PyQt4.QtGui import QMainWindow, QApplication, QMenu, QIcon, QTabWidget, QGridLayout, QSpacerItem, QSizePolicy, \
QDockWidget, QStatusBar, QMenuBar, QToolBar, QKeySequence
@@ -188,17 +190,22 @@ def runSqlWindow(self):

from dlg_sql_window import DlgSqlWindow

dlg = DlgSqlWindow(self.iface, db, self)
# refreshDb = lambda x: self.refreshItem( db.connection() ) # refresh the database tree
#self.connect( dlg, SIGNAL( "queryExecuted(const QString &)" ), refreshDb )
dlg.show()
dlg.exec_()
query = DlgSqlWindow(self.iface, db, self)
index = self.tabs.addTab(query, self.tr("Query"))
self.tabs.setCurrentIndex(index)
try:
self.tabs.setTabIcon(index, self.tree.currentItem().icon())
except AttributeError:
pass
query.nameChanged.connect(functools.partial(self.update_tab_name, index))

def update_tab_name(self, index, name):
name = name + "(query)"
self.tabs.setTabText(index, name)

def showSystemTables(self):
self.tree.showSystemTables(self.actionShowSystemTables.isChecked())


def registerAction(self, action, menuName, callback=None):
""" register an action to the manager's main menu """
if not hasattr(self, '_registeredDbActions'):
@@ -340,13 +347,21 @@ def unregisterAllActions(self):
self.unregisterAction(action, menuName)
del self._registeredDbActions

def close_tab(self, index):
widget = self.tabs.widget(index)
if widget not in [self.info, self.table, self.preview]:
self.tabs.removeTab(index)
widget.deleteLater()

def setupUi(self):
self.setWindowTitle(self.tr("DB Manager"))
self.setWindowIcon(QIcon(":/db_manager/icon"))
self.resize(QSize(700, 500).expandedTo(self.minimumSizeHint()))

# create central tab widget
self.tabs = QTabWidget()
self.tabs.setTabsClosable(True)
self.tabs.tabCloseRequested.connect(self.close_tab)
self.info = InfoViewer(self)
self.tabs.addTab(self.info, self.tr("Info"))
self.table = TableViewer(self)
@@ -22,8 +22,9 @@
***************************************************************************/
"""

from PyQt4.QtCore import Qt, QObject, QSettings, QByteArray, SIGNAL
from PyQt4.QtGui import QDialog, QAction, QKeySequence, QDialogButtonBox, QApplication, QCursor, QMessageBox, QClipboard, QInputDialog, QIcon
from PyQt4.QtCore import Qt, QObject, QSettings, QByteArray, SIGNAL, pyqtSignal
from PyQt4.QtGui import QDialog, QWidget, QAction, QKeySequence, \
QDialogButtonBox, QApplication, QCursor, QMessageBox, QClipboard, QInputDialog, QIcon
from PyQt4.Qsci import QsciAPIs

from qgis.core import QgsProject
@@ -45,9 +46,10 @@
import re


class DlgSqlWindow(QDialog, Ui_Dialog):
class DlgSqlWindow(QWidget, Ui_Dialog):
nameChanged = pyqtSignal(str)
def __init__(self, iface, db, parent=None):
QDialog.__init__(self, parent)
QWidget.__init__(self, parent)
self.iface = iface
self.db = db
self.setupUi(self)
@@ -56,9 +58,6 @@ def __init__(self, iface, db, parent=None):

self.defaultLayerName = 'QueryLayer'

settings = QSettings()
self.restoreGeometry(settings.value("/DB_Manager/sqlWindow/geometry", QByteArray(), type=QByteArray))

self.editSql.setFocus()
self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.initCompleter()
@@ -67,36 +66,39 @@ def __init__(self, iface, db, parent=None):
copyAction = QAction("copy", self)
self.viewResult.addAction(copyAction)
copyAction.setShortcuts(QKeySequence.Copy)
QObject.connect(copyAction, SIGNAL("triggered()"), self.copySelectedResults)

self.connect(self.btnExecute, SIGNAL("clicked()"), self.executeSql)
self.connect(self.btnClear, SIGNAL("clicked()"), self.clearSql)
self.connect(self.buttonBox.button(QDialogButtonBox.Close), SIGNAL("clicked()"), self.close)
copyAction.triggered.connect(self.copySelectedResults)

self.btnExecute.clicked.connect(self.executeSql)
self.btnClear.clicked.connect(self.clearSql)

self.presetStore.clicked.connect(self.storePreset)
self.presetDelete.clicked.connect(self.deletePreset)
self.presetCombo.activated[str].connect(self.loadPreset)
self.presetCombo.activated[str].connect(self.presetName.setText)

self.connect(self.presetStore, SIGNAL("clicked()"), self.storePreset)
self.connect(self.presetDelete, SIGNAL("clicked()"), self.deletePreset)
self.connect(self.presetCombo, SIGNAL("activated(QString)"), self.loadPreset)
self.connect(self.presetCombo, SIGNAL("activated(QString)"), self.presetName.setText)
self.updatePresetsCombobox()

# hide the load query as layer if feature is not supported
self._loadAsLayerAvailable = self.db.connector.hasCustomQuerySupport()
self.loadAsLayerGroup.setVisible(self._loadAsLayerAvailable)
if self._loadAsLayerAvailable:
self.layerTypeWidget.hide() # show if load as raster is supported
self.connect(self.loadLayerBtn, SIGNAL("clicked()"), self.loadSqlLayer)
self.connect(self.getColumnsBtn, SIGNAL("clicked()"), self.fillColumnCombos)
self.connect(self.loadAsLayerGroup, SIGNAL("toggled(bool)"), self.loadAsLayerToggled)
self.loadLayerBtn.clicked.connect(self.loadSqlLayer)
self.getColumnsBtn.clicked.connect(self.fillColumnCombos)
self.loadAsLayerGroup.toggled.connect(self.loadAsLayerToggled)
self.loadAsLayerToggled(False)

self._createViewAvailable = self.db.connector.hasCreateSpatialViewSupport()
self.btnCreateView.setVisible( self._createViewAvailable )
if self._createViewAvailable:
self.connect( self.btnCreateView, SIGNAL("clicked()"), self.createView )
self.btnCreateView.clicked.connect(self.createView)

self.queryBuilderFirst = True
self.queryBuilderBtn.setIcon(QIcon(":/db_manager/icons/sql.gif"))
self.connect( self.queryBuilderBtn, SIGNAL("clicked()"), self.displayQueryBuilder )
self.queryBuilderBtn.clicked.connect(self.displayQueryBuilder)

self.presetName.textChanged.connect(self.nameChanged)

def updatePresetsCombobox(self):
self.presetCombo.clear()
@@ -135,13 +137,6 @@ def loadPreset(self, name):
name = QgsProject.instance().readEntry('DBManager', 'savedQueries/q' + unicode(name.__hash__()) + '/name')[0]
self.editSql.setText(query)

def closeEvent(self, e):
""" save window state """
settings = QSettings()
settings.setValue("/DB_Manager/sqlWindow/geometry", self.saveGeometry())

QDialog.closeEvent(self, e)

def loadAsLayerToggled(self, checked):
self.loadAsLayerGroup.setChecked(checked)
self.loadAsLayerWidget.setVisible(checked)

0 comments on commit 5fb52fa

Please sign in to comment.
You can’t perform that action at this time.