1 /*
2     SPDX-FileCopyrightText: 2010 Silvère Lestang <silvere.lestang@gmail.com>
3     SPDX-FileCopyrightText: 2010 Julien Desgats <julien.desgats@gmail.com>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef KDEVPLATFORM_PLUGIN_GREPOUTPUTVIEW_H
9 #define KDEVPLATFORM_PLUGIN_GREPOUTPUTVIEW_H
10 
11 #include <QList>
12 
13 #include <interfaces/iuicontroller.h>
14 #include <interfaces/itoolviewactionlistener.h>
15 
16 #include "ui_grepoutputview.h"
17 
18 namespace KDevelop
19 {
20     class IStatus;
21 }
22 
23 class QModelIndex;
24 
25 class GrepViewPlugin;
26 class GrepOutputModel;
27 struct GrepJobSettings;
28 
29 class GrepOutputViewFactory: public KDevelop::IToolViewFactory
30 {
31 public:
32     explicit GrepOutputViewFactory(GrepViewPlugin* plugin);
33     QWidget* create(QWidget* parent = nullptr) override;
34     Qt::DockWidgetArea defaultPosition() const override;
35     QString id() const override;
36 private:
37     GrepViewPlugin* m_plugin;
38 };
39 
40 class GrepOutputView : public QWidget, Ui::GrepOutputView, public KDevelop::IToolViewActionListener
41 {
42     Q_OBJECT
43     Q_INTERFACES(KDevelop::IToolViewActionListener)
44 
45 public:
46     enum MessageType {
47         Information,
48         Error
49     };
50 
51     GrepOutputView(QWidget* parent, GrepViewPlugin* plugin);
52     ~GrepOutputView() override;
53     GrepOutputModel* model();
54 
55     /**
56      * This causes the creation of a new model, the old one is kept in model history.
57      * Oldest models are deleted if needed.
58      * @return pointer to the new model
59      */
60     GrepOutputModel* renewModel(const GrepJobSettings& settings, const QString& description);
61 
62     void setMessage(const QString& msg, MessageType type = Information);
63 
64 public Q_SLOTS:
65     void showErrorMessage( const QString& errorMessage );
66     void showMessage( KDevelop::IStatus*, const QString& message );
67     void updateApplyState(const QModelIndex &topLeft, const QModelIndex &bottomRight);
68     void changeModel(int index);
69     void replacementTextChanged();
70 
71 Q_SIGNALS:
72     void outputViewIsClosed();
73 
74 private:
75     static const int HISTORY_SIZE;
76     QAction* m_next;
77     QAction* m_prev;
78     QAction* m_collapseAll;
79     QAction* m_expandAll;
80     QAction* m_refresh;
81     QAction* m_clearSearchHistory;
82     QLabel*  m_statusLabel;
83     GrepViewPlugin *m_plugin;
84     QVector<GrepJobSettings> m_settingsHistory;
85 
86 private Q_SLOTS:
87     void selectPreviousItem() override;
88     void selectNextItem() override;
89     void collapseAllItems();
90     void expandAllItems();
91     void onApply();
92     void showDialog();
93     void refresh();
94     void expandElements( const QModelIndex & parent );
95     void updateButtonState(bool enable);
96     void rowsRemoved();
97     void clearSearchHistory();
98     void modelSelectorContextMenu(const QPoint& pos);
99     void updateScrollArea();
100     void updateCheckable();
101 };
102 
103 #endif // KDEVPLATFORM_PLUGIN_GREPOUTPUTVIEW_H
104