1 #ifndef _FMTWIDGETITEM_H_
2 #define _FMTWIDGETITEM_H_
4 Bacula® - The Network Backup Solution
6 Copyright (C) 2007-2010 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.
31 * TreeView formatting helpers - Riccardo Ghetta, May 2008
35 class QTreeWidgetItem;
37 class QTableWidgetItem;
43 * common conversion routines
46 QString convertJobStatus(const QString &sts);
48 /* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
49 QString convertBytesIEC(qint64 fld);
51 /* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
52 QString convertBytesSI(qint64 fld);
55 * disable widget updating
70 * base class for formatters
73 class ItemFormatterBase
76 enum BYTES_CONVERSION {
77 BYTES_CONVERSION_NONE,
83 virtual ~ItemFormatterBase();
85 /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
86 void setBoolFld(int index, const QString &fld, bool center = true);
87 void setBoolFld(int index, int fld, bool center = true);
89 /* Print nice icon to represent percent */
90 void setPercent(int index, float number);
92 /* Normal text field. Centers field if center true*/
93 void setTextFld(int index, const QString &fld, bool center = false);
95 /* Right-aligned text field. */
96 void setRightFld(int index, const QString &fld);
98 /* Numeric field - sorted as numeric type */
99 void setNumericFld(int index, const QString &fld);
100 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
102 /* fld value interpreted as bytes and formatted with size suffixes */
103 void setBytesFld(int index, const QString &fld);
105 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
106 void setDurationFld(int index, const QString &fld);
108 /* fld value interpreted as volume status. Colored accordingly */
109 void setVolStatusFld(int index, const QString &fld, bool center = true);
111 /* fld value interpreted as job status. Colored accordingly */
112 void setJobStatusFld(int index, const QString &status, bool center = true);
114 /* fld value interpreted as job type. */
115 void setJobTypeFld(int index, const QString &fld, bool center = false);
117 /* fld value interpreted as job level. */
118 void setJobLevelFld(int index, const QString &fld, bool center = false);
120 /* fld value interpreted as Online/Offline */
121 void setInChanger(int index, const QString &InChanger);
123 static void setBytesConversion(BYTES_CONVERSION b) {
126 static BYTES_CONVERSION getBytesConversion() {
131 /* only derived classes can create one of these */
134 virtual void setText(int index, const QString &fld) = 0;
135 virtual void setTextAlignment(int index, int align) = 0;
136 virtual void setBackground(int index, const QBrush &) = 0;
137 virtual void setPixmap(int index, const QPixmap &pix) = 0;
138 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
140 /* sets the *optional* value used for sorting */
141 virtual void setSortValue(int index, const QVariant &value) = 0;
144 static BYTES_CONVERSION cnvFlag;
148 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
149 * to format data fields.
150 * All setXXXFld routines receive a column index and the unformatted string value.
152 class TreeItemFormatter : public ItemFormatterBase
156 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
158 /* access internal widget */
159 QTreeWidgetItem *widget() { return wdg; }
160 const QTreeWidgetItem *widget() const { return wdg; }
163 virtual void setText(int index, const QString &fld);
164 virtual void setTextAlignment(int index, int align);
165 virtual void setBackground(int index, const QBrush &);
166 virtual void setSortValue(int index, const QVariant &value);
167 virtual void setPixmap(int index, const QPixmap &pix);
170 QTreeWidgetItem *wdg;
175 * This class can be used instead of QTableWidgetItem (it allocates one internally,
176 * to format data fields.
177 * All setXXXFld routines receive the column and the unformatted string value.
179 class TableItemFormatter : public ItemFormatterBase
183 /* specialized widget item - allows an optional data property for sorting */
184 class BatSortingTableItem : public QTableWidgetItem
187 static const int SORTDATA_ROLE = Qt::UserRole + 100;
189 BatSortingTableItem();
191 /* uses the sort data if available, reverts to default behavior othervise */
192 virtual bool operator< ( const QTableWidgetItem & o ) const;
194 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
195 void setSortData(const QVariant &d);
200 TableItemFormatter(QTableWidget &parent, int row);
202 /* access internal widget at column col*/
203 QTableWidgetItem *widget(int col);
204 const QTableWidgetItem *widget(int col) const;
207 virtual void setText(int index, const QString &fld);
208 virtual void setTextAlignment(int index, int align);
209 virtual void setBackground(int index, const QBrush &);
210 virtual void setSortValue(int index, const QVariant &value);
211 virtual void setPixmap(int index, const QPixmap &pix);
212 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
215 QTableWidget *parent;
217 BatSortingTableItem *last;
220 #endif /* _FMTWIDGETITEM_H_ */