1 #ifndef _FMTWIDGETITEM_H_
2 #define _FMTWIDGETITEM_H_
4 Bacula(R) - The Network Backup Solution
6 Copyright (C) 2000-2015 Kern Sibbald
7 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
9 The original author of Bacula is Kern Sibbald, with contributions
10 from many others, a complete list can be found in the file AUTHORS.
12 You may use this file and others of this release according to the
13 license defined in the LICENSE file, which includes the Affero General
14 Public License, v3.0 ("AGPLv3") and some additional permissions and
15 terms pursuant to its AGPLv3 Section 7.
17 This notice must be preserved when any source code is
18 conveyed and/or propagated.
20 Bacula(R) is a registered trademark of Kern Sibbald.
23 * TreeView formatting helpers - Riccardo Ghetta, May 2008
27 class QTreeWidgetItem;
29 class QTableWidgetItem;
35 * common conversion routines
38 QString convertJobStatus(const QString &sts);
40 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
41 QString convertBytesIEC(qint64 fld);
43 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
44 QString convertBytesSI(qint64 fld);
47 * disable widget updating
62 * base class for formatters
65 class ItemFormatterBase
68 enum BYTES_CONVERSION {
69 BYTES_CONVERSION_NONE,
75 virtual ~ItemFormatterBase();
77 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
78 void setBoolFld(int index, const QString &fld, bool center = true);
79 void setBoolFld(int index, int fld, bool center = true);
81 /* Print nice icon to represent percent */
82 void setPercent(int index, float number);
84 /* Normal text field. Centers field if center true*/
85 void setTextFld(int index, const QString &fld, bool center = false);
87 /* Normal date field. Centers field if center true*/
88 void setDateFld(int index, utime_t fld, bool center = false);
90 /* Right-aligned text field. */
91 void setRightFld(int index, const QString &fld);
93 /* Numeric field - sorted as numeric type */
94 void setNumericFld(int index, const QString &fld);
95 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
97 /* fld value interpreted as bytes and formatted with size suffixes */
98 void setBytesFld(int index, const QString &fld);
100 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
101 void setDurationFld(int index, const QString &fld);
103 /* fld value interpreted as volume status. Colored accordingly */
104 void setVolStatusFld(int index, const QString &fld, bool center = true);
106 /* fld value interpreted as job status. Colored accordingly */
107 void setJobStatusFld(int index, const QString &status, bool center = true);
109 /* fld value interpreted as job type. */
110 void setJobTypeFld(int index, const QString &fld, bool center = false);
112 /* fld value interpreted as job level. */
113 void setJobLevelFld(int index, const QString &fld, bool center = false);
115 /* fld value interpreted as Online/Offline */
116 void setInChanger(int index, const QString &InChanger);
118 /* fld value interpreted as file or folder */
119 void setFileType(int index, const QString &type);
121 static void setBytesConversion(BYTES_CONVERSION b) {
124 static BYTES_CONVERSION getBytesConversion() {
129 /* only derived classes can create one of these */
132 virtual void setText(int index, const QString &fld) = 0;
133 virtual void setTextAlignment(int index, int align) = 0;
134 virtual void setBackground(int index, const QBrush &) = 0;
135 virtual void setPixmap(int index, const QPixmap &pix) = 0;
136 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
138 /* sets the *optional* value used for sorting */
139 virtual void setSortValue(int index, const QVariant &value) = 0;
142 static BYTES_CONVERSION cnvFlag;
146 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
147 * to format data fields.
148 * All setXXXFld routines receive a column index and the unformatted string value.
150 class TreeItemFormatter : public ItemFormatterBase
154 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
156 /* access internal widget */
157 QTreeWidgetItem *widget() { return wdg; }
158 const QTreeWidgetItem *widget() const { return wdg; }
161 virtual void setText(int index, const QString &fld);
162 virtual void setTextAlignment(int index, int align);
163 virtual void setBackground(int index, const QBrush &);
164 virtual void setSortValue(int index, const QVariant &value);
165 virtual void setPixmap(int index, const QPixmap &pix);
168 QTreeWidgetItem *wdg;
173 * This class can be used instead of QTableWidgetItem (it allocates one internally,
174 * to format data fields.
175 * All setXXXFld routines receive the column and the unformatted string value.
177 class TableItemFormatter : public ItemFormatterBase
181 /* specialized widget item - allows an optional data property for sorting */
182 class BatSortingTableItem : public QTableWidgetItem
185 static const int SORTDATA_ROLE = Qt::UserRole + 100;
187 BatSortingTableItem();
189 /* uses the sort data if available, reverts to default behavior othervise */
190 virtual bool operator< ( const QTableWidgetItem & o ) const;
192 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
193 void setSortData(const QVariant &d);
198 TableItemFormatter(QTableWidget &parent, int row);
200 /* access internal widget at column col*/
201 QTableWidgetItem *widget(int col);
202 const QTableWidgetItem *widget(int col) const;
205 virtual void setText(int index, const QString &fld);
206 virtual void setTextAlignment(int index, int align);
207 virtual void setBackground(int index, const QBrush &);
208 virtual void setSortValue(int index, const QVariant &value);
209 virtual void setPixmap(int index, const QPixmap &pix);
210 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
213 QTableWidget *parent;
215 BatSortingTableItem *last;
218 #endif /* _FMTWIDGETITEM_H_ */