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
36 class QTreeWidgetItem;
38 class QTableWidgetItem;
44 * common conversion routines
47 QString convertJobStatus(const QString &sts);
51 * base class for formatters
54 class ItemFormatterBase
57 enum BYTES_CONVERSION {
58 BYTES_CONVERSION_NONE,
64 virtual ~ItemFormatterBase();
66 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
67 void setBoolFld(int index, const QString &fld, bool center = true);
68 void setBoolFld(int index, int fld, bool center = true);
70 /* Normal text field. Centers field if center true*/
71 void setTextFld(int index, const QString &fld, bool center = false);
73 /* Right-aligned text field. */
74 void setRightFld(int index, const QString &fld);
76 /* Numeric field - sorted as numeric type */
77 void setNumericFld(int index, const QString &fld);
78 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
80 /* fld value interpreted as bytes and formatted with size suffixes */
81 void setBytesFld(int index, const QString &fld);
83 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
84 void setDurationFld(int index, const QString &fld);
86 /* fld value interpreted as volume status. Colored accordingly */
87 void setVolStatusFld(int index, const QString &fld, bool center = true);
89 /* fld value interpreted as job status. Colored accordingly */
90 void setJobStatusFld(int index, const QString &status, bool center = true);
92 /* fld value interpreted as job type. */
93 void setJobTypeFld(int index, const QString &fld, bool center = false);
95 /* fld value interpreted as job level. */
96 void setJobLevelFld(int index, const QString &fld, bool center = false);
98 static void setBytesConversion(BYTES_CONVERSION b) {
101 static BYTES_CONVERSION getBytesConversion() {
106 /* only derived classes can create one of these */
109 virtual void setText(int index, const QString &fld) = 0;
110 virtual void setTextAlignment(int index, int align) = 0;
111 virtual void setBackground(int index, const QBrush &) = 0;
113 /* sets the *optional* value used for sorting */
114 virtual void setSortValue(int index, const QVariant &value) = 0;
118 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
119 static QString convertBytesIEC(qint64 fld);
121 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
122 static QString convertBytesSI(qint64 fld);
125 static BYTES_CONVERSION cnvFlag;
129 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
130 * to format data fields.
131 * All setXXXFld routines receive a column index and the unformatted string value.
133 class TreeItemFormatter : public ItemFormatterBase
137 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
139 /* access internal widget */
140 QTreeWidgetItem *widget() { return wdg; }
141 const QTreeWidgetItem *widget() const { return wdg; }
144 virtual void setText(int index, const QString &fld);
145 virtual void setTextAlignment(int index, int align);
146 virtual void setBackground(int index, const QBrush &);
147 virtual void setSortValue(int index, const QVariant &value);
150 QTreeWidgetItem *wdg;
155 * This class can be used instead of QTableWidgetItem (it allocates one internally,
156 * to format data fields.
157 * All setXXXFld routines receive the column and the unformatted string value.
159 class TableItemFormatter : public ItemFormatterBase
163 /* specialized widget item - allows an optional data property for sorting */
164 class BatSortingTableItem : public QTableWidgetItem
167 static const int SORTDATA_ROLE = Qt::UserRole + 100;
169 BatSortingTableItem();
171 /* uses the sort data if available, reverts to default behavior othervise */
172 virtual bool operator< ( const QTableWidgetItem & o ) const;
174 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
175 void setSortData(const QVariant &d);
180 TableItemFormatter(QTableWidget &parent, int row);
182 /* access internal widget at column col*/
183 QTableWidgetItem *widget(int col);
184 const QTableWidgetItem *widget(int col) const;
187 virtual void setText(int index, const QString &fld);
188 virtual void setTextAlignment(int index, int align);
189 virtual void setBackground(int index, const QBrush &);
190 virtual void setSortValue(int index, const QVariant &value);
193 QTableWidget *parent;
195 BatSortingTableItem *last;
198 #endif /* _FMTWIDGETITEM_H_ */