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

0001 /*
0002     SPDX-FileCopyrightText: 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef PROBLEMMODELSET_H
0008 #define PROBLEMMODELSET_H
0009 
0010 #include <shell/shellexport.h>
0011 #include <QObject>
0012 
0013 namespace KDevelop
0014 {
0015 
0016 class ProblemModel;
0017 class ProblemModelSetPrivate;
0018 
0019 /// Struct that handles the model and it's name as one unit, stored in ProblemModelSet
0020 struct ModelData
0021 {
0022     QString id;
0023     QString name;
0024     ProblemModel *model;
0025 };
0026 
0027 /**
0028  * @brief Stores name/model pairs and emits signals when they are added/removed.
0029  *
0030  * Typically it's used from plugins, which maintains a reference to the model added.
0031  * Therefore It assumes that models get removed, so it doesn't delete!
0032  *
0033  * Usage example:
0034  * @code
0035  * ProblemModelSet *set = new ProblemModelSet();
0036  * ProblemModel *model = new ProblemModel(nullptr);
0037  * set->addModel(QStringLiteral("MODEL_ID"), QStringLiteral("MODEL"), model); // added() signal is emitted
0038  * set->models().count(); // returns 1
0039  * set->findModel(QStringLiteral("MODEL_ID")); // returns the model just added
0040  * set->removeModel(QStringLiteral("MODEL_ID")); // removed() signal is emitted
0041  * @endcode
0042  *
0043  */
0044 class KDEVPLATFORMSHELL_EXPORT ProblemModelSet : public QObject
0045 {
0046     Q_OBJECT
0047 public:
0048     explicit ProblemModelSet(QObject *parent = nullptr);
0049     ~ProblemModelSet() override;
0050 
0051     /// Adds a model
0052     void addModel(const QString &id, const QString &name, ProblemModel *model);
0053 
0054     /// Finds a model
0055     ProblemModel* findModel(const QString &id) const;
0056 
0057     /// Removes a model
0058     void removeModel(const QString &id);
0059 
0060     /// Show model in ProblemsView
0061     void showModel(const QString &id);
0062 
0063     /// Retrieves a list of models stored
0064     QVector<ModelData> models() const;
0065 
0066 Q_SIGNALS:
0067     /// Emitted when a new model is added
0068     void added(const ModelData &model);
0069 
0070     /// Emitted when a model is removed
0071     void removed(const QString &id);
0072 
0073     /// Emitted when showModel() is called
0074     void showRequested(const QString &id);
0075 
0076     /// Emitted when any model emits problemsChanged()
0077     void problemsChanged();
0078 
0079 private:
0080     const QScopedPointer<class ProblemModelSetPrivate> d_ptr;
0081     Q_DECLARE_PRIVATE(ProblemModelSet)
0082 };
0083 
0084 }
0085 
0086 Q_DECLARE_TYPEINFO(KDevelop::ModelData, Q_MOVABLE_TYPE);
0087 
0088 #endif
0089