Skip to content

Commit

Permalink
fix #1673 and #1674
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10693 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 1, 2009
1 parent 9172f47 commit e46cc1f
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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ QgsGeomTypeDialog::QgsGeomTypeDialog( QWidget *parent, Qt::WFlags fl )
setupUi( this ); setupUi( this );
mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) ); mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
mRemoveAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionDeleteAttribute.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( "String" ), "String" );
mTypeBox->addItem( tr( "Integer" ), "Integer" );
mTypeBox->addItem( tr( "Real" ), "Real" );


mPointRadioButton->setChecked( true ); mPointRadioButton->setChecked( true );
mFileFormatComboBox->addItem( "ESRI Shapefile" ); 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 QGis::WkbType QgsGeomTypeDialog::selectedType() const
{ {
if ( mPointRadioButton->isChecked() ) if ( mPointRadioButton->isChecked() )
Expand All @@ -65,9 +70,11 @@ QGis::WkbType QgsGeomTypeDialog::selectedType() const
void QgsGeomTypeDialog::on_mAddAttributeButton_clicked() void QgsGeomTypeDialog::on_mAddAttributeButton_clicked()
{ {
QString myName = mNameEdit->text(); QString myName = mNameEdit->text();
QString myWidth = mWidth->text();
QString myPrecision = mPrecision->text();
//use userrole to avoid translated type string //use userrole to avoid translated type string
QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString(); 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 ) if ( mAttributeView->topLevelItemCount() > 0 )
{ {
mOkButton->setEnabled( true ); mOkButton->setEnabled( true );
Expand Down Expand Up @@ -95,8 +102,9 @@ void QgsGeomTypeDialog::attributes( std::list<std::pair<QString, QString> >& at
while ( *it ) while ( *it )
{ {
QTreeWidgetItem *item = *it; QTreeWidgetItem *item = *it;
at.push_back( std::make_pair( item->text( 0 ), item->text( 1 ) ) ); QString type = QString( "%1;%2;%3" ).arg( item->text( 1 ) ).arg( item->text( 2 ) ).arg( item->text( 3 ) );
QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( item->text( 1 ) ) ); at.push_back( std::make_pair( item->text( 0 ), type ) );
QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( type ) );
++it; ++it;
} }
} }
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeomtypedialog.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class QgsGeomTypeDialog: public QDialog, private Ui::QgsGeomTypeDialogBase
void on_mAddAttributeButton_clicked(); void on_mAddAttributeButton_clicked();
void on_mRemoveAttributeButton_clicked(); void on_mRemoveAttributeButton_clicked();
void on_buttonBox_helpRequested(); void on_buttonBox_helpRequested();
void on_mTypeBox_currentIndexChanged( int index );


private: private:
QPushButton * mOkButton; QPushButton * mOkButton;
Expand Down
61 changes: 40 additions & 21 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Original file line Diff line number Diff line change
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 ) 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 ); if ( width == -1 )
OGR_Fld_SetPrecision( field, 3 ); width = 32;
OGR_Fld_SetWidth( field, 32 ); if ( precision == -1 )
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE ) precision = 3;
{
QgsLogger::warning( "creation of OFTReal field failed" ); 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 ); if ( width == -1 || width > 10 )
OGR_Fld_SetWidth( field, 10 ); // limit to 10. otherwise OGR sets it to 11 and recognizes as OFTDouble later width = 10;
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
{ field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTInteger );
QgsLogger::warning( "creation of OFTInteger field failed" ); // 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 ( width == -1 )
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE ) width = 80;
{
QgsLogger::warning( "creation of OFTString field failed" ); 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
Loading

0 comments on commit e46cc1f

Please sign in to comment.