QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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"
25 #include "qgsvectordataprovider.h"
26 #include "qgsfieldmodel.h"
28 
29 #include "ui_qgsnewvectortabledialogbase.h"
30 
31 class QgsNewVectorTableFieldModel;
32 
47 class GUI_EXPORT QgsNewVectorTableDialog : public QDialog, private Ui_QgsNewVectorTableDialogBase
48 {
49  public:
50 
57 
61  void setSchemaName( const QString &name );
62 
66  void setTableName( const QString &name );
67 
71  void setGeometryType( QgsWkbTypes::Type 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  QgsWkbTypes::Type geometryType() const;
107 
111  void setFields( const QgsFields &fields );
112 
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  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 
143 
145 
146 #ifndef SIP_RUN
147 class QgsNewVectorTableDialogFieldsDelegate: public QStyledItemDelegate
148 {
149  public:
150 
151  QgsNewVectorTableDialogFieldsDelegate( const QList< QgsVectorDataProvider::NativeType> &typeList, QObject *parent = nullptr );
152 
153  // QAbstractItemDelegate interface
154  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
155  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
156  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
157 
158  public slots:
159 
160  void onFieldTypeChanged( int index );
161 
162  private:
163 
164  const QList< QgsVectorDataProvider::NativeType> mTypeList;
165 
166 };
167 
168 
169 class QgsNewVectorTableFieldModel: public QgsFieldModel
170 {
171 
172  public:
173 
174  enum ColumnHeaders
175  {
176  Name,
177  Type,
178  ProviderType,
179  Length,
180  Precision,
181  Comment
182  };
183 
184  QgsNewVectorTableFieldModel( const QList< QgsVectorDataProvider::NativeType> &nativeTypes, QObject *parent = nullptr );
185 
186  // QAbstractItemModel interface
187  int columnCount( const QModelIndex & ) const override;
188  QVariant data( const QModelIndex &index, int role ) const override;
189  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
190  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
191  Qt::ItemFlags flags( const QModelIndex &index ) const override;
192 
193  QList<QgsVectorDataProvider::NativeType> nativeTypes() const;
194  QgsVectorDataProvider::NativeType nativeType( const QString &typeName ) const;
195  QgsVectorDataProvider::NativeType nativeType( int row ) const;
196 
197  private:
198 
199  const QList< QgsVectorDataProvider::NativeType> mNativeTypes;
200  QString typeDesc( const QString &typeName ) const;
201  QVariant::Type type( const QString &typeName ) const;
202 
203 };
204 
205 
206 #endif
207 
209 
210 #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