27 : QAbstractTableModel( parent )
28 , mSearchContext( searchContext )
30 qRegisterMetaType< QgsLayerMetadataSearchResults>(
"QgsLayerMetadataSearchResults" );
31 qRegisterMetaType< QgsLayerMetadataProviderResult>(
"QgsLayerMetadataProviderResult" );
41 return parent.isValid() ? 0 : mResult.
metadata().count();
46 return parent.isValid() ? 0 : 5;
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:
75 return tr(
"Raster" );
83 case Qt::ItemDataRole::ToolTipRole:
86 return tr( R
"HTML(<html><body><!-- metadata headers ---><h3>Identification</h3>%1</body></html>)HTML" )
91 case Qt::ItemDataRole::DecorationRole:
93 if ( index.column() == 0 )
98 return QgsIconUtils::iconForGeometryType( md.geometryType() == QgsWkbTypes::GeometryType::UnknownGeometry ? QgsWkbTypes::GeometryType::NullGeometry : md.geometryType() );
102 case Roles::Metadata:
104 return QVariant::fromValue( mResult.
metadata().at( index.row() ) );
117 if ( orientation == Qt::Orientation::Horizontal && section <
columnCount( createIndex( -1, -1 ) ) )
119 if ( role == Qt::ItemDataRole::DisplayRole )
123 case Sections::Identifier:
124 return tr(
"Identifier" );
125 case Sections::Title:
126 return tr(
"Title" );
127 case Sections::Abstract:
128 return tr(
"Abstract" );
129 case Sections::DataProviderName:
130 return tr(
"Provider" );
131 case Sections::GeometryType:
132 return tr(
"Layer Type" );
137 return QAbstractTableModel::headerData( section, orientation, role );
149 const QList<QgsLayerMetadataProviderResult> results { mdProvider->search( mSearchContext ).metadata() };
165 mFeedback->setProgress( 0 );
169 std::unique_ptr<QgsMetadataResultsFetcher> fetcher = std::make_unique<QgsMetadataResultsFetcher>( mdProvider, mSearchContext, mFeedback.get() );
170 std::unique_ptr<QThread> thread = std::make_unique<QThread>();
171 fetcher->moveToThread( thread.get() );
175 resultsReady( results );
177 connect( thread.get(), &QThread::started, fetcher.get(), &QgsMetadataResultsFetcher::fetchMetadata );
178 mWorkerThreads.push_back( std::move( thread ) );
179 mWorkers.push_back( std::move( fetcher ) );
180 mWorkerThreads.back()->start();
187 beginInsertRows( QModelIndex(), mResult.
metadata().count(), mResult.
metadata().count() + results.
metadata().count() - 1 );
188 const QList<QgsLayerMetadataProviderResult> metadata { results.
metadata() };
203 for (
const auto &workerThread : std::as_const( mWorkerThreads ) )
205 workerThread->quit();
206 workerThread->wait();
210 mWorkerThreads.clear();
212 mFeedback = std::make_unique<QgsFeedback>();
220 : mLayerMetadataProvider( metadataProvider )
221 , mSearchContext( searchContext )
222 , mFeedback( feedback )
226void QgsMetadataResultsFetcher::fetchMetadata()
228 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(QgsWkbTypes::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.
static QString geometryDisplayString(GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.
@ RasterLayer
Raster layer.