[QGIS Commit] r10693 - in trunk/qgis/src: app providers/ogr ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri May 1 12:14:02 EDT 2009


Author: jef
Date: 2009-05-01 12:14:02 -0400 (Fri, 01 May 2009)
New Revision: 10693

Modified:
   trunk/qgis/src/app/qgsgeomtypedialog.cpp
   trunk/qgis/src/app/qgsgeomtypedialog.h
   trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
   trunk/qgis/src/ui/qgsgeomtypedialogbase.ui
Log:
fix #1673 and #1674

Modified: trunk/qgis/src/app/qgsgeomtypedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsgeomtypedialog.cpp	2009-05-01 08:56:30 UTC (rev 10692)
+++ trunk/qgis/src/app/qgsgeomtypedialog.cpp	2009-05-01 16:14:02 UTC (rev 10693)
@@ -28,9 +28,9 @@
   setupUi( this );
   mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
   mRemoveAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionDeleteAttribute.png" ) );
+  mTypeBox->addItem( tr( "String" ), "String" );
+  mTypeBox->addItem( tr( "Integer" ), "Integer" );
   mTypeBox->addItem( tr( "Real" ), "Real" );
-  mTypeBox->addItem( tr( "Integer" ), "Integer" );;
-  mTypeBox->addItem( tr( "String" ), "String" );
 
   mPointRadioButton->setChecked( true );
   mFileFormatComboBox->addItem( "ESRI Shapefile" );
@@ -45,6 +45,11 @@
 {
 }
 
+void QgsGeomTypeDialog::on_mTypeBox_currentIndexChanged( int index )
+{
+  mPrecision->setEnabled( index == 2 );  // Real
+}
+
 QGis::WkbType QgsGeomTypeDialog::selectedType() const
 {
   if ( mPointRadioButton->isChecked() )
@@ -65,9 +70,11 @@
 void QgsGeomTypeDialog::on_mAddAttributeButton_clicked()
 {
   QString myName = mNameEdit->text();
+  QString myWidth = mWidth->text();
+  QString myPrecision = mPrecision->text();
   //use userrole to avoid translated type string
   QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
-  mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType ) );
+  mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType << myWidth << myPrecision ) );
   if ( mAttributeView->topLevelItemCount() > 0 )
   {
     mOkButton->setEnabled( true );
@@ -95,8 +102,9 @@
   while ( *it )
   {
     QTreeWidgetItem *item = *it;
-    at.push_back( std::make_pair( item->text( 0 ), item->text( 1 ) ) );
-    QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( item->text( 1 ) ) );
+    QString type = QString( "%1;%2;%3" ).arg( item->text( 1 ) ).arg( item->text( 2 ) ).arg( item->text( 3 ) );
+    at.push_back( std::make_pair( item->text( 0 ), type ) );
+    QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( type ) );
     ++it;
   }
 }

Modified: trunk/qgis/src/app/qgsgeomtypedialog.h
===================================================================
--- trunk/qgis/src/app/qgsgeomtypedialog.h	2009-05-01 08:56:30 UTC (rev 10692)
+++ trunk/qgis/src/app/qgsgeomtypedialog.h	2009-05-01 16:14:02 UTC (rev 10693)
@@ -41,6 +41,7 @@
     void on_mAddAttributeButton_clicked();
     void on_mRemoveAttributeButton_clicked();
     void on_buttonBox_helpRequested();
+    void on_mTypeBox_currentIndexChanged( int index );
 
   private:
     QPushButton * mOkButton;

Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2009-05-01 08:56:30 UTC (rev 10692)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp	2009-05-01 16:14:02 UTC (rev 10693)
@@ -1410,33 +1410,52 @@
 
   for ( std::list<std::pair<QString, QString> >::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
   {
-    if ( it->second == "Real" )
+    QStringList fields = it->second.split( ";" );
+
+    if ( fields.size() == 0 )
+      continue;
+
+    int width = fields.size() > 1 ? fields[1].toInt() : -1;
+    int precision = fields.size() > 2 ? fields[2].toInt() : -1;
+
+    OGRFieldDefnH field;
+    if ( fields[0] == "Real" )
     {
-      OGRFieldDefnH field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTReal );
-      OGR_Fld_SetPrecision( field, 3 );
-      OGR_Fld_SetWidth( field, 32 );
-      if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
-      {
-        QgsLogger::warning( "creation of OFTReal field failed" );
-      }
+      if ( width == -1 )
+        width = 32;
+      if ( precision == -1 )
+        precision = 3;
+
+      field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTReal );
+      OGR_Fld_SetWidth( field, width );
+      OGR_Fld_SetPrecision( field, precision );
     }
-    else if ( it->second == "Integer" )
+    else if ( fields[0] == "Integer" )
     {
-      OGRFieldDefnH field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTInteger );
-      OGR_Fld_SetWidth( field, 10 ); // limit to 10.  otherwise OGR sets it to 11 and recognizes as OFTDouble later
-      if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
-      {
-        QgsLogger::warning( "creation of OFTInteger field failed" );
-      }
+      if ( width == -1 || width > 10 )
+        width = 10;
+
+      field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTInteger );
+      // limit to 10.  otherwise OGR sets it to 11 and recognizes as OFTDouble later
+      OGR_Fld_SetWidth( field, width );
     }
-    else if ( it->second == "String" )
+    else if ( fields[0] == "String" )
     {
-      OGRFieldDefnH field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTString );
-      if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
-      {
-        QgsLogger::warning( "creation of OFTString field failed" );
-      }
+      if ( width == -1 )
+        width = 80;
+
+      field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTString );
+      OGR_Fld_SetWidth( field, width );
     }
+    else
+    {
+      continue;
+    }
+
+    if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
+    {
+      QgsLogger::warning( "creation of field failed" );
+    }
   }
 
   OGR_DS_Destroy( dataSource );

Modified: trunk/qgis/src/ui/qgsgeomtypedialogbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsgeomtypedialogbase.ui	2009-05-01 08:56:30 UTC (rev 10692)
+++ trunk/qgis/src/ui/qgsgeomtypedialogbase.ui	2009-05-01 16:14:02 UTC (rev 10693)
@@ -1,57 +1,58 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>QgsGeomTypeDialogBase</class>
- <widget class="QDialog" name="QgsGeomTypeDialogBase" >
-  <property name="geometry" >
+ <widget class="QDialog" name="QgsGeomTypeDialogBase">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>395</width>
-    <height>422</height>
+    <width>353</width>
+    <height>397</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>New Vector Layer</string>
   </property>
-  <property name="modal" >
+  <property name="modal">
    <bool>true</bool>
   </property>
-  <layout class="QGridLayout" >
-   <item row="0" column="0" >
-    <widget class="QLabel" name="mFileFormatLabel" >
-     <property name="text" >
+  <layout class="QGridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="mFileFormatLabel">
+     <property name="text">
       <string>File format</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>mFileFormatComboBox</cstring>
      </property>
     </widget>
    </item>
-   <item row="0" column="1" colspan="3" >
-    <widget class="QComboBox" name="mFileFormatComboBox" />
+   <item row="0" column="1" colspan="3">
+    <widget class="QComboBox" name="mFileFormatComboBox"/>
    </item>
-   <item row="1" column="0" colspan="4" >
-    <widget class="QGroupBox" name="buttonGroup1" >
-     <property name="title" >
+   <item row="1" column="0" colspan="4">
+    <widget class="QGroupBox" name="buttonGroup1">
+     <property name="title">
       <string>Type</string>
      </property>
-     <layout class="QGridLayout" >
-      <item row="0" column="0" >
-       <widget class="QRadioButton" name="mPointRadioButton" >
-        <property name="text" >
+     <layout class="QGridLayout">
+      <item row="0" column="0">
+       <widget class="QRadioButton" name="mPointRadioButton">
+        <property name="text">
          <string>Point</string>
         </property>
        </widget>
       </item>
-      <item row="0" column="1" >
-       <widget class="QRadioButton" name="mLineRadioButton" >
-        <property name="text" >
+      <item row="0" column="1">
+       <widget class="QRadioButton" name="mLineRadioButton">
+        <property name="text">
          <string>Line</string>
         </property>
        </widget>
       </item>
-      <item row="0" column="2" >
-       <widget class="QRadioButton" name="mPolygonRadioButton" >
-        <property name="text" >
+      <item row="0" column="2">
+       <widget class="QRadioButton" name="mPolygonRadioButton">
+        <property name="text">
          <string>Polygon</string>
         </property>
        </widget>
@@ -59,117 +60,149 @@
      </layout>
     </widget>
    </item>
-   <item row="2" column="0" colspan="4" >
-    <widget class="QLabel" name="mAttributeLabel" >
-     <property name="text" >
+   <item row="2" column="0" colspan="4">
+    <widget class="QLabel" name="mAttributeLabel">
+     <property name="text">
       <string>Attributes</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="0" >
-    <widget class="QLabel" name="textLabel1" >
-     <property name="text" >
+   <item row="3" column="0">
+    <widget class="QLabel" name="textLabel1">
+     <property name="text">
       <string>Name</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>mNameEdit</cstring>
      </property>
     </widget>
    </item>
-   <item row="3" column="1" colspan="3" >
-    <widget class="QLineEdit" name="mNameEdit" />
+   <item row="3" column="1" colspan="3">
+    <widget class="QLineEdit" name="mNameEdit"/>
    </item>
-   <item row="4" column="0" >
-    <widget class="QLabel" name="textLabel2" >
-     <property name="text" >
+   <item row="4" column="0">
+    <widget class="QLabel" name="textLabel2">
+     <property name="text">
       <string>Type</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>mTypeBox</cstring>
      </property>
     </widget>
    </item>
-   <item row="4" column="1" colspan="3" >
-    <widget class="QComboBox" name="mTypeBox" />
+   <item row="4" column="1" colspan="3">
+    <widget class="QComboBox" name="mTypeBox"/>
    </item>
-   <item row="5" column="0" colspan="2" >
-    <spacer>
-     <property name="orientation" >
+   <item row="6" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Width</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="1">
+    <widget class="QLineEdit" name="mWidth"/>
+   </item>
+   <item row="6" column="2">
+    <widget class="QLabel" name="label_2">
+     <property name="text">
+      <string>Precision</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="3">
+    <widget class="QLineEdit" name="mPrecision">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item row="13" column="0" colspan="4">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="sizeHint" >
-      <size>
-       <width>291</width>
-       <height>20</height>
-      </size>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
      </property>
-    </spacer>
+    </widget>
    </item>
-   <item row="5" column="2" >
-    <widget class="QToolButton" name="mRemoveAttributeButton" >
-     <property name="toolTip" >
+   <item row="7" column="0">
+    <widget class="QToolButton" name="mRemoveAttributeButton">
+     <property name="toolTip">
       <string>Delete selected attribute</string>
      </property>
-     <property name="text" >
+     <property name="text">
       <string>...</string>
      </property>
-     <property name="icon" >
-      <iconset>../../images/themes/default/mActionDeleteAttribute.png</iconset>
+     <property name="icon">
+      <iconset>
+       <normaloff>../../images/themes/default/mActionDeleteAttribute.png</normaloff>../../images/themes/default/mActionDeleteAttribute.png</iconset>
      </property>
     </widget>
    </item>
-   <item row="5" column="3" >
-    <widget class="QToolButton" name="mAddAttributeButton" >
-     <property name="toolTip" >
+   <item row="7" column="3">
+    <widget class="QToolButton" name="mAddAttributeButton">
+     <property name="toolTip">
       <string>Add attribute</string>
      </property>
-     <property name="text" >
+     <property name="layoutDirection">
+      <enum>Qt::RightToLeft</enum>
+     </property>
+     <property name="text">
       <string>...</string>
      </property>
-     <property name="icon" >
-      <iconset>../../images/themes/default/mActionNewAttribute.png</iconset>
+     <property name="icon">
+      <iconset>
+       <normaloff>../../images/themes/default/mActionNewAttribute.png</normaloff>../../images/themes/default/mActionNewAttribute.png</iconset>
      </property>
     </widget>
    </item>
-   <item row="6" column="0" colspan="4" >
-    <widget class="QTreeWidget" name="mAttributeView" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
+   <item row="12" column="0" colspan="4">
+    <widget class="QTreeWidget" name="mAttributeView">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="alternatingRowColors" >
+     <property name="alternatingRowColors">
       <bool>true</bool>
      </property>
-     <property name="rootIsDecorated" >
+     <property name="rootIsDecorated">
       <bool>false</bool>
      </property>
+     <property name="columnCount">
+      <number>4</number>
+     </property>
      <column>
-      <property name="text" >
+      <property name="text">
        <string>Name</string>
       </property>
      </column>
      <column>
-      <property name="text" >
+      <property name="text">
        <string>Type</string>
       </property>
      </column>
+     <column>
+      <property name="text">
+       <string>Width</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>Precision</string>
+      </property>
+     </column>
     </widget>
    </item>
-   <item row="7" column="0" colspan="4" >
-    <widget class="QDialogButtonBox" name="buttonBox" >
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="standardButtons" >
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="11" />
+ <layoutdefault spacing="6" margin="11"/>
  <tabstops>
   <tabstop>mFileFormatComboBox</tabstop>
   <tabstop>mPointRadioButton</tabstop>
@@ -177,8 +210,6 @@
   <tabstop>mPolygonRadioButton</tabstop>
   <tabstop>mNameEdit</tabstop>
   <tabstop>mTypeBox</tabstop>
-  <tabstop>mRemoveAttributeButton</tabstop>
-  <tabstop>mAddAttributeButton</tabstop>
   <tabstop>mAttributeView</tabstop>
   <tabstop>buttonBox</tabstop>
  </tabstops>
@@ -190,11 +221,11 @@
    <receiver>QgsGeomTypeDialogBase</receiver>
    <slot>accept()</slot>
    <hints>
-    <hint type="sourcelabel" >
+    <hint type="sourcelabel">
      <x>349</x>
      <y>400</y>
     </hint>
-    <hint type="destinationlabel" >
+    <hint type="destinationlabel">
      <x>387</x>
      <y>304</y>
     </hint>
@@ -206,11 +237,11 @@
    <receiver>QgsGeomTypeDialogBase</receiver>
    <slot>reject()</slot>
    <hints>
-    <hint type="sourcelabel" >
+    <hint type="sourcelabel">
      <x>275</x>
      <y>400</y>
     </hint>
-    <hint type="destinationlabel" >
+    <hint type="destinationlabel">
      <x>242</x>
      <y>308</y>
     </hint>



More information about the QGIS-commit mailing list