Skip to content
Permalink
Browse files

Add comment option on db_manager pluging postgis tables (#8734) [FEAT…

…URE]

Add possibility to create a comment on a postgres table when import or using the alter table button from db_manager.
  • Loading branch information
Ailurupoda authored and m-kuhn committed Jan 5, 2019
1 parent be451d9 commit ed9c9b33af4fd368581bdb57ec967c59220599b1
@@ -156,7 +156,6 @@ 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 reloadInputLayer(self):
@@ -369,6 +368,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,29 @@ 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 using the NULL definition
self.db.connector._execute(None, 'COMMENT ON TABLE "{0}"."{1}" IS NULL;'.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>
@@ -310,8 +324,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>334</x>
<y>486</y>
<x>343</x>
<y>617</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
@@ -326,12 +340,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>129</x>
<y>239</y>
<x>155</x>
<y>268</y>
</hint>
<hint type="destinationlabel">
<x>460</x>
<y>239</y>
<x>463</x>
<y>272</y>
</hint>
</hints>
</connection>
@@ -342,12 +356,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>141</x>
<y>265</y>
<x>167</x>
<y>306</y>
</hint>
<hint type="destinationlabel">
<x>442</x>
<y>265</y>
<x>463</x>
<y>310</y>
</hint>
</hints>
</connection>
@@ -358,12 +372,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>343</y>
<x>145</x>
<y>404</y>
</hint>
<hint type="destinationlabel">
<x>455</x>
<y>343</y>
<x>463</x>
<y>406</y>
</hint>
</hints>
</connection>
@@ -374,8 +388,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>461</x>
<y>486</y>
<x>470</x>
<y>617</y>
</hint>
<hint type="destinationlabel">
<x>508</x>
@@ -390,12 +404,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>134</x>
<y>281</y>
<x>160</x>
<y>341</y>
</hint>
<hint type="destinationlabel">
<x>357</x>
<y>281</y>
<x>463</x>
<y>341</y>
</hint>
</hints>
</connection>
@@ -406,12 +420,28 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>134</x>
<y>307</y>
<x>160</x>
<y>372</y>
</hint>
<hint type="destinationlabel">
<x>463</x>
<y>372</y>
</hint>
</hints>
</connection>
<connection>
<sender>chkCom</sender>
<signal>toggled(bool)</signal>
<receiver>editComment</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>64</x>
<y>549</y>
</hint>
<hint type="destinationlabel">
<x>357</x>
<y>307</y>
<x>215</x>
<y>552</y>
</hint>
</hints>
</connection>
@@ -23,7 +23,7 @@
<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 comment</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 comment</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>

0 comments on commit ed9c9b3

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