Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] allow output directly on PostGIS tables
- Loading branch information
Showing
8 changed files
with
256 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import os | ||
from PyQt4 import uic, QtCore, QtGui | ||
from processing.algs.qgis.postgis_utils import GeoDB | ||
from qgis.core import * | ||
from PyQt4.QtGui import QMessageBox | ||
|
||
pluginPath = os.path.split(os.path.dirname(__file__))[0] | ||
WIDGET, BASE = uic.loadUiType( | ||
os.path.join(pluginPath, 'ui', 'DlgPostgisTableSelector.ui')) | ||
|
||
|
||
class PostgisTableSelector(BASE, WIDGET): | ||
|
||
def __init__(self, parent, tablename): | ||
super(PostgisTableSelector, self).__init__(parent) | ||
self.connection = None | ||
self.table = None | ||
self.schema = None | ||
self.setupUi(self) | ||
settings = QtCore.QSettings() | ||
settings.beginGroup('/PostgreSQL/connections/') | ||
names = settings.childGroups() | ||
settings.endGroup() | ||
for n in names: | ||
item = ConnectionItem(n) | ||
self.treeConnections.addTopLevelItem(item) | ||
|
||
def itemExpanded(item): | ||
try: | ||
item.populateSchemas() | ||
except: | ||
pass | ||
|
||
self.treeConnections.itemExpanded.connect(itemExpanded) | ||
|
||
self.textTableName.setText(tablename) | ||
|
||
self.buttonBox.accepted.connect(self.okPressed) | ||
self.buttonBox.rejected.connect(self.cancelPressed) | ||
|
||
def cancelPressed(self): | ||
self.close() | ||
|
||
def okPressed(self): | ||
if self.textTableName.text().strip() == "": | ||
self.textTableName.setStyleSheet("QLineEdit{background: yellow}") | ||
return | ||
item = self.treeConnections.currentItem() | ||
if isinstance(item, ConnectionItem): | ||
QMessageBox.warning(self, "Wrong selection", "Select a schema item in the tree") | ||
return | ||
self.schema = item.text(0) | ||
self.table = self.textTableName.text().strip() | ||
self.connection = item.parent().text(0) | ||
self.close() | ||
|
||
class ConnectionItem(QtGui.QTreeWidgetItem): | ||
|
||
connIcon = QtGui.QIcon(os.path.dirname(__file__) + '/../images/postgis.png') | ||
schemaIcon = QtGui.QIcon(os.path.dirname(__file__) + '/../images/namespace.png') | ||
|
||
def __init__(self, connection): | ||
QtGui.QTreeWidgetItem.__init__(self) | ||
self.setChildIndicatorPolicy(QtGui.QTreeWidgetItem.ShowIndicator) | ||
self.connection = connection | ||
self.setText(0, connection) | ||
self.setIcon(0, self.connIcon) | ||
|
||
def populateSchemas(self): | ||
if self.childCount() != 0: | ||
return | ||
settings = QtCore.QSettings() | ||
connSettings = '/PostgreSQL/connections/' + self.connection | ||
database = settings.value(connSettings + '/database') | ||
user = settings.value(connSettings + '/username') | ||
host = settings.value(connSettings + '/host') | ||
port = settings.value(connSettings + '/port') | ||
passwd = settings.value(connSettings + '/password') | ||
uri = QgsDataSourceURI() | ||
uri.setConnection(host, str(port), database, user, passwd) | ||
connInfo = uri.connectionInfo() | ||
(success, user, passwd ) = QgsCredentials.instance().get(connInfo, None, None) | ||
if success: | ||
QgsCredentials.instance().put(connInfo, user, passwd) | ||
geodb = GeoDB(host, int(port), database, user, passwd) | ||
schemas = geodb.list_schemas() | ||
for oid, name, owner, perms in schemas: | ||
item = QtGui.QTreeWidgetItem() | ||
item.setText(0, name) | ||
item.setIcon(0, self.schemaIcon) | ||
self.addChild(item) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>464</width> | ||
<height>395</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string> output table</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="text"> | ||
<string>Select connection and schema</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QTreeWidget" name="treeConnections"> | ||
<attribute name="headerVisible"> | ||
<bool>false</bool> | ||
</attribute> | ||
<column> | ||
<property name="text"> | ||
<string notr="true">1</string> | ||
</property> | ||
</column> | ||
</widget> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>Table name</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QLineEdit" name="textTableName"/> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |