Skip to content
Permalink
Browse files

Add comment option on db_manager pluging postgis tables

  • Loading branch information
Ailurupoda committed Dec 21, 2018
1 parent 9200f53 commit 09a6b33a329d555cb00faaa80b6576882b47700b
@@ -39,6 +39,7 @@
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 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
self.db = outDb
self.outUri = outUri
self.setupUi(self)
print(self.db)

self.default_pk = "id"
self.default_geom = "geom"
@@ -80,7 +82,9 @@ def setupWorkingMode(self, mode):

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 @@ def chooseInputFile(self):
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 @@ def accept(self):
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."))
@@ -59,6 +59,10 @@ def __init__(self, table, parent=None):
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 @@ def __init__(self, table, parent=None):
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 @@ def deleteIndex(self):
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"))

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>482</width>
<height>496</height>
<height>627</height>
</rect>
</property>
<property name="windowTitle">
@@ -254,6 +254,20 @@
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QCheckBox" name="chkCom">
<property name="text">
<string>Comment</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLineEdit" name="editCom">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -17,13 +17,13 @@
<item>
<widget class="QTabWidget" name="tabs">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tabColumns">
<attribute name="title">
<string>Columns</string>
</attribute>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
@@ -68,8 +68,8 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
<width>13</width>
<height>29</height>
</size>
</property>
</spacer>
@@ -89,7 +89,7 @@
<attribute name="title">
<string>Constraints</string>
</attribute>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
@@ -141,7 +141,7 @@
<attribute name="title">
<string>Indexes</string>
</attribute>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
@@ -157,7 +157,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QPushButton" name="btnAddIndex">
<property name="text">
@@ -196,6 +196,57 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabComment">
<property name="enabled">
<bool>true</bool>
</property>
<attribute name="title">
<string>Comment</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Comment defined for this table:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="viewComment"/>
</item>
<item>
<layout class="QHBoxLayout" name="_4">
<item>
<widget class="QPushButton" name="btnAddComment">
<property name="text">
<string>Add index</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnDeleteComment">
<property name="text">
<string>Delete index</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>

0 comments on commit 09a6b33

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