QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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:
57
61 void setSchemaName( const QString &name );
62
66 void setTableName( const QString &name );
67
71 void setGeometryType( Qgis::WkbType type );
72
76 void setCrs( const QgsCoordinateReferenceSystem &crs );
77
82
86 QString tableName() const;
87
91 QString schemaName() const;
92
96 QString geometryColumnName() const;
97
101 QgsFields fields() const;
102
106 Qgis::WkbType geometryType() const;
107
111 void setFields( const QgsFields &fields );
112
116 bool createSpatialIndex();
117
121 QStringList validationErrors() const;
122
123 private:
124 QgsAbstractDatabaseProviderConnection *mConnection = nullptr;
125 QgsNewVectorTableFieldModel *mFieldModel = nullptr;
126 int mCurrentRow = -1;
127 // Used by validator
128 QStringList mTableNames;
129 QStringList mValidationErrors;
130
131 QSet<QString> mIllegalFieldNames;
132
133 void updateButtons();
134 void selectRow( int row );
135 void validate();
136
137 // QWidget interface
138 protected:
139 void showEvent( QShowEvent *event ) override;
140};
141
142
144
145#ifndef SIP_RUN
146class QgsNewVectorTableDialogFieldsDelegate : public QStyledItemDelegate
147{
148 Q_OBJECT
149 public:
150 QgsNewVectorTableDialogFieldsDelegate( const QList<QgsVectorDataProvider::NativeType> &typeList, QObject *parent = nullptr );
151
152 // QAbstractItemDelegate interface
153 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
154 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
155 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
156
157 public slots:
158
159 void onFieldTypeChanged( int index );
160
161 private:
162 const QList<QgsVectorDataProvider::NativeType> mTypeList;
163};
164
165
166class QgsNewVectorTableFieldModel : public QgsFieldModel
167{
168 Q_OBJECT
169
170 public:
171 enum ColumnHeaders
172 {
173 Name,
174 Type,
175 ProviderType,
176 Length,
177 Precision,
178 Comment
179 };
180
181 QgsNewVectorTableFieldModel( const QList<QgsVectorDataProvider::NativeType> &nativeTypes, QObject *parent = nullptr );
182
183 // QAbstractItemModel interface
184 int columnCount( const QModelIndex & ) const override;
185 QVariant data( const QModelIndex &index, int role ) const override;
186 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
187 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
188 Qt::ItemFlags flags( const QModelIndex &index ) const override;
189
190 QList<QgsVectorDataProvider::NativeType> nativeTypes() const;
191 QgsVectorDataProvider::NativeType nativeType( const QString &typeName ) const;
192 QgsVectorDataProvider::NativeType nativeType( int row ) const;
193
194 private:
195 const QList<QgsVectorDataProvider::NativeType> mNativeTypes;
196 QString typeDesc( const QString &typeName ) const;
197 QMetaType::Type type( const QString &typeName ) const;
198};
199
200
201#endif
202
204
205#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