Skip to content

Commit c3471bd

Browse files
author
jef
committedMay 1, 2009
fix #1673 and #1674
git-svn-id: http://svn.osgeo.org/qgis/trunk@10693 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 50c9b44 commit c3471bd

File tree

4 files changed

+173
-114
lines changed

4 files changed

+173
-114
lines changed
 

‎src/app/qgsgeomtypedialog.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ QgsGeomTypeDialog::QgsGeomTypeDialog( QWidget *parent, Qt::WFlags fl )
2828
setupUi( this );
2929
mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
3030
mRemoveAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionDeleteAttribute.png" ) );
31-
mTypeBox->addItem( tr( "Real" ), "Real" );
32-
mTypeBox->addItem( tr( "Integer" ), "Integer" );;
3331
mTypeBox->addItem( tr( "String" ), "String" );
32+
mTypeBox->addItem( tr( "Integer" ), "Integer" );
33+
mTypeBox->addItem( tr( "Real" ), "Real" );
3434

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

48+
void QgsGeomTypeDialog::on_mTypeBox_currentIndexChanged( int index )
49+
{
50+
mPrecision->setEnabled( index == 2 ); // Real
51+
}
52+
4853
QGis::WkbType QgsGeomTypeDialog::selectedType() const
4954
{
5055
if ( mPointRadioButton->isChecked() )
@@ -65,9 +70,11 @@ QGis::WkbType QgsGeomTypeDialog::selectedType() const
6570
void QgsGeomTypeDialog::on_mAddAttributeButton_clicked()
6671
{
6772
QString myName = mNameEdit->text();
73+
QString myWidth = mWidth->text();
74+
QString myPrecision = mPrecision->text();
6875
//use userrole to avoid translated type string
6976
QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
70-
mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType ) );
77+
mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType << myWidth << myPrecision ) );
7178
if ( mAttributeView->topLevelItemCount() > 0 )
7279
{
7380
mOkButton->setEnabled( true );
@@ -95,8 +102,9 @@ void QgsGeomTypeDialog::attributes( std::list<std::pair<QString, QString> >& at
95102
while ( *it )
96103
{
97104
QTreeWidgetItem *item = *it;
98-
at.push_back( std::make_pair( item->text( 0 ), item->text( 1 ) ) );
99-
QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( item->text( 1 ) ) );
105+
QString type = QString( "%1;%2;%3" ).arg( item->text( 1 ) ).arg( item->text( 2 ) ).arg( item->text( 3 ) );
106+
at.push_back( std::make_pair( item->text( 0 ), type ) );
107+
QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( type ) );
100108
++it;
101109
}
102110
}

‎src/app/qgsgeomtypedialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class QgsGeomTypeDialog: public QDialog, private Ui::QgsGeomTypeDialogBase
4141
void on_mAddAttributeButton_clicked();
4242
void on_mRemoveAttributeButton_clicked();
4343
void on_buttonBox_helpRequested();
44+
void on_mTypeBox_currentIndexChanged( int index );
4445

4546
private:
4647
QPushButton * mOkButton;

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,32 +1410,51 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
14101410

14111411
for ( std::list<std::pair<QString, QString> >::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
14121412
{
1413-
if ( it->second == "Real" )
1413+
QStringList fields = it->second.split( ";" );
1414+
1415+
if ( fields.size() == 0 )
1416+
continue;
1417+
1418+
int width = fields.size() > 1 ? fields[1].toInt() : -1;
1419+
int precision = fields.size() > 2 ? fields[2].toInt() : -1;
1420+
1421+
OGRFieldDefnH field;
1422+
if ( fields[0] == "Real" )
14141423
{
1415-
OGRFieldDefnH field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTReal );
1416-
OGR_Fld_SetPrecision( field, 3 );
1417-
OGR_Fld_SetWidth( field, 32 );
1418-
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
1419-
{
1420-
QgsLogger::warning( "creation of OFTReal field failed" );
1421-
}
1424+
if ( width == -1 )
1425+
width = 32;
1426+
if ( precision == -1 )
1427+
precision = 3;
1428+
1429+
field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTReal );
1430+
OGR_Fld_SetWidth( field, width );
1431+
OGR_Fld_SetPrecision( field, precision );
14221432
}
1423-
else if ( it->second == "Integer" )
1433+
else if ( fields[0] == "Integer" )
14241434
{
1425-
OGRFieldDefnH field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTInteger );
1426-
OGR_Fld_SetWidth( field, 10 ); // limit to 10. otherwise OGR sets it to 11 and recognizes as OFTDouble later
1427-
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
1428-
{
1429-
QgsLogger::warning( "creation of OFTInteger field failed" );
1430-
}
1435+
if ( width == -1 || width > 10 )
1436+
width = 10;
1437+
1438+
field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTInteger );
1439+
// limit to 10. otherwise OGR sets it to 11 and recognizes as OFTDouble later
1440+
OGR_Fld_SetWidth( field, width );
14311441
}
1432-
else if ( it->second == "String" )
1442+
else if ( fields[0] == "String" )
14331443
{
1434-
OGRFieldDefnH field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTString );
1435-
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
1436-
{
1437-
QgsLogger::warning( "creation of OFTString field failed" );
1438-
}
1444+
if ( width == -1 )
1445+
width = 80;
1446+
1447+
field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTString );
1448+
OGR_Fld_SetWidth( field, width );
1449+
}
1450+
else
1451+
{
1452+
continue;
1453+
}
1454+
1455+
if ( OGR_L_CreateField( layer, field, TRUE ) != OGRERR_NONE )
1456+
{
1457+
QgsLogger::warning( "creation of field failed" );
14391458
}
14401459
}
14411460

‎src/ui/qgsgeomtypedialogbase.ui

Lines changed: 119 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,215 @@
1-
<ui version="4.0" >
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
23
<class>QgsGeomTypeDialogBase</class>
3-
<widget class="QDialog" name="QgsGeomTypeDialogBase" >
4-
<property name="geometry" >
4+
<widget class="QDialog" name="QgsGeomTypeDialogBase">
5+
<property name="geometry">
56
<rect>
67
<x>0</x>
78
<y>0</y>
8-
<width>395</width>
9-
<height>422</height>
9+
<width>353</width>
10+
<height>397</height>
1011
</rect>
1112
</property>
12-
<property name="windowTitle" >
13+
<property name="windowTitle">
1314
<string>New Vector Layer</string>
1415
</property>
15-
<property name="modal" >
16+
<property name="modal">
1617
<bool>true</bool>
1718
</property>
18-
<layout class="QGridLayout" >
19-
<item row="0" column="0" >
20-
<widget class="QLabel" name="mFileFormatLabel" >
21-
<property name="text" >
19+
<layout class="QGridLayout">
20+
<item row="0" column="0">
21+
<widget class="QLabel" name="mFileFormatLabel">
22+
<property name="text">
2223
<string>File format</string>
2324
</property>
24-
<property name="buddy" >
25+
<property name="buddy">
2526
<cstring>mFileFormatComboBox</cstring>
2627
</property>
2728
</widget>
2829
</item>
29-
<item row="0" column="1" colspan="3" >
30-
<widget class="QComboBox" name="mFileFormatComboBox" />
30+
<item row="0" column="1" colspan="3">
31+
<widget class="QComboBox" name="mFileFormatComboBox"/>
3132
</item>
32-
<item row="1" column="0" colspan="4" >
33-
<widget class="QGroupBox" name="buttonGroup1" >
34-
<property name="title" >
33+
<item row="1" column="0" colspan="4">
34+
<widget class="QGroupBox" name="buttonGroup1">
35+
<property name="title">
3536
<string>Type</string>
3637
</property>
37-
<layout class="QGridLayout" >
38-
<item row="0" column="0" >
39-
<widget class="QRadioButton" name="mPointRadioButton" >
40-
<property name="text" >
38+
<layout class="QGridLayout">
39+
<item row="0" column="0">
40+
<widget class="QRadioButton" name="mPointRadioButton">
41+
<property name="text">
4142
<string>Point</string>
4243
</property>
4344
</widget>
4445
</item>
45-
<item row="0" column="1" >
46-
<widget class="QRadioButton" name="mLineRadioButton" >
47-
<property name="text" >
46+
<item row="0" column="1">
47+
<widget class="QRadioButton" name="mLineRadioButton">
48+
<property name="text">
4849
<string>Line</string>
4950
</property>
5051
</widget>
5152
</item>
52-
<item row="0" column="2" >
53-
<widget class="QRadioButton" name="mPolygonRadioButton" >
54-
<property name="text" >
53+
<item row="0" column="2">
54+
<widget class="QRadioButton" name="mPolygonRadioButton">
55+
<property name="text">
5556
<string>Polygon</string>
5657
</property>
5758
</widget>
5859
</item>
5960
</layout>
6061
</widget>
6162
</item>
62-
<item row="2" column="0" colspan="4" >
63-
<widget class="QLabel" name="mAttributeLabel" >
64-
<property name="text" >
63+
<item row="2" column="0" colspan="4">
64+
<widget class="QLabel" name="mAttributeLabel">
65+
<property name="text">
6566
<string>Attributes</string>
6667
</property>
6768
</widget>
6869
</item>
69-
<item row="3" column="0" >
70-
<widget class="QLabel" name="textLabel1" >
71-
<property name="text" >
70+
<item row="3" column="0">
71+
<widget class="QLabel" name="textLabel1">
72+
<property name="text">
7273
<string>Name</string>
7374
</property>
74-
<property name="buddy" >
75+
<property name="buddy">
7576
<cstring>mNameEdit</cstring>
7677
</property>
7778
</widget>
7879
</item>
79-
<item row="3" column="1" colspan="3" >
80-
<widget class="QLineEdit" name="mNameEdit" />
80+
<item row="3" column="1" colspan="3">
81+
<widget class="QLineEdit" name="mNameEdit"/>
8182
</item>
82-
<item row="4" column="0" >
83-
<widget class="QLabel" name="textLabel2" >
84-
<property name="text" >
83+
<item row="4" column="0">
84+
<widget class="QLabel" name="textLabel2">
85+
<property name="text">
8586
<string>Type</string>
8687
</property>
87-
<property name="buddy" >
88+
<property name="buddy">
8889
<cstring>mTypeBox</cstring>
8990
</property>
9091
</widget>
9192
</item>
92-
<item row="4" column="1" colspan="3" >
93-
<widget class="QComboBox" name="mTypeBox" />
93+
<item row="4" column="1" colspan="3">
94+
<widget class="QComboBox" name="mTypeBox"/>
9495
</item>
95-
<item row="5" column="0" colspan="2" >
96-
<spacer>
97-
<property name="orientation" >
96+
<item row="6" column="0">
97+
<widget class="QLabel" name="label">
98+
<property name="text">
99+
<string>Width</string>
100+
</property>
101+
</widget>
102+
</item>
103+
<item row="6" column="1">
104+
<widget class="QLineEdit" name="mWidth"/>
105+
</item>
106+
<item row="6" column="2">
107+
<widget class="QLabel" name="label_2">
108+
<property name="text">
109+
<string>Precision</string>
110+
</property>
111+
</widget>
112+
</item>
113+
<item row="6" column="3">
114+
<widget class="QLineEdit" name="mPrecision">
115+
<property name="sizePolicy">
116+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
117+
<horstretch>0</horstretch>
118+
<verstretch>0</verstretch>
119+
</sizepolicy>
120+
</property>
121+
</widget>
122+
</item>
123+
<item row="13" column="0" colspan="4">
124+
<widget class="QDialogButtonBox" name="buttonBox">
125+
<property name="orientation">
98126
<enum>Qt::Horizontal</enum>
99127
</property>
100-
<property name="sizeHint" >
101-
<size>
102-
<width>291</width>
103-
<height>20</height>
104-
</size>
128+
<property name="standardButtons">
129+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
105130
</property>
106-
</spacer>
131+
</widget>
107132
</item>
108-
<item row="5" column="2" >
109-
<widget class="QToolButton" name="mRemoveAttributeButton" >
110-
<property name="toolTip" >
133+
<item row="7" column="0">
134+
<widget class="QToolButton" name="mRemoveAttributeButton">
135+
<property name="toolTip">
111136
<string>Delete selected attribute</string>
112137
</property>
113-
<property name="text" >
138+
<property name="text">
114139
<string>...</string>
115140
</property>
116-
<property name="icon" >
117-
<iconset>../../images/themes/default/mActionDeleteAttribute.png</iconset>
141+
<property name="icon">
142+
<iconset>
143+
<normaloff>../../images/themes/default/mActionDeleteAttribute.png</normaloff>../../images/themes/default/mActionDeleteAttribute.png</iconset>
118144
</property>
119145
</widget>
120146
</item>
121-
<item row="5" column="3" >
122-
<widget class="QToolButton" name="mAddAttributeButton" >
123-
<property name="toolTip" >
147+
<item row="7" column="3">
148+
<widget class="QToolButton" name="mAddAttributeButton">
149+
<property name="toolTip">
124150
<string>Add attribute</string>
125151
</property>
126-
<property name="text" >
152+
<property name="layoutDirection">
153+
<enum>Qt::RightToLeft</enum>
154+
</property>
155+
<property name="text">
127156
<string>...</string>
128157
</property>
129-
<property name="icon" >
130-
<iconset>../../images/themes/default/mActionNewAttribute.png</iconset>
158+
<property name="icon">
159+
<iconset>
160+
<normaloff>../../images/themes/default/mActionNewAttribute.png</normaloff>../../images/themes/default/mActionNewAttribute.png</iconset>
131161
</property>
132162
</widget>
133163
</item>
134-
<item row="6" column="0" colspan="4" >
135-
<widget class="QTreeWidget" name="mAttributeView" >
136-
<property name="sizePolicy" >
137-
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
164+
<item row="12" column="0" colspan="4">
165+
<widget class="QTreeWidget" name="mAttributeView">
166+
<property name="sizePolicy">
167+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
138168
<horstretch>0</horstretch>
139169
<verstretch>0</verstretch>
140170
</sizepolicy>
141171
</property>
142-
<property name="alternatingRowColors" >
172+
<property name="alternatingRowColors">
143173
<bool>true</bool>
144174
</property>
145-
<property name="rootIsDecorated" >
175+
<property name="rootIsDecorated">
146176
<bool>false</bool>
147177
</property>
178+
<property name="columnCount">
179+
<number>4</number>
180+
</property>
148181
<column>
149-
<property name="text" >
182+
<property name="text">
150183
<string>Name</string>
151184
</property>
152185
</column>
153186
<column>
154-
<property name="text" >
187+
<property name="text">
155188
<string>Type</string>
156189
</property>
157190
</column>
158-
</widget>
159-
</item>
160-
<item row="7" column="0" colspan="4" >
161-
<widget class="QDialogButtonBox" name="buttonBox" >
162-
<property name="orientation" >
163-
<enum>Qt::Horizontal</enum>
164-
</property>
165-
<property name="standardButtons" >
166-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
167-
</property>
191+
<column>
192+
<property name="text">
193+
<string>Width</string>
194+
</property>
195+
</column>
196+
<column>
197+
<property name="text">
198+
<string>Precision</string>
199+
</property>
200+
</column>
168201
</widget>
169202
</item>
170203
</layout>
171204
</widget>
172-
<layoutdefault spacing="6" margin="11" />
205+
<layoutdefault spacing="6" margin="11"/>
173206
<tabstops>
174207
<tabstop>mFileFormatComboBox</tabstop>
175208
<tabstop>mPointRadioButton</tabstop>
176209
<tabstop>mLineRadioButton</tabstop>
177210
<tabstop>mPolygonRadioButton</tabstop>
178211
<tabstop>mNameEdit</tabstop>
179212
<tabstop>mTypeBox</tabstop>
180-
<tabstop>mRemoveAttributeButton</tabstop>
181-
<tabstop>mAddAttributeButton</tabstop>
182213
<tabstop>mAttributeView</tabstop>
183214
<tabstop>buttonBox</tabstop>
184215
</tabstops>
@@ -190,11 +221,11 @@
190221
<receiver>QgsGeomTypeDialogBase</receiver>
191222
<slot>accept()</slot>
192223
<hints>
193-
<hint type="sourcelabel" >
224+
<hint type="sourcelabel">
194225
<x>349</x>
195226
<y>400</y>
196227
</hint>
197-
<hint type="destinationlabel" >
228+
<hint type="destinationlabel">
198229
<x>387</x>
199230
<y>304</y>
200231
</hint>
@@ -206,11 +237,11 @@
206237
<receiver>QgsGeomTypeDialogBase</receiver>
207238
<slot>reject()</slot>
208239
<hints>
209-
<hint type="sourcelabel" >
240+
<hint type="sourcelabel">
210241
<x>275</x>
211242
<y>400</y>
212243
</hint>
213-
<hint type="destinationlabel" >
244+
<hint type="destinationlabel">
214245
<x>242</x>
215246
<y>308</y>
216247
</hint>

0 commit comments

Comments
 (0)
Please sign in to comment.