@@ -37,6 +37,8 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
37
37
setupUi ( this );
38
38
connect ( mAddAttributeButton , &QToolButton::clicked, this , &QgsNewVectorLayerDialog::mAddAttributeButton_clicked );
39
39
connect ( mRemoveAttributeButton , &QToolButton::clicked, this , &QgsNewVectorLayerDialog::mRemoveAttributeButton_clicked );
40
+ connect ( mFileNameEdit , &QLineEdit::textChanged, this , &QgsNewVectorLayerDialog::checkOk );
41
+ connect ( mBrowseFileName , &QToolButton::clicked, this , &QgsNewVectorLayerDialog::selectFileName );
40
42
connect ( mFileFormatComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsNewVectorLayerDialog::mFileFormatComboBox_currentIndexChanged );
41
43
connect ( mTypeBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged );
42
44
connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsNewVectorLayerDialog::showHelp );
@@ -54,7 +56,13 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
54
56
mWidth ->setValidator ( new QIntValidator ( 1 , 255 , this ) );
55
57
mPrecision ->setValidator ( new QIntValidator ( 0 , 15 , this ) );
56
58
57
- mPointRadioButton ->setChecked ( true );
59
+ mGeometryTypeBox ->addItem ( tr ( " Point" ), QgsWkbTypes::Point );
60
+ mGeometryTypeBox ->addItem ( tr ( " Line" ), QgsWkbTypes::LineString );
61
+ mGeometryTypeBox ->addItem ( tr ( " Polygon" ), QgsWkbTypes::Polygon );
62
+
63
+ mOkButton = buttonBox->button ( QDialogButtonBox::Ok );
64
+ mOkButton ->setEnabled ( false );
65
+
58
66
mFileFormatComboBox ->addItem ( tr ( " ESRI Shapefile" ), " ESRI Shapefile" );
59
67
#if 0
60
68
// Disabled until provider properly supports editing the created file formats
@@ -76,7 +84,7 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
76
84
// Use default encoding if none supplied
77
85
QString enc = QgsSettings ().value ( QStringLiteral ( " /UI/encoding" ), " System" ).toString ();
78
86
79
- // The specified decoding is added if not existing alread , and then set current.
87
+ // The specified decoding is added if not existing already , and then set current.
80
88
// This should select it.
81
89
int encindex = mFileEncoding ->findText ( enc );
82
90
if ( encindex < 0 )
@@ -86,8 +94,6 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
86
94
}
87
95
mFileEncoding ->setCurrentIndex ( encindex );
88
96
89
- mOkButton = buttonBox->button ( QDialogButtonBox::Ok );
90
-
91
97
mAttributeView ->addTopLevelItem ( new QTreeWidgetItem ( QStringList () << QStringLiteral ( " id" ) << QStringLiteral ( " Integer" ) << QStringLiteral ( " 10" ) << QLatin1String ( " " ) ) );
92
98
connect ( mNameEdit , &QLineEdit::textChanged, this , &QgsNewVectorLayerDialog::nameChanged );
93
99
connect ( mAttributeView , &QTreeWidget::itemSelectionChanged, this , &QgsNewVectorLayerDialog::selectionChanged );
@@ -146,18 +152,8 @@ void QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged( int index )
146
152
QgsWkbTypes::Type QgsNewVectorLayerDialog::selectedType () const
147
153
{
148
154
QgsWkbTypes::Type wkbType = QgsWkbTypes::Unknown;
149
- if ( mPointRadioButton ->isChecked () )
150
- {
151
- wkbType = QgsWkbTypes::Point ;
152
- }
153
- else if ( mLineRadioButton ->isChecked () )
154
- {
155
- wkbType = QgsWkbTypes::LineString;
156
- }
157
- else if ( mPolygonRadioButton ->isChecked () )
158
- {
159
- wkbType = QgsWkbTypes::Polygon;
160
- }
155
+ wkbType = static_cast <QgsWkbTypes::Type>
156
+ ( mGeometryTypeBox ->currentData ( Qt::UserRole ).toInt () );
161
157
162
158
if ( mGeometryWithZCheckBox ->isChecked () && wkbType != QgsWkbTypes::Unknown )
163
159
wkbType = QgsWkbTypes::to25D ( wkbType );
@@ -183,20 +179,14 @@ void QgsNewVectorLayerDialog::mAddAttributeButton_clicked()
183
179
// use userrole to avoid translated type string
184
180
QString myType = mTypeBox ->currentData ( Qt::UserRole ).toString ();
185
181
mAttributeView ->addTopLevelItem ( new QTreeWidgetItem ( QStringList () << myName << myType << myWidth << myPrecision ) );
186
- if ( mAttributeView ->topLevelItemCount () > 0 )
187
- {
188
- mOkButton ->setEnabled ( true );
189
- }
182
+ checkOk ();
190
183
mNameEdit ->clear ();
191
184
}
192
185
193
186
void QgsNewVectorLayerDialog::mRemoveAttributeButton_clicked ()
194
187
{
195
188
delete mAttributeView ->currentItem ();
196
- if ( mAttributeView ->topLevelItemCount () == 0 )
197
- {
198
- mOkButton ->setEnabled ( false );
199
- }
189
+ checkOk ();
200
190
}
201
191
202
192
void QgsNewVectorLayerDialog::attributes ( QList< QPair<QString, QString> > &at ) const
@@ -234,6 +224,31 @@ void QgsNewVectorLayerDialog::selectionChanged()
234
224
mRemoveAttributeButton ->setDisabled ( mAttributeView ->selectedItems ().isEmpty () );
235
225
}
236
226
227
+ void QgsNewVectorLayerDialog::selectFileName ()
228
+ {
229
+ QString fileformat = mFileFormatComboBox ->currentData ( Qt::UserRole ).toString ();
230
+ QgsSettings settings;
231
+ QString lastUsedDir = settings.value ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QDir::homePath () ).toString ();
232
+ QString filterString = QgsVectorFileWriter::filterForDriver ( fileformat );
233
+ QString fileName = QFileDialog::getSaveFileName ( nullptr , tr ( " Save Layer as..." ), lastUsedDir, filterString );
234
+ if ( fileName.isEmpty () )
235
+ return ;
236
+
237
+ if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && !fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) )
238
+ fileName += QLatin1String ( " .shp" );
239
+ mFileNameEdit ->setText ( fileName );
240
+ }
241
+
242
+ QString QgsNewVectorLayerDialog::filename () const
243
+ {
244
+ return mFileNameEdit ->text ();
245
+ }
246
+
247
+ void QgsNewVectorLayerDialog::checkOk ()
248
+ {
249
+ bool ok = ( !mFileNameEdit ->text ().isEmpty () && mAttributeView ->topLevelItemCount () > 0 );
250
+ mOkButton ->setEnabled ( ok );
251
+ }
237
252
238
253
// this is static
239
254
QString QgsNewVectorLayerDialog::runAndCreateLayer ( QWidget *parent, QString *pEnc, const QgsCoordinateReferenceSystem &crs )
@@ -254,16 +269,8 @@ QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget *parent, QString *pE
254
269
geomDialog.attributes ( attributes );
255
270
256
271
QgsSettings settings;
257
- QString lastUsedDir = settings.value ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QDir::homePath () ).toString ();
258
272
QString filterString = QgsVectorFileWriter::filterForDriver ( fileformat );
259
- QString fileName = QFileDialog::getSaveFileName ( nullptr , tr ( " Save layer as..." ), lastUsedDir, filterString );
260
- if ( fileName.isNull () )
261
- {
262
- return QLatin1String ( " " );
263
- }
264
-
265
- if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && !fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) )
266
- fileName += QLatin1String ( " .shp" );
273
+ QString fileName = geomDialog.filename ();
267
274
268
275
settings.setValue ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QFileInfo ( fileName ).absolutePath () );
269
276
settings.setValue ( QStringLiteral ( " UI/encoding" ), enc );
0 commit comments