Skip to content

Commit

Permalink
add LastDir for SQL File
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Nov 13, 2018
1 parent 5eecbf2 commit ebdc932
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions python/plugins/db_manager/dlg_sql_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from builtins import str
from hashlib import md5

import os

from qgis.PyQt.QtCore import Qt, pyqtSignal, QDir
from qgis.PyQt.QtWidgets import QDialog, QWidget, QAction, QApplication, QInputDialog, QStyledItemDelegate, QTableWidgetItem, QFileDialog
from qgis.PyQt.QtGui import QKeySequence, QCursor, QClipboard, QIcon, QStandardItemModel, QStandardItem
Expand Down Expand Up @@ -231,31 +233,42 @@ def storePreset(self):
self.presetCombo.setCurrentIndex(index)

def saveAsFilePreset(self):
settings = QgsSettings()
lastDir = settings.value('DB_Manager/lastDirSQLFIle', "")

query = self._getSqlQuery()
if query == "":
return

filename, ext = QFileDialog.getSaveFileName(
filename, _ = QFileDialog.getSaveFileName(
self,
self.tr('Save SQL Query'),
QDir.homePath(),
lastDir,
"SQL File (*.sql)")

if filename:
with open(filename, 'w') as f:
f.write(query)
lastDir = os.path.dirname(filename)
settings.setValue('DB_Manager/lastDirSQLFile', lastDir)

def loadFilePreset(self):
filename = QFileDialog.getOpenFileName(
self,
self.tr("Load SQL Query"),
QDir.homePath(),
"SQL File (*.sql)");
settings = QgsSettings()
lastDir = settings.value('DB_Manager/lastDirSQLFIle', "")

filename, _ = QFileDialog.getOpenFileName(
self,
self.tr("Load SQL Query"),
lastDir,
"SQL File (*.sql)")

if filename:
with open(filename[0], 'r') as f:
with open(filename, 'r') as f:
self.editSql.clear()
for line in f:
self.editSql.insertText(line)
lastDir = os.path.dirname(filename)
settings.setValue('DB_Manager/lastDirSQLFile', lastDir)

def deletePreset(self):
name = self.presetCombo.currentText()
Expand Down

0 comments on commit ebdc932

Please sign in to comment.