QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsnewvectortabledialog.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsnewvectortabledialog.h - QgsNewVectorTableDialog
3
4 ---------------------
5 begin : 12.7.2020
6 copyright : (C) 2020 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSNEWVECTORTABLEDIALOG_H
17#define QGSNEWVECTORTABLEDIALOG_H
18
19#include "ui_qgsnewvectortabledialogbase.h"
20
21#include "qgis_gui.h"
22#include "qgis_sip.h"
24#include "qgsfieldmodel.h"
25#include "qgsfields.h"
27#include "qgswkbtypes.h"
28
29#include <QStyledItemDelegate>
30
31class QgsNewVectorTableFieldModel;
32
49class GUI_EXPORT QgsNewVectorTableDialog : public QDialog, private Ui_QgsNewVectorTableDialogBase
50{
51 Q_OBJECT
52 public:
59
63 void setSchemaName( const QString &name );
64
68 void setTableName( const QString &name );
69
73 void setGeometryType( Qgis::WkbType type );
74
79
84
88 QString tableName() const;
89
93 QString schemaName() const;
94
98 QString geometryColumnName() const;
99
103 QgsFields fields() const;
104
109
113 void setFields( const QgsFields &fields );
114
118 bool createSpatialIndex();
119
123 QStringList validationErrors() const;
124
125 private:
126 QgsAbstractDatabaseProviderConnection *mConnection = nullptr;
127 QgsNewVectorTableFieldModel *mFieldModel = nullptr;
128 int mCurrentRow = -1;
129 // Used by validator
130 QStringList mTableNames;
131 QStringList mValidationErrors;
132
133 QSet<QString> mIllegalFieldNames;
134
135 void updateButtons();
136 void selectRow( int row );
137 void validate();
138
139 // QWidget interface
140 protected:
141 void showEvent( QShowEvent *event ) override;
142};
143
144
146
147#ifndef SIP_RUN
148class QgsNewVectorTableDialogFieldsDelegate : public QStyledItemDelegate
149{
150 Q_OBJECT
151 public:
152 QgsNewVectorTableDialogFieldsDelegate( const QList<QgsVectorDataProvider::NativeType> &typeList, QObject *parent = nullptr );
153
154 // QAbstractItemDelegate interface
155 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
156 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
157 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
158
159 public slots:
160
161 void onFieldTypeChanged( int index );
162
163 private:
164 const QList<QgsVectorDataProvider::NativeType> mTypeList;
165};
166
167
168class QgsNewVectorTableFieldModel : public QgsFieldModel
169{
170 Q_OBJECT
171
172 public:
173 enum ColumnHeaders
174 {
175 Name,
176 Type,
177 ProviderType,
178 Length,
179 Precision,
180 Comment
181 };
182
183 QgsNewVectorTableFieldModel( const QList<QgsVectorDataProvider::NativeType> &nativeTypes, QObject *parent = nullptr );
184
185 // QAbstractItemModel interface
186 int columnCount( const QModelIndex & ) const override;
187 QVariant data( const QModelIndex &index, int role ) const override;
188 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
189 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
190 Qt::ItemFlags flags( const QModelIndex &index ) const override;
191
192 QList<QgsVectorDataProvider::NativeType> nativeTypes() const;
193 QgsVectorDataProvider::NativeType nativeType( const QString &typeName ) const;
194 QgsVectorDataProvider::NativeType nativeType( int row ) const;
195
196 private:
197 const QList<QgsVectorDataProvider::NativeType> mNativeTypes;
198 QString typeDesc( const QString &typeName ) const;
199 QMetaType::Type type( const QString &typeName ) const;
200};
201
202
203#endif
204
206
207#endif // QGSNEWVECTORTABLEDIALOG_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
Provides common functionality for database based connections.
Represents a coordinate reference system (CRS).
A model which displays the list of fields in widgets (optionally associated with a vector layer).
int columnCount(const QModelIndex &parent) const override
QVariant data(const QModelIndex &index, int role) const override
Container of fields for a vector layer.
Definition qgsfields.h:46
QString schemaName() const
Returns the schema name.
bool createSpatialIndex()
Returns true if spatialindex checkbox is checked.
void setGeometryType(Qgis::WkbType type)
Sets the geometry type.
QgsFields fields() const
Returns the fields.
QStringList validationErrors() const
Returns the validation errors or an empty list if the dialog is valid.
void setFields(const QgsFields &fields)
Sets the fields to fields.
QgsCoordinateReferenceSystem crs() const
Returns the CRS.
QString tableName() const
Returns the table name.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the CRS to crs.
QString geometryColumnName() const
Returns the geometry column name.
void setSchemaName(const QString &name)
Sets the schema name.
Qgis::WkbType geometryType() const
Returns the geometry type.
QgsNewVectorTableDialog(QgsAbstractDatabaseProviderConnection *conn, QWidget *parent=nullptr)
QgsNewVectorTableDialog constructor.
void setTableName(const QString &name)
Sets the table name.
void showEvent(QShowEvent *event) override
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53