libyui-qt-pkg  2.45.6
YQPkgPatternList.h
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgPatternList.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 
41 #ifndef YQPkgPatternList_h
42 #define YQPkgPatternList_h
43 
44 #include "YQPkgObjList.h"
45 #include <QMap>
46 
47 
50 
51 
52 /**
53  * @short Display a list of zypp::Pattern objects.
54  **/
56 {
57  Q_OBJECT
58 
59 public:
60 
61  /**
62  * Constructor.
63  *
64  * Set 'autoFill' to 'false' if you don't want the list to be filled in the
65  * constructor. In that case, use fillList() (e.g., when connections are
66  * set up).
67  *
68  * Set 'autoFilter' to 'false' if there is no need to do (expensive)
69  * filtering because the 'filterMatch' signal is not connected anyway.
70  **/
71  YQPkgPatternList( QWidget * parent, bool autoFill = true, bool autoFilter = true );
72 
73  /**
74  * Destructor
75  **/
76  virtual ~YQPkgPatternList();
77 
78 public slots:
79 
80  /**
81  * Filter according to the view's rules and current selection.
82  * Emits those signals:
83  * filterStart()
84  * filterMatch() for each pkg that matches the filter
85  * filterFinished()
86  **/
87  void filter();
88 
89  /**
90  * Same as filter(), but only if this widget is currently visible.
91  **/
92  void filterIfVisible();
93 
94 
95  /**
96  * Add a pattern to the list. Connect a filter's filterMatch() signal to
97  * this slot. Remember to connect filterStart() to clear() (inherited from
98  * QListView).
99  **/
100  void addPatternItem( ZyppSel selectable,
101  ZyppPattern pattern );
102 
103  /**
104  * Fill the pattern list.
105  **/
106  void fillList();
107 
108  /**
109  * Dispatcher slot for mouse click: cycle status depending on column.
110  * For pattern category items, emulate tree open / close behaviour.
111  *
112  * Reimplemented from YQPkgObjList.
113  **/
114  virtual void pkgObjClicked( int button,
115  QTreeWidgetItem * item,
116  int col,
117  const QPoint & pos );
118 
119  /**
120  * Select the first selectable list entry that is not a pattern category.
121  *
122  * Reimplemented from QY2ListView.
123  **/
124  virtual void selectSomething();
125 
126 
127 public:
128 
129  /**
130  * Returns the currently selected item or 0 if there is none.
131  **/
133 
134  int howmanyCol() const { return _howmanyCol; }
135 signals:
136 
137  /**
138  * Emitted when the filtering starts. Use this to clear package lists
139  * etc. prior to adding new entries.
140  **/
141  void filterStart();
142 
143  /**
144  * Emitted during filtering for each pkg that matches the filter.
145  **/
146  void filterMatch( ZyppSel selectable,
147  ZyppPkg pkg );
148 
149  /**
150  * Emitted when filtering is finished.
151  **/
152  void filterFinished();
153 
154 protected:
155 
156  /**
157  * Returns the category item with the specified name. Creates such a
158  * category if it doesn't exist yet and categoryName is not empty. Returns
159  * 0 if categoryName is empty.
160  **/
161  YQPkgPatternCategoryItem * category( const QString & categoryName );
162 
163 
164  //
165  // Data members
166  //
167 
168  QMap<QString, YQPkgPatternCategoryItem*> _categories;
169  int _howmanyCol;
170 };
171 
172 
173 
175 {
176 public:
177 
178  /**
179  * Constructor for root items
180  **/
181  YQPkgPatternListItem( YQPkgPatternList * patternList,
182  ZyppSel selectable,
183  ZyppPattern zyppPattern );
184 
185  /**
186  * Constructor for items that belong to a category
187  **/
188  YQPkgPatternListItem( YQPkgPatternList * patternList,
189  YQPkgPatternCategoryItem * parentCategory,
190  ZyppSel selectable,
191  ZyppPattern zyppPattern );
192 
193  /**
194  * Destructor
195  **/
196  virtual ~YQPkgPatternListItem();
197 
198  /**
199  * Returns the original object within the package manager backend.
200  **/
201  ZyppPattern zyppPattern() const { return _zyppPattern; }
202 
203  /**
204  * Cycle the package status to the next valid value.
205  * Reimplemented from YQPkgObjList.
206  **/
207  virtual void cycleStatus();
208 
209  /**
210  * sorting function
211  */
212  virtual bool operator< ( const QTreeWidgetItem & other ) const;
213 
214  // Columns
215 
216  int statusCol() const { return _patternList->statusCol(); }
217  int summaryCol() const { return _patternList->summaryCol(); }
218 
219  int totalPackages() const { return _total; }
220  int installedPackages() const { return _installed; }
221 
222  // setters for installed and total packages values
223  void setTotalPackages(int v) { _total = v; }
224  void setInstalledPackages(int v) { _installed = v; }
225 
226  /**
227  * resets the tooltip with the current available information
228  */
229  void resetToolTip();
230 
231 protected:
232 
233  /**
234  * Initialize things common to all constructors.
235  **/
236  void init();
237 
238  /**
239  * Propagate status changes in this list to other lists:
240  * Have the solver transact all patterns.
241  *
242  * Reimplemented from YQPkgObjListItem.
243  **/
244  virtual void applyChanges();
245 
246 
247  // Data members
248 
249  YQPkgPatternList * _patternList;
250  ZyppPattern _zyppPattern;
251  // cache for total and installed packages
252  int _total;
253  int _installed;
254 };
255 
256 
257 
258 class YQPkgPatternCategoryItem: public QY2ListViewItem
259 {
260 public:
261 
262  /**
263  * Constructor
264  **/
266  const QString & category );
267 
268  /**
269  * Destructor
270  **/
271  virtual ~YQPkgPatternCategoryItem();
272 
273  /**
274  * Returns the first pattern. This should be the first in sort order.
275  **/
276  ZyppPattern firstPattern() const { return _firstPattern; }
277 
278  /**
279  * Add a pattern to this category. This method sets firstPattern() if necessary.
280  **/
281  void addPattern( ZyppPattern pattern );
282 
283  /**
284  * sorting function
285  */
286  virtual bool operator< ( const QTreeWidgetItem & other ) const;
287 
288  /*
289  * Open or close this subtree
290  *
291  * Reimplemented from QListViewItem to force categories open at all times
292  **/
293  virtual void setExpanded( bool open );
294 
295 
296 protected:
297 
298  /**
299  * Set a suitable tree open/close icon depending on this category's
300  * open/close status.
301  *
302  * The default QListView plus/minus icons would require treeStepSize() to
303  * be set >0 and rootItemDecorated( true ), but that would look very ugly
304  * in this context, so the pattern categories paint their own tree open /
305  * close icons.
306  **/
307  void setTreeIcon( void );
308  //
309  // Data members
310  //
311 
312  YQPkgPatternList * _patternList;
313  ZyppPattern _firstPattern;
314 };
315 
316 
317 #endif // ifndef YQPkgPatternList_h
virtual void selectSomething()
Select the first selectable list entry that is not a pattern category.
void filterFinished()
Emitted when filtering is finished.
ZyppPattern firstPattern() const
Returns the first pattern.
Abstract base class to display a list of zypp::ResObjects.
Definition: YQPkgObjList.h:68
YQPkgPatternCategoryItem * category(const QString &categoryName)
Returns the category item with the specified name.
void fillList()
Fill the pattern list.
void filterMatch(ZyppSel selectable, ZyppPkg pkg)
Emitted during filtering for each pkg that matches the filter.
virtual ~YQPkgPatternList()
Destructor.
void filterIfVisible()
Same as filter(), but only if this widget is currently visible.
void filter()
Filter according to the view&#39;s rules and current selection.
Display a list of zypp::Pattern objects.
void filterStart()
Emitted when the filtering starts.
YQPkgPatternListItem * selection() const
Returns the currently selected item or 0 if there is none.
YQPkgPatternList(QWidget *parent, bool autoFill=true, bool autoFilter=true)
Constructor.
ZyppPattern zyppPattern() const
Returns the original object within the package manager backend.
virtual void pkgObjClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Dispatcher slot for mouse click: cycle status depending on column.
void addPatternItem(ZyppSel selectable, ZyppPattern pattern)
Add a pattern to the list.