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

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_IOUTPUTVIEW_H
0008 #define KDEVPLATFORM_IOUTPUTVIEW_H
0009 
0010 #include <QMetaType>
0011 #include <QFlags>
0012 #include <QIcon>
0013 #include <QtPlugin>
0014 
0015 #include "outputviewexport.h"
0016 
0017 class QString;
0018 class QAbstractItemModel;
0019 class QModelIndex;
0020 class QAbstractItemDelegate;
0021 class QAction;
0022 
0023 /**
0024 @author Andreas Pakulat
0025 */
0026 namespace KDevelop
0027 {
0028 
0029 class KDEVPLATFORMOUTPUTVIEW_EXPORT IOutputView
0030 {
0031 public:
0032 
0033     enum Behaviour
0034     {
0035         AllowUserClose = 0x1 /**< allow the user to close the view */,
0036         AlwaysShowView = 0x2 /**< always show the view */,
0037         AutoScroll     = 0x4 /**< automatically scroll the view */
0038     };
0039     Q_DECLARE_FLAGS(Behaviours, Behaviour)
0040 
0041     enum Option
0042     {
0043         NoOptions = 0x0,
0044         ShowItemsButton = 0x1 /**< show the two buttons (select and focus) */,
0045         AddFilterAction = 0x2 /**< add a filter action */
0046     };
0047     Q_DECLARE_FLAGS(Options, Option)
0048 
0049     enum ViewType
0050     {
0051         OneView      = 0 /**< there's only one outputview, newly registered outputs will replace existing ones */,
0052         HistoryView  = 1 /**< The tool view will have a history with forward/backward buttons */,
0053         MultipleView = 2 /**< show multiples outputs in a tool view at the same time */
0054     };
0055 
0056     enum StandardToolView
0057     {
0058         BuildView = 0 /**< the standard outputview for building output */,
0059         RunView =   1 /**< the standard outputview for running apps */,
0060         DebugView = 2 /**< the standard outputview for debugging apps */,
0061         TestView  = 4 /**< the standard outputview for verbose test output */,
0062         VcsView   = 8 /**< the standard outputview for VCS commands */
0063     };
0064 
0065     virtual ~IOutputView();
0066 
0067     /**
0068      * Fetch the identifier for one of the standard tool views.
0069      * This will automatically create the tool view if it doesn't exist yet
0070      * @param view the standard tool view to get the identifier for
0071      * @returns the identifier for the standard tool view
0072      */
0073     virtual int standardToolView( StandardToolView view ) = 0;
0074 
0075     /**
0076      * Register a new tool view for output with the given title, behaviour and type.
0077      * If there already exists a tool view with this title and type return the existing id
0078      * @param configSubgroupName the name of the config group used to save settings related to the view.
0079      *                           An empty name disables settings for the tool view.
0080      * @param title the Title to be displayed on the tool view
0081      * @param type the type of view that should be created
0082      * @param icon the icon of the tool view
0083      * @param option the options of the tool view
0084      * @param actionList list of actions adding to the toolbar
0085      * @returns an tool view id that identifies the new view and is used in the other
0086      *          methods
0087      */
0088     virtual int registerToolView(const QByteArray& configSubgroupName, const QString& title, ViewType type = OneView,
0089                                  const QIcon& icon = QIcon(), Options option = ShowItemsButton,
0090                                  const QList<QAction*>& actionList = QList<QAction*>()) = 0;
0091 
0092     /**
0093      * Register a new output view in a given tool view. How this new view is created depends
0094      * on the type of the tool view.
0095      * @param toolViewId the id of the tool view, created by registerToolView
0096      * @param title the title to use for the new output in the tool view
0097      * @param behaviour the Behaviour of the output
0098      * @returns the id of the output to supply to the other methods
0099      */
0100     virtual int registerOutputInToolView( int toolViewId, const QString& title,
0101                                           Behaviours behaviour = AllowUserClose ) = 0;
0102 
0103     /**
0104      * Raise a given view
0105      */
0106     virtual void raiseOutput( int outputId ) = 0;
0107 
0108     virtual void scrollOutputTo( int outputId, const QModelIndex& ) = 0;
0109 
0110     /**
0111      * Sets the model of the registered output identified by @p outputId to @p model.
0112      *
0113      * Does nothing if the id doesn't exist. The output view takes ownership of the model.
0114      *
0115      * NOTE: Do not reuse the same model for different views.
0116      */
0117     virtual void setModel( int outputId, QAbstractItemModel* model ) = 0;
0118     /**
0119      * Sets the item delegate of the registered output identified by @p outputId to @p delegate.
0120      *
0121      * Does nothing if the id doesn't exist. The output view takes ownership of the delegate.
0122      *
0123      * NOTE: Do not reuse the same delegate for different views.
0124      */
0125     virtual void setDelegate( int outputId, QAbstractItemDelegate* model ) = 0;
0126 
0127     /**
0128      * Sets a @p title for the specified @p outputIds
0129      */
0130     virtual void setTitle( int outputId, const QString& title ) = 0;
0131 
0132     /**
0133      * Remove a tool view, don't forget to emit toolViewRemoved when you implement this.
0134      *
0135      * @param toolViewId identifies the view to remove
0136      */
0137     virtual void removeToolView(int toolViewId) = 0;
0138 
0139     /**
0140      * Remove an output view from a tool view. Don't forget to emit outputRemoved
0141      * when you implement this.
0142      * @param outputId the id of the outputview to remove
0143      */
0144     virtual void removeOutput( int outputId ) = 0;
0145 
0146 Q_SIGNALS:
0147     /**
0148      * Emitted after a tool view was removed.
0149      *
0150      * @param toolViewId identifies the removed tool view
0151      */
0152     void toolViewRemoved(int toolViewId);
0153 
0154     /**
0155      * Emitted after a tool view was removed.
0156      *
0157      * @param toolViewId identifies the removed tool view
0158      * @param outputId identifies the removed output
0159      */
0160     void outputRemoved(int toolViewId, int outputId);
0161 };
0162 
0163 Q_DECLARE_OPERATORS_FOR_FLAGS(IOutputView::Behaviours)
0164 Q_DECLARE_OPERATORS_FOR_FLAGS(IOutputView::Options)
0165 } // namespace KDevelop
0166 
0167 Q_DECLARE_METATYPE(KDevelop::IOutputView::StandardToolView)
0168 
0169 Q_DECLARE_INTERFACE( KDevelop::IOutputView, "org.kdevelop.IOutputView" )
0170 
0171 #endif