16 changes: 0 additions & 16 deletions python/plugins/db_manager/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from .db_tree import DBTree

from .db_plugins import getDbPluginErrors
from .db_plugins.plugin import BaseError
from .dlg_db_error import DlgDbError

Expand All @@ -53,21 +52,6 @@ def __init__(self, iface, parent=None):
self.connect(self.tree, SIGNAL("selectedItemChanged"), self.itemChanged)
self.itemChanged(None)

self.displayDbPluginErrors()

def displayDbPluginErrors(self):
if len(getDbPluginErrors()) <= 0:
return

if not hasattr(self, '_dbPluginErrorIndex') or self._dbPluginErrorIndex >= len(getDbPluginErrors()):
self._dbPluginErrorIndex = 0

msg = getDbPluginErrors()[self._dbPluginErrorIndex]
self._dbPluginErrorIndex += 1

self.statusBar.showMessage( msg, 5000 )
QTimer.singleShot( 6000, self.displayDbPluginErrors)


def closeEvent(self, e):
self.unregisterAllActions()
Expand Down
13 changes: 2 additions & 11 deletions python/plugins/db_manager/db_plugins/info_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,14 @@ def spatialInfo(self):

tbl = [
("Library:", info[0]),
("Scripts:", info[1]),
("GEOS:", info[3]),
("Proj:", info[4]),
("Use stats:", info[5])
("GEOS:", info[1]),
("Proj:", info[2])
]
ret.append( HtmlTable( tbl ) )

if info[1] != None and info[1] != info[2]:
ret.append( HtmlParagraph( u"<warning> Version of installed scripts doesn't match version of released scripts!\n" \
"This is probably a result of incorrect PostGIS upgrade." ) )

if not self.db.connector.has_geometry_columns:
ret.append( HtmlParagraph( u"<warning> geometry_columns table doesn't exist!\n" \
"This table is essential for many GIS applications for enumeration of tables." ) )
elif not self.db.connector.has_geometry_columns_access:
ret.append( HtmlParagraph( u"<warning> This user doesn't have privileges to read contents of geometry_columns table!\n" \
"This table is essential for many GIS applications for enumeration of tables." ) )

return ret

Expand Down
9 changes: 4 additions & 5 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,17 @@ def getInfo(self):
def getSpatialInfo(self):
""" returns tuple about postgis support:
- lib version
- installed scripts version
- released scripts version
- geos version
- proj version
- whether uses stats
- installed scripts version
- released scripts version
"""
if not self.has_spatial:
return

c = self._get_cursor()
try:
self._execute(c, u"SELECT postgis_lib_version(), postgis_scripts_installed(), postgis_scripts_released(), postgis_geos_version(), postgis_proj_version(), postgis_uses_stats()")
self._execute(c, u"SELECT postgis_lib_version(), postgis_geos_version(), postgis_proj_version(), postgis_scripts_installed(), postgis_scripts_released()")
except DbError:
return

Expand All @@ -151,7 +150,7 @@ def fieldTypes(self):
"integer", "bigint", "smallint", # integers
"serial", "bigserial", # auto-incrementing ints
"real", "double precision", "numeric", # floats
"varchar", "varchar(n)", "char(n)", "text", # strings
"varchar", "varchar(255)", "char(20)", "text", # strings
"date", "time", "timestamp" # date/time
]

Expand Down
28 changes: 28 additions & 0 deletions python/plugins/db_manager/db_plugins/postgis/info_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ def generalInfo(self):

return ret

def getSpatialInfo(self):
ret = []

info = self.db.connector.getSpatialInfo()
if info == None:
return

tbl = [
("Library:", info[0]),
("Scripts:", info[3]),
("GEOS:", info[1]),
("Proj:", info[2])
]
ret.append( HtmlTable( tbl ) )

if info[1] != None and info[1] != info[2]:
ret.append( HtmlParagraph( u"<warning> Version of installed scripts doesn't match version of released scripts!\n" \
"This is probably a result of incorrect PostGIS upgrade." ) )

if not self.db.connector.has_geometry_columns:
ret.append( HtmlParagraph( u"<warning> geometry_columns table doesn't exist!\n" \
"This table is essential for many GIS applications for enumeration of tables." ) )
elif not self.db.connector.has_geometry_columns_access:
ret.append( HtmlParagraph( u"<warning> This user doesn't have privileges to read contents of geometry_columns table!\n" \
"This table is essential for many GIS applications for enumeration of tables." ) )

return ret


def fieldsDetails(self):
tbl = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def fieldTypes(self):
return [
"integer", "bigint", "smallint", # integers
"real", "double", "float", "numeric", # floats
"varchar", "varchar(n)", "character(n)", "text", # strings
"varchar", "varchar(255)", "character(20)", "text", # strings
"date", "datetime" # date/time
]

Expand Down
20 changes: 0 additions & 20 deletions python/plugins/db_manager/db_plugins/spatialite/info_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,6 @@ def connectionDetails(self):
]
return HtmlTable( tbl )

def spatialInfo(self):
ret = []

info = self.db.connector.getSpatialInfo()
if info == None:
return

tbl = [
("Library:", info[0]),
("GEOS:", info[1]),
("Proj:", info[2])
]
ret.append( HtmlTable( tbl ) )

if not self.db.connector.has_geometry_columns:
ret.append( HtmlParagraph( u"<warning> geometry_columns table doesn't exist!\n" \
"This table is essential for many GIS applications for enumeration of tables." ) )

return ret

def generalInfo(self):
info = self.db.connector.getInfo()
tbl = [
Expand Down
14 changes: 8 additions & 6 deletions python/plugins/db_manager/dlg_import_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

self.default_pk = "id"
self.default_geom = "geom"

# updates of UI
for widget in [self.radCreate, self.chkDropTable, self.radAppend,
self.chkPrimaryKey, self.chkGeomColumn, self.chkSpatialIndex,
Expand All @@ -58,11 +58,14 @@ def __init__(self, inLayer, outDb, outUri, parent=None):
self.populateEncodings()
self.updateUi()

# set default values
self.cboTable.setEditText(self.outUri.table())

pk = self.outUri.keyColumn()
self.editPrimaryKey.setText(pk if pk != "" else self.default_pk)
geom = self.outUri.geometryColumn()
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)

inCrs = self.inLayer.crs()
srid = inCrs.postgisSrid() if inCrs.isValid() else 4236
self.editSourceSrid.setText( "%s" % srid )
Expand All @@ -73,7 +76,7 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

def checkSupports(self):
allowSpatial = self.db.connector.hasSpatialSupport()
self.chkGeomColumn.setEnabled(allowSpatial)
self.chkGeomColumn.setEnabled(allowSpatial and self.inLayer.hasGeometryType())
self.chkSourceSrid.setEnabled(allowSpatial)
self.chkTargetSrid.setEnabled(allowSpatial)
self.chkSpatialIndex.setEnabled(allowSpatial)
Expand Down Expand Up @@ -168,12 +171,11 @@ def importLayer(self):
schema = self.outUri.schema() if not self.cboSchema.isEnabled() else self.cboSchema.currentText()
table = self.cboTable.currentText()

# get pk and geom field names from the source layer or use the
# ones defined by the user
pk = self.outUri.keyColumn() if not self.chkPrimaryKey.isChecked() else self.editPrimaryKey.text()
pk = pk if pk != "" else self.default_pk

geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
if self.inLayer.hasGeometryType():
geom = geom if geom != "" else self.default_geom
geom = geom if geom != "" else self.default_geom

self.outUri.setDataSource( schema, table, geom, QString(), pk )
uri = self.outUri.uri()
Expand Down
12 changes: 11 additions & 1 deletion python/plugins/db_manager/info_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, parent=None):
self.dirty = False

self._clear()
self._showPluginInfo()

self.connect(self, SIGNAL("anchorClicked(const QUrl&)"), self._linkClicked)

def _linkClicked(self, url):
Expand Down Expand Up @@ -89,6 +91,15 @@ def _clear(self):
self.item = None
self.setHtml("")


def _showPluginInfo(self):
from .db_plugins import getDbPluginErrors
html = u'<div style="background-color:#ffffcc;"><h1>&nbsp;DB Manager</h1></div>'
html += '<div style="margin-left:8px;">'
for msg in getDbPluginErrors():
html += u"<p>%s" % msg
self.setHtml(html)

def _showDatabaseInfo(self, connection):
html = u'<div style="background-color:#ccffcc;"><h1>&nbsp;%s</h1></div>' % connection.connectionName()
html += '<div style="margin-left:8px;">'
Expand Down Expand Up @@ -126,7 +137,6 @@ def _showTableInfo(self, table):
return True



def setHtml(self, html):
# convert special tags :)
html = unicode(html).replace( '<warning>', '<img src=":/db_manager/warning">&nbsp;&nbsp; ' )
Expand Down
32 changes: 30 additions & 2 deletions src/core/qgsvectorlayerimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,41 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
}

QgsFieldMap fields = skipAttributeCreation ? QgsFieldMap() : layer->pendingFields();
QGis::WkbType wkbType = layer->wkbType();

// Special handling for Shapefiles
if ( layer->providerType() == "ogr" && layer->storageType() == "ESRI Shapefile" )
{
// convert field names to lowercase
for ( QgsFieldMap::iterator fldIt = fields.begin(); fldIt != fields.end(); ++fldIt )
{
fldIt.value().setName( fldIt.value().name().toLower() );
}

// convert wkbtype to multipart (see #5547)
switch ( wkbType )
{
case QGis::WKBPoint:
wkbType = QGis::WKBMultiPoint;
break;
case QGis::WKBLineString:
wkbType = QGis::WKBMultiLineString;
break;
case QGis::WKBPolygon:
wkbType = QGis::WKBMultiPolygon;
break;
case QGis::WKBPoint25D:
wkbType = QGis::WKBMultiPoint25D;
break;
case QGis::WKBLineString25D:
wkbType = QGis::WKBMultiLineString25D;
break;
case QGis::WKBPolygon25D:
wkbType = QGis::WKBMultiPolygon25D;
break;
default:
break;
}
}

bool overwrite = false;
Expand All @@ -220,7 +248,7 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
}

QgsVectorLayerImport * writer =
new QgsVectorLayerImport( uri, providerKey, fields, layer->wkbType(), outputCRS, overwrite, options );
new QgsVectorLayerImport( uri, providerKey, fields, wkbType, outputCRS, overwrite, options );

// check whether file creation was successful
ImportError err = writer->hasError();
Expand All @@ -240,7 +268,7 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
QgsAttributeList allAttr = skipAttributeCreation ? QgsAttributeList() : layer->pendingAllAttributesList();
QgsFeature fet;

layer->select( allAttr, QgsRectangle(), layer->wkbType() != QGis::WKBNoGeometry );
layer->select( allAttr, QgsRectangle(), wkbType != QGis::WKBNoGeometry );

const QgsFeatureIds& ids = layer->selectedFeaturesIds();

Expand Down