30#include "moc_qgsprocessingprojectmodelprovider.cpp"
32using namespace Qt::StringLiterals;
52 return tr(
"Project models" );
57 return tr(
"Models embedded in the current project" );
89 mModelDefinitions.clear();
95 const QVariant definition = model.toVariant();
96 mModelDefinitions.insert( model.name(), definition );
105 if ( mModelDefinitions.contains( model->name() ) )
107 mModelDefinitions.remove( model->name() );
114 mModelDefinitions.clear();
115 const QDomNodeList projectModelsNodes = document.elementsByTagName( u
"projectModels"_s );
116 if ( !projectModelsNodes.isEmpty() )
118 const QDomNode projectModelsNode = projectModelsNodes.at( 0 );
119 const QDomNodeList modelNodes = projectModelsNode.childNodes();
120 for (
int i = 0; i < modelNodes.count(); ++i )
122 const QDomElement modelElement = modelNodes.at( i ).toElement();
125 if (
algorithm.loadVariant( definition ) )
127 mModelDefinitions.insert(
algorithm.name(), definition );
137 const QDomNodeList qgisNodes = document.elementsByTagName( u
"qgis"_s );
138 if ( qgisNodes.isEmpty() )
141 QDomNode qgisNode = qgisNodes.at( 0 );
142 QDomElement projectModelsNode = document.createElement( u
"projectModels"_s );
144 const QList< const QgsProcessingAlgorithm * > algs =
algorithms();
147 auto model =
dynamic_cast< const QgsProcessingModelAlgorithm *
>(
algorithm );
151 const QVariant definition = model->toVariant();
153 projectModelsNode.appendChild( element );
156 qgisNode.appendChild( projectModelsNode );
166 for (
auto it = mModelDefinitions.constBegin(); it != mModelDefinitions.constEnd(); ++it )
168 auto algorithm = std::make_unique< QgsProcessingModelAlgorithm >();
169 if (
algorithm->loadVariant( it.value() ) )
182void QgsProcessingProjectModelProvider::onProviderAdded(
const QString &providerId )
184 if ( providerId ==
id() )
@ Critical
Critical/error message.
static QgsProcessingRegistry * processingRegistry()
Returns the application's processing registry, used for managing processing providers,...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Abstract base class for processing algorithms.
QString longName() const override
Returns the longer version of the provider name, which can include extra details such as version numb...
void writeProject(QDomDocument &document)
Writes project model definitions into a project DOM document document.
void loadAlgorithms() override
Loads all algorithms belonging to this provider.
void readProject(const QDomDocument &document)
Reads project model definitions from a project DOM document document.
bool load() override
Loads the provider.
QString id() const override
Returns the unique provider id, used for identifying the provider.
void removeModel(const QgsProcessingModelAlgorithm *model)
Removes a model from the provider.
QIcon icon() const override
Returns an icon for the provider.
QString name() const override
Returns the provider name, which is used to describe the provider within the GUI.
bool supportsNonFileBasedOutput() const override
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
void addModel(const QgsProcessingModelAlgorithm &model)
Adds a model to the provider.
QString svgIconPath() const override
Returns a path to an SVG version of the provider's icon.
void clear()
Clears all models from the provider.
QgsProcessingProjectModelProvider(QgsProject *project, QObject *parent=nullptr)
Constructor for QgsProcessingProjectModelProvider, storing models in the specified project.
const QgsProcessingAlgorithm * algorithm(const QString &name) const
Returns the matching algorithm by name, or nullptr if no matching algorithm is contained by this prov...
QgsProcessingProvider(QObject *parent=nullptr)
Constructor for QgsProcessingProvider.
void refreshAlgorithms()
Refreshes the algorithms available from the provider, causing it to re-populate with all associated a...
bool addAlgorithm(QgsProcessingAlgorithm *algorithm)
Adds an algorithm to the provider.
QList< const QgsProcessingAlgorithm * > algorithms() const
Returns a list of algorithms supplied by this provider.
void providerAdded(const QString &id)
Emitted when a provider has been added to the registry.
static const QString PROJECT_PROVIDER_ID
Constant used for the project model provider's ID.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
void readProject(const QDomDocument &document)
Emitted when a project is being read.
void writeProject(QDomDocument &document)
Emitted when the project is being written.
Scoped object for logging of the runtime for a single operation or group of operations.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.