mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Add comment option on db_manager pluging postgis tables (#8734) [FEATURE]
Add possibility to create a comment on a postgres table when import or using the alter table button from db_manager.
This commit is contained in:
parent
be451d98c9
commit
ed9c9b33af
@ -156,7 +156,6 @@ class DlgImportVector(QDialog, Ui_Dialog):
|
|||||||
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())
|
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())
|
||||||
settings.setValue("/UI/lastVectorFileFilter", lastVectorFormat)
|
settings.setValue("/UI/lastVectorFileFilter", lastVectorFormat)
|
||||||
|
|
||||||
self.cboInputLayer.setCurrentIndex(-1)
|
|
||||||
self.cboInputLayer.setEditText(filename)
|
self.cboInputLayer.setEditText(filename)
|
||||||
|
|
||||||
def reloadInputLayer(self):
|
def reloadInputLayer(self):
|
||||||
@ -369,6 +368,11 @@ class DlgImportVector(QDialog, Ui_Dialog):
|
|||||||
if self.chkSpatialIndex.isEnabled() and self.chkSpatialIndex.isChecked():
|
if self.chkSpatialIndex.isEnabled() and self.chkSpatialIndex.isChecked():
|
||||||
self.db.connector.createSpatialIndex((schema, table), geom)
|
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.connection().reconnect()
|
||||||
self.db.refresh()
|
self.db.refresh()
|
||||||
QMessageBox.information(self, self.tr("Import to Database"), self.tr("Import was successful."))
|
QMessageBox.information(self, self.tr("Import to Database"), self.tr("Import was successful."))
|
||||||
|
@ -59,6 +59,10 @@ class DlgTableProperties(QDialog, Ui_Dialog):
|
|||||||
m = TableIndexesModel(self)
|
m = TableIndexesModel(self)
|
||||||
self.viewIndexes.setModel(m)
|
self.viewIndexes.setModel(m)
|
||||||
|
|
||||||
|
#Display comment in line edit
|
||||||
|
m = self.table.comment
|
||||||
|
self.viewComment.setText(m)
|
||||||
|
|
||||||
self.btnAddColumn.clicked.connect(self.addColumn)
|
self.btnAddColumn.clicked.connect(self.addColumn)
|
||||||
self.btnAddGeometryColumn.clicked.connect(self.addGeometryColumn)
|
self.btnAddGeometryColumn.clicked.connect(self.addGeometryColumn)
|
||||||
self.btnEditColumn.clicked.connect(self.editColumn)
|
self.btnEditColumn.clicked.connect(self.editColumn)
|
||||||
@ -71,6 +75,11 @@ class DlgTableProperties(QDialog, Ui_Dialog):
|
|||||||
self.btnAddSpatialIndex.clicked.connect(self.createSpatialIndex)
|
self.btnAddSpatialIndex.clicked.connect(self.createSpatialIndex)
|
||||||
self.btnDeleteIndex.clicked.connect(self.deleteIndex)
|
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()
|
self.refresh()
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
@ -322,3 +331,29 @@ class DlgTableProperties(QDialog, Ui_Dialog):
|
|||||||
self.refresh()
|
self.refresh()
|
||||||
except BaseError as e:
|
except BaseError as e:
|
||||||
DlgDbError.showError(e, self)
|
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"))
|
||||||
|
80
python/plugins/db_manager/ui/DlgImportVector.ui
Normal file → Executable file
80
python/plugins/db_manager/ui/DlgImportVector.ui
Normal file → Executable file
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>482</width>
|
<width>482</width>
|
||||||
<height>496</height>
|
<height>627</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -254,6 +254,20 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -310,8 +324,8 @@
|
|||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>334</x>
|
<x>343</x>
|
||||||
<y>486</y>
|
<y>617</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>286</x>
|
<x>286</x>
|
||||||
@ -326,12 +340,12 @@
|
|||||||
<slot>setEnabled(bool)</slot>
|
<slot>setEnabled(bool)</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>129</x>
|
<x>155</x>
|
||||||
<y>239</y>
|
<y>268</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>460</x>
|
<x>463</x>
|
||||||
<y>239</y>
|
<y>272</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
@ -342,12 +356,12 @@
|
|||||||
<slot>setEnabled(bool)</slot>
|
<slot>setEnabled(bool)</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>141</x>
|
<x>167</x>
|
||||||
<y>265</y>
|
<y>306</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>442</x>
|
<x>463</x>
|
||||||
<y>265</y>
|
<y>310</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
@ -358,12 +372,12 @@
|
|||||||
<slot>setEnabled(bool)</slot>
|
<slot>setEnabled(bool)</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>119</x>
|
<x>145</x>
|
||||||
<y>343</y>
|
<y>404</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>455</x>
|
<x>463</x>
|
||||||
<y>343</y>
|
<y>406</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
@ -374,8 +388,8 @@
|
|||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>461</x>
|
<x>470</x>
|
||||||
<y>486</y>
|
<y>617</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>508</x>
|
<x>508</x>
|
||||||
@ -390,12 +404,12 @@
|
|||||||
<slot>setEnabled(bool)</slot>
|
<slot>setEnabled(bool)</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>134</x>
|
<x>160</x>
|
||||||
<y>281</y>
|
<y>341</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>357</x>
|
<x>463</x>
|
||||||
<y>281</y>
|
<y>341</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
@ -406,12 +420,28 @@
|
|||||||
<slot>setEnabled(bool)</slot>
|
<slot>setEnabled(bool)</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>134</x>
|
<x>160</x>
|
||||||
<y>307</y>
|
<y>372</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>357</x>
|
<x>463</x>
|
||||||
<y>307</y>
|
<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>215</x>
|
||||||
|
<y>552</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
63
python/plugins/db_manager/ui/DlgTableProperties.ui
Normal file → Executable file
63
python/plugins/db_manager/ui/DlgTableProperties.ui
Normal file → Executable file
@ -23,7 +23,7 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Columns</string>
|
<string>Columns</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -68,8 +68,8 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>13</width>
|
||||||
<height>20</height>
|
<height>29</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
@ -89,7 +89,7 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Constraints</string>
|
<string>Constraints</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -141,7 +141,7 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Indexes</string>
|
<string>Indexes</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -157,7 +157,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout">
|
<layout class="QHBoxLayout" name="_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnAddIndex">
|
<widget class="QPushButton" name="btnAddIndex">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -196,6 +196,57 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</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>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user