]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQTree.h
- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / YQTree.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQTree.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQTree_h
21 #define YQTree_h
22
23 #include <QFrame>
24 #include <QTreeWidget>
25
26 #include "YTree.h"
27
28
29 class YQWidgetCaption;
30 class YQTreeItem;
31
32
33 class YQTree : public QFrame, public YTree
34 {
35     Q_OBJECT
36
37 public:
38
39     /**
40      * Constructor.
41      **/
42     YQTree( YWidget * parent, const string & label );
43
44     /**
45      * Destructor.
46      **/
47     virtual ~YQTree();
48
49     /**
50      * Change the label text.
51      *
52      * Reimplemented from YSelectionWidget.
53      **/
54     virtual void setLabel( const string & label );
55
56     /**
57      * Rebuild the displayed tree from the internally stored YTreeItems.
58      *
59      * The application should call this (once) after all items have been added
60      * with addItem(). YTree::addItems() calls this automatically.
61      *
62      * Implemented from YTree.
63      **/
64     virtual void rebuildTree();
65
66     /**
67      * Select or deselect an item.
68      *
69      * Reimplemented from YSelectionWidget.
70      **/
71     virtual void selectItem( YItem * item, bool selected = true );
72
73     /**
74      * Deselect all items.
75      *
76      * Reimplemented from YSelectionWidget.
77      **/
78     virtual void deselectAllItems();
79
80     /**
81      * Delete all items.
82      *
83      * Reimplemented from YSelectionWidget.
84      **/
85     virtual void deleteAllItems();
86
87     /**
88      * Set enabled/disbled state.
89      *
90      * Reimplemented from YWidget.
91      **/
92     virtual void setEnabled( bool enabled );
93
94     /**
95      * Preferred width of the widget.
96      *
97      * Reimplemented from YWidget.
98      **/
99     virtual int preferredWidth();
100
101     /**
102      * Preferred height of the widget.
103      *
104      * Reimplemented from YWidget.
105      **/
106     virtual int preferredHeight();
107
108     /**
109      * Set the new size of the widget.
110      *
111      * Reimplemented from YWidget.
112      **/
113     virtual void setSize( int newWidth, int newHeight );
114
115     /**
116      * Accept the keyboard focus.
117      **/
118     virtual bool setKeyboardFocus();
119
120
121 protected slots:
122
123     /**
124      * Propagate a tree item selection.
125      *
126      * This will trigger a 'SelectionChanged' event if 'notify' is set.
127      **/
128     void slotSelectionChanged ( );
129
130     /**
131      * Propagate a double click or pressing the space key on a tree item.
132      *
133      * This will trigger an 'Activated' event if 'notify' is set.
134      **/
135     void slotActivated( QTreeWidgetItem * item);
136
137
138 protected:
139
140     /**
141      * Select an item via the corresponding YQTreItem.
142      **/
143     void selectItem( YQTreeItem * item );
144
145     /**
146      * Open the branch of 'item' recursively to its toplevel item.
147      **/
148     void openBranch( QTreeWidgetItem * item );
149
150     /**
151      * Build a tree of items that will be displayed (YQTreeItems) from the
152      * original items between iterators 'begin' and 'end' as child items of
153      * 'parentItem' (or as toplevel items if 'parentItem' is 0).
154      **/
155     void buildDisplayTree( YQTreeItem *         parentItem,
156                            YItemIterator        begin,
157                            YItemIterator        end );
158
159     //
160     // Data members
161     //
162
163     YQWidgetCaption *   _caption;
164     QTreeWidget *       _qt_listView;
165     int                 _nextSerialNo;
166 };
167
168
169 class YQTreeItem: public QTreeWidgetItem
170 {
171 public:
172
173     /**
174      * Constructor for a top level item.
175      **/
176     YQTreeItem( YQTree  *       tree,
177                 QTreeWidget *   parent,
178                 YTreeItem *     origItem,
179                 int             serial  );
180
181     /**
182      * Constructor for a non-top level item.
183      **/
184     YQTreeItem( YQTree  *       tree,
185                 YQTreeItem *    parent,
186                 YTreeItem *     origItem,
187                 int             serial  );
188
189     /**
190      * Returns the original YTreeItem of which this item is a clone.
191      **/
192     YTreeItem * origItem() { return _origItem; }
193
194     /**
195      * Open this item.
196      *
197      * Reimplemented from QTreeWidgetItem.
198      **/
199     virtual void setOpen( bool open );
200
201
202 private:
203
204     /**
205      * Init function. All constructors end up here.
206      **/
207     void init( YQTree *         tree,
208                YTreeItem *      yTreeItem,
209                int              serial );
210
211
212 protected:
213
214     /**
215      * Sort key of this item.
216      *
217      * Reimplemented from QTreeWidgetItem.
218      **/
219     QString key( int column, bool ascending ) const;
220
221
222     //
223     // Data members
224     //
225
226     YQTree *    _tree;
227     YTreeItem * _origItem;
228     int         _serialNo;
229
230 };
231
232
233 #endif // ifndef YQTree_h