28 #include <QPushButton> 32 #include <QFileDialog> 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" );
53 mPointRadioButton->setChecked(
true );
54 mFileFormatComboBox->addItem(
tr(
"ESRI Shapefile" ),
"ESRI Shapefile" );
58 mFileFormatComboBox->addItem(
tr(
"Comma Separated Value" ),
"Comma Separated Value" );
59 mFileFormatComboBox->addItem(
tr(
"GML" ),
"GML" );
60 mFileFormatComboBox->addItem(
tr(
"Mapinfo File" ),
"Mapinfo File" );
62 if ( mFileFormatComboBox->count() == 1 )
64 mFileFormatComboBox->setVisible(
false );
65 mFileFormatLabel->setVisible(
false );
68 mFileFormatComboBox->setCurrentIndex( 0 );
77 int encindex = mFileEncoding->findText( enc );
80 mFileEncoding->insertItem( 0, enc );
83 mFileEncoding->setCurrentIndex( encindex );
85 mOkButton = buttonBox->button( QDialogButtonBox::Ok );
91 mCrsSelector->setCrs( defaultCrs );
96 mAddAttributeButton->setEnabled(
false );
97 mRemoveAttributeButton->setEnabled(
false );
109 if ( mFileFormatComboBox->currentText() ==
tr(
"ESRI Shapefile" ) )
110 mNameEdit->setMaxLength( 10 );
112 mNameEdit->setMaxLength( 32767 );
121 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 255 )
122 mWidth->setText(
"80" );
123 mPrecision->setEnabled(
false );
128 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 10 )
129 mWidth->setText(
"10" );
130 mPrecision->setEnabled(
false );
135 if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 20 )
136 mWidth->setText(
"20" );
137 mPrecision->setEnabled(
true );
149 if ( mPointRadioButton->isChecked() )
153 else if ( mLineRadioButton->isChecked() )
157 else if ( mPolygonRadioButton->isChecked() )
166 return mCrsSelector->crs().srsid();
171 QString myName = mNameEdit->text();
172 QString myWidth = mWidth->text();
173 QString myPrecision = mPrecision->isEnabled() ? mPrecision->text() :
"";
175 QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
177 if ( mAttributeView->topLevelItemCount() > 0 )
186 delete mAttributeView->currentItem();
187 if ( mAttributeView->topLevelItemCount() == 0 )
209 QString myType = mFileFormatComboBox->itemData( mFileFormatComboBox->currentIndex(), Qt::UserRole ).toString();
215 return mFileEncoding->currentText();
220 mAddAttributeButton->setDisabled( name.
isEmpty() || !mAttributeView->findItems( name, Qt::MatchExactly ).isEmpty() );
225 mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().isEmpty() );
233 if ( geomDialog.
exec() == QDialog::Rejected )
256 if ( fileformat ==
"ESRI Shapefile" && !fileName.
endsWith(
".shp", Qt::CaseInsensitive ) )
259 settings.
setValue(
"/UI/lastVectorFileFilterDir",
QFileInfo( fileName ).absolutePath() );
260 settings.
setValue(
"/UI/encoding", enc );
267 bool loaded = myLib->
load();
272 typedef bool ( *createEmptyDataSourceProc )(
const QString&,
const QString&,
const QString&,
QGis::WkbType,
274 createEmptyDataSourceProc createEmptyDataSource = ( createEmptyDataSourceProc )
cast_to_fptr( myLib->
resolve(
"createEmptyDataSource" ) );
275 if ( createEmptyDataSource )
280 if ( !createEmptyDataSource( fileName, fileformat, enc, geometrytype, attributes, &srs ) )
282 return QString::null;
288 return QString::null;
293 QgsDebugMsg(
"Resolving newEmptyDataSource(...) failed" );
294 return QString::null;
void nameChanged(const QString &)
QByteArray toByteArray() const
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
QString selectedFileEncoding() const
Returns the file format for storage.
QgsCoordinateReferenceSystem crsByOgcWmsCrs(const QString &ogcCrs) const
Returns the CRS from a given OGC WMS-format Coordinate Reference System string.
QString selectedFileFormat() const
Returns the file format for storage.
void on_mTypeBox_currentIndexChanged(int index)
void validate()
Perform some validation on this CRS.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
QString library(const QString &providerKey) const
Return path for the library of the provider.
WkbType
Used for symbology operations.
~QgsNewVectorLayerDialog()
void attributes(QList< QPair< QString, QString > > &at) const
Appends the chosen attribute names and types to at.
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsCoordinateReferenceSystem crsBySrsId(long srsId) const
Returns the CRS from a specified QGIS SRS ID.
static const QStringList & availableEncodings()
Returns a list of available encodings.
void setValue(const QString &key, const QVariant &value)
const char * name() const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void on_mAddAttributeButton_clicked()
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
void on_mRemoveAttributeButton_clicked()
A registry / canonical manager of data providers.
QGis::WkbType selectedType() const
Returns the selected geometry type.
int selectedCrsId() const
Returns the selected crs id.
QVariant value(const QString &key, const QVariant &defaultValue) const
void * resolve(const char *symbol)
static QString runAndCreateLayer(QWidget *parent=nullptr, QString *enc=nullptr)
Class for storing a coordinate reference system (CRS)
QgsNewVectorLayerDialog(QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
void(*)() cast_to_fptr(void *p)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
static QgsCRSCache * instance()
Returns a pointer to the QgsCRSCache singleton.
QString text(int column) const
void on_mFileFormatComboBox_currentIndexChanged(int index)
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.