25#include "moc_qgsdatabasetablemodel.cpp"
27using namespace Qt::StringLiterals;
30 : QAbstractItemModel(
parent )
37 Q_ASSERT( mConnection );
42 : QAbstractItemModel(
parent )
43 , mConnection( connection )
46 Q_ASSERT( mConnection );
50void QgsDatabaseTableModel::init()
53 mTables = mConnection->tables( mSchema );
68 return mTables.count() + ( mAllowEmpty ? 1 : 0 );
80 if ( !
index.isValid() )
83 if (
index.row() == 0 && mAllowEmpty )
91 if (
index.row() - ( mAllowEmpty ? 1 : 0 ) >= mTables.count() )
100 case Qt::DisplayRole:
101 case Qt::ToolTipRole:
112 case Qt::DecorationRole:
118 if ( role == Qt::DecorationRole )
124 if ( role == Qt::DecorationRole )
163 return static_cast< int >( table.
flags() );
178 if ( hasIndex( row, column,
parent ) )
180 return createIndex( row, column, row );
183 return QModelIndex();
188 if ( allowEmpty == mAllowEmpty )
193 beginInsertRows( QModelIndex(), 0, 0 );
199 beginRemoveRows( QModelIndex(), 0, 0 );
207 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > newTables = mConnection->tables( mSchema );
208 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > oldTables = mTables;
212 if ( !newTables.contains( oldTable ) )
214 const int r = mTables.indexOf( oldTable );
215 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
216 mTables.removeAt( r );
223 if ( !mTables.contains( newTable ) )
225 beginInsertRows( QModelIndex(), mTables.count() + ( mAllowEmpty ? 1 : 0 ), mTables.count() + ( mAllowEmpty ? 1 : 0 ) );
226 mTables.append( newTable );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Provides common functionality for database based connections.
QgsDatabaseTableModel(const QString &provider, const QString &connection, const QString &schema=QString(), QObject *parent=nullptr)
Constructor for QgsDatabaseTableModel, for the specified provider and connection name.
QModelIndex parent(const QModelIndex &child) const override
void refresh()
Refreshes the table list by querying the underlying connection.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
void setAllowEmptyTable(bool allowEmpty)
Sets whether an optional empty table ("not set") option is present in the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
@ CustomInfo
Custom info variant map role.
@ TableFlags
Table flags role.
@ Crs
CRS for primary (first) geometry column in table.
@ WkbType
WKB type for primary (first) geometry column in table.
@ Empty
Entry is an empty entry.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
static QIcon iconLine()
Returns an icon representing line geometries.
static QIcon iconPolygon()
Returns an icon representing polygon geometries.
static QIcon iconGeometryCollection()
Returns an icon representing geometry collections.
static QIcon iconPoint()
Returns an icon representing point geometries.
static QIcon iconTable()
Returns an icon representing non-spatial layers (tables).
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
The TableProperty class represents a database table or view.
QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > geometryColumnTypes() const
Returns the list of geometry column types and CRSs.
QString tableName() const
Returns the table name.
QVariantMap info() const
Returns additional information about the table.
QString comment() const
Returns the table comment.
QString schema() const
Returns the schema or an empty string for backends that do not support a schema.
TableFlags flags() const
Returns the table flags.