26QgsLayerMetadataResultsModel::QgsLayerMetadataResultsModel(
const QgsMetadataSearchContext &searchContext, QObject *parent )
27 : QAbstractTableModel( parent )
28 , mSearchContext( searchContext )
30 qRegisterMetaType< QgsLayerMetadataSearchResults>(
"QgsLayerMetadataSearchResults" );
31 qRegisterMetaType< QgsLayerMetadataProviderResult>(
"QgsLayerMetadataProviderResult" );
34QgsLayerMetadataResultsModel::~QgsLayerMetadataResultsModel()
39int QgsLayerMetadataResultsModel::rowCount(
const QModelIndex &parent )
const
41 return parent.isValid() ? 0 : mResult.metadata().count();
44int QgsLayerMetadataResultsModel::columnCount(
const QModelIndex &parent )
const
46 return parent.isValid() ? 0 : 5;
49QVariant QgsLayerMetadataResultsModel::data(
const QModelIndex &index,
int role )
const
51 if ( index.isValid() && index.row() < mResult.metadata().count( ) )
55 case Qt::ItemDataRole::DisplayRole:
57 switch ( index.column() )
59 case Sections::Identifier:
60 return mResult.metadata().at( index.row() ).identifier( );
62 return mResult.metadata().at( index.row() ).title();
63 case Sections::Abstract:
64 return mResult.metadata().at( index.row() ).abstract();
65 case Sections::DataProviderName:
67 const QString providerName { mResult.metadata().at( index.row() ).dataProviderName() };
71 case Sections::GeometryType:
73 const QList<QgsLayerMetadataProviderResult> metadata = mResult.metadata();
76 return tr(
"Raster" );
84 case Qt::ItemDataRole::ToolTipRole:
87 return tr( R
"HTML(<html><body><!-- metadata headers ---><h3>Identification</h3>%1</body></html>)HTML" )
92 case Qt::ItemDataRole::DecorationRole:
94 if ( index.column() == 0 )
96 const QList<QgsLayerMetadataProviderResult> metadata = mResult.metadata();
104 case static_cast< int >( CustomRole::Metadata ):
106 return QVariant::fromValue( mResult.metadata().at( index.row() ) );
117QVariant QgsLayerMetadataResultsModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
119 if ( orientation == Qt::Orientation::Horizontal && section < columnCount( createIndex( -1, -1 ) ) )
121 if ( role == Qt::ItemDataRole::DisplayRole )
125 case Sections::Identifier:
126 return tr(
"Identifier" );
127 case Sections::Title:
128 return tr(
"Title" );
129 case Sections::Abstract:
130 return tr(
"Abstract" );
131 case Sections::DataProviderName:
132 return tr(
"Provider" );
133 case Sections::GeometryType:
134 return tr(
"Layer Type" );
139 return QAbstractTableModel::headerData( section, orientation, role );
142void QgsLayerMetadataResultsModel::reload()
151 const QList<QgsLayerMetadataProviderResult> results { mdProvider->search( mSearchContext ).metadata() };
154 mResult.addMetadata( metadata );
160void QgsLayerMetadataResultsModel::reloadAsync()
167 mFeedback->setProgress( 0 );
171 std::unique_ptr<QgsMetadataResultsFetcher> fetcher = std::make_unique<QgsMetadataResultsFetcher>( mdProvider, mSearchContext, mFeedback.get() );
172 std::unique_ptr<QThread> thread = std::make_unique<QThread>();
173 fetcher->moveToThread( thread.get() );
177 resultsReady( results );
179 connect( thread.get(), &QThread::started, fetcher.get(), &QgsMetadataResultsFetcher::fetchMetadata );
180 mWorkerThreads.push_back( std::move( thread ) );
181 mWorkers.push_back( std::move( fetcher ) );
182 mWorkerThreads.back()->start();
189 beginInsertRows( QModelIndex(), mResult.metadata().count(), mResult.metadata().count() + results.
metadata().count() - 1 );
190 const QList<QgsLayerMetadataProviderResult> metadata { results.
metadata() };
193 mResult.addMetadata( result );
198void QgsLayerMetadataResultsModel::cancel()
205 for (
const auto &workerThread : std::as_const( mWorkerThreads ) )
207 workerThread->quit();
208 workerThread->wait();
212 mWorkerThreads.clear();
214 mFeedback = std::make_unique<QgsFeedback>();
222 : mLayerMetadataProvider( metadataProvider )
223 , mSearchContext( searchContext )
224 , mFeedback( feedback )
228void QgsMetadataResultsFetcher::fetchMetadata()
230 emit resultsReady( mLayerMetadataProvider->search( mSearchContext, QString(),
QgsRectangle(), mFeedback ) );
static QgsLayerMetadataProviderRegistry * layerMetadataProviderRegistry()
Returns registry of available layer metadata provider implementations.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
static QIcon iconForGeometryType(Qgis::GeometryType typeGroup)
Returns the icon for a vector layer whose geometry typeGroup is provided.
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.
A rectangle specified with double values.
Handles storage of information regarding WKB types and their properties.
static QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.