QGIS API Documentation 3.37.0-Master (c2d15952569)
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 <QStyledItemDelegate>
20
21#include "qgis_sip.h"
22#include "qgis_gui.h"
23#include "qgsfields.h"
24#include "qgswkbtypes.h"
26#include "qgsfieldmodel.h"
28
29#include "ui_qgsnewvectortabledialogbase.h"
30
31class QgsNewVectorTableFieldModel;
32
47class GUI_EXPORT QgsNewVectorTableDialog : public QDialog, private Ui_QgsNewVectorTableDialogBase
48{
49 Q_OBJECT
50 public:
51
58
62 void setSchemaName( const QString &name );
63
67 void setTableName( const QString &name );
68
72 void setGeometryType( Qgis::WkbType type );
73
77 void setCrs( const QgsCoordinateReferenceSystem &crs );
78
83
87 QString tableName() const;
88
92 QString schemaName() const;
93
97 QString geometryColumnName() const;
98
102 QgsFields fields() const;
103
107 Qgis::WkbType geometryType() const;
108
112 void setFields( const QgsFields &fields );
113
118 bool createSpatialIndex();
119
123 QStringList validationErrors() const;
124
125 private:
126
127 QgsAbstractDatabaseProviderConnection *mConnection = nullptr;
128 QgsNewVectorTableFieldModel *mFieldModel = nullptr;
129 int mCurrentRow = -1;
130 // Used by validator
131 QStringList mTableNames;
132 QStringList mValidationErrors;
133
134 QSet<QString> mIllegalFieldNames;
135
136 void updateButtons();
137 void selectRow( int row );
138 void validate();
139
140 // QWidget interface
141 protected:
142 void showEvent( QShowEvent *event ) override;
143};
144
145
146
148
149#ifndef SIP_RUN
150class QgsNewVectorTableDialogFieldsDelegate: public QStyledItemDelegate
151{
152 Q_OBJECT
153 public:
154
155 QgsNewVectorTableDialogFieldsDelegate( const QList< QgsVectorDataProvider::NativeType> &typeList, QObject *parent = nullptr );
156
157 // QAbstractItemDelegate interface
158 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
159 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
160 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
161
162 public slots:
163
164 void onFieldTypeChanged( int index );
165
166 private:
167
168 const QList< QgsVectorDataProvider::NativeType> mTypeList;
169
170};
171
172
173class QgsNewVectorTableFieldModel: public QgsFieldModel
174{
175 Q_OBJECT
176
177 public:
178
179 enum ColumnHeaders
180 {
181 Name,
182 Type,
183 ProviderType,
184 Length,
185 Precision,
186 Comment
187 };
188
189 QgsNewVectorTableFieldModel( const QList< QgsVectorDataProvider::NativeType> &nativeTypes, QObject *parent = nullptr );
190
191 // QAbstractItemModel interface
192 int columnCount( const QModelIndex & ) const override;
193 QVariant data( const QModelIndex &index, int role ) const override;
194 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
195 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
196 Qt::ItemFlags flags( const QModelIndex &index ) const override;
197
198 QList<QgsVectorDataProvider::NativeType> nativeTypes() const;
199 QgsVectorDataProvider::NativeType nativeType( const QString &typeName ) const;
200 QgsVectorDataProvider::NativeType nativeType( int row ) const;
201
202 private:
203
204 const QList< QgsVectorDataProvider::NativeType> mNativeTypes;
205 QString typeDesc( const QString &typeName ) const;
206 QVariant::Type type( const QString &typeName ) const;
207
208};
209
210
211#endif
212
214
215#endif // QGSNEWVECTORTABLEDIALOG_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
This class represents a coordinate reference system (CRS).
The QgsFieldModel class is a model to display the list of fields in widgets (optionally associated wi...
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:45
The QgsNewVectorTableDialog class is a provider-agnostic database vector and aspatial table designer ...
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
const QgsCoordinateReferenceSystem & crs
const QString & typeName