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:
73 const QList<QgsLayerMetadataProviderResult> metadata = mResult.
metadata();
75 if ( md.layerType() == Qgis::LayerType::Raster )
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();
98 if ( md.layerType() == Qgis::LayerType::Raster )
104 case Roles::Metadata:
106 return QVariant::fromValue( mResult.
metadata().at( index.row() ) );
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 );
151 const QList<QgsLayerMetadataProviderResult> results { mdProvider->search( mSearchContext ).metadata() };
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() };
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.
static QString geometryDisplayString(Qgis::GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.