QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
117 bool createSpatialIndex();
118
122 QStringList validationErrors() const;
123
124 private:
125
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
145
147
148#ifndef SIP_RUN
149class QgsNewVectorTableDialogFieldsDelegate: public QStyledItemDelegate
150{
151 Q_OBJECT
152 public:
153
154 QgsNewVectorTableDialogFieldsDelegate( const QList< QgsVectorDataProvider::NativeType> &typeList, QObject *parent = nullptr );
155
156 // QAbstractItemDelegate interface
157 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
158 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
159 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
160
161 public slots:
162
163 void onFieldTypeChanged( int index );
164
165 private:
166
167 const QList< QgsVectorDataProvider::NativeType> mTypeList;
168
169};
170
171
172class QgsNewVectorTableFieldModel: public QgsFieldModel
173{
174 Q_OBJECT
175
176 public:
177
178 enum ColumnHeaders
179 {
180 Name,
181 Type,
182 ProviderType,
183 Length,
184 Precision,
185 Comment
186 };
187
188 QgsNewVectorTableFieldModel( const QList< QgsVectorDataProvider::NativeType> &nativeTypes, QObject *parent = nullptr );
189
190 // QAbstractItemModel interface
191 int columnCount( const QModelIndex & ) const override;
192 QVariant data( const QModelIndex &index, int role ) const override;
193 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
194 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
195 Qt::ItemFlags flags( const QModelIndex &index ) const override;
196
197 QList<QgsVectorDataProvider::NativeType> nativeTypes() const;
198 QgsVectorDataProvider::NativeType nativeType( const QString &typeName ) const;
199 QgsVectorDataProvider::NativeType nativeType( int row ) const;
200
201 private:
202
203 const QList< QgsVectorDataProvider::NativeType> mNativeTypes;
204 QString typeDesc( const QString &typeName ) const;
205 QMetaType::Type type( const QString &typeName ) const;
206
207};
208
209
210#endif
211
213
214#endif // QGSNEWVECTORTABLEDIALOG_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
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:46
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