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

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 TAGLIBRARYINTERFACE_H
0011 #define TAGLIBRARYINTERFACE_H
0012 
0013 #include "outputstream.h"
0014 
0015 #include <QHash>
0016 #include <QtPlugin>
0017 
0018 namespace KTextTemplate
0019 {
0020 class AbstractNodeFactory;
0021 class Filter;
0022 
0023 /// @headerfile taglibraryinterface.h <KTextTemplate/TagLibraryInterface>
0024 
0025 /**
0026   @brief The **%TagLibraryInterface** returns available tags and filters from
0027   libraries.
0028 
0029   This interface must be implemented in tag and filter libraries.
0030 
0031   The implementation will usually be very simple.
0032 
0033   @code
0034     class MyTagLibrary : public QObject, public TagLibraryInterface
0035     {
0036       Q_OBJECT
0037       Q_INTERFACES( KTextTemplate::TagLibraryInterface )
0038     public:
0039       MyTagLibrary( QObject *parent = {} )
0040           : QObject( parent ) {
0041       }
0042 
0043       QHash<QString, AbstractNodeFactory*>
0044       nodeFactories(const QString &name = {}) {
0045         Q_UNUSED( name );
0046         QHash<QString, AbstractNodeFactory*> nodeFactories;
0047         nodeFactories.insert( "mytag1", new MyTag1() );
0048         nodeFactories.insert( "mytag2", new MyTag2() );
0049         return nodeFactories;
0050       }
0051 
0052       QHash<QString, Filter*> filters( const QString &name = {} ) {
0053         Q_UNUSED( name );
0054 
0055         QHash<QString, Filter*> filters;
0056 
0057         filters.insert( "myfilter1", new MyFilter1() );
0058         filters.insert( "myfilter2", new MyFilter2() );
0059 
0060         return filters;
0061       }
0062     };
0063   @endcode
0064 
0065   @author Stephen Kelly <steveire@gmail.com>
0066 */
0067 class TagLibraryInterface
0068 {
0069 public:
0070     virtual ~TagLibraryInterface()
0071     {
0072     }
0073 
0074     /**
0075       Returns the AbstractNodeFactory implementations available in this library.
0076     */
0077     virtual QHash<QString, AbstractNodeFactory *> nodeFactories(const QString &name = {})
0078     {
0079         Q_UNUSED(name);
0080         static const QHash<QString, AbstractNodeFactory *> h;
0081         return h;
0082     };
0083 
0084     /**
0085       Returns the Filter implementations available in this library.
0086     */
0087     virtual QHash<QString, Filter *> filters(const QString &name = {})
0088     {
0089         Q_UNUSED(name);
0090         static const QHash<QString, Filter *> h;
0091         return h;
0092     };
0093 };
0094 }
0095 
0096 Q_DECLARE_INTERFACE(KTextTemplate::TagLibraryInterface, "org.kde.KTextTemplate.TagLibraryInterface/1.0")
0097 
0098 #endif