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 PROBLEMSTORE_H 0008 #define PROBLEMSTORE_H 0009 0010 #include <QObject> 0011 #include <shell/shellexport.h> 0012 #include <interfaces/iproblem.h> 0013 0014 #include "problemconstants.h" 0015 0016 namespace KDevelop 0017 { 0018 0019 class WatchedDocumentSet; 0020 class ProblemStoreNode; 0021 class IndexedString; 0022 class ProblemStorePrivate; 0023 0024 /** 0025 * @brief Stores and handles problems. Does no ordering or filtering, those should be done in subclasses. 0026 * 0027 * Used to store problems that are ordered, filtered somewhere else. For example: DUChain problems gathered by ProblemReporter. 0028 * Stores the problems in ProblemStoreNodes. 0029 * When implementing a subclass, first and foremost the rebuild method needs to be implemented, which is called every time there's a change in scope and severity filter. 0030 * If grouping is desired then also the setGrouping method must be implemented. 0031 * ProblemStore depending on settings uses CurrentDocumentSet, OpenDocumentSet, CurrentProjectSet, or AllProjectSet for scope support (NOTE: Filtering still has to be implemented in either a subclass, or somewhere else). 0032 * When the scope changes it emits the changed() signal. 0033 * 0034 * Scope set / query methods: 0035 * \li setScope() 0036 * \li scope() 0037 * 0038 * Valid scope settings: 0039 * \li CurrentDocument 0040 * \li OpenDocuments 0041 * \li CurrentProject 0042 * \li AllProjects 0043 * \li BypassScopeFilter 0044 * 0045 * Usage example: 0046 * @code 0047 * QVector<IProblem::Ptr> problems; 0048 * // Add 4 problems 0049 * ... 0050 * ProblemStore *store = new ProblemStore(); 0051 * store->setProblems(problems); 0052 * store->count(); // Returns 4 0053 * 0054 * ProblemStoreNode *node = store->findNode(0); // Returns the node with the first problem 0055 * @endcode 0056 * 0057 */ 0058 class KDEVPLATFORMSHELL_EXPORT ProblemStore : public QObject 0059 { 0060 Q_OBJECT 0061 public: 0062 explicit ProblemStore(QObject *parent = nullptr); 0063 ~ProblemStore() override; 0064 0065 /// Adds a problem 0066 virtual void addProblem(const IProblem::Ptr &problem); 0067 0068 /// Clears the current problems, and adds new ones from a list 0069 virtual void setProblems(const QVector<IProblem::Ptr> &problems); 0070 0071 /// Retrieve problems for selected document 0072 QVector<IProblem::Ptr> problems(const KDevelop::IndexedString& document) const; 0073 0074 /// Finds the specified node 0075 virtual const ProblemStoreNode* findNode(int row, ProblemStoreNode *parent = nullptr) const; 0076 0077 /// Returns the number of problems 0078 virtual int count(ProblemStoreNode *parent = nullptr) const; 0079 0080 /// Clears the problems 0081 virtual void clear(); 0082 0083 /// Rebuild the problems list, if applicable. It does nothing in the base class. 0084 virtual void rebuild(); 0085 0086 /// Specifies the severity filter 0087 virtual void setSeverity(int severity);///old-style severity access 0088 0089 virtual void setSeverities(KDevelop::IProblem::Severities severities);///new-style severity access 0090 0091 /// Retrieves the severity filter settings 0092 int severity() const;///old-style severity access 0093 0094 KDevelop::IProblem::Severities severities() const;//new-style severity access 0095 0096 /// Retrieves the currently watched document set 0097 WatchedDocumentSet* documents() const; 0098 0099 /// Sets the scope filter 0100 void setScope(ProblemScope scope); 0101 0102 /// Returns the current scope 0103 ProblemScope scope() const; 0104 0105 /// Sets the grouping method 0106 virtual void setGrouping(int grouping); 0107 0108 /// Set 'show imports' filter value 0109 void setShowImports(bool showImports); 0110 0111 /// Retrieve 'show imports' filter setting 0112 int showImports() const; 0113 0114 /// Sets the currently shown document (in the editor, it's triggered by the IDE) 0115 void setCurrentDocument(const IndexedString &doc); 0116 0117 /// Retrieves the path of the current document 0118 const KDevelop::IndexedString& currentDocument() const; 0119 0120 /// Sets the path to a folder to be used by the ProblemScope::DocumentsInPath scope 0121 void setPathForDocumentsInPathScope(const QString& path); 0122 0123 /// Retrieves the path to the folder to be used by the ProblemScope::DocumentsInPath scope 0124 QString pathForDocumentsInPathScope() const; 0125 0126 Q_SIGNALS: 0127 /// Emitted when any store setting (grouping, scope, severity, document) is changed 0128 void changed(); 0129 0130 /// Emitted when the stored problems are changed with clear(), addProblem() and setProblems() 0131 /// methods. This signal emitted only when internal problems storage is really changed: 0132 /// for example, it is not emitted when we call clear() method for empty storage. 0133 void problemsChanged(); 0134 0135 /// Emitted before the problemlist is rebuilt 0136 void beginRebuild(); 0137 0138 /// Emitted once the problemlist has been rebuilt 0139 void endRebuild(); 0140 0141 private Q_SLOTS: 0142 /// Triggered when the watched document set changes. E.g.:document closed, new one added, etc 0143 virtual void onDocumentSetChanged(); 0144 0145 protected: 0146 ProblemStoreNode* rootNode() const; 0147 0148 private: 0149 const QScopedPointer<class ProblemStorePrivate> d_ptr; 0150 Q_DECLARE_PRIVATE(ProblemStore) 0151 }; 0152 0153 } 0154 0155 #endif 0156