From: Eric Bollengier Date: Fri, 23 Oct 2009 09:49:04 +0000 (+0200) Subject: bat: Display a nice graphic on media usage depending on the average X-Git-Tag: Release-7.0.0~2599^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=00be6ada3459eedda80fd138f28d30783c7e2623;p=bacula%2Fbacula bat: Display a nice graphic on media usage depending on the average size for this mediatype. --- diff --git a/bacula/src/qt-console/images/0p.png b/bacula/src/qt-console/images/0p.png new file mode 100644 index 0000000000..3a1b1d008c Binary files /dev/null and b/bacula/src/qt-console/images/0p.png differ diff --git a/bacula/src/qt-console/images/16p.png b/bacula/src/qt-console/images/16p.png new file mode 100644 index 0000000000..bae7a4837d Binary files /dev/null and b/bacula/src/qt-console/images/16p.png differ diff --git a/bacula/src/qt-console/images/32p.png b/bacula/src/qt-console/images/32p.png new file mode 100644 index 0000000000..83bfa863ec Binary files /dev/null and b/bacula/src/qt-console/images/32p.png differ diff --git a/bacula/src/qt-console/images/48p.png b/bacula/src/qt-console/images/48p.png new file mode 100644 index 0000000000..93a098a300 Binary files /dev/null and b/bacula/src/qt-console/images/48p.png differ diff --git a/bacula/src/qt-console/images/64p.png b/bacula/src/qt-console/images/64p.png new file mode 100644 index 0000000000..f1d5e20e7f Binary files /dev/null and b/bacula/src/qt-console/images/64p.png differ diff --git a/bacula/src/qt-console/images/80p.png b/bacula/src/qt-console/images/80p.png new file mode 100644 index 0000000000..01c69a10fa Binary files /dev/null and b/bacula/src/qt-console/images/80p.png differ diff --git a/bacula/src/qt-console/images/96p.png b/bacula/src/qt-console/images/96p.png new file mode 100644 index 0000000000..440c19acd6 Binary files /dev/null and b/bacula/src/qt-console/images/96p.png differ diff --git a/bacula/src/qt-console/main.qrc b/bacula/src/qt-console/main.qrc index 6ce0b03e48..224154e91d 100644 --- a/bacula/src/qt-console/main.qrc +++ b/bacula/src/qt-console/main.qrc @@ -1,5 +1,12 @@ + images/0p.png + images/16p.png + images/32p.png + images/48p.png + images/64p.png + images/80p.png + images/96p.png images/A.png images/R.png images/T.png diff --git a/bacula/src/qt-console/medialist/mediaview.cpp b/bacula/src/qt-console/medialist/mediaview.cpp index bcaaf0beab..3210ad505b 100644 --- a/bacula/src/qt-console/medialist/mediaview.cpp +++ b/bacula/src/qt-console/medialist/mediaview.cpp @@ -283,16 +283,16 @@ void MediaView::populateTable() query = "SELECT AVG(VolBytes) AS size, COUNT(1) as nb, " - "MediaType, VolStatus FROM Media " + "MediaType FROM Media " "WHERE VolStatus IN ('Full', 'Used') " - "GROUP BY MediaType, VolStatus"; + "GROUP BY MediaType"; if (m_console->sql_cmd(query, results)) { foreach (resultline, results) { fieldlist = resultline.split("\t"); - if (fieldlist.at(1).toInt() > 2) { - // MediaType + VolStatus (Used or Full) - hash_size[fieldlist.at(2) + fieldlist.at(3)] + if (fieldlist.at(1).toInt() >= 1) { + // MediaType + hash_size[fieldlist.at(2)] = fieldlist.at(0).toFloat(); } } @@ -342,12 +342,12 @@ void MediaView::populateTable() /* Usage */ usage = 0; - if (hash_size.contains(MediaType + VolStatus) && - hash_size[MediaType + VolStatus] != 0) + if (hash_size.contains(MediaType) && + hash_size[MediaType] != 0) { - usage = VolBytes.toLongLong() * 100 / hash_size[MediaType + VolStatus]; + usage = VolBytes.toLongLong() * 100 / hash_size[MediaType]; } - mediaitem.setTextFld(index++, str_usage.setNum(usage, 'f')); + mediaitem.setPercent(index++, usage); /* Volstatus */ mediaitem.setVolStatusFld(index++, VolStatus); diff --git a/bacula/src/qt-console/util/fmtwidgetitem.cpp b/bacula/src/qt-console/util/fmtwidgetitem.cpp index f673175755..2c36e36929 100644 --- a/bacula/src/qt-console/util/fmtwidgetitem.cpp +++ b/bacula/src/qt-console/util/fmtwidgetitem.cpp @@ -192,6 +192,40 @@ ItemFormatterBase::~ItemFormatterBase() { } +void ItemFormatterBase::setPercent(int index, float value) +{ + char buf[100]; + bsnprintf(buf, sizeof(buf), "%.2f%%", value); + QString val = buf; + QString pix; + if (value < 8) { + pix = ":images/0p.png"; + } else if (value < 24) { + pix = ":images/16p.png"; + } else if (value < 40) { + pix = ":images/32p.png"; + } else if (value < 56) { + pix = ":images/48p.png"; + } else if (value < 72) { + pix = ":images/64p.png"; + } else if (value < 88) { + pix = ":images/80p.png"; + } else { + pix = ":images/96p.png"; + } + setPixmap(index, QPixmap(pix), val); + setSortValue(index, (int) value); +} + +/* By default, the setPixmap implementation with tooltip don't implement + * the tooltip stuff + */ +void ItemFormatterBase::setPixmap(int index, const QPixmap &pix, + const QString &tip) +{ + setPixmap(index, pix); +} + void ItemFormatterBase::setInChanger(int index, const QString &InChanger) { setPixmap(index, @@ -448,13 +482,27 @@ last(NULL) void TableItemFormatter::setPixmap(int index, const QPixmap &pix) { // Centered, but not sortable ! -// QLabel *lbl = new QLabel(); -// lbl->setAlignment(Qt::AlignCenter); -// lbl->setPixmap(pix); -// parent->setCellWidget(row, index, lbl); - last = new BatSortingTableItem; - parent->setItem(row, index, last); - last->setIcon(pix); + QLabel *lbl = new QLabel(); + lbl->setAlignment(Qt::AlignCenter); + lbl->setPixmap(pix); + parent->setCellWidget(row, index, lbl); +} + +void TableItemFormatter::setPixmap(int index, const QPixmap &pix, + const QString &tips) +{ +// Centered, but not sortable ! + QLabel *lbl = new QLabel(); + lbl->setAlignment(Qt::AlignCenter); + lbl->setPixmap(pix); + if (!tips.isEmpty()) { + lbl->setToolTip(tips); + } + parent->setCellWidget(row, index, lbl); + +// last = new BatSortingTableItem; +// parent->setItem(row, index, last); +// last->setIcon(pix); } void TableItemFormatter::setText(int col, const QString &fld) diff --git a/bacula/src/qt-console/util/fmtwidgetitem.h b/bacula/src/qt-console/util/fmtwidgetitem.h index 43e9da5346..976d1bb58b 100644 --- a/bacula/src/qt-console/util/fmtwidgetitem.h +++ b/bacula/src/qt-console/util/fmtwidgetitem.h @@ -88,6 +88,9 @@ public: void setBoolFld(int index, const QString &fld, bool center = true); void setBoolFld(int index, int fld, bool center = true); + /* Print nice icon to represent percent */ + void setPercent(int index, float number); + /* Normal text field. Centers field if center true*/ void setTextFld(int index, const QString &fld, bool center = false); @@ -134,6 +137,7 @@ protected: virtual void setTextAlignment(int index, int align) = 0; virtual void setBackground(int index, const QBrush &) = 0; virtual void setPixmap(int index, const QPixmap &pix) = 0; + virtual void setPixmap(int index, const QPixmap &pix, const QString &tip); /* sets the *optional* value used for sorting */ virtual void setSortValue(int index, const QVariant &value) = 0; @@ -207,6 +211,7 @@ protected: virtual void setBackground(int index, const QBrush &); virtual void setSortValue(int index, const QVariant &value); virtual void setPixmap(int index, const QPixmap &pix); + virtual void setPixmap(int index, const QPixmap &pix, const QString &tip); private: QTableWidget *parent;