picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / pkg / YQPkgRpmGroupTagsFilterView.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgRpmGroupTagsFilterView.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQPkgRpmGroupTagsFilterView_h
21 #define YQPkgRpmGroupTagsFilterView_h
22
23 #include "YQZypp.h"
24 #include <q3listview.h>
25 #include <YRpmGroupsTree.h>
26
27
28 using std::string;
29
30 class YQPkgRpmGroupTag;
31
32
33 /**
34  * @short RPM group tags filter view: Display the RPM group tags tree and emit
35  * signals if any group tag is selected so a package list can be filled or
36  * updated.
37  **/
38 class YQPkgRpmGroupTagsFilterView : public Q3ListView
39 {
40     Q_OBJECT
41
42 public:
43
44     /**
45      * Constructor
46      **/
47     YQPkgRpmGroupTagsFilterView( QWidget * parent );
48
49     /**
50      * Destructor
51      **/
52     virtual ~YQPkgRpmGroupTagsFilterView();
53
54     /**
55      * Returns the currently selected item or 0 if there is none.
56      **/
57     YQPkgRpmGroupTag * selection() const;
58
59     /**
60      * Check if 'pkg' matches the selected RPM group.
61      * Returns true if there is a match, false otherwise.
62      **/
63     bool check( ZyppSel selectable,
64                 ZyppPkg pkg );
65
66     /**
67      * Returns the (untranslated!) currently selected RPM group as string.
68      * Special case: "*" is returned if "zzz_All" is selected.
69      **/
70     const string & selectedRpmGroup() const { return _selectedRpmGroup; }
71
72
73 public slots:
74
75     /**
76      * Filter according to the view's rules and current selection.
77      * Emits those signals:
78      *    filterStart()
79      *    filterMatch() for each pkg that matches the filter
80      *    filterFinished()
81      **/
82     void filter();
83
84     /**
85      * Same as filter(), but only if this widget is currently visible.
86      **/
87     void filterIfVisible();
88
89     /**
90      * Select a list entry (if there is any).
91      * Usually this will be the first list entry, but don't rely on that - this
92      * might change without notice. Emits signal selectionChanged().
93      **/
94     void selectSomething();
95
96     /**
97      * Returns the internal RPM groups tree and fills it
98      * if it doesn't exist yet.
99      **/
100     static YRpmGroupsTree * rpmGroupsTree();
101
102
103 signals:
104
105     /**
106      * Emitted when the filtering starts. Use this to clear package lists
107      * etc. prior to adding new entries.
108      **/
109     void filterStart();
110
111     /**
112      * Emitted during filtering for each pkg that matches the filter.
113      **/
114     void filterMatch( ZyppSel   selectable,
115                       ZyppPkg   pkg );
116
117     /**
118      * Emitted when filtering is finished.
119      **/
120     void filterFinished();
121
122
123 protected slots:
124
125     /**
126      * Update _selectedRpmGroup and filter data
127      **/
128     void slotSelectionChanged( Q3ListViewItem * newSelection );
129
130
131 protected:
132
133     /**
134      * Fill the internal RPM groups tree with RPM groups of all packages
135      * currently in the pool
136      **/
137     static void fillRpmGroupsTree();
138
139     /**
140      * Recursively clone the RPM group tag tree for the QListView widget:
141      * Make a deep copy of the tree starting at 'parentRpmGroup' and
142      * 'parentClone'.
143      **/
144     void cloneTree( YStringTreeItem *   parentRpmGroup,
145                     YQPkgRpmGroupTag *  parentClone = 0 );
146
147     //
148     // Data members
149     //
150
151     string _selectedRpmGroup;
152
153     static YRpmGroupsTree * _rpmGroupsTree;
154 };
155
156
157
158 class YQPkgRpmGroupTag: public Q3ListViewItem
159 {
160 public:
161
162     /**
163      * Constructor for toplevel RPM group tags
164      **/
165     YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView *     parentFilterView,
166                       YStringTreeItem *                 rpmGroup        );
167
168     /**
169      * Constructor for RPM group tags that have a parent
170      **/
171     YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView *     parentFilterView,
172                       YQPkgRpmGroupTag *                parentGroupTag,
173                       YStringTreeItem *                 rpmGroup );
174
175     /**
176      * Constructor for toplevel RPM group tags via STL string
177      * ( for special cases like "zzz All" )
178      **/
179     YQPkgRpmGroupTag( YQPkgRpmGroupTagsFilterView *     parentFilterView,
180                       const QString &                   rpmGroupName,
181                       YStringTreeItem *                 rpmGroup        );
182
183     /**
184      * Destructor
185      **/
186     virtual ~YQPkgRpmGroupTag();
187
188
189     /**
190      * Returns the parent filter view
191      **/
192     YQPkgRpmGroupTagsFilterView * filterView() const { return _filterView; }
193
194     /**
195      * Returns the original tree item
196      **/
197     const YStringTreeItem * rpmGroup() const { return _rpmGroup; }
198
199
200 private:
201
202     // Data members
203
204     YQPkgRpmGroupTagsFilterView *       _filterView;
205     YStringTreeItem *                   _rpmGroup;
206 };
207
208
209 #endif // ifndef YQPkgRpmGroupTagsFilterView_h