1 #ifndef _FMTWIDGETITEM_H_
2 #define _FMTWIDGETITEM_H_
4 Bacula(R) - The Network Backup Solution
6 Copyright (C) 2000-2016 Kern Sibbald
8 The original author of Bacula is Kern Sibbald, with contributions
9 from many 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 This notice must be preserved when any source code is
17 conveyed and/or propagated.
19 Bacula(R) is a registered trademark of Kern Sibbald.
22 * TreeView formatting helpers - Riccardo Ghetta, May 2008
26 class QTreeWidgetItem;
28 class QTableWidgetItem;
34 * common conversion routines
37 QString convertJobStatus(const QString &sts);
39 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
40 QString convertBytesIEC(qint64 fld);
42 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
43 QString convertBytesSI(qint64 fld);
46 * disable widget updating
61 * base class for formatters
64 class ItemFormatterBase
67 enum BYTES_CONVERSION {
68 BYTES_CONVERSION_NONE,
74 virtual ~ItemFormatterBase();
76 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
77 void setBoolFld(int index, const QString &fld, bool center = true);
78 void setBoolFld(int index, int fld, bool center = true);
80 /* Print nice icon to represent percent */
81 void setPercent(int index, float number);
83 /* Normal text field. Centers field if center true*/
84 void setTextFld(int index, const QString &fld, bool center = false);
86 /* Normal date field. Centers field if center true*/
87 void setDateFld(int index, utime_t fld, bool center = false);
89 /* Right-aligned text field. */
90 void setRightFld(int index, const QString &fld);
92 /* Numeric field - sorted as numeric type */
93 void setNumericFld(int index, const QString &fld);
94 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
96 /* fld value interpreted as bytes and formatted with size suffixes */
97 void setBytesFld(int index, const QString &fld);
99 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
100 void setDurationFld(int index, const QString &fld);
102 /* fld value interpreted as volume status. Colored accordingly */
103 void setVolStatusFld(int index, const QString &fld, bool center = true);
105 /* fld value interpreted as job status. Colored accordingly */
106 void setJobStatusFld(int index, const QString &status, bool center = true);
108 /* fld value interpreted as job type. */
109 void setJobTypeFld(int index, const QString &fld, bool center = false);
111 /* fld value interpreted as job level. */
112 void setJobLevelFld(int index, const QString &fld, bool center = false);
114 /* fld value interpreted as Online/Offline */
115 void setInChanger(int index, const QString &InChanger);
117 /* fld value interpreted as file or folder */
118 void setFileType(int index, const QString &type);
120 static void setBytesConversion(BYTES_CONVERSION b) {
123 static BYTES_CONVERSION getBytesConversion() {
128 /* only derived classes can create one of these */
131 virtual void setText(int index, const QString &fld) = 0;
132 virtual void setTextAlignment(int index, int align) = 0;
133 virtual void setBackground(int index, const QBrush &) = 0;
134 virtual void setPixmap(int index, const QPixmap &pix) = 0;
135 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
137 /* sets the *optional* value used for sorting */
138 virtual void setSortValue(int index, const QVariant &value) = 0;
141 static BYTES_CONVERSION cnvFlag;
145 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
146 * to format data fields.
147 * All setXXXFld routines receive a column index and the unformatted string value.
149 class TreeItemFormatter : public ItemFormatterBase
153 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
155 /* access internal widget */
156 QTreeWidgetItem *widget() { return wdg; }
157 const QTreeWidgetItem *widget() const { return wdg; }
160 virtual void setText(int index, const QString &fld);
161 virtual void setTextAlignment(int index, int align);
162 virtual void setBackground(int index, const QBrush &);
163 virtual void setSortValue(int index, const QVariant &value);
164 virtual void setPixmap(int index, const QPixmap &pix);
167 QTreeWidgetItem *wdg;
172 * This class can be used instead of QTableWidgetItem (it allocates one internally,
173 * to format data fields.
174 * All setXXXFld routines receive the column and the unformatted string value.
176 class TableItemFormatter : public ItemFormatterBase
180 /* specialized widget item - allows an optional data property for sorting */
181 class BatSortingTableItem : public QTableWidgetItem
184 static const int SORTDATA_ROLE = Qt::UserRole + 100;
186 BatSortingTableItem();
188 /* uses the sort data if available, reverts to default behavior othervise */
189 virtual bool operator< ( const QTableWidgetItem & o ) const;
191 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
192 void setSortData(const QVariant &d);
197 TableItemFormatter(QTableWidget &parent, int row);
199 /* access internal widget at column col*/
200 QTableWidgetItem *widget(int col);
201 const QTableWidgetItem *widget(int col) const;
204 virtual void setText(int index, const QString &fld);
205 virtual void setTextAlignment(int index, int align);
206 virtual void setBackground(int index, const QBrush &);
207 virtual void setSortValue(int index, const QVariant &value);
208 virtual void setPixmap(int index, const QPixmap &pix);
209 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
212 QTableWidget *parent;
214 BatSortingTableItem *last;
217 #endif /* _FMTWIDGETITEM_H_ */