Skip to content
Permalink
Browse files

fix #1673 and #1674

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10693 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed May 1, 2009
1 parent 9172f47 commit e46cc1fe76255c728407006a937afd9072eefa35
Showing with 173 additions and 114 deletions.
  1. +13 −5 src/app/qgsgeomtypedialog.cpp
  2. +1 −0 src/app/qgsgeomtypedialog.h
  3. +40 −21 src/providers/ogr/qgsogrprovider.cpp
  4. +119 −88 src/ui/qgsgeomtypedialogbase.ui
@@ -28,9 +28,9 @@ QgsGeomTypeDialog::QgsGeomTypeDialog( QWidget *parent, Qt::WFlags fl )
setupUi( this );
mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
mRemoveAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionDeleteAttribute.png" ) );
mTypeBox->addItem( tr( "Real" ), "Real" );
mTypeBox->addItem( tr( "Integer" ), "Integer" );;
mTypeBox->addItem( tr( "String" ), "String" );
mTypeBox->addItem( tr( "Integer" ), "Integer" );
mTypeBox->addItem( tr( "Real" ), "Real" );

mPointRadioButton->setChecked( true );
mFileFormatComboBox->addItem( "ESRI Shapefile" );
@@ -45,6 +45,11 @@ QgsGeomTypeDialog::~QgsGeomTypeDialog()
{
}

void QgsGeomTypeDialog::on_mTypeBox_currentIndexChanged( int index )
{
mPrecision->setEnabled( index == 2 ); // Real
}

QGis::WkbType QgsGeomTypeDialog::selectedType() const
{
if ( mPointRadioButton->isChecked() )
@@ -65,9 +70,11 @@ QGis::WkbType QgsGeomTypeDialog::selectedType() const
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 @@ void QgsGeomTypeDialog::attributes( std::list<std::pair<QString, QString> >& at
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;
}
}
@@ -41,6 +41,7 @@ class QgsGeomTypeDialog: public QDialog, private Ui::QgsGeomTypeDialogBase
void on_mAddAttributeButton_clicked();
void on_mRemoveAttributeButton_clicked();
void on_buttonBox_helpRequested();
void on_mTypeBox_currentIndexChanged( int index );

private:
QPushButton * mOkButton;
@@ -1410,32 +1410,51 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,

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" );
}
}

0 comments on commit e46cc1f

Please sign in to comment.
You can’t perform that action at this time.