From 84ccfaa697f90c18512415449086ec37301690cb Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 23 Oct 2009 11:49:04 +0200 Subject: [PATCH] bat: Display a nice graphic on media usage depending on the average size for this mediatype. --- bacula/src/qt-console/images/0p.png | Bin 0 -> 240 bytes bacula/src/qt-console/images/16p.png | Bin 0 -> 252 bytes bacula/src/qt-console/images/32p.png | Bin 0 -> 257 bytes bacula/src/qt-console/images/48p.png | Bin 0 -> 261 bytes bacula/src/qt-console/images/64p.png | Bin 0 -> 261 bytes bacula/src/qt-console/images/80p.png | Bin 0 -> 262 bytes bacula/src/qt-console/images/96p.png | Bin 0 -> 240 bytes bacula/src/qt-console/main.qrc | 7 ++ bacula/src/qt-console/medialist/mediaview.cpp | 18 ++--- bacula/src/qt-console/util/fmtwidgetitem.cpp | 62 ++++++++++++++++-- bacula/src/qt-console/util/fmtwidgetitem.h | 5 ++ 11 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 bacula/src/qt-console/images/0p.png create mode 100644 bacula/src/qt-console/images/16p.png create mode 100644 bacula/src/qt-console/images/32p.png create mode 100644 bacula/src/qt-console/images/48p.png create mode 100644 bacula/src/qt-console/images/64p.png create mode 100644 bacula/src/qt-console/images/80p.png create mode 100644 bacula/src/qt-console/images/96p.png diff --git a/bacula/src/qt-console/images/0p.png b/bacula/src/qt-console/images/0p.png new file mode 100644 index 0000000000000000000000000000000000000000..3a1b1d008cef19a6e3e523b9d04014a8359692a4 GIT binary patch literal 240 zcmeAS@N?(olHy`uVBq!ia0vp^%0Mi_!3HGRm$mo+DaPU;cPEB*=VV?2Ic!PZ?k)`f zL2$v|<&%LToCO|{#S9GG!XV7ZFl&wkNNb6wuPggaE^!VO-6Q*JRs)43OI#yLobz*Y zQ}ap~oQqNuOHxx5$}>wc6x=<11Hv2m#DR*uJzX3_JdP(PNU$z$Fgeh1#P@wnq|j)Jm>wc6x=<11Hv2m#DR*!JzX3_JdP(PNU$z$Fgeh1X!gku@~!jF z9jJJAMpDF3SXg*f_rV)J66d^|lT;K`RgVI(Yp~&)K1m0IS2F^S_gJMxShcY_r-&_E llzx8R#h4tCo+d?phT@|dEN4G$Qvh1Q;OXk;vd$@?2>>8@O~C*F literal 0 HcmV?d00001 diff --git a/bacula/src/qt-console/images/32p.png b/bacula/src/qt-console/images/32p.png new file mode 100644 index 0000000000000000000000000000000000000000..83bfa863eca6b0ee12de29fd8f8a9f82815a6e83 GIT binary patch literal 257 zcmeAS@N?(olHy`uVBq!ia0vp^%0Mi_!3HGRm$mo+DaPU;cPEB*=VV?2Ic!PZ?k)`f zL2$v|<&%LToCO|{#S9GG!XV7ZFl&wkNNb6wuPggaE^!Vq^^;Nuj{t=vOI#yLobz*Y zQ}ap~oQqNuOHxx5$}>wc6x=<11Hv2m#DR)pJY5_^JdP(PNU$z$Fgeh1X!gku@~!jF z9q90Vb7rQoMv|JEnn>rt8$J@}yqlAll7fPQcz`%W`0%?Kj4X@$Bume%NN!u29AV&+ qmKfOT`sU{5^bk>L*2M`Ym>HO*Rb+nj9xnyj!{F)a=d#Wzp$P!Ze^0jn literal 0 HcmV?d00001 diff --git a/bacula/src/qt-console/images/48p.png b/bacula/src/qt-console/images/48p.png new file mode 100644 index 0000000000000000000000000000000000000000..93a098a300634afaa8b2b2b4d3932255e9f857fb GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0vp^%0Mi_!3HGRm$mo+DaPU;cPEB*=VV?2Ic!PZ?k)`f zL2$v|<&%LToCO|{#S9GG!XV7ZFl&wkNNb6wuPggaE^!WV9rw$cyg(tz64!_l=ltB< z)VvY~=c3falGGH1^30M91$R&1fbd2>aiF3EPZ!4!kK@S+60D0GOb&FMv7CMCgZ#{V zo7s&MBQ_eRpIgu|bH)q-UAAQ7g}cvb2sfP+oIGh#(u7Hql)QOXC$kClSfyPtT-+x) wtuN70+`?QoSa4&~`FXa=(K#YLO^W;sC46d^)o%J-1KP#l>FVdQ&MBb@08gb)P5=M^ literal 0 HcmV?d00001 diff --git a/bacula/src/qt-console/images/64p.png b/bacula/src/qt-console/images/64p.png new file mode 100644 index 0000000000000000000000000000000000000000..f1d5e20e7f3918e467d92208032c0f87ad67fb66 GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0vp^%0Mi_!3HGRm$mo+DaPU;cPEB*=VV?2Ic!PZ?k)`f zL2$v|<&%LToCO|{#S9GG!XV7ZFl&wkNNb6wuPggaE^!VChEJ0t6@fyMC9V-A&iT2y zsd*&~&PAz-C8;S2<(VZJ3hti10pX2&;y^_So-U3d9>lRhV>$cO2l<)# zHnSTi3T-q_KewP`=8PE$qRks;UWiSf!g=tD(Bw&zk|s==q@>Yy)sUIfP1g9;jKJeO y-p4mA;GQ$PZ)Jzj#`N>^1Xazr+zw7)XE=LJRiXIDibFuV7(8A5T-G@yGywo*>r{6D literal 0 HcmV?d00001 diff --git a/bacula/src/qt-console/images/80p.png b/bacula/src/qt-console/images/80p.png new file mode 100644 index 0000000000000000000000000000000000000000..01c69a10fa8406ed73d094fb8dd8ff35514fd8ca GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^%0Mi_!3HGRm$mo+DaPU;cPEB*=VV?2Ic!PZ?k)`f zL2$v|<&%LToCO|{#S9GG!XV7ZFl&wkNNb6wuPggaE^!VC)t%FO(||&fC9V-A&iT2y zsd*&~&PAz-C8;S2<(VZJ3hti10pX2&;y^`-o-U3d9>lRhbMv(F2l<)r z|2$<@-g@-h9Lr{mdKI;Vst0GhN^!~g&Q literal 0 HcmV?d00001 diff --git a/bacula/src/qt-console/images/96p.png b/bacula/src/qt-console/images/96p.png new file mode 100644 index 0000000000000000000000000000000000000000..440c19acd6521f434ffed3589829302335254ffe GIT binary patch literal 240 zcmeAS@N?(olHy`uVBq!ia0vp^%0Mi_!3HGRm$mo+DaPU;cPEB*=VV?2Ic!PZ?k)`f zL2$v|<&%LToCO|{#S9GG!XV7ZFl&wkNNb6wuPggaE^!VC(lRhbMv(F2l<)r z|2$<@wmp)NqgHa=a;1ln#Y&G$u{^7j*@Swm(ykaT?vtF>m*^;dqx`w$VTX?1ra*%y aj11M!bcI^PFNXk)W$<+Mb6Mw<&;$TFe@P<% literal 0 HcmV?d00001 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; -- 2.39.5