File indexing completed on 2025-02-09 04:28:37

0001 /*
0002   This file is part of the KTextTemplate library
0003 
0004   SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com>
0005 
0006   SPDX-License-Identifier: LGPL-2.1-or-later
0007 
0008 */
0009 
0010 #ifndef KTEXTTEMPLATE_ENGINE_P_H
0011 #define KTEXTTEMPLATE_ENGINE_P_H
0012 
0013 #include "engine.h"
0014 #include "filter.h"
0015 #include "pluginpointer_p.h"
0016 #include "taglibraryinterface.h"
0017 
0018 namespace KTextTemplate
0019 {
0020 
0021 class ScriptableTagLibrary;
0022 
0023 class ScriptableLibraryContainer : public TagLibraryInterface
0024 {
0025 public:
0026     ScriptableLibraryContainer(const QHash<QString, AbstractNodeFactory *> &factories, const QHash<QString, Filter *> &filters)
0027         : m_nodeFactories(factories)
0028         , m_filters(filters)
0029     {
0030     }
0031 
0032     void setNodeFactories(const QHash<QString, AbstractNodeFactory *> &factories)
0033     {
0034         m_nodeFactories = factories;
0035     }
0036 
0037     void setFilters(const QHash<QString, Filter *> &filters)
0038     {
0039         m_filters = filters;
0040     }
0041 
0042     // Warning: should only be called by Engine::loadDefaultLibraries
0043     void clear()
0044     {
0045         qDeleteAll(m_nodeFactories);
0046         qDeleteAll(m_filters);
0047         m_nodeFactories.clear();
0048         m_filters.clear();
0049     }
0050 
0051     QHash<QString, AbstractNodeFactory *> nodeFactories(const QString &name = {}) override
0052     {
0053         Q_UNUSED(name);
0054         return m_nodeFactories;
0055     }
0056 
0057     QHash<QString, Filter *> filters(const QString &name = {}) override
0058     {
0059         Q_UNUSED(name);
0060         return m_filters;
0061     }
0062 
0063 private:
0064     QHash<QString, AbstractNodeFactory *> m_nodeFactories;
0065     QHash<QString, Filter *> m_filters;
0066 };
0067 
0068 class EnginePrivate
0069 {
0070     explicit EnginePrivate(Engine *engine);
0071 
0072     TagLibraryInterface *loadLibrary(const QString &name);
0073     QString getScriptLibraryName(const QString &name) const;
0074 #ifdef QT_QML_LIB
0075     ScriptableLibraryContainer *loadScriptableLibrary(const QString &name);
0076 #endif
0077     PluginPointer<TagLibraryInterface> loadCppLibrary(const QString &name);
0078 
0079     Q_DECLARE_PUBLIC(Engine)
0080     Engine *const q_ptr;
0081 
0082     QHash<QString, PluginPointer<TagLibraryInterface>> m_libraries;
0083 #ifdef QT_QML_LIB
0084     QHash<QString, ScriptableLibraryContainer *> m_scriptableLibraries;
0085 #endif
0086 
0087     QList<QSharedPointer<AbstractTemplateLoader>> m_loaders;
0088     QStringList m_pluginDirs;
0089     QStringList m_defaultLibraries;
0090 #ifdef QT_QML_LIB
0091     ScriptableTagLibrary *m_scriptableTagLibrary;
0092 #endif
0093     bool m_smartTrimEnabled;
0094 };
0095 }
0096 
0097 #endif