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

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003     SPDX-FileCopyrightText: 2007 Dukju Ahn <dukjuahn@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_PLUGIN_OUTPUTWIDGET_H
0009 #define KDEVPLATFORM_PLUGIN_OUTPUTWIDGET_H
0010 
0011 #include <QHash>
0012 #include <QRegularExpression>
0013 #include <QWidget>
0014 
0015 #include <interfaces/itoolviewactionlistener.h>
0016 #include <outputview/ioutputviewmodel.h>
0017 #include <outputview/ioutputview.h>
0018 
0019 class KExpandableLineEdit;
0020 class KToggleAction;
0021 class StandardOutputViewTest;
0022 class QAction;
0023 class QAbstractItemView;
0024 class QLineEdit;
0025 class QModelIndex;
0026 class QSortFilterProxyModel;
0027 class QStackedWidget;
0028 class QString;
0029 class QTabWidget;
0030 class QToolButton;
0031 class QTreeView;
0032 class QWidgetAction;
0033 class ToolViewData;
0034 class OutputWidgetConfig;
0035 
0036 class OutputWidget : public QWidget, public KDevelop::IToolViewActionListener
0037 {
0038     Q_OBJECT
0039     Q_INTERFACES(KDevelop::IToolViewActionListener)
0040 
0041     friend class StandardOutputViewTest;
0042 
0043 public:
0044     OutputWidget(QWidget* parent, const ToolViewData* data);
0045     ~OutputWidget() override;
0046 
0047     void removeOutput( int id );
0048     void raiseOutput( int id );
0049 public Q_SLOTS:
0050     void addOutput( int id );
0051     void changeModel( int id );
0052     void changeDelegate( int id );
0053     void closeActiveView();
0054     void closeOtherViews();
0055     void selectFirstItem();
0056     void selectNextItem() override;
0057     void selectPreviousItem() override;
0058     void selectLastItem();
0059     void activate(const QModelIndex&);
0060     void scrollToIndex( const QModelIndex& );
0061     void setTitle(int outputId, const QString& title);
0062 
0063 Q_SIGNALS:
0064     void outputRemoved( int, int );
0065 
0066 private Q_SLOTS:
0067     void nextOutput();
0068     void previousOutput();
0069     void setWordWrap(bool);
0070     void copySelection();
0071     void selectAll();
0072     void outputFilter(const QString& filter);
0073     void updateFilter(int index);
0074     void currentViewChanged(int index);
0075     void clearModel();
0076 
0077 private:
0078     enum SelectionMode {
0079         Last,
0080         Next,
0081         Previous,
0082         First
0083     };
0084     void selectItem(SelectionMode selectionMode);
0085 
0086     QTreeView* createListView(int id);
0087     void setCurrentWidget( QTreeView* view );
0088     QWidget* currentWidget() const;
0089     void enableActions();
0090     KDevelop::IOutputViewModel* outputViewModel() const;
0091     QAbstractItemView* outputView() const;
0092     void activateIndex(const QModelIndex& index, QAbstractItemView* view, KDevelop::IOutputViewModel* iface);
0093     void eventuallyDoFocus();
0094     int currentOutputIndex();
0095 
0096     /**
0097      * Closes @p view and destroys all associated objects
0098      * @param view a nonnull widget in @a m_tabwidget or @a m_stackwidget
0099      * @return @c true if the view was closed successfully, @c false otherwise
0100      */
0101     bool closeView(const QWidget* view);
0102 
0103     template<class ViewContainer>
0104     void closeFirstViewIfTooMany(const ViewContainer& viewContainer);
0105     template<class ViewContainer>
0106     void closeFirstViewsWhileTooMany(const ViewContainer& viewContainer, int maxViewCount);
0107 
0108     struct FilteredView {
0109         QTreeView* view = nullptr;
0110         QSortFilterProxyModel* proxyModel = nullptr;
0111         /// Contains possibly invalid pattern entered by the user verbatim, which may differ
0112         /// from always valid (if proxyModel != nullptr) proxyModel->filterRegularExpression().
0113         QRegularExpression filter;
0114     };
0115     using FilteredViews = QHash<int, FilteredView>;
0116 
0117     static FilteredViews::const_iterator constIterator(FilteredViews::iterator it);
0118     template<typename ForwardIt>
0119     static ForwardIt findFilteredView(ForwardIt first, ForwardIt last, const QAbstractItemView* view);
0120 
0121     FilteredViews::iterator findFilteredView(const QAbstractItemView* view);
0122     FilteredViews::const_iterator constFindFilteredView(const QAbstractItemView* view) const;
0123 
0124     void updateFilterInputAppearance(FilteredViews::const_iterator currentView);
0125 
0126     FilteredViews m_views;
0127     QTabWidget* m_tabwidget;
0128     QStackedWidget* m_stackwidget;
0129     const ToolViewData* data;
0130     QToolButton* m_closeButton;
0131     QAction* m_closeOthersAction;
0132     QAction* m_nextAction;
0133     QAction* m_previousAction;
0134     KToggleAction* m_activateOnSelect;
0135     KToggleAction* m_focusOnSelect;
0136     KExpandableLineEdit* m_filterInput;
0137     QWidgetAction* m_filterAction;
0138     OutputWidgetConfig* m_outputWidgetConfig;
0139     bool m_wordWrap = false;
0140 };
0141 
0142 #endif
0143