28 #include <QPushButton>
32 #include <QFileDialog>
36 : QDialog( parent, fl )
41 restoreGeometry( settings.value(
"/Windows/NewVectorLayer/geometry" ).toByteArray() );
45 mTypeBox->addItem(
tr(
"Text data" ),
"String" );
46 mTypeBox->addItem(
tr(
"Whole number" ),
"Integer" );
47 mTypeBox->addItem(
tr(
"Decimal number" ),
"Real" );
48 mTypeBox->addItem(
tr(
"Date" ),
"Date" );
50 mWidth->setValidator(
new QIntValidator( 1, 255,
this ) );
51 mPrecision->setValidator(
new QIntValidator( 0, 15,
this ) );
53 mPointRadioButton->setChecked(
true );
54 mFileFormatComboBox->addItem(
tr(
"ESRI Shapefile" ),
"ESRI Shapefile" );
57 mFileFormatComboBox->addItem(
tr(
"Comma Separated Value" ),
"Comma Separated Value" );
58 mFileFormatComboBox->addItem(
tr(
"GML" ),
"GML" );
59 mFileFormatComboBox->addItem(
tr(
"Mapinfo File" ),
"Mapinfo File" );
61 if ( mFileFormatComboBox->count() == 1 )
63 mFileFormatComboBox->setVisible(
false );
64 mFileFormatLabel->setVisible(
false );
67 mFileFormatComboBox->setCurrentIndex( 0 );
72 QString enc = QSettings().value(
"/UI/encoding",
"System" ).toString();
76 int encindex = mFileEncoding->findText( enc );
79 mFileEncoding->insertItem( 0, enc );
82 mFileEncoding->setCurrentIndex( encindex );
84 mOkButton = buttonBox->button( QDialogButtonBox::Ok );
86 mAttributeView->addTopLevelItem(
new QTreeWidgetItem( QStringList() <<
"id" <<
"Integer" <<
"10" <<
"" ) );
96 connect( mNameEdit, SIGNAL( textChanged( QString ) ),
this, SLOT(
nameChanged( QString ) ) );
97 connect( mAttributeView, SIGNAL( itemSelectionChanged() ),
this, SLOT(
selectionChanged() ) );
99 mAddAttributeButton->setEnabled(
false );
100 mRemoveAttributeButton->setEnabled(
false );
106 settings.setValue(
"/Windows/NewVectorLayer/geometry", saveGeometry() );
112 if ( mFileFormatComboBox->currentText() ==
tr(
"ESRI Shapefile" ) )
113 mNameEdit->setMaxLength( 10 );
115 mNameEdit->setMaxLength( 32767 );
124 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 255 )
125 mWidth->setText(
"80" );
126 mPrecision->setEnabled(
false );
127 mWidth->setValidator(
new QIntValidator( 1, 255,
this ) );
131 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 10 )
132 mWidth->setText(
"10" );
133 mPrecision->setEnabled(
false );
134 mWidth->setValidator(
new QIntValidator( 1, 10,
this ) );
138 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 20 )
139 mWidth->setText(
"20" );
140 mPrecision->setEnabled(
true );
141 mWidth->setValidator(
new QIntValidator( 1, 20,
this ) );
152 if ( mPointRadioButton->isChecked() )
156 else if ( mLineRadioButton->isChecked() )
160 else if ( mPolygonRadioButton->isChecked() )
174 QString myName = mNameEdit->text();
175 QString myWidth = mWidth->text();
176 QString myPrecision = mPrecision->isEnabled() ? mPrecision->text() :
"";
178 QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
179 mAttributeView->addTopLevelItem(
new QTreeWidgetItem( QStringList() << myName << myType << myWidth << myPrecision ) );
180 if ( mAttributeView->topLevelItemCount() > 0 )
189 delete mAttributeView->currentItem();
190 if ( mAttributeView->topLevelItemCount() == 0 )
201 if ( mySelector->exec() )
210 QApplication::restoreOverrideCursor();
217 QTreeWidgetItemIterator it( mAttributeView );
220 QTreeWidgetItem *item = *it;
221 QString type = QString(
"%1;%2;%3" ).arg( item->text( 1 ) ).arg( item->text( 2 ) ).arg( item->text( 3 ) );
222 at.push_back( qMakePair( item->text( 0 ), type ) );
223 QgsDebugMsg( QString(
"appending %1//%2" ).arg( item->text( 0 ) ).arg( type ) );
231 QString myType = mFileFormatComboBox->itemData( mFileFormatComboBox->currentIndex(), Qt::UserRole ).toString();
237 return mFileEncoding->currentText();
242 mAddAttributeButton->setDisabled( name.isEmpty() || mAttributeView->findItems( name, Qt::MatchExactly ).size() > 0 );
247 mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().size() == 0 );
255 if ( geomDialog.exec() == QDialog::Rejected )
264 QgsDebugMsg( QString(
"New file format will be: %1" ).arg( fileformat ) );
270 QString lastUsedDir = settings.value(
"/UI/lastVectorFileFilterDir",
"." ).toString();
272 QString fileName = QFileDialog::getSaveFileName( 0,
tr(
"Save layer as..." ), lastUsedDir, filterString );
273 if ( fileName.isNull() )
278 if ( fileformat ==
"ESRI Shapefile" && !fileName.endsWith(
".shp", Qt::CaseInsensitive ) )
281 settings.setValue(
"/UI/lastVectorFileFilterDir", QFileInfo( fileName ).absolutePath() );
282 settings.setValue(
"/UI/encoding", enc );
286 QString ogrlib = pReg->
library(
"ogr" );
288 QLibrary* myLib =
new QLibrary( ogrlib );
289 bool loaded = myLib->load();
294 typedef bool ( *createEmptyDataSourceProc )(
const QString&,
const QString&,
const QString&,
QGis::WkbType,
296 createEmptyDataSourceProc createEmptyDataSource = ( createEmptyDataSourceProc )
cast_to_fptr( myLib->resolve(
"createEmptyDataSource" ) );
297 if ( createEmptyDataSource )
302 if ( !createEmptyDataSource( fileName, fileformat, enc, geometrytype, attributes, &srs ) )
304 return QString::null;
310 return QString::null;
315 QgsDebugMsg(
"Resolving newEmptyDataSource(...) failed" );
316 return QString::null;
QString selectedFileEncoding() const
Returns the file format for storage.
void on_mTypeBox_currentIndexChanged(int index)
void nameChanged(QString)
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
QString library(const QString &providerKey) const
Return path for the library of the provider.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
A generic dialog to prompt the user for a Coordinate Reference System.
int selectedCrsId() const
Returns the selected crs id.
WkbType
Used for symbology operations.
~QgsNewVectorLayerDialog()
QString selectedFileFormat() const
Returns the file format for storage.
static const QStringList & availableEncodings()
Returns a list of available encodings.
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
static QString runAndCreateLayer(QWidget *parent=0, QString *enc=0)
void setMessage(QString theMessage="")
If no parameter is passed, the message will be a generic 'define the CRS for this layer'...
void on_pbnChangeSpatialRefSys_clicked()
void on_mAddAttributeButton_clicked()
void on_mRemoveAttributeButton_clicked()
A registry / canonical manager of data providers.
QgsNewVectorLayerDialog(QWidget *parent=0, Qt::WindowFlags fl=QgisGui::ModalDialogFlags)
void attributes(QList< QPair< QString, QString > > &at) const
Appends the chosen attribute names and types to at.
QGis::WkbType selectedType() const
Returns the selected geometry type.
void setSelectedCrsId(long theID)
Class for storing a coordinate reference system (CRS)
void(*)() cast_to_fptr(void *p)
QString description() const
void on_mFileFormatComboBox_currentIndexChanged(int index)
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.