ViewSolutions
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
22class VIEWSOLUTION_EXPORT ModelStorage: public QObject, public QEnableSharedFromThis<ModelStorage>
23{
24 Q_OBJECT
25public:
26 ModelStorage(QQmlApplicationEngine* engine = nullptr);
27
34 bool addModel(const QSharedPointer<iModel>& model);
35
41 Q_INVOKABLE QObject* getModel(const QString& modeId) const;
42
43 template <class Type>
44 QSharedPointer<Type> get(const QString& modeId) const {
45 return _storage.value(modeId).staticCast<Type>();
46 }
47
52 QQmlApplicationEngine *engine() const;
53
54private:
55 QHash<QString, QSharedPointer<iModel>> _storage;
56 QQmlApplicationEngine * _engine = nullptr;
57};
58
59}
60
61#endif // MODELSTORAGE_H
The ModelStorage class main model storage object. Provide access to all models in the application.
QSharedPointer< Type > get(const QString &modeId) const
the ViewSolutions namespace
#define VIEWSOLUTION_EXPORT