]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgPatternList.h
don't create QObjects in ycp thread - make timeouts work
[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      * sorting function
191      */
192     virtual bool operator< ( const QTreeWidgetItem & other ) const;
193
194     // Columns
195
196     int statusCol()     const   { return _patternList->statusCol();     }
197     int summaryCol()    const   { return _patternList->summaryCol();    }
198
199 protected:
200
201     /**
202      * Initialize things common to all constructors.
203      **/
204     void init();
205     
206     /**
207      * Propagate status changes in this list to other lists:
208      * Have the solver transact all patterns.
209      *
210      * Reimplemented from YQPkgObjListItem.
211      **/
212     virtual void applyChanges();
213
214
215     // Data members
216
217     YQPkgPatternList *  _patternList;
218     ZyppPattern         _zyppPattern;
219 };
220
221
222
223 class YQPkgPatternCategoryItem: public QY2ListViewItem
224 {
225 public:
226
227     /**
228      * Constructor
229      **/
230     YQPkgPatternCategoryItem( YQPkgPatternList *        patternList,
231                               const QString &           category        );
232
233     /**
234      * Destructor
235      **/
236     virtual ~YQPkgPatternCategoryItem();
237
238     /**
239      * Returns the first pattern. This should be the first in sort order.
240      **/
241     ZyppPattern firstPattern() const { return _firstPattern; }
242
243     /**
244      * Add a pattern to this category. This method sets firstPattern() if necessary.
245      **/
246     void addPattern( ZyppPattern pattern );
247
248     /**
249      * sorting function
250      */
251     virtual bool operator< ( const QTreeWidgetItem & other ) const;
252
253     /*
254      * Open or close this subtree
255      *
256      * Reimplemented from QListViewItem to force categories open at all times
257      **/
258     virtual void setOpen( bool open );
259     
260
261 protected:
262
263     /**
264      * Set a suitable tree open/close icon depending on this category's
265      * open/close status.
266      *
267      * The default QListView plus/minus icons would require treeStepSize() to
268      * be set >0 and rootItemDecorated( true ), but that would look very ugly
269      * in this context, so the pattern categories paint their own tree open /
270      * close icons.
271      **/
272     void setTreeIcon( void );
273     //
274     // Data members
275     //
276
277     YQPkgPatternList *  _patternList;
278     ZyppPattern         _firstPattern;
279 };
280
281
282 #endif // ifndef YQPkgPatternList_h