libyui
 
Loading...
Searching...
No Matches
YItem.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2000-2012 Novell, Inc
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: YItem.h
20
21 Author: Stefan Hundhammer <shundhammer@suse.de>
22
23/-*/
24
25#ifndef YItem_h
26#define YItem_h
27
28#include <string>
29#include <vector>
30#include <iosfwd>
31
32
33class YItem;
34
35// without "documenting" the file, typedefs will be dropped
37
39typedef std::vector<YItem *> YItemCollection;
40
42typedef YItemCollection::iterator YItemIterator;
43
45typedef YItemCollection::const_iterator YItemConstIterator;
46
47
55class YItem
56{
57public:
61 YItem( const std::string & label,
62 bool selected = false )
63 : _label( label )
64 , _status( selected ? 1 : 0 )
65 , _index( -1 )
66 , _data( 0 )
67 {}
68
72 YItem( const std::string & label,
73 const std::string & iconName,
74 bool selected = false )
75 : _label( label )
76 , _iconName( iconName )
77 , _status( selected ? 1 : 0 )
78 , _index( -1 )
79 , _data( 0 )
80 {}
81
85 virtual ~YItem() {}
86
91 virtual const char * itemClass() const { return "YItem"; }
92
97 std::string label() const { return _label; }
98
102 void setLabel( const std::string & newLabel ) { _label = newLabel; }
103
107 std::string iconName() const { return _iconName; }
108
112 bool hasIconName() const { return ! _iconName.empty(); }
113
117 void setIconName( const std::string & newIconName ) { _iconName = newIconName; }
118
122 bool selected() const { return _status != 0; }
123
129 void setSelected( bool sel = true ) { _status = sel ? 1 : 0; }
130
136 int status() const { return _status; }
137
143 void setStatus( int newStatus ) { _status = newStatus; }
144
148 void setIndex( int index ) { _index = index; }
149
153 int index() const { return _index; }
154
163 void setData( void * newData ) { _data = newData; }
164
168 void * data() const { return _data; }
169
170 //
171 // Children management stubs.
172 //
173 // Derived classes that can handle child items should reimplement those
174 // functions.
175 // The following default implementations don't do anything with children;
176 // they act as if this item didn't have any children.
177 //
178
182 virtual bool hasChildren() const { return false; }
183
201 virtual YItemIterator childrenBegin() { return _noChildren.end(); }
202 virtual YItemConstIterator childrenBegin() const { return _noChildren.end(); }
203
210 virtual YItemIterator childrenEnd() { return _noChildren.end(); }
211 virtual YItemConstIterator childrenEnd() const { return _noChildren.end(); }
212
218 virtual YItem * parent() const { return 0; }
219
224 virtual std::string debugLabel() const;
225
230 std::string limitLength( const std::string & text, int limit ) const;
231
232
233private:
234
235 std::string _label;
236 std::string _iconName;
237 int _status;
238 int _index;
239 void * _data;
240
245 static YItemCollection _noChildren;
246};
247
248
249std::ostream & operator<<( std::ostream & stream, const YItem * item );
250
251
252
253#endif // YItem_h
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
Definition YItem.h:45
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
Definition YItem.h:42
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
Definition YItem.h:39
Definition YItem.h:56
std::string label() const
Definition YItem.h:97
virtual const char * itemClass() const
Definition YItem.h:91
int status() const
Definition YItem.h:136
bool selected() const
Definition YItem.h:122
void setIconName(const std::string &newIconName)
Definition YItem.h:117
YItem(const std::string &label, bool selected=false)
Definition YItem.h:61
virtual YItem * parent() const
Definition YItem.h:218
virtual YItemIterator childrenBegin()
Definition YItem.h:201
std::string limitLength(const std::string &text, int limit) const
Definition YItem.cc:51
virtual ~YItem()
Definition YItem.h:85
void setLabel(const std::string &newLabel)
Definition YItem.h:102
bool hasIconName() const
Definition YItem.h:112
virtual std::string debugLabel() const
Definition YItem.cc:44
void setStatus(int newStatus)
Definition YItem.h:143
virtual bool hasChildren() const
Definition YItem.h:182
YItem(const std::string &label, const std::string &iconName, bool selected=false)
Definition YItem.h:72
int index() const
Definition YItem.h:153
void setSelected(bool sel=true)
Definition YItem.h:129
void * data() const
Definition YItem.h:168
void setIndex(int index)
Definition YItem.h:148
void setData(void *newData)
Definition YItem.h:163
virtual YItemIterator childrenEnd()
Definition YItem.h:210
std::string iconName() const
Definition YItem.h:107