1 /*************************************************************************** 2 qgsdb2tablemodel.h - description 3 -------------------------------------- 4 Date : 2016-01-27 5 Copyright : (C) 2016 by David Adler 6 Shirley Xiao, David Nguyen 7 Email : dadler at adtechgeospatial.com 8 xshirley2012 at yahoo.com, davidng0123 at gmail.com 9 **************************************************************************** 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 ***************************************************************************/ 17 18 #ifndef QGSDB2TABLEMODEL_H 19 #define QGSDB2TABLEMODEL_H 20 21 #include <QStandardItemModel> 22 #include <QString> 23 #include <QObject> 24 #include "qgsdataitem.h" 25 #include "qgswkbtypes.h" 26 27 //! Layer Property structure 28 struct QgsDb2LayerProperty 29 { 30 QString type; 31 QString schemaName; 32 QString tableName; 33 QString geometryColName; 34 QStringList pkCols; 35 QString pkColumnName; 36 QString srid; 37 QString srsName; 38 QString sql; 39 QString extents; 40 }; 41 42 43 class QIcon; 44 45 /** 46 * A model that holds the tables of a database in a hierarchy where the 47 schemas are the root elements that contain the individual tables as children. 48 The tables have the following columns: Type, Schema, Tablename, Geometry Column, Sql*/ 49 class QgsDb2TableModel : public QStandardItemModel 50 { 51 Q_OBJECT 52 public: 53 QgsDb2TableModel(); 54 55 //! Adds entry for one database table to the model 56 void addTableEntry( const QgsDb2LayerProperty &property ); 57 58 //! Sets an sql statement that belongs to a cell specified by a model index 59 void setSql( const QModelIndex &index, const QString &sql ); 60 61 /** 62 * Sets one or more geometry types to a row. In case of several types, additional rows are inserted. 63 * This is for tables where the type is detected later by thread. 64 */ 65 void setGeometryTypesForTable( QgsDb2LayerProperty layerProperty ); 66 67 //! Returns the number of tables in the model tableCount()68 int tableCount() const { return mTableCount; } 69 70 enum Columns 71 { 72 DbtmSchema = 0, 73 DbtmTable, 74 DbtmType, 75 DbtmGeomCol, 76 DbtmSrid, 77 DbtmPkCol, 78 DbtmSelectAtId, 79 DbtmSql, 80 DbtmColumns 81 }; 82 83 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override; 84 85 QString layerURI( const QModelIndex &index, const QString &connInfo, bool useEstimatedMetadata ); 86 87 static QIcon iconForWkbType( QgsWkbTypes::Type type ); 88 89 static QgsWkbTypes::Type wkbTypeFromDb2( QString dbType, int dim = 2 ); 90 91 private: 92 //! Number of tables in the model 93 int mTableCount = 0; 94 }; 95 #endif 96