File indexing completed on 2024-12-08 13:18:51

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-only
0003     SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org>
0004  */
0005 
0006 #ifndef ACTION_DATA_GROUP_H
0007 #define ACTION_DATA_GROUP_H
0008 
0009 #include "action_data_base.h"
0010 #include "actions/actions.h"
0011 #include "triggers/triggers.h"
0012 
0013 #include "QList"
0014 
0015 
0016 namespace KHotKeys
0017 {
0018 /**
0019  * A group of \c ActionDataBase objects
0020  *
0021  * # The group can contain actions or action groups.
0022  * # The group has its own list of conditions. These conditions apply to all children.
0023  */
0024 class Q_DECL_EXPORT ActionDataGroup : public ActionDataBase
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     enum system_group_t {
0030         SYSTEM_NONE, //!< TODO
0031         SYSTEM_MENUENTRIES, //!< Shortcuts for menu entries.
0032         SYSTEM_ROOT, //!< TODO
0033         /* last one*/ SYSTEM_MAX, //!< End of enum marker
0034     }; // don't remove entries
0035 
0036     /**
0037      * Create a \c ActionDataGroup object.
0038      *
0039      * \param parent_P  A ActionDataGroup or 0. If provided this action is
0040      *        registered with the group.
0041      * \param name_P    Name for the object.
0042      * \param comment_P Comment for the object.
0043      * \param condition_P Conditions for the object or 0
0044      * \param system_group_t Group type
0045      * \param enabled_P Is the action enabled?
0046      */
0047     ActionDataGroup(ActionDataGroup *parent_P,
0048                     const QString &name_P = QString(),
0049                     const QString &comment_P = QString(),
0050                     Condition_list *conditions_P = nullptr,
0051                     system_group_t system_group_P = SYSTEM_NONE);
0052 
0053     ~ActionDataGroup() override;
0054 
0055     /**
0056      * Visitor pattern
0057      */
0058     void accept(ActionDataVisitor *visitor) override;
0059     void accept(ActionDataConstVisitor *visitor) const override;
0060 
0061     void update_triggers() override;
0062 
0063     /**
0064      * What kind of actions are allowed for this group?
0065      */
0066     Action::ActionTypes allowedActionTypes() const;
0067 
0068     /**
0069      * What kind of trigger are allowed for this group?
0070      */
0071     Trigger::TriggerTypes allowedTriggerTypes() const;
0072 
0073     /**
0074      * Get a shallow copy of the list of children.
0075      */
0076     const QList<ActionDataBase *> children() const;
0077 
0078     /**
0079      * Number of children.
0080      */
0081     int size() const;
0082 
0083     /**
0084      * @reimp
0085      */
0086     void aboutToBeErased() override;
0087 
0088     /**
0089      * Is this a system group?
0090      *
0091      * @{
0092      */
0093     bool is_system_group() const;
0094     system_group_t system_group() const;
0095     void set_system_group(system_group_t group);
0096     //@}
0097 
0098     // CHECKME : Why this?
0099     using ActionDataBase::set_conditions; // make public
0100 
0101     //! Add a child to this collection
0102     void add_child(ActionDataBase *child_P, int position);
0103 
0104     //! Add a child to this collection
0105     void add_child(ActionDataBase *child_P);
0106 
0107     //! Remove a child from this collection
0108     void remove_child(ActionDataBase *child_P);
0109 
0110 Q_SIGNALS:
0111 
0112     void stateChanged(bool isEnabled);
0113 
0114 protected:
0115     //! The children
0116     QList<ActionDataBase *> _list;
0117 
0118     //! System group type
0119     system_group_t _system_group; // e.g. menuedit entries, can't be deleted or renamed
0120 
0121     void doEnable() override;
0122 
0123     void doDisable() override;
0124 };
0125 
0126 } // namespace KHotKeys
0127 
0128 #endif