File: text_status.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 (133 lines) | stat: -rw-r--r-- 4,521 bytes parent folder | download | duplicates (2)
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
/************************************************************************
 *
 * Copyright (C) 2017-2025 IRCAD France
 * Copyright (C) 2017-2020 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 <data/string_serializable.hpp>

#include <ui/__/editor.hpp>

#include <QLabel>
#include <QPointer>

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

/**
 * @brief This service is used to displays and update values (int, double or string) in a QLabel.
 * Values are set using slots or using a data::string input.
 *
 * @section Slots Slots
 * - \b set_int_parameter(int): display the value in the QLabel.
 * - \b set_double_parameter(double): display the value in the QLabel.
 * - \b set_bool_parameter(int): display the value in the QLabel.
 * - \b set_string_parameter(int): display the value in the QLabel.
 *
 * @section XML XML Configuration
 * @code{.xml}
    <service uid="..." type="sight::module::ui::qt::text_status">
        <in key="string" uid="..." />
        <label>my label</label>
        <suffix>units</suffix>
        <color>#FF0000</color>
        <decimals>2<decimals>
    </service>
   @endcode
 *
 * @subsection Input Input
 * - \b string(data::object, optional): data to display, should be displayable as a string, thus inheriting from
 * data::string_serializable.
 *
 * @subsection Configuration Configuration
 * - \b label (optional, default="") : text to show before the data
 * - \b suffix (optional, default="") : text to add after the data
 * - \b color (optional, default="red") : needed color of the displayed label in a CSS style as names (ex: red),
 * rgb/rgba (ex: rgb(0,255,137,0.3)) or hexadecimal (ex: #355C66).
 * - \b size (optional, default="14pt") : size of the font used in the label, as supported by 'font-size' QSS attribute
 * - \b weight (optional, default="bold") : normal, bold any value supported by 'font-weight' QSS attribute
 * - \b decimals (optional, default="2") : if a sight::data::real data is provided, number of decimals to display
 */
class text_status final : public QObject,
                          public sight::ui::editor
{
public:

    /// Generates default methods as New, dynamicCast, ...
    SIGHT_DECLARE_SERVICE(text_status, sight::ui::editor);

    /// Initializes slots and member.
    text_status();

    /// Destroys the service.
    ~text_status() override = default;

private:

    /// Configures the service.
    void configuring() override;

    /// Installs the layout and gets the input data if it exists and displays it.
    void starting() override;

    /// Gets the input data if it exists and displays it.
    void updating() override;

    /// Destroys the layout.
    void stopping() override;

    /**
     * @brief Proposals to connect service slots to associated object signals.
     * @return A map of each proposed connection.
     *
     * Connect data::object::MODIFIED_SIG of s_STRING_INPUT to service::slots::UPDATE
     */
    connections_t auto_connections() const override;

    /// Sets the interger to display.
    void set_int_parameter(int _val);

    /// Sets the double to display.
    void set_double_parameter(double _val);

    /// Sets the boolean to display.
    void set_bool_parameter(bool _val);

    /// Sets the string to display.
    void set_string_parameter(std::string _val);

    /// Stores the label.
    QPointer<QLabel> m_label_value;

    /// Stores the static text to be displayed.
    QPointer<QLabel> m_label_static_text;

    /// Stores the suffix.
    QPointer<QLabel> m_suffix_value;

    /// Number of decimals if we display a float value
    int m_decimals {2};

    static constexpr std::string_view STRING_INPUT = "string";
    data::ptr<data::object, sight::data::access::in> m_string {this, STRING_INPUT, true};
};

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