1 #ifndef _FMTWIDGETITEM_H_
2 #define _FMTWIDGETITEM_H_
4 Bacula® - The Network Backup Solution
6 Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
8 The main author of Bacula is Kern Sibbald, with contributions from
9 many others, a complete list can be found in the file AUTHORS.
10 This program is Free Software; you can redistribute it and/or
11 modify it under the terms of version two of the GNU General Public
12 License as published by the Free Software Foundation and included
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Bacula® is a registered trademark of Kern Sibbald.
26 The licensor of Bacula is the Free Software Foundation Europe
27 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
28 Switzerland, email:ftf@fsfeurope.org.
33 * TreeView formatting helpers - Riccardo Ghetta, May 2008
37 class QTreeWidgetItem;
39 class QTableWidgetItem;
45 * common conversion routines
48 QString convertJobStatus(const QString &sts);
50 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
51 QString convertBytesIEC(qint64 fld);
53 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
54 QString convertBytesSI(qint64 fld);
57 * disable widget updating
72 * base class for formatters
75 class ItemFormatterBase
78 enum BYTES_CONVERSION {
79 BYTES_CONVERSION_NONE,
85 virtual ~ItemFormatterBase();
87 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
88 void setBoolFld(int index, const QString &fld, bool center = true);
89 void setBoolFld(int index, int fld, bool center = true);
91 /* Normal text field. Centers field if center true*/
92 void setTextFld(int index, const QString &fld, bool center = false);
94 /* Right-aligned text field. */
95 void setRightFld(int index, const QString &fld);
97 /* Numeric field - sorted as numeric type */
98 void setNumericFld(int index, const QString &fld);
99 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
101 /* fld value interpreted as bytes and formatted with size suffixes */
102 void setBytesFld(int index, const QString &fld);
104 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
105 void setDurationFld(int index, const QString &fld);
107 /* fld value interpreted as volume status. Colored accordingly */
108 void setVolStatusFld(int index, const QString &fld, bool center = true);
110 /* fld value interpreted as job status. Colored accordingly */
111 void setJobStatusFld(int index, const QString &status, bool center = true);
113 /* fld value interpreted as job type. */
114 void setJobTypeFld(int index, const QString &fld, bool center = false);
116 /* fld value interpreted as job level. */
117 void setJobLevelFld(int index, const QString &fld, bool center = false);
119 static void setBytesConversion(BYTES_CONVERSION b) {
122 static BYTES_CONVERSION getBytesConversion() {
127 /* only derived classes can create one of these */
130 virtual void setText(int index, const QString &fld) = 0;
131 virtual void setTextAlignment(int index, int align) = 0;
132 virtual void setBackground(int index, const QBrush &) = 0;
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);
163 QTreeWidgetItem *wdg;
168 * This class can be used instead of QTableWidgetItem (it allocates one internally,
169 * to format data fields.
170 * All setXXXFld routines receive the column and the unformatted string value.
172 class TableItemFormatter : public ItemFormatterBase
176 /* specialized widget item - allows an optional data property for sorting */
177 class BatSortingTableItem : public QTableWidgetItem
180 static const int SORTDATA_ROLE = Qt::UserRole + 100;
182 BatSortingTableItem();
184 /* uses the sort data if available, reverts to default behavior othervise */
185 virtual bool operator< ( const QTableWidgetItem & o ) const;
187 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
188 void setSortData(const QVariant &d);
193 TableItemFormatter(QTableWidget &parent, int row);
195 /* access internal widget at column col*/
196 QTableWidgetItem *widget(int col);
197 const QTableWidgetItem *widget(int col) const;
200 virtual void setText(int index, const QString &fld);
201 virtual void setTextAlignment(int index, int align);
202 virtual void setBackground(int index, const QBrush &);
203 virtual void setSortValue(int index, const QVariant &value);
206 QTableWidget *parent;
208 BatSortingTableItem *last;
211 #endif /* _FMTWIDGETITEM_H_ */