diff --git a/resources/context_help/QgsNewSpatialiteLayerDialog-en_US b/resources/context_help/QgsNewSpatialiteLayerDialog-en_US
index f3ff4132f35..decb2e8ed74 100644
--- a/resources/context_help/QgsNewSpatialiteLayerDialog-en_US
+++ b/resources/context_help/QgsNewSpatialiteLayerDialog-en_US
@@ -10,6 +10,8 @@ Enter a name for the geometry column or accept the default.
Choose the type of layer you want to create.
EPSG SRID
Enter the EPSG number for the spatial reference id (SRID). By default the SRID for WGS 84 is filled in for you. Click on button to change the coordinate reference system of the layer if needed. The SRID must exist within the spatial_ref_sys in your Spatialite database. You can search for the SRID using partial matches on both name and SRID.
+
Create an Autoincrementing Primary Key
+Clicking this checkbox will add a primary key to the new layer. This key field will be autoincrementing, meaning you don't have to enter a value for it when adding features to the attribute table of the layer.
New attribute
Add the desired attributes by clicking on the button after you have specified a name and type for the attribute. Only real, integer, and string attributes are supported.
Width and precision are irrelevant in a Spatialite database so you do not have to specify these.
diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp
index fc5e3d12704..76bc2e6c5d8 100644
--- a/src/app/qgisapp.cpp
+++ b/src/app/qgisapp.cpp
@@ -3131,7 +3131,16 @@ void QgisApp::newSpatialiteLayer()
// Build up the sql statement for creating the table
//
- QString sql = QString( "create table %1(" ).arg( quotedIdentifier( newLayerName ) );
+ QString baseSQL;
+ if ( spatialiteDialog.includePrimaryKey() )
+ {
+ baseSQL = "create table %1(pkuid integer primary key autoincrement, ";
+ }
+ else
+ {
+ baseSQL = "create table %1(";
+ }
+ QString sql = baseSQL.arg( quotedIdentifier( newLayerName ) );
// iterate through the field names and add them to the create statement
// (use indexed access since this is just as fast as iterators
for ( int i = 0; i < items->size(); ++i )
diff --git a/src/app/qgsnewspatialitelayerdialog.cpp b/src/app/qgsnewspatialitelayerdialog.cpp
index a1fc8a74538..75f92343d8a 100644
--- a/src/app/qgsnewspatialitelayerdialog.cpp
+++ b/src/app/qgsnewspatialitelayerdialog.cpp
@@ -232,6 +232,11 @@ QString QgsNewSpatialiteLayerDialog::geometryColumn() const
return leGeometryColumn->text();
}
+bool QgsNewSpatialiteLayerDialog::includePrimaryKey() const
+{
+ return checkBoxPrimaryKey->isChecked();
+}
+
bool QgsNewSpatialiteLayerDialog::createDb()
{
QFile newDb( mDatabaseComboBox->currentText() );
diff --git a/src/app/qgsnewspatialitelayerdialog.h b/src/app/qgsnewspatialitelayerdialog.h
index 5ffb660951a..dca55c99c18 100644
--- a/src/app/qgsnewspatialitelayerdialog.h
+++ b/src/app/qgsnewspatialitelayerdialog.h
@@ -49,6 +49,8 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL
QString geometryColumn() const;
/**Returns the selected crs id*/
QString selectedCrsId() const;
+ /**Returns the state of the primary key checkbox*/
+ bool includePrimaryKey() const;
/** Create a new database */
bool createDb();
diff --git a/src/ui/qgsnewspatialitelayerdialogbase.ui b/src/ui/qgsnewspatialitelayerdialogbase.ui
index 9c312e0055c..7de1ce82be6 100644
--- a/src/ui/qgsnewspatialitelayerdialogbase.ui
+++ b/src/ui/qgsnewspatialitelayerdialogbase.ui
@@ -6,8 +6,8 @@
00
- 411
- 593
+ 431
+ 648
@@ -227,6 +227,16 @@
+
+
+ Add an integer id field as the primary key for the new layer
+
+
+ Create an autoincrementing primary key
+
+
+
+ New attribute
@@ -284,7 +294,7 @@
-
+ Attributes list
@@ -397,7 +407,7 @@
-
+ Qt::Horizontal