QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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( QgsWkbTypes::Type 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 QgsWkbTypes::Type 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 void updateButtons();
135 void selectRow( int row );
136 void validate();
137
138 // QWidget interface
139 protected:
140 void showEvent( QShowEvent *event ) override;
141};
142
143
144
146
147#ifndef SIP_RUN
148class QgsNewVectorTableDialogFieldsDelegate: public QStyledItemDelegate
149{
150 Q_OBJECT
151 public:
152
153 QgsNewVectorTableDialogFieldsDelegate( const QList< QgsVectorDataProvider::NativeType> &typeList, QObject *parent = nullptr );
154
155 // QAbstractItemDelegate interface
156 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
157 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
158 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
159
160 public slots:
161
162 void onFieldTypeChanged( int index );
163
164 private:
165
166 const QList< QgsVectorDataProvider::NativeType> mTypeList;
167
168};
169
170
171class QgsNewVectorTableFieldModel: public QgsFieldModel
172{
173 Q_OBJECT
174
175 public:
176
177 enum ColumnHeaders
178 {
179 Name,
180 Type,
181 ProviderType,
182 Length,
183 Precision,
184 Comment
185 };
186
187 QgsNewVectorTableFieldModel( const QList< QgsVectorDataProvider::NativeType> &nativeTypes, QObject *parent = nullptr );
188
189 // QAbstractItemModel interface
190 int columnCount( const QModelIndex & ) const override;
191 QVariant data( const QModelIndex &index, int role ) const override;
192 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
193 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
194 Qt::ItemFlags flags( const QModelIndex &index ) const override;
195
196 QList<QgsVectorDataProvider::NativeType> nativeTypes() const;
197 QgsVectorDataProvider::NativeType nativeType( const QString &typeName ) const;
198 QgsVectorDataProvider::NativeType nativeType( int row ) const;
199
200 private:
201
202 const QList< QgsVectorDataProvider::NativeType> mNativeTypes;
203 QString typeDesc( const QString &typeName ) const;
204 QVariant::Type type( const QString &typeName ) const;
205
206};
207
208
209#endif
210
212
213#endif // QGSNEWVECTORTABLEDIALOG_H
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...
Definition: qgsfieldmodel.h:39
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 ...
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
const QgsCoordinateReferenceSystem & crs
const QString & typeName