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 three of the GNU Affero 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 Affero 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 /* Normal date field. Centers field if center true*/
96 void setDateFld(int index, utime_t fld, bool center = false);
98 /* Right-aligned text field. */
99 void setRightFld(int index, const QString &fld);
101 /* Numeric field - sorted as numeric type */
102 void setNumericFld(int index, const QString &fld);
103 void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
105 /* fld value interpreted as bytes and formatted with size suffixes */
106 void setBytesFld(int index, const QString &fld);
108 /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
109 void setDurationFld(int index, const QString &fld);
111 /* fld value interpreted as volume status. Colored accordingly */
112 void setVolStatusFld(int index, const QString &fld, bool center = true);
114 /* fld value interpreted as job status. Colored accordingly */
115 void setJobStatusFld(int index, const QString &status, bool center = true);
117 /* fld value interpreted as job type. */
118 void setJobTypeFld(int index, const QString &fld, bool center = false);
120 /* fld value interpreted as job level. */
121 void setJobLevelFld(int index, const QString &fld, bool center = false);
123 /* fld value interpreted as Online/Offline */
124 void setInChanger(int index, const QString &InChanger);
126 /* fld value interpreted as file or folder */
127 void setFileType(int index, const QString &type);
129 static void setBytesConversion(BYTES_CONVERSION b) {
132 static BYTES_CONVERSION getBytesConversion() {
137 /* only derived classes can create one of these */
140 virtual void setText(int index, const QString &fld) = 0;
141 virtual void setTextAlignment(int index, int align) = 0;
142 virtual void setBackground(int index, const QBrush &) = 0;
143 virtual void setPixmap(int index, const QPixmap &pix) = 0;
144 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
146 /* sets the *optional* value used for sorting */
147 virtual void setSortValue(int index, const QVariant &value) = 0;
150 static BYTES_CONVERSION cnvFlag;
154 * This class can be used instead of QTreeWidgetItem (it allocates one internally,
155 * to format data fields.
156 * All setXXXFld routines receive a column index and the unformatted string value.
158 class TreeItemFormatter : public ItemFormatterBase
162 TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
164 /* access internal widget */
165 QTreeWidgetItem *widget() { return wdg; }
166 const QTreeWidgetItem *widget() const { return wdg; }
169 virtual void setText(int index, const QString &fld);
170 virtual void setTextAlignment(int index, int align);
171 virtual void setBackground(int index, const QBrush &);
172 virtual void setSortValue(int index, const QVariant &value);
173 virtual void setPixmap(int index, const QPixmap &pix);
176 QTreeWidgetItem *wdg;
181 * This class can be used instead of QTableWidgetItem (it allocates one internally,
182 * to format data fields.
183 * All setXXXFld routines receive the column and the unformatted string value.
185 class TableItemFormatter : public ItemFormatterBase
189 /* specialized widget item - allows an optional data property for sorting */
190 class BatSortingTableItem : public QTableWidgetItem
193 static const int SORTDATA_ROLE = Qt::UserRole + 100;
195 BatSortingTableItem();
197 /* uses the sort data if available, reverts to default behavior othervise */
198 virtual bool operator< ( const QTableWidgetItem & o ) const;
200 /* set the value used for sorting - MUST BE A NUMERIC TYPE */
201 void setSortData(const QVariant &d);
206 TableItemFormatter(QTableWidget &parent, int row);
208 /* access internal widget at column col*/
209 QTableWidgetItem *widget(int col);
210 const QTableWidgetItem *widget(int col) const;
213 virtual void setText(int index, const QString &fld);
214 virtual void setTextAlignment(int index, int align);
215 virtual void setBackground(int index, const QBrush &);
216 virtual void setSortValue(int index, const QVariant &value);
217 virtual void setPixmap(int index, const QPixmap &pix);
218 virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
221 QTableWidget *parent;
223 BatSortingTableItem *last;
226 #endif /* _FMTWIDGETITEM_H_ */