22 : QAbstractItemModel( parent )
29 Q_ASSERT( mConnection );
34 : QAbstractItemModel( parent )
35 , mConnection( connection )
38 Q_ASSERT( mConnection );
42 void QgsDatabaseTableModel::init()
44 Q_ASSERT( mConnection->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::Tables );
45 mTables = mConnection->tables( mSchema );
60 return mTables.count() + ( mAllowEmpty ? 1 : 0 );
72 if ( !
index.isValid() )
75 if (
index.row() == 0 && mAllowEmpty )
83 if (
index.row() - ( mAllowEmpty ? 1 : 0 ) >= mTables.count() )
104 case Qt::DecorationRole:
110 if ( role == Qt::DecorationRole )
116 if ( role == Qt::DecorationRole )
150 return static_cast< int >( table.
flags() );
165 if ( hasIndex( row, column,
parent ) )
167 return createIndex( row, column, row );
170 return QModelIndex();
175 if ( allowEmpty == mAllowEmpty )
180 beginInsertRows( QModelIndex(), 0, 0 );
186 beginRemoveRows( QModelIndex(), 0, 0 );
194 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > newTables = mConnection->tables( mSchema );
195 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > oldTables = mTables;
199 if ( !newTables.contains( oldTable ) )
201 int r = mTables.indexOf( oldTable );
202 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
203 mTables.removeAt( r );
210 if ( !mTables.contains( newTable ) )
212 beginInsertRows( QModelIndex(), mTables.count() + ( mAllowEmpty ? 1 : 0 ), mTables.count() + ( mAllowEmpty ? 1 : 0 ) );
213 mTables.append( newTable );