]> git.sur5r.net Git - bacula/bacula/commitdiff
bat: Display a nice graphic on media usage depending on the average
authorEric Bollengier <eric@eb.homelinux.org>
Fri, 23 Oct 2009 09:49:04 +0000 (11:49 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Fri, 23 Oct 2009 09:49:04 +0000 (11:49 +0200)
size for this mediatype.

bacula/src/qt-console/images/0p.png [new file with mode: 0644]
bacula/src/qt-console/images/16p.png [new file with mode: 0644]
bacula/src/qt-console/images/32p.png [new file with mode: 0644]
bacula/src/qt-console/images/48p.png [new file with mode: 0644]
bacula/src/qt-console/images/64p.png [new file with mode: 0644]
bacula/src/qt-console/images/80p.png [new file with mode: 0644]
bacula/src/qt-console/images/96p.png [new file with mode: 0644]
bacula/src/qt-console/main.qrc
bacula/src/qt-console/medialist/mediaview.cpp
bacula/src/qt-console/util/fmtwidgetitem.cpp
bacula/src/qt-console/util/fmtwidgetitem.h

diff --git a/bacula/src/qt-console/images/0p.png b/bacula/src/qt-console/images/0p.png
new file mode 100644 (file)
index 0000000..3a1b1d0
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 (file)
index 0000000..bae7a48
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 (file)
index 0000000..83bfa86
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 (file)
index 0000000..93a098a
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 (file)
index 0000000..f1d5e20
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 (file)
index 0000000..01c69a1
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 (file)
index 0000000..440c19a
Binary files /dev/null and b/bacula/src/qt-console/images/96p.png differ
index 6ce0b03e4816bf401ae15c9876d48969df0612dc..224154e91df3fbc0c93ac63877050353e49c9375 100644 (file)
@@ -1,5 +1,12 @@
 <RCC>
     <qresource prefix="/" >
+        <file>images/0p.png</file>
+        <file>images/16p.png</file>
+        <file>images/32p.png</file>
+        <file>images/48p.png</file>
+        <file>images/64p.png</file>
+        <file>images/80p.png</file>
+        <file>images/96p.png</file>
         <file>images/A.png</file>
         <file>images/R.png</file>
         <file>images/T.png</file>
index bcaaf0beab2ae7366a576dd30dc9ffd9c5f7c8a1..3210ad505b828c054bd0434259ea8bede5fa958c 100644 (file)
@@ -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);
index f6731757551ffa4255753575fb8036fc4543f4b7..2c36e3692903be5b8161b028aaf806233278bc81 100644 (file)
@@ -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)
index 43e9da534639fd0e665aaafb28a096fb4bdba602..976d1bb58b9a8fa0ae4bd7475993c7a0cf8084d3 100644 (file)
@@ -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;