Skip to content

Commit 09a6b33

Browse files
committedDec 21, 2018
Add comment option on db_manager pluging postgis tables
1 parent 9200f53 commit 09a6b33

File tree

4 files changed

+128
-10
lines changed

4 files changed

+128
-10
lines changed
 

‎python/plugins/db_manager/dlg_import_vector.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from qgis.gui import QgsMessageViewer
4040
from qgis.utils import OverrideCursor
4141

42+
import psycopg2
4243
from .ui.ui_DlgImportVector import Ui_DbManagerDlgImportVector as Ui_Dialog
4344

4445

@@ -51,6 +52,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
5152
self.db = outDb
5253
self.outUri = outUri
5354
self.setupUi(self)
55+
print(self.db)
5456

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

8183
if mode == self.ASK_FOR_INPUT_MODE:
8284
self.btnChooseInputFile.clicked.connect(self.chooseInputFile)
83-
self.cboInputLayer.currentTextChanged.connect(self.updateInputLayer)
85+
# self.cboInputLayer.lineEdit().editingFinished.connect(self.updateInputLayer)
86+
self.cboInputLayer.editTextChanged.connect(self.inputPathChanged)
87+
# self.cboInputLayer.currentIndexChanged.connect(self.updateInputLayer)
8488
self.btnUpdateInputLayer.clicked.connect(self.updateInputLayer)
8589

8690
self.editPrimaryKey.setText(self.default_pk)
@@ -156,9 +160,16 @@ def chooseInputFile(self):
156160
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())
157161
settings.setValue("/UI/lastVectorFileFilter", lastVectorFormat)
158162

159-
self.cboInputLayer.setCurrentIndex(-1)
160163
self.cboInputLayer.setEditText(filename)
161164

165+
def inputPathChanged(self, path):
166+
if self.cboInputLayer.currentIndex() < 0:
167+
return
168+
self.cboInputLayer.blockSignals(True)
169+
self.cboInputLayer.setCurrentIndex(-1)
170+
self.cboInputLayer.setEditText(path)
171+
self.cboInputLayer.blockSignals(False)
172+
162173
def reloadInputLayer(self):
163174
""" create the input layer and update available options """
164175
if self.mode != self.ASK_FOR_INPUT_MODE:
@@ -369,6 +380,11 @@ def accept(self):
369380
if self.chkSpatialIndex.isEnabled() and self.chkSpatialIndex.isChecked():
370381
self.db.connector.createSpatialIndex((schema, table), geom)
371382

383+
#Add comment on table
384+
if self.chkCom.isEnabled() and self.chkCom.isChecked():
385+
#Using connector executing COMMENT ON TABLE query (with editCome.text() value)
386+
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}E\' '.format(schema, table ,self.editCom.text()))
387+
372388
self.db.connection().reconnect()
373389
self.db.refresh()
374390
QMessageBox.information(self, self.tr("Import to Database"), self.tr("Import was successful."))

‎python/plugins/db_manager/dlg_table_properties.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def __init__(self, table, parent=None):
5959
m = TableIndexesModel(self)
6060
self.viewIndexes.setModel(m)
6161

62+
#Display comment in line edit
63+
m = self.table.comment
64+
self.viewComment.setText(m)
65+
6266
self.btnAddColumn.clicked.connect(self.addColumn)
6367
self.btnAddGeometryColumn.clicked.connect(self.addGeometryColumn)
6468
self.btnEditColumn.clicked.connect(self.editColumn)
@@ -71,6 +75,11 @@ def __init__(self, table, parent=None):
7175
self.btnAddSpatialIndex.clicked.connect(self.createSpatialIndex)
7276
self.btnDeleteIndex.clicked.connect(self.deleteIndex)
7377

78+
#Connect button add Comment to function
79+
self.btnAddComment.clicked.connect(self.createComment)
80+
#Connect button delete Comment to function
81+
self.btnDeleteComment.clicked.connect(self.deleteComment)
82+
7483
self.refresh()
7584

7685
def refresh(self):
@@ -322,3 +331,31 @@ def deleteIndex(self):
322331
self.refresh()
323332
except BaseError as e:
324333
DlgDbError.showError(e, self)
334+
335+
def createComment(self):
336+
#Function that add a comment to the selected table
337+
try:
338+
#Using the db connector, executing de SQL query Comment on table
339+
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'{2}\' '.format(self.table.schema().name, self.table.name ,self.viewComment.text()))
340+
except DbError as e:
341+
DlgDbError.showError(e, self)
342+
return
343+
self.refresh()
344+
#Display successful message
345+
QMessageBox.information(self, self.tr("Add comment"), self.tr("Table successfully commented"))
346+
347+
348+
def deleteComment(self):
349+
#Function that drop the comment to the selected table
350+
try:
351+
#Using the db connector, executing de SQL query Comment on table. Comment is void ''
352+
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS E\'\' '.format(self.table.schema().name, self.table.name))
353+
except DbError as e:
354+
DlgDbError.showError(e, self)
355+
return
356+
self.refresh()
357+
#Refresh line edit, put a void comment
358+
self.viewComment.setText('')
359+
#Display successful message
360+
QMessageBox.information(self, self.tr("Delete comment"), self.tr("Comment deleted"))
361+

‎python/plugins/db_manager/ui/DlgImportVector.ui

100644100755
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>482</width>
10-
<height>496</height>
10+
<height>627</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -254,6 +254,20 @@
254254
</property>
255255
</widget>
256256
</item>
257+
<item row="10" column="0">
258+
<widget class="QCheckBox" name="chkCom">
259+
<property name="text">
260+
<string>Comment</string>
261+
</property>
262+
</widget>
263+
</item>
264+
<item row="10" column="1">
265+
<widget class="QLineEdit" name="editCom">
266+
<property name="enabled">
267+
<bool>false</bool>
268+
</property>
269+
</widget>
270+
</item>
257271
</layout>
258272
</widget>
259273
</item>

‎python/plugins/db_manager/ui/DlgTableProperties.ui

100644100755
Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
<item>
1818
<widget class="QTabWidget" name="tabs">
1919
<property name="currentIndex">
20-
<number>0</number>
20+
<number>3</number>
2121
</property>
2222
<widget class="QWidget" name="tabColumns">
2323
<attribute name="title">
2424
<string>Columns</string>
2525
</attribute>
26-
<layout class="QVBoxLayout">
26+
<layout class="QVBoxLayout" name="verticalLayout_4">
2727
<item>
2828
<widget class="QLabel" name="label">
2929
<property name="text">
@@ -68,8 +68,8 @@
6868
</property>
6969
<property name="sizeHint" stdset="0">
7070
<size>
71-
<width>40</width>
72-
<height>20</height>
71+
<width>13</width>
72+
<height>29</height>
7373
</size>
7474
</property>
7575
</spacer>
@@ -89,7 +89,7 @@
8989
<attribute name="title">
9090
<string>Constraints</string>
9191
</attribute>
92-
<layout class="QVBoxLayout">
92+
<layout class="QVBoxLayout" name="verticalLayout_3">
9393
<item>
9494
<widget class="QLabel" name="label_3">
9595
<property name="text">
@@ -141,7 +141,7 @@
141141
<attribute name="title">
142142
<string>Indexes</string>
143143
</attribute>
144-
<layout class="QVBoxLayout">
144+
<layout class="QVBoxLayout" name="verticalLayout_2">
145145
<item>
146146
<widget class="QLabel" name="label_2">
147147
<property name="text">
@@ -157,7 +157,7 @@
157157
</widget>
158158
</item>
159159
<item>
160-
<layout class="QHBoxLayout">
160+
<layout class="QHBoxLayout" name="_3">
161161
<item>
162162
<widget class="QPushButton" name="btnAddIndex">
163163
<property name="text">
@@ -196,6 +196,57 @@
196196
</item>
197197
</layout>
198198
</widget>
199+
<widget class="QWidget" name="tabComment">
200+
<property name="enabled">
201+
<bool>true</bool>
202+
</property>
203+
<attribute name="title">
204+
<string>Comment</string>
205+
</attribute>
206+
<layout class="QVBoxLayout" name="verticalLayout">
207+
<item>
208+
<widget class="QLabel" name="label_4">
209+
<property name="text">
210+
<string>Comment defined for this table:</string>
211+
</property>
212+
</widget>
213+
</item>
214+
<item>
215+
<widget class="QLineEdit" name="viewComment"/>
216+
</item>
217+
<item>
218+
<layout class="QHBoxLayout" name="_4">
219+
<item>
220+
<widget class="QPushButton" name="btnAddComment">
221+
<property name="text">
222+
<string>Add index</string>
223+
</property>
224+
</widget>
225+
</item>
226+
<item>
227+
<spacer>
228+
<property name="orientation">
229+
<enum>Qt::Horizontal</enum>
230+
</property>
231+
<property name="sizeHint" stdset="0">
232+
<size>
233+
<width>40</width>
234+
<height>20</height>
235+
</size>
236+
</property>
237+
</spacer>
238+
</item>
239+
<item>
240+
<widget class="QPushButton" name="btnDeleteComment">
241+
<property name="text">
242+
<string>Delete index</string>
243+
</property>
244+
</widget>
245+
</item>
246+
</layout>
247+
</item>
248+
</layout>
249+
</widget>
199250
</widget>
200251
</item>
201252
<item>

0 commit comments

Comments
 (0)
Please sign in to comment.