1 #ifndef _FMTWIDGETITEM_H_
2 #define _FMTWIDGETITEM_H_
4 Bacula® - The Network Backup Solution
6 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
8 The main author of Bacula is Kern Sibbald, with contributions from many
9 others, a complete list can be found in the file AUTHORS.
11 You may use this file and others of this release according to the
12 license defined in the LICENSE file, which includes the Affero General
13 Public License, v3.0 ("AGPLv3") and some additional permissions and
14 terms pursuant to its AGPLv3 Section 7.
16 Bacula® is a registered trademark of Kern Sibbald.
19 * TreeView formatting helpers - Riccardo Ghetta, May 2008
23 class QTreeWidgetItem;
25 class QTableWidgetItem;
31 * common conversion routines
34 QString convertJobStatus(const QString &sts);
36 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
37 QString convertBytesIEC(qint64 fld);
39 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
40 QString convertBytesSI(qint64 fld);
43 * disable widget updating
58 * base class for formatters
61 class ItemFormatterBase
64 enum BYTES_CONVERSION {
65 BYTES_CONVERSION_NONE,
71 virtual ~ItemFormatterBase();
73 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
74 void setBoolFld(int index, const QString &fld, bool center = true);
75 void setBoolFld(int index, int fld, bool center = true);
77 /* Print nice icon to represent percent */
78 void setPercent(int index, float number);
80 /* Normal text field. Centers field if center true*/
81 void setTextFld(int index, const QString &fld, bool center = false);
83 /* Normal date field. Centers field if center true*/
84 void setDateFld(int index, utime_t fld, bool center = false);
86 /* Right-aligned text field. */
87 void setRightFld(int index, const QString &fld);
89 /* Numeric field - sorted as numeric type */
90 void setNumericFld(int index, const QString &fld);
91 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
93 /* fld value interpreted as bytes and formatted with size suffixes */
94 void setBytesFld(int index, const QString &fld);
96 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
97 void setDurationFld(int index, const QString &fld);
99 /* fld value interpreted as volume status. Colored accordingly */
100 void setVolStatusFld(int index, const QString &fld, bool center = true);
102 /* fld value interpreted as job status. Colored accordingly */
103 void setJobStatusFld(int index, const QString &status, bool center = true);
105 /* fld value interpreted as job type. */
106 void setJobTypeFld(int index, const QString &fld, bool center = false);
108 /* fld value interpreted as job level. */
109 void setJobLevelFld(int index, const QString &fld, bool center = false);
111 /* fld value interpreted as Online/Offline */
112 void setInChanger(int index, const QString &InChanger);
114 /* fld value interpreted as file or folder */
115 void setFileType(int index, const QString &type);
117 static void setBytesConversion(BYTES_CONVERSION b) {
120 static BYTES_CONVERSION getBytesConversion() {
125 /* only derived classes can create one of these */
128 virtual void setText(int index, const QString &fld) = 0;
129 virtual void setTextAlignment(int index, int align) = 0;
130 virtual void setBackground(int index, const QBrush &) = 0;
131 virtual void setPixmap(int index, const QPixmap &pix) = 0;
132 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
134 /* sets the *optional* value used for sorting */
135 virtual void setSortValue(int index, const QVariant &value) = 0;
138 static BYTES_CONVERSION cnvFlag;
142 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
143 * to format data fields.
144 * All setXXXFld routines receive a column index and the unformatted string value.
146 class TreeItemFormatter : public ItemFormatterBase
150 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
152 /* access internal widget */
153 QTreeWidgetItem *widget() { return wdg; }
154 const QTreeWidgetItem *widget() const { return wdg; }
157 virtual void setText(int index, const QString &fld);
158 virtual void setTextAlignment(int index, int align);
159 virtual void setBackground(int index, const QBrush &);
160 virtual void setSortValue(int index, const QVariant &value);
161 virtual void setPixmap(int index, const QPixmap &pix);
164 QTreeWidgetItem *wdg;
169 * This class can be used instead of QTableWidgetItem (it allocates one internally,
170 * to format data fields.
171 * All setXXXFld routines receive the column and the unformatted string value.
173 class TableItemFormatter : public ItemFormatterBase
177 /* specialized widget item - allows an optional data property for sorting */
178 class BatSortingTableItem : public QTableWidgetItem
181 static const int SORTDATA_ROLE = Qt::UserRole + 100;
183 BatSortingTableItem();
185 /* uses the sort data if available, reverts to default behavior othervise */
186 virtual bool operator< ( const QTableWidgetItem & o ) const;
188 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
189 void setSortData(const QVariant &d);
194 TableItemFormatter(QTableWidget &parent, int row);
196 /* access internal widget at column col*/
197 QTableWidgetItem *widget(int col);
198 const QTableWidgetItem *widget(int col) const;
201 virtual void setText(int index, const QString &fld);
202 virtual void setTextAlignment(int index, int align);
203 virtual void setBackground(int index, const QBrush &);
204 virtual void setSortValue(int index, const QVariant &value);
205 virtual void setPixmap(int index, const QPixmap &pix);
206 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
209 QTableWidget *parent;
211 BatSortingTableItem *last;
214 #endif /* _FMTWIDGETITEM_H_ */