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 John Walker.
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
36 class QTreeWidgetItem;
38 class QTableWidgetItem;
43 * base class for formatters
46 class ItemFormatterBase
49 enum BYTES_CONVERSION {
50 BYTES_CONVERSION_NONE,
56 virtual ~ItemFormatterBase();
58 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
59 void setBoolFld(int index, const QString &fld, bool center = true);
60 void setBoolFld(int index, int fld, bool center = true);
62 /* Normal text field. Centers field if center true*/
63 void setTextFld(int index, const QString &fld, bool center = false);
65 /* Right-aligned text field. */
66 void setRightFld(int index, const QString &fld);
68 /* Numeric field - sorted as numeric type */
69 void setNumericFld(int index, const QString &fld);
70 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
72 /* fld value interpreted as bytes and formatted with size suffixes */
73 void setBytesFld(int index, const QString &fld);
75 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
76 void setDurationFld(int index, const QString &fld);
78 /* fld value interpreted as volume status. Colored accordingly */
79 void setVolStatusFld(int index, const QString &fld, bool center = true);
81 /* fld value interpreted as job status. Colored accordingly */
82 void setJobStatusFld(int index, const QString &shortStatus, const QString &longstatus,
85 /* fld value interpreted as job type. */
86 void setJobTypeFld(int index, const QString &fld, bool center = false);
88 /* fld value interpreted as job level. */
89 void setJobLevelFld(int index, const QString &fld, bool center = false);
91 static void setBytesConversion(BYTES_CONVERSION b) {
94 static BYTES_CONVERSION getBytesConversion() {
99 /* only derived classes can create one of these */
102 virtual void setText(int index, const QString &fld) = 0;
103 virtual void setTextAlignment(int index, int align) = 0;
104 virtual void setBackground(int index, const QBrush &) = 0;
106 /* sets the *optional* value used for sorting */
107 virtual void setSortValue(int index, const QVariant &value) = 0;
111 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
112 static QString convertBytesIEC(qint64 fld);
114 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
115 static QString convertBytesSI(qint64 fld);
118 static BYTES_CONVERSION cnvFlag;
122 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
123 * to format data fields.
124 * All setXXXFld routines receive a column index and the unformatted string value.
126 class TreeItemFormatter : public ItemFormatterBase
130 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
132 /* access internal widget */
133 QTreeWidgetItem *widget() { return wdg; }
134 const QTreeWidgetItem *widget() const { return wdg; }
137 virtual void setText(int index, const QString &fld);
138 virtual void setTextAlignment(int index, int align);
139 virtual void setBackground(int index, const QBrush &);
140 virtual void setSortValue(int index, const QVariant &value);
143 QTreeWidgetItem *wdg;
148 * This class can be used instead of QTableWidgetItem (it allocates one internally,
149 * to format data fields.
150 * All setXXXFld routines receive the column and the unformatted string value.
152 class TableItemFormatter : public ItemFormatterBase
156 /* specialized widget item - allows an optional data property for sorting */
157 class BatSortingTableItem : public QTableWidgetItem
160 static const int SORTDATA_ROLE = Qt::UserRole + 100;
162 BatSortingTableItem();
164 /* uses the sort data if available, reverts to default behavior othervise */
165 virtual bool operator< ( const QTableWidgetItem & o ) const;
167 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
168 void setSortData(const QVariant &d);
173 TableItemFormatter(QTableWidget &parent, int row);
175 /* access internal widget at column col*/
176 QTableWidgetItem *widget(int col);
177 const QTableWidgetItem *widget(int col) const;
180 virtual void setText(int index, const QString &fld);
181 virtual void setTextAlignment(int index, int align);
182 virtual void setBackground(int index, const QBrush &);
183 virtual void setSortValue(int index, const QVariant &value);
186 QTableWidget *parent;
188 BatSortingTableItem *last;
191 #endif /* _FMTWIDGETITEM_H_ */