libyui  3.10.0
YItemCustomStatus.h
1 /*
2  Copyright (c) [2019] SUSE LLC
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YItemCustomStatus.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef YItemCustomStatus_h
26 #define YItemCustomStatus_h
27 
28 #include <string>
29 #include <vector>
30 
31 
32 /**
33  * Class describing a non-binary status for an item.
34  *
35  * This is an extension of normal boolean item states: Rather than just "on" or
36  * "off" like for check boxes or radio buttons, a status of this kind can have
37  * any nonnegative integer number. The number is implicitly the index of this
38  * status in the corresponding vector.
39  *
40  * For symmetry with boolean states, a value of 0 is defined to have the same
41  * semantics as "off" / "unselected", 1 has the semantics of "on" / "fully
42  * selected", and all other values are purely application-defined.
43  **/
45 {
46 public:
47  /**
48  * Constructor.
49  **/
50  YItemCustomStatus( const std::string & iconName,
51  const std::string & textIndicator,
52  int nextStatus = -1 )
53  : _iconName( iconName )
54  , _textIndicator( textIndicator )
55  , _nextStatus( nextStatus )
56  {}
57 
58  /**
59  * The name of an icon to use in the widget in a graphical UI if an item
60  * has this status.
61  **/
62  const std::string & iconName() const { return _iconName; }
63 
64  /**
65  * A text representation of this status in a text-based UI if an item has
66  * this status, for example "[ ]", "[x]" or "[ ], "[ +]", "[a+]".
67  *
68  * It is recommended to use the same character length for all states so all
69  * items line up properly, even if they have different states.
70  **/
71  const std::string & textIndicator() const { return _textIndicator; }
72 
73  /**
74  * This returns the next status to cycle through if the user clicks on the
75  * status or cycles through status values with the corresponding shortcut
76  * key.
77  *
78  * If no such value was specified, this returns -1. The application can
79  * then still choose to set a different status depending on other
80  * application data.
81  **/
82  int nextStatus() const { return _nextStatus; }
83 
84  /**
85  * Set the next status. This should only be done once when the status
86  * transition map is evaluated.
87  **/
88  void setNextStatus( int value ) { _nextStatus = value; }
89 
90  /**
91  * Return 'true' if a next status to cylce to is defined for this status,
92  * 'false' if not.
93  **/
94  bool hasNextStatus() const { return _nextStatus != -1; }
95 
96 protected:
97 
98  std::string _iconName;
99  std::string _textIndicator;
100  int _nextStatus;
101 };
102 
103 
104 typedef std::vector<YItemCustomStatus> YItemCustomStatusVector;
105 
106 
107 #endif // YItemCustomStatus_h
YItemCustomStatus
Class describing a non-binary status for an item.
Definition: YItemCustomStatus.h:44
YItemCustomStatus::nextStatus
int nextStatus() const
This returns the next status to cycle through if the user clicks on the status or cycles through stat...
Definition: YItemCustomStatus.h:82
YItemCustomStatus::textIndicator
const std::string & textIndicator() const
A text representation of this status in a text-based UI if an item has this status,...
Definition: YItemCustomStatus.h:71
YItemCustomStatus::YItemCustomStatus
YItemCustomStatus(const std::string &iconName, const std::string &textIndicator, int nextStatus=-1)
Constructor.
Definition: YItemCustomStatus.h:50
YItemCustomStatus::iconName
const std::string & iconName() const
The name of an icon to use in the widget in a graphical UI if an item has this status.
Definition: YItemCustomStatus.h:62
YItemCustomStatus::setNextStatus
void setNextStatus(int value)
Set the next status.
Definition: YItemCustomStatus.h:88
YItemCustomStatus::hasNextStatus
bool hasNextStatus() const
Return 'true' if a next status to cylce to is defined for this status, 'false' if not.
Definition: YItemCustomStatus.h:94