ViewSolutions
Loading...
Searching...
No Matches
modelstorage.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2020-2025 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#include "modelstorage.h"
9
10#include <QQmlEngine>
11
12namespace ViewSolutions {
13
14ModelStorage::ModelStorage(QQmlApplicationEngine *engine) {
15 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
16 _engine = engine;
17}
18
19bool ModelStorage::addModel(const QSharedPointer<iModel> &model) {
20 if (_storage.contains(model->modelId())) {
21 return false;
22 }
23
24 if (QObject* qobject = dynamic_cast<QObject*>(model.get())) {
25 QQmlEngine::setObjectOwnership(qobject, QQmlEngine::CppOwnership);
26 }
27
28 _storage[model->modelId()] = model;
29 model->initStorage(sharedFromThis().toWeakRef());
30
31 return true;
32}
33
34QObject* ModelStorage::getModel(const QString &modeId) const {
35 return dynamic_cast<QObject*>(_storage.value(modeId).get());
36}
37
38QQmlApplicationEngine *ModelStorage::engine() const {
39 return _engine;
40}
41}
QQmlApplicationEngine * engine() const
engine returns context qml engine.
bool addModel(const QSharedPointer< iModel > &model)
addModel adds new model into storage.
ModelStorage(QQmlApplicationEngine *engine=nullptr)
Q_INVOKABLE QObject * getModel(const QString &modeId) const
getModel This method isible on The QML and using for gettings required GUI models.
the ViewSolutions namespace