24 #include <QPushButton>
33 : QDialog( parent, fl )
38 restoreGeometry( settings.value(
"/Windows/NewVectorLayer/geometry" ).toByteArray() );
42 mTypeBox->addItem(
tr(
"Text data" ),
"String" );
43 mTypeBox->addItem(
tr(
"Whole number" ),
"Integer" );
44 mTypeBox->addItem(
tr(
"Decimal number" ),
"Real" );
45 mTypeBox->addItem(
tr(
"Date" ),
"Date" );
47 mWidth->setValidator(
new QIntValidator( 1, 255,
this ) );
48 mPrecision->setValidator(
new QIntValidator( 0, 15,
this ) );
50 mPointRadioButton->setChecked(
true );
51 mFileFormatComboBox->addItem(
tr(
"ESRI Shapefile" ),
"ESRI Shapefile" );
54 mFileFormatComboBox->addItem(
tr(
"Comma Separated Value" ),
"Comma Separated Value" );
55 mFileFormatComboBox->addItem(
tr(
"GML" ),
"GML" );
56 mFileFormatComboBox->addItem(
tr(
"Mapinfo File" ),
"Mapinfo File" );
58 if ( mFileFormatComboBox->count() == 1 )
60 mFileFormatComboBox->setVisible(
false );
61 mFileFormatLabel->setVisible(
false );
64 mOkButton = buttonBox->button( QDialogButtonBox::Ok );
66 mAttributeView->addTopLevelItem(
new QTreeWidgetItem( QStringList() <<
"id" <<
"Integer" <<
"10" <<
"" ) );
76 connect( mNameEdit, SIGNAL( textChanged( QString ) ),
this, SLOT(
nameChanged( QString ) ) );
77 connect( mAttributeView, SIGNAL( itemSelectionChanged() ),
this, SLOT(
selectionChanged() ) );
79 mAddAttributeButton->setEnabled(
false );
80 mRemoveAttributeButton->setEnabled(
false );
86 settings.setValue(
"/Windows/NewVectorLayer/geometry", saveGeometry() );
95 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 255 )
96 mWidth->setText(
"80" );
97 mPrecision->setEnabled(
false );
98 mWidth->setValidator(
new QIntValidator( 1, 255,
this ) );
102 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 10 )
103 mWidth->setText(
"10" );
104 mPrecision->setEnabled(
false );
105 mWidth->setValidator(
new QIntValidator( 1, 10,
this ) );
109 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 20 )
110 mWidth->setText(
"20" );
111 mPrecision->setEnabled(
true );
112 mWidth->setValidator(
new QIntValidator( 1, 20,
this ) );
123 if ( mPointRadioButton->isChecked() )
127 else if ( mLineRadioButton->isChecked() )
131 else if ( mPolygonRadioButton->isChecked() )
145 QString myName = mNameEdit->text();
146 QString myWidth = mWidth->text();
147 QString myPrecision = mPrecision->isEnabled() ? mPrecision->text() :
"";
149 QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
150 mAttributeView->addTopLevelItem(
new QTreeWidgetItem( QStringList() << myName << myType << myWidth << myPrecision ) );
151 if ( mAttributeView->topLevelItemCount() > 0 )
160 delete mAttributeView->currentItem();
161 if ( mAttributeView->topLevelItemCount() == 0 )
172 if ( mySelector->exec() )
181 QApplication::restoreOverrideCursor();
188 QTreeWidgetItemIterator it( mAttributeView );
191 QTreeWidgetItem *item = *it;
192 QString type = QString(
"%1;%2;%3" ).arg( item->text( 1 ) ).arg( item->text( 2 ) ).arg( item->text( 3 ) );
193 at.push_back( qMakePair( item->text( 0 ), type ) );
194 QgsDebugMsg( QString(
"appending %1//%2" ).arg( item->text( 0 ) ).arg( type ) );
202 QString myType = mFileFormatComboBox->itemData( mFileFormatComboBox->currentIndex(), Qt::UserRole ).toString();
208 mAddAttributeButton->setDisabled( name.isEmpty() || mAttributeView->findItems( name, Qt::MatchExactly ).size() > 0 );
213 mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().size() == 0 );
221 if ( geomDialog.exec() == QDialog::Rejected )
229 QgsDebugMsg( QString(
"New file format will be: %1" ).arg( fileformat ) );
238 QString lastUsedDir = settings.value(
"/UI/lastVectorFileFilterDir",
"." ).toString();
240 QgsDebugMsg(
"Saving vector file dialog without filters: " );
245 openFileDialog->setFileMode( QFileDialog::AnyFile );
246 openFileDialog->setAcceptMode( QFileDialog::AcceptSave );
247 openFileDialog->setConfirmOverwrite(
true );
249 if ( settings.contains(
"/UI/lastVectorFileFilter" ) )
251 QString lastUsedFilter = settings.value(
"/UI/lastVectorFileFilter", QVariant( QString::null ) ).toString();
252 openFileDialog->selectFilter( lastUsedFilter );
255 if ( openFileDialog->exec() == QDialog::Rejected )
257 delete openFileDialog;
261 fileName = openFileDialog->selectedFiles().first();
263 if ( fileformat ==
"ESRI Shapefile" && !fileName.endsWith(
".shp", Qt::CaseInsensitive ) )
268 settings.setValue(
"/UI/lastVectorFileFilter", openFileDialog->selectedFilter() );
269 settings.setValue(
"/UI/lastVectorFileFilterDir", openFileDialog->directory().absolutePath() );
271 delete openFileDialog;
275 QString ogrlib = pReg->
library(
"ogr" );
277 QLibrary* myLib =
new QLibrary( ogrlib );
278 bool loaded = myLib->load();
283 typedef bool ( *createEmptyDataSourceProc )(
const QString&,
const QString&,
const QString&,
QGis::WkbType,
285 createEmptyDataSourceProc createEmptyDataSource = ( createEmptyDataSourceProc )
cast_to_fptr( myLib->resolve(
"createEmptyDataSource" ) );
286 if ( createEmptyDataSource )
291 if ( !createEmptyDataSource( fileName, fileformat, enc, geometrytype, attributes, &srs ) )
304 QgsDebugMsg(
"Resolving newEmptyDataSource(...) failed" );