libyui-qt  2.49.2
QY2DiskUsageList.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2DiskUsageList.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23  This is a pure Qt widget - it can be used independently of YaST2.
24 
25 /-*/
26 
27 
28 #ifndef QY2DiskUsageList_h
29 #define QY2DiskUsageList_h
30 
31 #include <QY2ListView.h>
32 #include <yui/FSize.h>
33 #include <qcolor.h>
34 
35 
37 
38 
39 /**
40  * Generic scrollable list of disk usage for any number of partitions.
41  **/
43 {
44  Q_OBJECT
45 
46 public:
47 
48  /**
49  * Constructor.
50  *
51  * Adds a standard set of list columns if 'addStdColumns' is
52  *'true'. Otherwise the caller is responsible for adding any columns.
53  **/
54  QY2DiskUsageList( QWidget * parent, bool addStdColumns = true );
55 
56  /**
57  * Destructor
58  **/
59  virtual ~QY2DiskUsageList();
60 
61 
62  // Column numbers
63 
64  int nameCol() const { return _nameCol; }
65  int percentageBarCol() const { return _percentageBarCol; }
66  int usedSizeCol() const { return _usedSizeCol; }
67  int freeSizeCol() const { return _freeSizeCol; }
68  int totalSizeCol() const { return _totalSizeCol; }
69  int deviceNameCol() const { return _deviceNameCol; }
70 
71 
72  virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
73 
74  // make it public
75  QTreeWidgetItem * itemFromIndex ( const QModelIndex & index ) const
76  { return QY2ListView::itemFromIndex(index); }
77 
78 protected:
79 
80  int _nameCol;
81  int _percentageBarCol;
82  int _usedSizeCol;
83  int _freeSizeCol;
84  int _totalSizeCol;
85  int _deviceNameCol;
86 };
87 
88 
89 
90 /**
91  * Abstract base class for one partition ( mount point ) to display in a
92  * QY2DiskUsageList.
93  *
94  * This class contains pure virtuals, so it cannot be used directly.
95  **/
97 {
98 protected:
99  /**
100  * Constructor.
101  *
102  * Call updateData() after the constructor for the initial display
103  * update. Unfortunately, this cannot be done automatically in the
104  * constructor since it uses virtual methods that are not available yet at
105  * this point.
106  **/
108 
109 
110  /**
111  * Destructor.
112  **/
113  virtual ~QY2DiskUsageListItem();
114 
115 
116 public:
117 
118  /**
119  * The currently used size of this partition.
120  *
121  * Derived classes need to implement this method.
122  **/
123 
124  virtual FSize usedSize() const = 0;
125 
126  /**
127  * The total size of this partition.
128  *
129  * Derived classes need to implement this method.
130  **/
131  virtual FSize totalSize() const = 0;
132 
133  /**
134  * The current free size of this partition.
135  *
136  * Derived classes can choose reimpmenent this if it is less expensive than
137  * calculating this value each time from usedSize() and totalSize() which
138  * is the default implementation.
139  **/
140  virtual FSize freeSize() const;
141 
142  /**
143  * The currently used percentage ( 0..100 ) of this partition.
144  *
145  * Derived classes can choose reimpmenent this if it is less expensive than
146  * calculating this value each time from usedSize() and totalSize() which
147  * is the default implementation.
148  **/
149  virtual int usedPercent() const;
150 
151  /**
152  * The name to display for this partition.
153  * It makes most sense to use the mount point here ( but this is not a
154  * requirement ). This is what will be displayed in the "Name" column.
155  *
156  * Derived classes need to implement this method.
157  **/
158  virtual QString name() const = 0;
159 
160  /**
161  * The device name of this partition.
162  *
163  * Derived classes may choose to reimplement this method.
164  * This default implementation returns an empty std::string.
165  **/
166  virtual QString deviceName() const { return ""; }
167 
168 
169  /**
170  * Update this item's status ( here: the numeric fields ).
171  * Triggered by QY2ListView::updateAllItemStates().
172  *
173  * Reimplemented from QY2ListViewItem.
174  **/
175  virtual void updateStatus();
176 
177  /**
178  * Update this item's data completely.
179  * Triggered by QY2ListView::updateAllItemData().
180  *
181  * Reimplemented from QY2ListViewItem.
182  **/
183  virtual void updateData();
184 
185  /**
186  * Re-declare ordinary setText() method so the compiler doesn't get
187  * confused which one to use.
188  **/
189  void setText( int column, const QString & text )
190  { QTreeWidgetItem::setText( column, text ); }
191 
192  /**
193  * Set a column text via FSize.
194  **/
195  void setText( int column, const FSize & size );
196 
197  /**
198  * Comparison function used for sorting the list.
199  * Reimplemented from QTreeWidgetItem
200  **/
201  virtual bool operator< ( const QTreeWidgetItem & other ) const;
202 
203  // Columns
204 
205  int nameCol() const { return _diskUsageList->nameCol(); }
206  int percentageBarCol() const { return _diskUsageList->percentageBarCol(); }
207  int usedSizeCol() const { return _diskUsageList->usedSizeCol(); }
208  int freeSizeCol() const { return _diskUsageList->freeSizeCol(); }
209  int totalSizeCol() const { return _diskUsageList->totalSizeCol(); }
210  int deviceNameCol() const { return _diskUsageList->deviceNameCol(); }
211 
212 
213 protected:
214 
215  /**
216  * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is
217  * 'true' ) or only the varying fields ( used, free, percentage ).
218  **/
219  void init( bool allFields );
220 
221  public:
222  /**
223  * Paint a percentage bar into a @ref QListViewItem cell.
224  * 'width' is the width of the entire cell.
225  * 'indent' is the number of pixels to indent the bar.
226  *
227  * Stolen from KDirStat::KDirTreeView with the author's permission.
228  **/
229  void paintPercentageBar( QPainter * painter,
230  QStyleOptionViewItem option,
231  const QColor & fillColor);
232 
233 protected:
234 
235 
236  //
237  // Data members
238  //
239 
240  QY2DiskUsageList * _diskUsageList;
241 };
242 
243 
244 
245 
246 #endif // ifndef QY2DiskUsageList_h
virtual FSize totalSize() const =0
The total size of this partition.
QY2DiskUsageList(QWidget *parent, bool addStdColumns=true)
Constructor.
virtual FSize usedSize() const =0
The currently used size of this partition.
virtual void updateStatus()
Update this item&#39;s status ( here: the numeric fields ).
QY2DiskUsageListItem(QY2DiskUsageList *parent)
Constructor.
virtual QString deviceName() const
The device name of this partition.
virtual void updateData()
Update this item&#39;s data completely.
virtual QString name() const =0
The name to display for this partition.
Abstract base class for one partition ( mount point ) to display in a QY2DiskUsageList.
void init(bool allFields)
( Re- ) initialize fields - all displayed fields ( if &#39;allFields&#39; is &#39;true&#39; ) or only the varying fie...
Generic scrollable list of disk usage for any number of partitions.
virtual FSize freeSize() const
The current free size of this partition.
virtual int usedPercent() const
The currently used percentage ( 0..100 ) of this partition.
Enhanced QTreeWidget.
Definition: QY2ListView.h:47
void setText(int column, const QString &text)
Re-declare ordinary setText() method so the compiler doesn&#39;t get confused which one to use...
virtual ~QY2DiskUsageListItem()
Destructor.
void paintPercentageBar(QPainter *painter, QStyleOptionViewItem option, const QColor &fillColor)
Paint a percentage bar into a QListViewItem cell.
Enhanced QTreeWidgetItem.
Definition: QY2ListView.h:233
virtual ~QY2DiskUsageList()
Destructor.
virtual bool operator<(const QTreeWidgetItem &other) const
Comparison function used for sorting the list.