1 /*
2     SPDX-License-Identifier: GPL-2.0-only
3     SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org>
4  */
5 
6 #ifndef ACTION_DATA_GROUP_H
7 #define ACTION_DATA_GROUP_H
8 
9 #include "action_data_base.h"
10 #include "actions/actions.h"
11 #include "triggers/triggers.h"
12 
13 #include "QList"
14 
15 
16 namespace KHotKeys
17 {
18 /**
19  * A group of \c ActionDataBase objects
20  *
21  * # The group can contain actions or action groups.
22  * # The group has its own list of conditions. These conditions apply to all children.
23  */
24 class Q_DECL_EXPORT ActionDataGroup : public ActionDataBase
25 {
26     Q_OBJECT
27 
28 public:
29     enum system_group_t {
30         SYSTEM_NONE, //!< TODO
31         SYSTEM_MENUENTRIES, //!< Shortcuts for menu entries.
32         SYSTEM_ROOT, //!< TODO
33         /* last one*/ SYSTEM_MAX, //!< End of enum marker
34     }; // don't remove entries
35 
36     /**
37      * Create a \c ActionDataGroup object.
38      *
39      * \param parent_P  A ActionDataGroup or 0. If provided this action is
40      *        registered with the group.
41      * \param name_P    Name for the object.
42      * \param comment_P Comment for the object.
43      * \param condition_P Conditions for the object or 0
44      * \param system_group_t Group type
45      * \param enabled_P Is the action enabled?
46      */
47     ActionDataGroup(ActionDataGroup *parent_P,
48                     const QString &name_P = QString(),
49                     const QString &comment_P = QString(),
50                     Condition_list *conditions_P = nullptr,
51                     system_group_t system_group_P = SYSTEM_NONE);
52 
53     virtual ~ActionDataGroup();
54 
55     /**
56      * Visitor pattern
57      */
58     void accept(ActionDataVisitor *visitor) Q_DECL_OVERRIDE;
59     void accept(ActionDataConstVisitor *visitor) const Q_DECL_OVERRIDE;
60 
61     void update_triggers() Q_DECL_OVERRIDE;
62 
63     /**
64      * What kind of actions are allowed for this group?
65      */
66     Action::ActionTypes allowedActionTypes() const;
67 
68     /**
69      * What kind of trigger are allowed for this group?
70      */
71     Trigger::TriggerTypes allowedTriggerTypes() const;
72 
73     /**
74      * Get a shallow copy of the list of children.
75      */
76     const QList<ActionDataBase *> children() const;
77 
78     /**
79      * Number of children.
80      */
81     int size() const;
82 
83     /**
84      * @reimp
85      */
86     void aboutToBeErased() Q_DECL_OVERRIDE;
87 
88     /**
89      * Is this a system group?
90      *
91      * @{
92      */
93     bool is_system_group() const;
94     system_group_t system_group() const;
95     void set_system_group(system_group_t group);
96     //@}
97 
98     // CHECKME : Why this?
99     using ActionDataBase::set_conditions; // make public
100 
101     //! Add a child to this collection
102     void add_child(ActionDataBase *child_P, int position);
103 
104     //! Add a child to this collection
105     void add_child(ActionDataBase *child_P);
106 
107     //! Remove a child from this collection
108     void remove_child(ActionDataBase *child_P);
109 
110 Q_SIGNALS:
111 
112     void stateChanged(bool isEnabled);
113 
114 protected:
115     //! The children
116     QList<ActionDataBase *> _list;
117 
118     //! System group type
119     system_group_t _system_group; // e.g. menuedit entries, can't be deleted or renamed
120 
121     void doEnable() Q_DECL_OVERRIDE;
122 
123     void doDisable() Q_DECL_OVERRIDE;
124 };
125 
126 } // namespace KHotKeys
127 
128 #endif
129