File indexing completed on 2024-04-28 04:37:04

0001 /*
0002     SPDX-FileCopyrightText: 2013 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PROJECTFILTERMANAGER_H
0008 #define KDEVPLATFORM_PROJECTFILTERMANAGER_H
0009 
0010 #include "projectexport.h"
0011 
0012 #include <QObject>
0013 #include <QVector>
0014 #include <QSharedPointer>
0015 
0016 namespace KDevelop {
0017 
0018 class IProjectFilter;
0019 class IProjectFilterProvider;
0020 class IPlugin;
0021 class IProject;
0022 class Path;
0023 class ProjectFilterManagerPrivate;
0024 
0025 /**
0026  * @short A helper class to manage project filtering in file managers.
0027  *
0028  * Use this class in implementations of IProjectFileManager to simplify
0029  * the management of IProjectFilter instances for projects managed by
0030  * your file manager.
0031  *
0032  * NOTE: This interface is _not_ threadsafe. But you can use filtersForProject()
0033  * to implement thread safe filtering.
0034  *
0035  * @author Milian Wolff
0036  */
0037 class KDEVPLATFORMPROJECT_EXPORT ProjectFilterManager : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     explicit ProjectFilterManager(QObject* parent = nullptr);
0043     ~ProjectFilterManager() override;
0044 
0045     /**
0046      * @copydoc IProjectFilter::isValid
0047      */
0048     bool isValid(const Path& path, bool isFolder, IProject* project) const;
0049 
0050     /**
0051      * Manage the filters of the given project.
0052      */
0053     void add(IProject* project);
0054 
0055     /**
0056      * Remove the managed filters of the given project.
0057      */
0058     void remove(IProject* project);
0059 
0060     /**
0061      * TODO: remove this once the cmake manager got cleaned up to not need this
0062      *       anymore.
0063      *
0064      * @return true if the project is managed, false otherwise.
0065      */
0066     bool isManaged(IProject* project) const;
0067 
0068     /**
0069      * @return the current list of project filters for a given managed project.
0070      *
0071      * This can be used to implement a thread safe project filtering
0072      */
0073     QVector<QSharedPointer<IProjectFilter> > filtersForProject(IProject* project) const;
0074 
0075 private:
0076     const QScopedPointer<class ProjectFilterManagerPrivate> d_ptr;
0077     Q_DECLARE_PRIVATE(ProjectFilterManager)
0078 
0079     Q_PRIVATE_SLOT(d_func(), void filterChanged( KDevelop::IProjectFilterProvider*, KDevelop::IProject* ) )
0080 };
0081 
0082 }
0083 
0084 #endif // KDEVPLATFORM_PROJECTFILTERMANAGER_H