]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgPatternList.h
restart qt4 porting
[duncan/yast2-qt4.git] / src / pkg / YQPkgPatternList.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgPatternList.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQPkgPatternList_h
21 #define YQPkgPatternList_h
22
23 #include "YQPkgObjList.h"
24 #include <qdict.h>
25
26
27 class YQPkgPatternListItem;
28 class YQPkgPatternCategoryItem;
29
30
31 /**
32  * @short Display a list of zypp::Pattern objects.
33  **/
34 class YQPkgPatternList : public YQPkgObjList
35 {
36     Q_OBJECT
37
38 public:
39
40     /**
41      * Constructor.
42      *
43      * Set 'autoFill' to 'false' if you don't want the list to be filled in the
44      * constructor. In that case, use fillList() (e.g., when connections are
45      * set up).
46      *
47      * Set 'autoFilter' to 'false' if there is no need to do (expensive)
48      * filtering because the 'filterMatch' signal is not connected anyway.
49      **/
50     YQPkgPatternList( QWidget * parent, bool autoFill = true, bool autoFilter = true );
51
52     /**
53      * Destructor
54      **/
55     virtual ~YQPkgPatternList();
56
57
58 public slots:
59
60     /**
61      * Filter according to the view's rules and current selection.
62      * Emits those signals:
63      *    filterStart()
64      *    filterMatch() for each pkg that matches the filter
65      *    filterFinished()
66      **/
67     void filter();
68
69     /**
70      * Same as filter(), but only if this widget is currently visible.
71      **/
72     void filterIfVisible();
73
74
75     /**
76      * Add a pattern to the list. Connect a filter's filterMatch() signal to
77      * this slot. Remember to connect filterStart() to clear() (inherited from
78      * QListView).
79      **/
80     void addPatternItem( ZyppSel        selectable,
81                          ZyppPattern    pattern );
82
83     /**
84      * Fill the pattern list.
85      **/
86     void fillList();
87
88     /**
89      * Dispatcher slot for mouse click: cycle status depending on column.
90      * For pattern category items, emulate tree open / close behaviour.
91      *
92      * Reimplemented from YQPkgObjList.
93      **/
94     virtual void pkgObjClicked( int             button,
95                                 QListViewItem * item,
96                                 int             col,
97                                 const QPoint &  pos );
98
99     /**
100      * Select the first selectable list entry that is not a pattern category.
101      *
102      * Reimplemented from QY2ListView.
103      **/
104     virtual void selectSomething();
105
106     
107 public:
108
109     /**
110      * Returns the currently selected item or 0 if there is none.
111      **/
112     YQPkgPatternListItem * selection() const;
113
114
115 signals:
116
117     /**
118      * Emitted when the filtering starts. Use this to clear package lists
119      * etc. prior to adding new entries.
120      **/
121     void filterStart();
122
123     /**
124      * Emitted during filtering for each pkg that matches the filter.
125      **/
126     void filterMatch( ZyppSel   selectable,
127                       ZyppPkg   pkg );
128
129     /**
130      * Emitted when filtering is finished.
131      **/
132     void filterFinished();
133
134
135 protected:
136
137     /**
138      * Returns the category item with the specified name. Creates such a
139      * category if it doesn't exist yet and categoryName is not empty. Returns
140      * 0 if categoryName is empty.
141      **/
142     YQPkgPatternCategoryItem * category( const QString & categoryName );
143
144
145     //
146     // Data members
147     //
148
149     QDict<YQPkgPatternCategoryItem> _categories;
150 };
151
152
153
154 class YQPkgPatternListItem: public YQPkgObjListItem
155 {
156 public:
157
158     /**
159      * Constructor for root items
160      **/
161     YQPkgPatternListItem( YQPkgPatternList *            patternList,
162                           ZyppSel                       selectable,
163                           ZyppPattern                   zyppPattern );
164
165     /**
166      * Constructor for items that belong to a category
167      **/
168     YQPkgPatternListItem( YQPkgPatternList *            patternList,
169                           YQPkgPatternCategoryItem *    parentCategory,
170                           ZyppSel                       selectable,
171                           ZyppPattern                   zyppPattern );
172
173     /**
174      * Destructor
175      **/
176     virtual ~YQPkgPatternListItem();
177
178     /**
179      * Returns the original object within the package manager backend.
180      **/
181     ZyppPattern zyppPattern() const { return _zyppPattern; }
182
183     /**
184      * Comparison function used for sorting the list.
185      * Returns:
186      * -1 if this <  other
187      *  0 if this == other
188      * +1 if this >  other
189      *
190      * Reimplemented from QListViewItem:
191      * Sort by zypp::Pattern::order() only.
192      **/
193     virtual int compare( QListViewItem *        other,
194                          int                    col,
195                          bool                   ascending ) const;
196
197     // Columns
198
199     int statusCol()     const   { return _patternList->statusCol();     }
200     int summaryCol()    const   { return _patternList->summaryCol();    }
201
202
203 protected:
204
205     /**
206      * Initialize things common to all constructors.
207      **/
208     void init();
209     
210     /**
211      * Propagate status changes in this list to other lists:
212      * Have the solver transact all patterns.
213      *
214      * Reimplemented from YQPkgObjListItem.
215      **/
216     virtual void applyChanges();
217
218
219     // Data members
220
221     YQPkgPatternList *  _patternList;
222     ZyppPattern         _zyppPattern;
223 };
224
225
226
227 class YQPkgPatternCategoryItem: public QY2ListViewItem
228 {
229 public:
230
231     /**
232      * Constructor
233      **/
234     YQPkgPatternCategoryItem( YQPkgPatternList *        patternList,
235                               const QString &           category        );
236
237     /**
238      * Destructor
239      **/
240     virtual ~YQPkgPatternCategoryItem();
241
242     /**
243      * Returns the first pattern. This should be the first in sort order.
244      **/
245     ZyppPattern firstPattern() const { return _firstPattern; }
246
247     /**
248      * Add a pattern to this category. This method sets firstPattern() if necessary.
249      **/
250     void addPattern( ZyppPattern pattern );
251
252     /**
253      * Comparison function used for sorting the list.
254      * Returns:
255      * -1 if this <  other
256      *  0 if this == other
257      * +1 if this >  other
258      *
259      * Reimplemented from QListViewItem:
260      * Sort by zypp::Pattern::order() only.
261      **/
262     virtual int compare( QListViewItem *        other,
263                          int                    col,
264                          bool                   ascending ) const;
265
266     /*
267      * Open or close this subtree
268      *
269      * Reimplemented from QListViewItem to force categories open at all times
270      **/
271     virtual void setOpen( bool open );
272     
273
274 protected:
275
276     /**
277      * Set a suitable tree open/close icon depending on this category's
278      * open/close status.
279      *
280      * The default QListView plus/minus icons would require treeStepSize() to
281      * be set >0 and rootItemDecorated( true ), but that would look very ugly
282      * in this context, so the pattern categories paint their own tree open /
283      * close icons.
284      **/
285     void setTreeIcon( void );
286     
287     /**
288      * Paint method. Reimplemented from @ref QListViewItem so a different
289      * font can be used.
290      *
291      * Reimplemented from QY2ListViewItem.
292      **/
293     virtual void paintCell( QPainter *          painter,
294                             const QColorGroup & colorGroup,
295                             int                 column,
296                             int                 width,
297                             int                 alignment );
298
299     //
300     // Data members
301     //
302
303     YQPkgPatternList *  _patternList;
304     ZyppPattern         _firstPattern;
305 };
306
307
308 #endif // ifndef YQPkgPatternList_h