File indexing completed on 2024-05-05 04:40:14

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 PROBLEMSVIEW_H
0008 #define PROBLEMSVIEW_H
0009 
0010 #include <interfaces/itoolviewactionlistener.h>
0011 
0012 #include <problemconstants.h>
0013 
0014 #include <QWidget>
0015 
0016 class ProblemTreeView;
0017 
0018 class KActionMenu;
0019 class KExpandableLineEdit;
0020 
0021 class QAction;
0022 class QActionGroup;
0023 class QLineEdit;
0024 class QTabWidget;
0025 
0026 namespace KDevelop
0027 {
0028 
0029 struct ModelData;
0030 
0031 /**
0032  * @brief Provides a tabbed view for models in the ProblemModelSet.
0033  *
0034  *
0035  * Also provides a toolbar for actions for the models and shows the number of messages in each tab's text.
0036  * When the load() method is called it looks up the models in the ProblemModelSet.
0037  * For each model it creates a treeview, which is then added to the tabbed view and a new tab.
0038  * The tab's text will be the name of the model + the number of items in the treeview.
0039  */
0040 class ProblemsView : public QWidget, public IToolViewActionListener
0041 {
0042     Q_OBJECT
0043     Q_INTERFACES(KDevelop::IToolViewActionListener)
0044 
0045 public:
0046     explicit ProblemsView(QWidget* parent = nullptr);
0047     ~ProblemsView() override;
0048 
0049     /// Load all the current models and create tabs for them
0050     void load();
0051 
0052 public Q_SLOTS:
0053     /// Triggered when a new model is added to the ModelSet
0054     void onModelAdded(const ModelData& data);
0055 
0056     /// Triggered when a model is removed from the ModelSet
0057     void onModelRemoved(const QString& id);
0058 
0059     /// Triggered when the user (or program) selects a new tab
0060     void onCurrentChanged(int idx);
0061 
0062     /// Triggered when a view changes (happens when the model data changes)
0063     void onViewChanged();
0064 
0065     /// Open tab for selected model
0066     void showModel(const QString& id);
0067 
0068     void selectNextItem() override;
0069     void selectPreviousItem() override;
0070 
0071 private:
0072     ProblemTreeView* currentView() const;
0073 
0074     void setupActions();
0075     void updateActions();
0076 
0077     void handleSeverityActionToggled();
0078     void setScope(ProblemScope scope);
0079 
0080     /// Create a view for the model and add to the tabbed widget
0081     void addModel(const ModelData& data);
0082 
0083     /// Update the tab's text (name + number of problems in that tab)
0084     void updateTab(int idx, int rows);
0085 
0086     QTabWidget* m_tabWidget;
0087 
0088     KActionMenu* m_scopeMenu = nullptr;
0089     KActionMenu* m_groupingMenu = nullptr;
0090     QAction* m_fullUpdateAction = nullptr;
0091     QAction* m_showImportsAction = nullptr;
0092     QActionGroup* m_severityActions = nullptr;
0093     QAction* m_currentDocumentAction = nullptr;
0094     QAction* m_showAllAction = nullptr;
0095     QAction* m_errorSeverityAction = nullptr;
0096     QAction* m_warningSeverityAction = nullptr;
0097     QAction* m_hintSeverityAction = nullptr;
0098 
0099     void setFilter(const QString& filterText);
0100     void setFilter(const QString& filterText, int tabIdx);
0101 
0102     KExpandableLineEdit* m_filterEdit;
0103     int m_prevTabIdx;
0104     QVector<ModelData> m_models;
0105 };
0106 }
0107 
0108 #endif