Skip to content

Commit

Permalink
- Change icons.
Browse files Browse the repository at this point in the history
- Fix #29 Error updating layer single user account.
- Fix #27 Error getting columns in SQL dialog.
  • Loading branch information
elesdoar committed Jul 29, 2015
1 parent e61f70d commit f0b0e79
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 44 deletions.
28 changes: 17 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@

* Default symbology for not supported symbols.
* Add messages for not supported symbols.
* Add uploaded message
* Add uploaded message.
* Change icons.

#### Fixes

* Fix #29 Error updating layer single user account.
* Fix #27 Error getting columns in SQL dialog.


<a name="0.1.8"></a>
### 0.1.8 (2015-07-11)

#### Enhancements

* Remove connection controls in SQL Editor
* Remove connection controls in SQL Editor.
* Add composite mode in create maps.
* Add dash style to lines in create maps.
* Add join style to lines in create maps.
Expand All @@ -23,9 +29,9 @@

#### Fixes

* Fix #19 Do not allow to edit read-only layers
* Show owner in shared layers, issue #18
* Fix #26 Encoding error creating map
* Fix #19 Do not allow to edit read-only layers.
* Show owner in shared layers, issue #18.
* Fix #26 Encoding error creating map.


<a name="0.1.6"></a>
Expand All @@ -39,7 +45,7 @@

#### Fixes

* Fix #23 Error conecting multiuser account
* Fix #23 Error conecting multiuser account.

<a name="0.1.5"></a>
### 0.1.5 (2015-06-16)
Expand All @@ -48,9 +54,9 @@

* Upload layers to CartoDB (More formats).
* Create basic visualization. Support:
* Borders
* Fill
* Label
* Borders.
* Fill.
* Label.

<a name="0.1.4"></a>
### 0.1.4 (2015-06-05)
Expand All @@ -65,7 +71,7 @@

#### Fixes

* Fix avatar size
* Fix avatar size.
* Fix #21 Insert data without complete fields.
* Enable buttons only if there is at least one created connection.

Expand Down Expand Up @@ -101,14 +107,14 @@
<a name="0.1.1"></a>
### 0.1.1 (2014-11-27)

* Fix error when repeat layer name at spatialite database.
#### New Features

* Load cartodb layers from SQL Queries.

#### Fixes.

* New connection dialog is now a modal window.
* Fix error when repeat layer name at spatialite database.

<a name="0.1.0"></a>
### 0.1.0 (2014-09-23)
Expand Down
9 changes: 5 additions & 4 deletions CartoDBPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def initGui(self):
self._mainAction = QAction(self.tr('Add CartoDB Layer'), self.iface.mainWindow())
self._mainAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/add.png"))
self._loadDataAction = QAction(self.tr('Upload layers to CartoDB'), self.iface.mainWindow())
self._loadDataAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/polygon.png"))
self._loadDataAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/upload.png"))
self._createVizAction = QAction(self.tr('Create New Map'), self.iface.mainWindow())
self._createVizAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/rectangle.png"))
self._createVizAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/map.png"))
self._addSQLAction = QAction(self.tr('Add SQL CartoDB Layer'), self.iface.mainWindow())
self._addSQLAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/add_sql.png"))
self._addSQLAction.setIcon(QIcon(":/plugins/qgis-cartodb/images/icons/sql.png"))

self.toolbar = CartoDBToolbar()
self.toolbar.setClick(self.connectionManager)
Expand Down Expand Up @@ -182,7 +182,8 @@ def run(self):
for i, table in enumerate(selectedItems):
widget = dlg.getItemWidget(table)
worker = CartoDBLayerWorker(self.iface, widget.tableName, widget.tableOwner, dlg,
filterByExtent=dlg.filterByExtent(), readonly=widget.readonly)
filterByExtent=dlg.filterByExtent(), readonly=widget.readonly,
multiuser=widget.multiuser)
worker.finished.connect(self.addLayer)
self.worker = worker
worker.load()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Voilá !!!!

#### Adding SQL CartoDB layer

Click on the icon: ![Icon](images/add_sql.png?raw=true "Icon") or on the web menu item "CartoDB Plugin" => "Add SQL CartoDB Layer"
Click on the icon: ![Icon](images/icons/sql.png?raw=true "Icon") or on the web menu item "CartoDB Plugin" => "Add SQL CartoDB Layer"

![Dialog 3](images/sql_dialog.png?raw=true "Adding SQL layer")

Expand Down
2 changes: 1 addition & 1 deletion dialogs/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def updateList(self, visualizations):

widget = CartoDBDatasetsListItem(
visualization['name'], owner, visualization['table']['size'], visualization['table']['row_count'],
shared=(owner != self.currentUser))
shared=(owner != self.currentUser), multiuser=self.currentMultiuser)
# item.setText(visualization['name'])
readonly = False
# qDebug('Vis:' + json.dumps(visualization, sort_keys=True, indent=2, separators=(',', ': ')))
Expand Down
22 changes: 15 additions & 7 deletions dialogs/NewSQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ def findTables(self):
if not str(self.currentMultiuser) in ['true', '1', 'True']:
sqlTables = "SELECT CDB_UserTables() table_name"
res = cl.sql(
"SELECT *, CDB_ColumnType(table_name, column_name) column_type \
FROM ( \
SELECT *, CDB_ColumnNames(table_name) column_name \
FROM (" + sqlTables + ") t1 \
) t2 \
WHERE CDB_ColumnType(table_name, column_name) != 'USER-DEFINED' \
ORDER BY table_name, column_name")
"WITH usertables AS (" + sqlTables + ") \
SELECT ut.table_name, c.column_name, c.data_type column_type \
FROM usertables ut \
JOIN information_schema.columns c ON c.table_name = ut.table_name \
WHERE c.data_type != 'USER-DEFINED' \
ORDER BY ut.table_name, c.column_name")
else:
sqlTables = "SELECT string_agg(privilege_type, ', ') AS privileges, table_schema, table_name \
FROM information_schema.role_table_grants tg \
Expand Down Expand Up @@ -208,3 +207,12 @@ def getQuery(self):
def showEvent(self, event):
worker = CartoDBPluginWorker(self, 'findTables')
worker.start()

'''
WITH usertables AS (SELECT CDB_UserTables() table_name)
SELECT ut.table_name, c.column_name, c.data_type column_type, ut.privileges
FROM usertables ut
JOIN information_schema.columns c ON c.table_name = ut.table_name
WHERE c.data_type != 'USER-DEFINED'
ORDER BY ut.table_name, c.column_name
'''
Binary file modified images/icons/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/icons/add_sql.png
Binary file not shown.
Binary file added images/icons/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/icons/sql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/upload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 27 additions & 17 deletions layers/CartoDBLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class CartoDBLayer(QgsVectorLayer):
LAYER_TNAME_PROPERTY = 'tableName'
LAYER_SQL_PROPERTY = 'cartoSQL'

def __init__(self, iface, tableName, user, apiKey, owner=None, sql=None, geoJSON=None, filterByExtent=False, spatiaLite=None, readonly=False):
def __init__(self, iface, tableName, user, apiKey, owner=None, sql=None, geoJSON=None,
filterByExtent=False, spatiaLite=None, readonly=False, multiuser=False):
# SQLite available?
self.iface = iface
self.user = user
self._apiKey = apiKey
self.layerType = 'ogr'
self.owner = owner
self.multiuser = multiuser
driverName = "SQLite"
sqLiteDrv = ogr.GetDriverByName(driverName)
self.databasePath = QgisCartoDB.CartoDBPlugin.PLUGIN_DIR + '/db/database.sqlite'
Expand All @@ -61,7 +63,7 @@ def __init__(self, iface, tableName, user, apiKey, owner=None, sql=None, geoJSON
self.forceReadOnly = False or readonly

if sql is None:
sql = 'SELECT * FROM ' + ((owner + '.') if owner is not None else '') + self.cartoTable
sql = 'SELECT * FROM ' + self._schema() + self.cartoTable
if filterByExtent:
extent = self.iface.mapCanvas().extent()
sql = sql + " WHERE ST_Intersects(ST_GeometryFromText('{}', 4326), the_geom)".format(extent.asWktPolygon())
Expand Down Expand Up @@ -169,7 +171,7 @@ def _loadData(self, sql, geoJSON=None, spatiaLite=None):
self.setCustomProperty(CartoDBLayer.LAYER_SQL_PROPERTY, sql)

def _uneditableFields(self):
schema = 'public' if self.owner is None else self.owner
schema = 'public' if not self.multiuser else self.owner
sql = "SELECT table_name, column_name, column_default, is_nullable, data_type, table_schema \
FROM information_schema.columns \
WHERE data_type != 'USER-DEFINED' AND table_schema = '" + schema + "' AND table_name = '" + self.cartoTable + "' \
Expand Down Expand Up @@ -224,11 +226,10 @@ def _beforeCommitChanges(self):
self._deleteFeatures(editBuffer.deletedFeatureIds())

def _updateAttributes(self, changedAttributeValues):
schema = '' if self.owner is None else (self.owner + '.')
provider = self.dataProvider()
for featureID, v in changedAttributeValues.iteritems():
QgsMessageLog.logMessage('Update attributes for feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO)
sql = "UPDATE " + schema + self.cartoTable + " SET "
sql = "UPDATE " + self._schema() + self.cartoTable + " SET "
request = QgsFeatureRequest().setFilterFid(featureID)
try:
feature = self.getFeatures(request).next()
Expand Down Expand Up @@ -263,12 +264,11 @@ def _updateAttributes(self, changedAttributeValues):
level=self.iface.messageBar().WARNING, duration=10)

def _updateGeometries(self, changedGeometries):
schema = '' if self.owner is None else (self.owner + '.')
for featureID, geom in changedGeometries.iteritems():
QgsMessageLog.logMessage('Update geometry for feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO)
request = QgsFeatureRequest().setFilterFid(featureID)
try:
sql = "UPDATE " + schema + self.cartoTable + " SET the_geom = "
sql = "UPDATE " + self._schema() + self.cartoTable + " SET the_geom = "
feature = self.getFeatures(request).next()
sql = sql + "ST_GeomFromText('" + geom.exportToWkt() + "', ST_SRID(the_geom)) WHERE cartodb_id = " + unicode(feature['cartodb_id'])
sql = sql.encode('utf-8')
Expand All @@ -285,11 +285,10 @@ def _updateGeometries(self, changedGeometries):
level=self.iface.messageBar().WARNING, duration=10)

def _addFeatures(self, addedFeatures):
schema = '' if self.owner is None else (self.owner + '.')
provider = self.dataProvider()
for featureID, feature in addedFeatures.iteritems():
QgsMessageLog.logMessage('Add feature with feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO)
sql = "INSERT INTO " + schema + self.cartoTable + " ("
sql = "INSERT INTO " + self._schema() + self.cartoTable + " ("
addComma = False
for field in feature.fields():
if unicode(feature[field.name()]) == 'NULL' or feature[field.name()] is None:
Expand All @@ -311,26 +310,29 @@ def _addFeatures(self, addedFeatures):
addComma = True
if addComma:
sql = sql + ", "
sql = sql + "ST_GeomFromText('" + feature.geometry().exportToWkt() + "', 4326)) RETURNING cartodb_id"
sql = sql + "ST_GeomFromText('" + feature.geometry().exportToWkt() + "', 4326)) RETURNING cartodb_id, created_at, updated_at"
sql = sql.encode('utf-8')
res = self._updateSQL(sql, 'Some error ocurred inserting feature')
if isinstance(res, dict) and res['total_rows'] == 1:
self.iface.messageBar().pushMessage('Info',
'Feature inserted at CartoDB servers',
level=self.iface.messageBar().INFO, duration=10)
self.setFieldEditable(self.fieldNameIndex('cartodb_id'), True)
self.editBuffer().changeAttributeValue(featureID, self.fieldNameIndex('cartodb_id'), res['rows'][0]['cartodb_id'], None)
self.setFieldEditable(self.fieldNameIndex('cartodb_id'), False)
for f in ['cartodb_id', 'created_at', 'updated_at']:
self._updateNullableFields(featureID, f, res['rows'][0][f])

def _updateNullableFields(self, featureID, fieldName, value):
self.setFieldEditable(self.fieldNameIndex(fieldName), True)
self.editBuffer().changeAttributeValue(featureID, self.fieldNameIndex(fieldName), value, None)
self.setFieldEditable(self.fieldNameIndex(fieldName), False)

def _deleteFeatures(self, deletedFeatureIds):
schema = '' if self.owner is None else (self.owner + '.')
provider = self.dataProvider()
for featureID in deletedFeatureIds:
QgsMessageLog.logMessage('Delete feature with feature ID: ' + str(featureID), 'CartoDB Plugin', QgsMessageLog.INFO)
request = QgsFeatureRequest().setFilterFid(featureID)
try:
feature = provider.getFeatures(request).next()
sql = "DELETE FROM " + schema + self.cartoTable + " WHERE cartodb_id = " + unicode(feature['cartodb_id'])
sql = "DELETE FROM " + self._schema() + self.cartoTable + " WHERE cartodb_id = " + unicode(feature['cartodb_id'])
res = self._updateSQL(sql, 'Some error ocurred deleting feature')
if isinstance(res, dict) and res['total_rows'] == 1:
self.iface.messageBar().pushMessage('Info',
Expand All @@ -354,6 +356,13 @@ def _updateSQL(self, sql, errorMsg):
self.iface.messageBar().pushMessage('Error!!', errorMsg, level=self.iface.messageBar().CRITICAL, duration=10)
return e

def _schema(self):
schema = self.schema()
return schema + ('.' if schema != '' else '')

def schema(self):
return '' if not self.multiuser else self.owner

def tableName(self):
return self.cartoTable

Expand All @@ -377,12 +386,13 @@ class CartoDBLayerWorker(QObject):
finished = pyqtSignal(CartoDBLayer)
error = pyqtSignal(Exception, basestring)

def __init__(self, iface, tableName, owner=None, dlg=None, sql=None, filterByExtent=False, readonly=False):
def __init__(self, iface, tableName, owner=None, dlg=None, sql=None, filterByExtent=False, readonly=False, multiuser=False):
QObject.__init__(self)
self.iface = iface
self.owner = owner
self.tableName = tableName
self.readonly = readonly
self.multiuser = multiuser
self.dlg = dlg
self.sql = sql
self.filterByExtent = filterByExtent
Expand All @@ -398,7 +408,7 @@ def load(self):
@pyqtSlot(str)
def _loadData(self, spatiaLite):
layer = CartoDBLayer(self.iface, self.tableName, self.dlg.currentUser, self.dlg.currentApiKey,
self.owner, self.sql, spatiaLite=spatiaLite, readonly=self.readonly)
self.owner, self.sql, spatiaLite=spatiaLite, readonly=self.readonly, multiuser=self.multiuser)
self.finished.emit(layer)

@pyqtSlot()
Expand Down
5 changes: 4 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ email=michaelsalgado@gkudos.com
changelog=0.1.9
- Default symbology for not supported symbols.
- Add messages for not supported symbols.
- Add uploaded message
- Add uploaded message.
- Change icons.
- Fix error updating layer single user account.
- Fix error getting columns in SQL dialog.
0.1.8
- Remove connection controls in SQL Editor.
- Add composite mode in create maps.
Expand Down
8 changes: 7 additions & 1 deletion resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<file>images/icons/rectangle.png</file>
</qresource>
<qresource prefix="/plugins/qgis-cartodb/">
<file>images/icons/add_sql.png</file>
<file>images/icons/sql.png</file>
</qresource>
<qresource prefix="/plugins/qgis-cartodb/">
<file>images/icons/text.png</file>
Expand All @@ -29,4 +29,10 @@
<qresource prefix="/plugins/qgis-cartodb/">
<file>images/icons/layers.png</file>
</qresource>
<qresource prefix="/plugins/qgis-cartodb/">
<file>images/icons/upload.png</file>
</qresource>
<qresource prefix="/plugins/qgis-cartodb/">
<file>images/icons/map.png</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions toolbars/CartoDBToolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, parent=None, flags=Qt.WindowFlags(0)):
if self.currentUser:
self.currentApiKey = self.settings.value('/CartoDBPlugin/%s/api' % self.currentUser)
self.currentMultiuser = self.settings.value('/CartoDBPlugin/%s/multiuser' % self.currentUser, False)
self.currentMultiuser = self.currentMultiuser in ['True', 'true', True]
else:
self.currentApiKey = None
self.currentMultiuser = None
Expand Down
3 changes: 2 additions & 1 deletion widgets/ListItemWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@


class CartoDBDatasetsListItem(QWidget):
def __init__(self, tableName=None, tableOwner=None, size=None, rows=None, shared=False):
def __init__(self, tableName=None, tableOwner=None, size=None, rows=None, multiuser=False, shared=False):
QWidget.__init__(self)
self.ui = Ui_ListItem()
self.ui.setupUi(self)

self.shared = shared
self.multiuser = multiuser
self.readonly = False
self.tableOwner = tableOwner

Expand Down

0 comments on commit f0b0e79

Please sign in to comment.