AusweisApp2
UILoader.h
gehe zur Dokumentation dieser Datei
1 
7 #pragma once
8 
9 #include "Env.h"
10 #include "UIPlugIn.h"
11 
12 #include <QJsonObject>
13 #include <QMap>
14 #include <QStringList>
15 
16 
17 class test_UILoader;
18 
19 namespace governikus
20 {
21 
22 class UILoader
23  : public QObject
24 {
25  Q_OBJECT
26  friend class Env;
27  friend class ::test_UILoader;
28 
29  private:
30  static QStringList cUserRequest;
31  QMap<QString, UIPlugIn*> mLoadedPlugIns;
32 
33  [[nodiscard]] static QStringList getInitialDefault();
34  [[nodiscard]] static QString unify(const QString& pName);
35  [[nodiscard]] static QString getName(const QMetaObject* pMeta);
36  [[nodiscard]] static QString getName(const QJsonObject& pJson);
37  [[nodiscard]] static inline bool isDefault(const QJsonObject& pJson);
38  [[nodiscard]] static QStringList getUserRequestOrDefault();
39  [[nodiscard]] static inline bool isPlugIn(const QJsonObject& pJson);
40 
41 
42 #ifndef QT_NO_DEBUG
43 
44  public:
45 #endif
46  UILoader();
47  ~UILoader() override;
48 
49  [[nodiscard]] bool load(const QString& pName);
50 
51  public:
52  // do not make this non-static as the CommandLineParser spawns
53  // this object on startup. Since this is a QObject this should be avoided.
54  [[nodiscard]] static QString getDefault();
55  static void setUserRequest(const QStringList& pRequest);
56 
57  [[nodiscard]] bool isLoaded() const;
58  [[nodiscard]] bool load();
59 
60  template<typename T>
61  [[nodiscard]] std::enable_if_t<std::is_base_of_v<UIPlugIn, T>, bool> load()
62  {
63  return load(getName(&T::staticMetaObject));
64  }
65 
66 
67  template<typename T>
68  [[nodiscard]] std::enable_if_t<std::is_base_of_v<UIPlugIn, T>, T*> getLoaded() const
69  {
70  return qobject_cast<T*>(mLoadedPlugIns.value(getName(&T::staticMetaObject)));
71  }
72 
73 
74  Q_INVOKABLE void shutdown();
75 
76  Q_SIGNALS:
77  void fireLoadedPlugin(UIPlugIn* pPlugin);
79 };
80 
81 } // namespace governikus
Definition: Env.h:44
Definition: UILoader.h:24
bool isLoaded() const
Definition: UILoader.cpp:53
std::enable_if_t< std::is_base_of_v< UIPlugIn, T >, T * > getLoaded() const
Definition: UILoader.h:68
void fireLoadedPlugin(UIPlugIn *pPlugin)
~UILoader() override
Definition: UILoader.cpp:25
std::enable_if_t< std::is_base_of_v< UIPlugIn, T >, bool > load()
Definition: UILoader.h:61
Q_INVOKABLE void shutdown()
Definition: UILoader.cpp:142
bool load()
Definition: UILoader.cpp:59
UILoader()
Definition: UILoader.cpp:19
static QString getDefault()
Definition: UILoader.cpp:120
static void setUserRequest(const QStringList &pRequest)
Definition: UILoader.cpp:130
#define T(v)
Definition: http_parser.cpp:237
A simple template renderer.
Definition: ActivationContext.h:15