Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab713e2
commit 2883215
Showing
8 changed files
with
594 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# The following has been generated automatically from src/core/providers/qgsprovidersublayermodel.h | ||
# monkey patching scoped based enum | ||
QgsProviderSublayerModel.Role.ProviderKey.__doc__ = "Provider key" | ||
QgsProviderSublayerModel.Role.LayerType.__doc__ = "Layer type" | ||
QgsProviderSublayerModel.Role.Uri.__doc__ = "Layer URI" | ||
QgsProviderSublayerModel.Role.Name.__doc__ = "Layer name" | ||
QgsProviderSublayerModel.Role.Description.__doc__ = "Layer description" | ||
QgsProviderSublayerModel.Role.Path.__doc__ = "Layer path" | ||
QgsProviderSublayerModel.Role.FeatureCount.__doc__ = "Feature count (for vector sublayers)" | ||
QgsProviderSublayerModel.Role.WkbType.__doc__ = "WKB geometry type (for vector sublayers)" | ||
QgsProviderSublayerModel.Role.GeometryColumnName.__doc__ = "Geometry column name (for vector sublayers)" | ||
QgsProviderSublayerModel.Role.LayerNumber.__doc__ = "Layer number" | ||
QgsProviderSublayerModel.Role.__doc__ = 'Custom model roles\n\n' + '* ``ProviderKey``: ' + QgsProviderSublayerModel.Role.ProviderKey.__doc__ + '\n' + '* ``LayerType``: ' + QgsProviderSublayerModel.Role.LayerType.__doc__ + '\n' + '* ``Uri``: ' + QgsProviderSublayerModel.Role.Uri.__doc__ + '\n' + '* ``Name``: ' + QgsProviderSublayerModel.Role.Name.__doc__ + '\n' + '* ``Description``: ' + QgsProviderSublayerModel.Role.Description.__doc__ + '\n' + '* ``Path``: ' + QgsProviderSublayerModel.Role.Path.__doc__ + '\n' + '* ``FeatureCount``: ' + QgsProviderSublayerModel.Role.FeatureCount.__doc__ + '\n' + '* ``WkbType``: ' + QgsProviderSublayerModel.Role.WkbType.__doc__ + '\n' + '* ``GeometryColumnName``: ' + QgsProviderSublayerModel.Role.GeometryColumnName.__doc__ + '\n' + '* ``LayerNumber``: ' + QgsProviderSublayerModel.Role.LayerNumber.__doc__ | ||
# -- | ||
# monkey patching scoped based enum | ||
QgsProviderSublayerModel.Column.Name.__doc__ = "Layer name" | ||
QgsProviderSublayerModel.Column.Description.__doc__ = "Layer description" | ||
QgsProviderSublayerModel.Column.__doc__ = 'Model columns\n\n' + '* ``Name``: ' + QgsProviderSublayerModel.Column.Name.__doc__ + '\n' + '* ``Description``: ' + QgsProviderSublayerModel.Column.Description.__doc__ | ||
# -- |
85 changes: 85 additions & 0 deletions
85
python/core/auto_generated/providers/qgsprovidersublayermodel.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/providers/qgsprovidersublayermodel.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsProviderSublayerModel: QAbstractItemModel | ||
{ | ||
%Docstring(signature="appended") | ||
|
||
|
||
.. versionadded:: 3.22 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsprovidersublayermodel.h" | ||
%End | ||
public: | ||
|
||
enum class Role | ||
{ | ||
ProviderKey, | ||
LayerType, | ||
Uri, | ||
Name, | ||
Description, | ||
Path, | ||
FeatureCount, | ||
WkbType, | ||
GeometryColumnName, | ||
LayerNumber, | ||
}; | ||
|
||
enum class Column | ||
{ | ||
Name, | ||
Description, | ||
}; | ||
|
||
QgsProviderSublayerModel( QObject *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsProviderSublayerModel, with the specified ``parent`` object. | ||
%End | ||
|
||
void setSublayerDetails( const QList< QgsProviderSublayerDetails > &details ); | ||
%Docstring | ||
Sets the sublayer ``details`` to show in the model. | ||
|
||
.. seealso:: :py:func:`sublayerDetails` | ||
%End | ||
|
||
QList< QgsProviderSublayerDetails > sublayerDetails() const; | ||
%Docstring | ||
Returns the sublayer details shown in the model. | ||
|
||
.. seealso:: :py:func:`setSublayerDetails` | ||
%End | ||
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; | ||
|
||
virtual QModelIndex parent( const QModelIndex &index ) const; | ||
|
||
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; | ||
|
||
virtual int rowCount( const QModelIndex &parent ) const; | ||
|
||
virtual QVariant data( const QModelIndex &index, int role ) const; | ||
|
||
virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/providers/qgsprovidersublayermodel.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
/*************************************************************************** | ||
qgsprovidersublayermodel.cpp | ||
---------------------- | ||
begin : June 2021 | ||
copyright : (C) 2021 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsprovidersublayermodel.h" | ||
#include "qgsprovidersublayerdetails.h" | ||
#include "qgsiconutils.h" | ||
#include <QLocale> | ||
|
||
QgsProviderSublayerModel::QgsProviderSublayerModel( QObject *parent ) | ||
: QAbstractItemModel( parent ) | ||
{ | ||
|
||
} | ||
|
||
void QgsProviderSublayerModel::setSublayerDetails( const QList<QgsProviderSublayerDetails> &details ) | ||
{ | ||
// remove layers which don't exist in new list | ||
for ( int i = mSublayers.count() - 1; i >= 0; --i ) | ||
{ | ||
if ( !details.contains( mSublayers.at( i ) ) ) | ||
{ | ||
beginRemoveRows( QModelIndex(), i, i ); | ||
mSublayers.removeAt( i ); | ||
endRemoveRows(); | ||
} | ||
} | ||
|
||
// and add new layers which exist only in new list | ||
for ( const QgsProviderSublayerDetails &layer : details ) | ||
{ | ||
if ( !mSublayers.contains( layer ) ) | ||
{ | ||
beginInsertRows( QModelIndex(), mSublayers.count(), mSublayers.count() ); | ||
mSublayers.append( layer ); | ||
endInsertRows(); | ||
} | ||
} | ||
} | ||
|
||
QList<QgsProviderSublayerDetails> QgsProviderSublayerModel::sublayerDetails() const | ||
{ | ||
return mSublayers; | ||
} | ||
|
||
QModelIndex QgsProviderSublayerModel::index( int row, int column, const QModelIndex &parent ) const | ||
{ | ||
if ( column < 0 || column >= columnCount() ) | ||
{ | ||
//column out of bounds | ||
return QModelIndex(); | ||
} | ||
|
||
if ( !parent.isValid() && row >= 0 && row < mSublayers.size() ) | ||
{ | ||
//return an index for the sublayer at this position | ||
return createIndex( row, column ); | ||
} | ||
|
||
//only top level supported for now | ||
return QModelIndex(); | ||
} | ||
|
||
QModelIndex QgsProviderSublayerModel::parent( const QModelIndex &index ) const | ||
{ | ||
Q_UNUSED( index ) | ||
|
||
//all items are top level for now | ||
return QModelIndex(); | ||
} | ||
|
||
int QgsProviderSublayerModel::columnCount( const QModelIndex &parent ) const | ||
{ | ||
Q_UNUSED( parent ) | ||
return static_cast< int >( Column::Description ) + 1; | ||
} | ||
|
||
int QgsProviderSublayerModel::rowCount( const QModelIndex &parent ) const | ||
{ | ||
if ( !parent.isValid() ) | ||
{ | ||
return mSublayers.size(); | ||
} | ||
else | ||
{ | ||
//no children for nw | ||
return 0; | ||
} | ||
} | ||
|
||
QVariant QgsProviderSublayerModel::data( const QModelIndex &index, int role ) const | ||
{ | ||
if ( !index.isValid() ) | ||
return QVariant(); | ||
|
||
if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) ) | ||
return QVariant(); | ||
|
||
const QgsProviderSublayerDetails details = mSublayers.at( index.row() ); | ||
|
||
switch ( role ) | ||
{ | ||
case Qt::DisplayRole: | ||
case Qt::ToolTipRole: | ||
case Qt::EditRole: | ||
{ | ||
switch ( static_cast< Column >( index.column() ) ) | ||
{ | ||
case QgsProviderSublayerModel::Column::Name: | ||
return details.name(); | ||
case QgsProviderSublayerModel::Column::Description: | ||
{ | ||
switch ( details.type() ) | ||
{ | ||
case QgsMapLayerType::VectorLayer: | ||
{ | ||
QString count; | ||
if ( details.featureCount() == static_cast< long long >( Qgis::FeatureCountState::Uncounted ) | ||
|| details.featureCount() == static_cast< long long >( Qgis::FeatureCountState::UnknownCount ) ) | ||
count = tr( "Uncounted" ); | ||
else | ||
count = QLocale().toString( details.featureCount() ); | ||
|
||
if ( !details.description().isEmpty() ) | ||
return QStringLiteral( "%1 - %2 (%3)" ).arg( details.description(), | ||
QgsWkbTypes::displayString( details.wkbType() ), | ||
count ); | ||
else | ||
return QStringLiteral( "%2 (%3)" ).arg( | ||
QgsWkbTypes::displayString( details.wkbType() ), | ||
count ); | ||
} | ||
|
||
case QgsMapLayerType::RasterLayer: | ||
case QgsMapLayerType::PluginLayer: | ||
case QgsMapLayerType::MeshLayer: | ||
case QgsMapLayerType::VectorTileLayer: | ||
case QgsMapLayerType::AnnotationLayer: | ||
case QgsMapLayerType::PointCloudLayer: | ||
return details.description(); | ||
} | ||
break; | ||
|
||
} | ||
} | ||
return details.name(); | ||
|
||
} | ||
|
||
case Qt::DecorationRole: | ||
{ | ||
if ( index.column() == 0 ) | ||
return details.type() == QgsMapLayerType::VectorLayer | ||
? QgsIconUtils::iconForWkbType( details.wkbType() ) | ||
: QgsIconUtils::iconForLayerType( details.type() ); | ||
else | ||
return QVariant(); | ||
} | ||
|
||
case static_cast< int >( Role::ProviderKey ): | ||
return details.providerKey(); | ||
|
||
case static_cast< int >( Role::LayerType ): | ||
return static_cast< int >( details.type() ); | ||
|
||
case static_cast< int >( Role::Uri ): | ||
return details.uri(); | ||
|
||
case static_cast< int >( Role::Name ): | ||
return details.name(); | ||
|
||
case static_cast< int >( Role::Description ): | ||
return details.description(); | ||
|
||
case static_cast< int >( Role::Path ): | ||
return details.path(); | ||
|
||
case static_cast< int >( Role::FeatureCount ): | ||
return details.featureCount(); | ||
|
||
case static_cast< int >( Role::WkbType ): | ||
return details.wkbType(); | ||
|
||
case static_cast< int >( Role::GeometryColumnName ): | ||
return details.geometryColumnName(); | ||
|
||
case static_cast< int >( Role::LayerNumber ): | ||
return details.layerNumber(); | ||
|
||
default: | ||
return QVariant(); | ||
} | ||
} | ||
|
||
QVariant QgsProviderSublayerModel::headerData( int section, Qt::Orientation orientation, int role ) const | ||
{ | ||
switch ( orientation ) | ||
{ | ||
case Qt::Vertical: | ||
break; | ||
case Qt::Horizontal: | ||
{ | ||
switch ( role ) | ||
{ | ||
case Qt::DisplayRole: | ||
case Qt::ToolTipRole: | ||
{ | ||
switch ( static_cast< Column>( section ) ) | ||
{ | ||
case QgsProviderSublayerModel::Column::Name: | ||
return tr( "Layer" ); | ||
case QgsProviderSublayerModel::Column::Description: | ||
return tr( "Description" ); | ||
} | ||
break; | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
return QVariant(); | ||
} |
Oops, something went wrong.