]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgPatternList.h
misc compile
[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 <QMap>
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      * Paint method. Reimplemented from @ref QTreeWidget so a different
59      * font can be used.
60      *
61      * Reimplemented from QY2ListViewItem.
62      **/
63     virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
64
65 public slots:
66
67     /**
68      * Filter according to the view's rules and current selection.
69      * Emits those signals:
70      *    filterStart()
71      *    filterMatch() for each pkg that matches the filter
72      *    filterFinished()
73      **/
74     void filter();
75
76     /**
77      * Same as filter(), but only if this widget is currently visible.
78      **/
79     void filterIfVisible();
80
81
82     /**
83      * Add a pattern to the list. Connect a filter's filterMatch() signal to
84      * this slot. Remember to connect filterStart() to clear() (inherited from
85      * QListView).
86      **/
87     void addPatternItem( ZyppSel        selectable,
88                          ZyppPattern    pattern );
89
90     /**
91      * Fill the pattern list.
92      **/
93     void fillList();
94
95     /**
96      * Dispatcher slot for mouse click: cycle status depending on column.
97      * For pattern category items, emulate tree open / close behaviour.
98      *
99      * Reimplemented from YQPkgObjList.
100      **/
101     virtual void pkgObjClicked( int             button,
102                                 QTreeWidgetItem * item,
103                                 int             col,
104                                 const QPoint &  pos );
105
106     /**
107      * Select the first selectable list entry that is not a pattern category.
108      *
109      * Reimplemented from QY2ListView.
110      **/
111     virtual void selectSomething();
112
113     
114 public:
115
116     /**
117      * Returns the currently selected item or 0 if there is none.
118      **/
119     YQPkgPatternListItem * selection() const;
120
121
122 signals:
123
124     /**
125      * Emitted when the filtering starts. Use this to clear package lists
126      * etc. prior to adding new entries.
127      **/
128     void filterStart();
129
130     /**
131      * Emitted during filtering for each pkg that matches the filter.
132      **/
133     void filterMatch( ZyppSel   selectable,
134                       ZyppPkg   pkg );
135
136     /**
137      * Emitted when filtering is finished.
138      **/
139     void filterFinished();
140
141 protected:
142
143     /**
144      * Returns the category item with the specified name. Creates such a
145      * category if it doesn't exist yet and categoryName is not empty. Returns
146      * 0 if categoryName is empty.
147      **/
148     YQPkgPatternCategoryItem * category( const QString & categoryName );
149
150
151     //
152     // Data members
153     //
154
155     QMap<QString, YQPkgPatternCategoryItem*> _categories;
156 };
157
158
159
160 class YQPkgPatternListItem: public YQPkgObjListItem
161 {
162 public:
163
164     /**
165      * Constructor for root items
166      **/
167     YQPkgPatternListItem( YQPkgPatternList *            patternList,
168                           ZyppSel                       selectable,
169                           ZyppPattern                   zyppPattern );
170
171     /**
172      * Constructor for items that belong to a category
173      **/
174     YQPkgPatternListItem( YQPkgPatternList *            patternList,
175                           YQPkgPatternCategoryItem *    parentCategory,
176                           ZyppSel                       selectable,
177                           ZyppPattern                   zyppPattern );
178
179     /**
180      * Destructor
181      **/
182     virtual ~YQPkgPatternListItem();
183
184     /**
185      * Returns the original object within the package manager backend.
186      **/
187     ZyppPattern zyppPattern() const { return _zyppPattern; }
188
189     /**
190      * Comparison function used for sorting the list.
191      * Returns:
192      * -1 if this <  other
193      *  0 if this == other
194      * +1 if this >  other
195      *
196      * Reimplemented from QListViewItem:
197      * Sort by zypp::Pattern::order() only.
198      **/
199     virtual int compare( QTreeWidgetItem *      other,
200                          int                    col,
201                          bool                   ascending ) const;
202
203     // Columns
204
205     int statusCol()     const   { return _patternList->statusCol();     }
206     int summaryCol()    const   { return _patternList->summaryCol();    }
207
208 protected:
209
210     /**
211      * Initialize things common to all constructors.
212      **/
213     void init();
214     
215     /**
216      * Propagate status changes in this list to other lists:
217      * Have the solver transact all patterns.
218      *
219      * Reimplemented from YQPkgObjListItem.
220      **/
221     virtual void applyChanges();
222
223
224     // Data members
225
226     YQPkgPatternList *  _patternList;
227     ZyppPattern         _zyppPattern;
228 };
229
230
231
232 class YQPkgPatternCategoryItem: public QY2ListViewItem
233 {
234 public:
235
236     /**
237      * Constructor
238      **/
239     YQPkgPatternCategoryItem( YQPkgPatternList *        patternList,
240                               const QString &           category        );
241
242     /**
243      * Destructor
244      **/
245     virtual ~YQPkgPatternCategoryItem();
246
247     /**
248      * Returns the first pattern. This should be the first in sort order.
249      **/
250     ZyppPattern firstPattern() const { return _firstPattern; }
251
252     /**
253      * Add a pattern to this category. This method sets firstPattern() if necessary.
254      **/
255     void addPattern( ZyppPattern pattern );
256
257     /**
258      * Comparison function used for sorting the list.
259      * Returns:
260      * -1 if this <  other
261      *  0 if this == other
262      * +1 if this >  other
263      *
264      * Reimplemented from QListViewItem:
265      * Sort by zypp::Pattern::order() only.
266      **/
267     virtual int compare( QTreeWidgetItem *      other,
268                          int                    col,
269                          bool                   ascending ) const;
270
271     /*
272      * Open or close this subtree
273      *
274      * Reimplemented from QListViewItem to force categories open at all times
275      **/
276     virtual void setOpen( bool open );
277     
278
279 protected:
280
281     /**
282      * Set a suitable tree open/close icon depending on this category's
283      * open/close status.
284      *
285      * The default QListView plus/minus icons would require treeStepSize() to
286      * be set >0 and rootItemDecorated( true ), but that would look very ugly
287      * in this context, so the pattern categories paint their own tree open /
288      * close icons.
289      **/
290     void setTreeIcon( void );
291     //
292     // Data members
293     //
294
295     YQPkgPatternList *  _patternList;
296     ZyppPattern         _firstPattern;
297 };
298
299
300 #endif // ifndef YQPkgPatternList_h