diff --git a/python/plugins/db_manager/dlg_import_vector.py b/python/plugins/db_manager/dlg_import_vector.py
index dd65310636d..954cda949c9 100644
--- a/python/plugins/db_manager/dlg_import_vector.py
+++ b/python/plugins/db_manager/dlg_import_vector.py
@@ -39,6 +39,7 @@ from qgis.core import (QgsDataSourceUri,
from qgis.gui import QgsMessageViewer
from qgis.utils import OverrideCursor
+import psycopg2
from .ui.ui_DlgImportVector import Ui_DbManagerDlgImportVector as Ui_Dialog
@@ -51,6 +52,7 @@ class DlgImportVector(QDialog, Ui_Dialog):
self.db = outDb
self.outUri = outUri
self.setupUi(self)
+ print(self.db)
self.default_pk = "id"
self.default_geom = "geom"
@@ -80,7 +82,9 @@ class DlgImportVector(QDialog, Ui_Dialog):
if mode == self.ASK_FOR_INPUT_MODE:
self.btnChooseInputFile.clicked.connect(self.chooseInputFile)
- self.cboInputLayer.currentTextChanged.connect(self.updateInputLayer)
+ # self.cboInputLayer.lineEdit().editingFinished.connect(self.updateInputLayer)
+ self.cboInputLayer.editTextChanged.connect(self.inputPathChanged)
+ # self.cboInputLayer.currentIndexChanged.connect(self.updateInputLayer)
self.btnUpdateInputLayer.clicked.connect(self.updateInputLayer)
self.editPrimaryKey.setText(self.default_pk)
@@ -156,9 +160,16 @@ class DlgImportVector(QDialog, Ui_Dialog):
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())
settings.setValue("/UI/lastVectorFileFilter", lastVectorFormat)
- self.cboInputLayer.setCurrentIndex(-1)
self.cboInputLayer.setEditText(filename)
+ def inputPathChanged(self, path):
+ if self.cboInputLayer.currentIndex() < 0:
+ return
+ self.cboInputLayer.blockSignals(True)
+ self.cboInputLayer.setCurrentIndex(-1)
+ self.cboInputLayer.setEditText(path)
+ self.cboInputLayer.blockSignals(False)
+
def reloadInputLayer(self):
""" create the input layer and update available options """
if self.mode != self.ASK_FOR_INPUT_MODE:
@@ -369,6 +380,11 @@ class DlgImportVector(QDialog, Ui_Dialog):
if self.chkSpatialIndex.isEnabled() and self.chkSpatialIndex.isChecked():
self.db.connector.createSpatialIndex((schema, table), geom)
+ #Add comment on table
+ if self.chkCom.isEnabled() and self.chkCom.isChecked():
+ #Using connector executing COMMENT ON TABLE query (with editCome.text() value)
+ self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}E\' '.format(schema, table ,self.editCom.text()))
+
self.db.connection().reconnect()
self.db.refresh()
QMessageBox.information(self, self.tr("Import to Database"), self.tr("Import was successful."))
diff --git a/python/plugins/db_manager/dlg_table_properties.py b/python/plugins/db_manager/dlg_table_properties.py
index 107a516a2df..f3a385897a6 100644
--- a/python/plugins/db_manager/dlg_table_properties.py
+++ b/python/plugins/db_manager/dlg_table_properties.py
@@ -59,6 +59,10 @@ class DlgTableProperties(QDialog, Ui_Dialog):
m = TableIndexesModel(self)
self.viewIndexes.setModel(m)
+ #Display comment in line edit
+ m = self.table.comment
+ self.viewComment.setText(m)
+
self.btnAddColumn.clicked.connect(self.addColumn)
self.btnAddGeometryColumn.clicked.connect(self.addGeometryColumn)
self.btnEditColumn.clicked.connect(self.editColumn)
@@ -71,6 +75,11 @@ class DlgTableProperties(QDialog, Ui_Dialog):
self.btnAddSpatialIndex.clicked.connect(self.createSpatialIndex)
self.btnDeleteIndex.clicked.connect(self.deleteIndex)
+ #Connect button add Comment to function
+ self.btnAddComment.clicked.connect(self.createComment)
+ #Connect button delete Comment to function
+ self.btnDeleteComment.clicked.connect(self.deleteComment)
+
self.refresh()
def refresh(self):
@@ -322,3 +331,31 @@ class DlgTableProperties(QDialog, Ui_Dialog):
self.refresh()
except BaseError as e:
DlgDbError.showError(e, self)
+
+ def createComment(self):
+ #Function that add a comment to the selected table
+ try:
+ #Using the db connector, executing de SQL query Comment on table
+ self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\' '.format(self.table.schema().name, self.table.name ,self.viewComment.text()))
+ except DbError as e:
+ DlgDbError.showError(e, self)
+ return
+ self.refresh()
+ #Display successful message
+ QMessageBox.information(self, self.tr("Add comment"), self.tr("Table successfully commented"))
+
+
+ def deleteComment(self):
+ #Function that drop the comment to the selected table
+ try:
+ #Using the db connector, executing de SQL query Comment on table. Comment is void ''
+ self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'\' '.format(self.table.schema().name, self.table.name))
+ except DbError as e:
+ DlgDbError.showError(e, self)
+ return
+ self.refresh()
+ #Refresh line edit, put a void comment
+ self.viewComment.setText('')
+ #Display successful message
+ QMessageBox.information(self, self.tr("Delete comment"), self.tr("Comment deleted"))
+
diff --git a/python/plugins/db_manager/ui/DlgImportVector.ui b/python/plugins/db_manager/ui/DlgImportVector.ui
old mode 100644
new mode 100755
index 8267b66316c..a1cd308b9ef
--- a/python/plugins/db_manager/ui/DlgImportVector.ui
+++ b/python/plugins/db_manager/ui/DlgImportVector.ui
@@ -7,7 +7,7 @@
0
0
482
- 496
+ 627
@@ -254,6 +254,20 @@
+ -
+
+
+ Comment
+
+
+
+ -
+
+
+ false
+
+
+
diff --git a/python/plugins/db_manager/ui/DlgTableProperties.ui b/python/plugins/db_manager/ui/DlgTableProperties.ui
old mode 100644
new mode 100755
index 82f7a245445..3cfa9ebc955
--- a/python/plugins/db_manager/ui/DlgTableProperties.ui
+++ b/python/plugins/db_manager/ui/DlgTableProperties.ui
@@ -17,13 +17,13 @@
-
- 0
+ 3
Columns
-
+
-
@@ -68,8 +68,8 @@
- 40
- 20
+ 13
+ 29
@@ -89,7 +89,7 @@
Constraints
-
+
-
@@ -141,7 +141,7 @@
Indexes
-
+
-
@@ -157,7 +157,7 @@
-
-
+
-
@@ -196,6 +196,57 @@
+
+
+ true
+
+
+ Comment
+
+
+ -
+
+
+ Comment defined for this table:
+
+
+
+ -
+
+
+ -
+
+
-
+
+
+ Add index
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Delete index
+
+
+
+
+
+
+
-