File: selector.hpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (145 lines) | stat: -rw-r--r-- 4,424 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/************************************************************************
 *
 * Copyright (C) 2016-2024 IRCAD France
 * Copyright (C) 2016-2019 IHU Strasbourg
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#pragma once

#include <activity/extension/activity.hpp>
#include <activity/message.hpp>

#include <ui/__/editor.hpp>

#include <QButtonGroup>
#include <QObject>
#include <QPointer>

namespace sight::module::ui::qt::activity
{

/**
 * @brief This editor launches an activity according to the given configuration
 *
 * This editor proposes all the available activities according to the given configuration.
 * It sends a signal with the activity identifier when a button is pushed.
 *
 * It should work with the module::ui::qt::editor::wizard that creates or updates the activity.
 *
 * @section Signals Signals
 * - \b activity_id_selected(std::string) : This signal is emitted when the activity is selected, it
 *      contains all activity identifier. It should be connected to the slot 'createActivity' of the service
 *     'wizard'.
 * - \b load_requested() : This signal is emitted when the "load activity" button is pushed.
 *
 * @section XML XML Configuration
 *
 * @code{.xml}
   <service uid="editor_newActivity" type="sight::module::ui::qt::activity::selector" >
       <filter>
           <mode>include</mode>
           <id>activity_viz_negato</id>
           <id>3DVisualizationActivity</id>
           <id>VolumeRenderingActivity</id>
       </filter>
   </service>
   @endcode
 *
 * - \b filter (optional): it allows to filter the activity that can be proposed.
 *    - \b mode: 'include' or 'exclude'. Defines if the activity in the following list are proposed (include) or not
 *      (exclude).
 *    - \b id: id of the activity
 */
class selector : public QObject,
                 public sight::ui::editor
{
Q_OBJECT

public:

    SIGHT_DECLARE_SERVICE(selector, sight::ui::editor);

    /// Constructor. Do nothing.
    selector() noexcept;

    /// Destructor. Do nothing.
    ~selector() noexcept override;

    /**
     * @name Signals API
     * @{
     */
    static const core::com::signals::key_t ACTIVITY_ID_SELECTED_SIG;
    using activity_id_selected_signal_t = core::com::signal<void (std::string)>;

    static const core::com::signals::key_t LOAD_REQUESTED_SIG;
    using load_requested_signal_t = core::com::signal<void ()>;

    /// @}

protected:

    /// Initialize the editor.
    void configuring() override;

    /// This method launches the editor::starting method.
    void starting() override;

    /// This method launches the editor::stopping method.
    void stopping() override;

    /// Show activity selector.
    void updating() override;

    using keys_t = std::vector<std::string>;

private Q_SLOTS:

    void on_clicked(int _id);

private:

    /**
     * @brief Slots to launch the given activity.
     * @param _activity the activity to be launched.
     */
    void launch_activity(data::activity::sptr _activity);

    using activity_infos_t = sight::activity::extension::activity::infos_t;

    /// Returns enabled activity infos according to activity filter.
    activity_infos_t get_enabled_activities(const activity_infos_t& _infos);

    /**
     * @brief filter mode : include or exclude activity configurations.
     * @note Allowed values : 'include' or 'exclude'
     */
    std::string m_filter_mode;

    /// Id-s of activity configurations to be enabled or disabled, according to filter mode.
    keys_t m_keys;

    /// Informations used to launch activities
    activity_infos_t m_activities_info;

    /// Pointer on the buttons group
    QPointer<QButtonGroup> m_button_group;
};

} // namespace sight::module::ui::qt::activity