Skip to content

Commit e24ccb8

Browse files
author
jef
committed
allow creation of multiple layers in spatialite creation dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk@13337 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9e93c6e commit e24ccb8

6 files changed

+249
-267
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h3>Einen neuen SpatiaLite-Layer erzeugen</h3>
2+
In diesem Dialog können Sie eine neue SpatiaLite-Datenbank und/oder einen leeren SpatiaLite Layer zur Bearbeitung erzeugen. Unten werden die Eingabemöglichkeiten des Dialogs beschrieben.
3+
<h4>Datenbank</h4>
4+
Wählen Sie die Datenbank aus der Liste. Diese Liste wird aus den gespeicherten
5+
SpatiaLite-Verbindungen erzeugt. Wenn sie keine gespeicherten Verbindungen
6+
haben oder oder eine neue Datenbank erzeugen wollen Klicken Sie auf
7+
<label>...</label> rechts der Liste.
8+
<h4>Layername</h4>
9+
Geben Sie dem Layer, den Sie erzeugen wollen, einen Namen. Der Name sollte nur ein Wort sein. Wenn Sie wollen, können Sie auch Unterstriche verwenden
10+
<h4>Geometriespalte</h4>
11+
Geben Sie der Geometriespalte einen Namen oder übernehmen Sie die Voreinstellung.
12+
<h4>Typ</h4>
13+
Legen Sie den Layertyp fest, den Sie erzeugen wollen.
14+
<h4>EPSG-SRID</h4>
15+
Geben Sie einen EPSG-Code für die SRID (räumliche Bezugskennung) an. Für die SRID wird Ihnen WGS 84 vorgeschlagen.
16+
Klicken Sie auf den Knopf <label>SRID finden</label> um das Koordinatenbezugssystem ggf. zu ändern.
17+
Die SRID muss in der Tabelle spatial_ref_sys in Ihre Datenbank existieren. Sie können SRIDs suchen indem Sie Suchbegriffe verwenden, die
18+
ganz oder teilweise zu Namen oder SRIDs passen.
19+
<h4>Einen automatisch inkrementierenden Primärschlüssel erzeugen</h4>
20+
Das Anwählen dieses Kontrolkästchen fügt dem Layer einen Primärschlüssel hinzu. Diese Feld wird automatisch inkrementiert, sodaß Sie keinen
21+
keinen Wert dafür beim Hinzufügen von Objekten zum Layer eingeben müssen.
22+
<h4>Neues Attribute</h4>
23+
Fügen Sie die gewünschten Attribute durch Klicken auf den Knopf <label>Attribute zur Liste hinzufügen</label> nachdem Sie Namen und Type des Attributes festgelegt haben. Nur Fließkomma-, ganzzahlige und Zeichenkettenattribute werden unterstützt.<br/>
24+
Breite und Genauigkeit sind irrelevant in einer SpatiaLite-Datenbank, daher brauchen Sie sie nicht anzugeben.
25+
<h4>Attributliste</h4>
26+
In diesem Abschnitt sehen Sie die Attributliste. Um eins davon zu löschen, klicken Sie auf den Knopf <label>Gewähltes Attribut löschen</label>.
27+
28+
<p>
29+
Klicken Sie auf <label>Ok</label> um den Layer anzulegen und den Dialog zu schließen. Ein Klick auf <label>Anwenden</label> erzeugt den Layer auch, aber hält den Dialog auf und erlaubt so mehr ähnliche Layer zu erzeugen. <label>Abbruch</label> schließt den Dialog ohne weitere Änderung.

resources/context_help/QgsNewSpatialiteLayerDialog-en_US

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h3>Create a New Spatialite Layer</h3>
22
You can use this dialog to create a new Spatialite database and/or an empty Spatialite layer for editing. See below for an explanation of the dialog inputs.
33
<h4>Database</h4>
4-
Choose the database from the drop-down list. This list is created from your saved Spatialite connections. If you don't have a saved connection or want to create a new database, click on the button (<label>...</label>) to the right of the drop-down. If you create a new database you will have to add it to your Spatialite connections in the <i>Add Spatialite Table(s)</i> dialog.
4+
Choose the database from the drop-down list. This list is created from your saved Spatialite connections. If you don't have a saved connection or want to create a new database, click on the button (<label>...</label>) to the right of the drop-down.
55
<h4>Layer name</h4>
66
Enter a name for the layer you want to create. The name should be one word. You can use underscores in the name if you like.
77
<h4>Geometry column</h4>
@@ -19,4 +19,4 @@ Width and precision are irrelevant in a Spatialite database so you do not have t
1919
In this section you can see the list of attributes. To delete one of them, click on it and choose <label>Remove selected attribute</label> button.
2020

2121
<p>
22-
To create the layer, click on <label>Apply</label>. The layer will be created and you will be returned to the dialog. From here you can click <label>Close</label> or change the parameters to create additional layers.
22+
Click on <label>Ok</label> to create the layer and close the dialog. Clicking <label>Apply</label> also creates the layer, but keeps the dialog open, thereby allowing you to create more similar layers. <label>Cancel</label> will close the layer without further changes.

src/app/qgisapp.cpp

+1-126
Original file line numberDiff line numberDiff line change
@@ -3098,18 +3098,6 @@ void QgisApp::newVectorLayer()
30983098
addVectorLayers( fileNames, enc, "file" );
30993099
}
31003100

3101-
static QString quotedIdentifier( QString id )
3102-
{
3103-
id.replace( "\"", "\"\"" );
3104-
return id.prepend( "\"" ).append( "\"" );
3105-
}
3106-
3107-
static QString quotedValue( QString value )
3108-
{
3109-
value.replace( "'", "''" );
3110-
return value.prepend( "'" ).append( "'" );
3111-
}
3112-
31133101
#ifdef HAVE_SPATIALITE
31143102
void QgisApp::newSpatialiteLayer()
31153103
{
@@ -3118,120 +3106,7 @@ void QgisApp::newSpatialiteLayer()
31183106
return;
31193107
}
31203108
QgsNewSpatialiteLayerDialog spatialiteDialog( this );
3121-
if ( spatialiteDialog.exec() == QDialog::Rejected )
3122-
{
3123-
return;
3124-
}
3125-
3126-
QString geometrytype = spatialiteDialog.selectedType();
3127-
//QString fileformat = geomDialog.selectedFileFormat();
3128-
QString crsId = spatialiteDialog.selectedCrsId();
3129-
QString databaseName = spatialiteDialog.databaseName();
3130-
QString newLayerName = spatialiteDialog.layerName();
3131-
QString newGeometryColumn = spatialiteDialog.geometryColumn();
3132-
//QgsDebugMsg( QString( "New file format will be: %1" ).arg( fileformat ) );
3133-
3134-
// Get the list containing the name/type pairs for each attribute
3135-
QList<QStringList> * items = spatialiteDialog.attributes( );
3136-
3137-
// Build up the sql statement for creating the table
3138-
//
3139-
QString baseSQL;
3140-
if ( spatialiteDialog.includePrimaryKey() )
3141-
{
3142-
baseSQL = "create table %1(pkuid integer primary key autoincrement, ";
3143-
}
3144-
else
3145-
{
3146-
baseSQL = "create table %1(";
3147-
}
3148-
QString sql = baseSQL.arg( quotedIdentifier( newLayerName ) );
3149-
// iterate through the field names and add them to the create statement
3150-
// (use indexed access since this is just as fast as iterators
3151-
for ( int i = 0; i < items->size(); ++i )
3152-
{
3153-
QStringList field = items->at( i );
3154-
if ( i > 0 )
3155-
sql += ",";
3156-
sql += QString( "%1 %2" ).arg( quotedIdentifier( field.at( 0 ) ) ).arg( field.at( 1 ) );
3157-
}
3158-
// complete the create table statement
3159-
sql += ")";
3160-
QgsDebugMsg( QString( "Creating table in database %1" ).arg( databaseName ) );
3161-
QgsDebugMsg( sql ); // OK
3162-
3163-
QString sqlAddGeom = QString( "select AddGeometryColumn(%1,%2,%3,%4,2)" )
3164-
.arg( quotedValue( newLayerName ) )
3165-
.arg( quotedValue( newGeometryColumn ) )
3166-
.arg( crsId )
3167-
.arg( quotedValue( geometrytype ) );
3168-
QgsDebugMsg( sqlAddGeom ); // OK
3169-
3170-
QString sqlCreateIndex = QString( "select CreateSpatialIndex(%1,%2)" ).arg( quotedValue( newLayerName ) ).arg( quotedValue( newGeometryColumn ) );
3171-
QgsDebugMsg( sqlCreateIndex ); // OK
3172-
3173-
spatialite_init( 0 );
3174-
3175-
sqlite3 *db;
3176-
int rc = sqlite3_open( databaseName.toUtf8(), &db );
3177-
if ( rc != SQLITE_OK )
3178-
{
3179-
QMessageBox::warning( this,
3180-
tr( "SpatiaLite Database" ),
3181-
tr( "Unable to open the database: %1" ).arg( databaseName ) );
3182-
}
3183-
else
3184-
{
3185-
char * errmsg;
3186-
rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
3187-
if ( rc != SQLITE_OK )
3188-
{
3189-
QMessageBox::warning( this,
3190-
tr( "Error Creating SpatiaLite Table" ),
3191-
tr( "Failed to create the SpatiaLite table %1. The database returned:\n%2" ).arg( newLayerName ).arg( errmsg ) );
3192-
sqlite3_free( errmsg );
3193-
}
3194-
else
3195-
{
3196-
// create the geometry column and the spatial index
3197-
rc = sqlite3_exec( db, sqlAddGeom.toUtf8(), NULL, NULL, &errmsg );
3198-
if ( rc != SQLITE_OK )
3199-
{
3200-
QMessageBox::warning( this,
3201-
tr( "Error Creating Geometry Column" ),
3202-
tr( "Failed to create the geometry column. The database returned:\n%1" ).arg( errmsg ) );
3203-
sqlite3_free( errmsg );
3204-
}
3205-
else
3206-
{
3207-
// create the spatial index
3208-
rc = sqlite3_exec( db, sqlCreateIndex.toUtf8(), NULL, NULL, &errmsg );
3209-
if ( rc != SQLITE_OK )
3210-
{
3211-
QMessageBox::warning( this,
3212-
tr( "Error Creating Spatial Index" ),
3213-
tr( "Failed to create the spatial index. The database returned:\n%1" ).arg( errmsg ) );
3214-
sqlite3_free( errmsg );
3215-
}
3216-
3217-
QgsVectorLayer *layer = new QgsVectorLayer( QString( "dbname='%1' table='%2'(%3) sql=" )
3218-
.arg( databaseName )
3219-
.arg( newLayerName )
3220-
.arg( newGeometryColumn ), newLayerName, "spatialite" );
3221-
if ( layer->isValid() )
3222-
{
3223-
// register this layer with the central layers registry
3224-
QgsMapLayerRegistry::instance()->addMapLayer( layer );
3225-
}
3226-
else
3227-
{
3228-
QgsDebugMsg( newLayerName + " is an invalid layer - not loaded" );
3229-
QMessageBox::critical( this, tr( "Invalid Layer" ), tr( "%1 is an invalid layer and cannot be loaded." ).arg( newLayerName ) );
3230-
delete layer;
3231-
}
3232-
}
3233-
}
3234-
}
3109+
spatialiteDialog.exec();
32353110
}
32363111
#endif
32373112

0 commit comments

Comments
 (0)