ViewSolutions 1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Loading...
Searching...
No Matches
modelstorage.h
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#ifndef MODELSTORAGE_H
9#define MODELSTORAGE_H
10
11#include "imodel.h"
12
13#include <QHash>
14#include <QObject>
15#include <QSharedPointer>
16
17namespace ViewSolutions {
18
45class VIEWSOLUTION_EXPORT ModelStorage: public QObject, public QEnableSharedFromThis<ModelStorage>
46{
47 Q_OBJECT
48public:
49 ModelStorage(QQmlEngine* engine = nullptr);
50
57 bool addModel(const QSharedPointer<iModel>& model);
58
64 Q_INVOKABLE QObject* getModel(const QString& modeId) const;
65
73 template <class Type>
74 QSharedPointer<Type> get(const QString& modeId) const {
75 return _storage.value(modeId).staticCast<Type>();
76 }
77
82 QQmlEngine *engine() const;
83
84private:
85 QHash<QString, QSharedPointer<iModel>> _storage;
86 QQmlEngine * _engine = nullptr;
87};
88
89}
90
91#endif // MODELSTORAGE_H
QSharedPointer< Type > get(const QString &modeId) const
get returns a typed shared pointer to the model with the given id.
ModelStorage(QQmlEngine *engine=nullptr)
QQmlEngine * engine() const
engine returns context qml engine.
bool addModel(const QSharedPointer< iModel > &model)
addModel adds new model into storage.
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.
#define VIEWSOLUTION_EXPORT
VIEWSOLUTION_EXPORT marks a symbol as part of the public ViewSolutions API.