Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #1673 and #1674
git-svn-id: http://svn.osgeo.org/qgis/trunk@10693 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 1, 2009
1 parent 50c9b44 commit c3471bd
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 114 deletions.
18 changes: 13 additions & 5 deletions src/app/qgsgeomtypedialog.cpp
Expand Up @@ -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" );
Expand All @@ -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() )
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeomtypedialog.h
Expand Up @@ -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;
Expand Down
61 changes: 40 additions & 21 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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" );
}
}

Expand Down

0 comments on commit c3471bd

Please sign in to comment.