File indexing completed on 2024-04-28 04:36:30

0001 /*
0002     SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_ISELECTIONCONTROLLER_H
0008 #define KDEVPLATFORM_ISELECTIONCONTROLLER_H
0009 
0010 #include <QObject>
0011 
0012 #include "interfacesexport.h"
0013 
0014 namespace KDevelop
0015 {
0016 
0017 class Context;
0018 
0019 /**
0020  * The main controller for selection updates in the GUI.
0021  *
0022  * This controller can be used by selection consumers and selection providers.
0023  *
0024  * A selection provider (for example a treeview for the projects) should
0025  * call updateSelection() with an appropriate context filled with the details
0026  * of the selection
0027  *
0028  * A selection consumer who is interested in notifications when the selection has
0029  * been changed, should connect to the selectionChanged signal. The consumer should
0030  * retrieve all necessary information that it might need to do something with the
0031  * selection and store those. Storing the whole Context* might be dangerous as it
0032  * will be deleted on the next selection change.
0033  *
0034  */
0035 class KDEVPLATFORMINTERFACES_EXPORT ISelectionController : public QObject
0036 {
0037     Q_OBJECT
0038 public:
0039     ///Constructor.
0040     explicit ISelectionController(QObject *parent);
0041     ~ISelectionController() override;
0042 
0043     /**
0044      * Provides the current selection, note that this might be 0
0045      */
0046     virtual Context* currentSelection() = 0;
0047 
0048 public Q_SLOTS:
0049     /**
0050      * updates the current selection.
0051      * The SelectionController takes ownership of the given context and
0052      * deletes it when the selection is updated the next time.
0053      * @param context the new selection
0054      */
0055     virtual void updateSelection( Context* context ) = 0;
0056 
0057 Q_SIGNALS:
0058     /**
0059      * Notify that the current selection changed.
0060      * @note The context might be deleted behind the back (when a new selection
0061      * is set) of the receivers of this signal, so make sure to copy all the
0062      * needed information.
0063      */
0064     void selectionChanged( KDevelop::Context* );
0065 
0066 };
0067 
0068 }
0069 
0070 #endif // KDEVPLATFORM_ISELECTIONCONTROLLER_H