[QGIS Commit] r13279 - in trunk/qgis: resources/context_help src/app src/ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Apr 7 22:43:32 EDT 2010


Author: gsherman
Date: 2010-04-07 22:43:31 -0400 (Wed, 07 Apr 2010)
New Revision: 13279

Modified:
   trunk/qgis/resources/context_help/QgsNewSpatialiteLayerDialog-en_US
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgsnewspatialitelayerdialog.cpp
   trunk/qgis/src/app/qgsnewspatialitelayerdialog.h
   trunk/qgis/src/ui/qgsnewspatialitelayerdialogbase.ui
Log:
Add the option to include a primary key when creating a new spatialite
layer.

Modified: trunk/qgis/resources/context_help/QgsNewSpatialiteLayerDialog-en_US
===================================================================
--- trunk/qgis/resources/context_help/QgsNewSpatialiteLayerDialog-en_US	2010-04-07 18:09:38 UTC (rev 13278)
+++ trunk/qgis/resources/context_help/QgsNewSpatialiteLayerDialog-en_US	2010-04-08 02:43:31 UTC (rev 13279)
@@ -10,6 +10,8 @@
 Choose the type of layer you want to create. 
 <h4>EPSG SRID</h4>
 Enter the EPSG number for the spatial reference id (SRID). By default the SRID for WGS 84 is filled in for you. Click on <label>Find SRID</label> 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.
+<h4>Create an Autoincrementing Primary Key</h4>
+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.
 <h4>New attribute</h4>
 Add the desired attributes by clicking on the <label>Add to attributes list</label> button after you have specified a name and type for the attribute. Only real, integer, and string attributes are supported.<br/>
 Width and precision are irrelevant in a Spatialite database so you do not have to specify these.

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2010-04-07 18:09:38 UTC (rev 13278)
+++ trunk/qgis/src/app/qgisapp.cpp	2010-04-08 02:43:31 UTC (rev 13279)
@@ -3131,7 +3131,16 @@
 
   // 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 )

Modified: trunk/qgis/src/app/qgsnewspatialitelayerdialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsnewspatialitelayerdialog.cpp	2010-04-07 18:09:38 UTC (rev 13278)
+++ trunk/qgis/src/app/qgsnewspatialitelayerdialog.cpp	2010-04-08 02:43:31 UTC (rev 13279)
@@ -232,6 +232,11 @@
   return leGeometryColumn->text();
 }
 
+bool QgsNewSpatialiteLayerDialog::includePrimaryKey() const
+{
+  return checkBoxPrimaryKey->isChecked();
+}
+
 bool QgsNewSpatialiteLayerDialog::createDb()
 {
   QFile newDb( mDatabaseComboBox->currentText() );

Modified: trunk/qgis/src/app/qgsnewspatialitelayerdialog.h
===================================================================
--- trunk/qgis/src/app/qgsnewspatialitelayerdialog.h	2010-04-07 18:09:38 UTC (rev 13278)
+++ trunk/qgis/src/app/qgsnewspatialitelayerdialog.h	2010-04-08 02:43:31 UTC (rev 13279)
@@ -49,6 +49,8 @@
     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();
 

Modified: trunk/qgis/src/ui/qgsnewspatialitelayerdialogbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsnewspatialitelayerdialogbase.ui	2010-04-07 18:09:38 UTC (rev 13278)
+++ trunk/qgis/src/ui/qgsnewspatialitelayerdialogbase.ui	2010-04-08 02:43:31 UTC (rev 13279)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>411</width>
-    <height>593</height>
+    <width>431</width>
+    <height>648</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -227,6 +227,16 @@
     </layout>
    </item>
    <item row="5" column="0">
+    <widget class="QCheckBox" name="checkBoxPrimaryKey">
+     <property name="toolTip">
+      <string>Add an integer id field as the primary key for the new layer</string>
+     </property>
+     <property name="text">
+      <string>Create an autoincrementing primary key</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="0">
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
       <string>New attribute</string>
@@ -284,7 +294,7 @@
      </layout>
     </widget>
    </item>
-   <item row="6" column="0">
+   <item row="7" column="0">
     <widget class="QGroupBox" name="groupBox_2">
      <property name="title">
       <string>Attributes list</string>
@@ -397,7 +407,7 @@
      </layout>
     </widget>
    </item>
-   <item row="7" column="0">
+   <item row="8" column="0">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>



More information about the QGIS-commit mailing list