chart tooltips improvements, other minor fixes
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Fri, 16 Mar 2018 15:39:42 +0000 (18:39 +0300)
committerAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Fri, 16 Mar 2018 15:39:42 +0000 (18:39 +0300)
src/analyze/gui/chartmodel.cpp
src/analyze/gui/chartwidgetqwtplot.cpp
src/analyze/gui/histogrammodel.cpp
src/analyze/gui/locationdata.h

index 31beec32a032d8e2618ab7296ff742526d96185b..c60f7b48a2c85c5bd5c4c035d468c3864e2228f6 100644 (file)
@@ -146,48 +146,54 @@ QVariant ChartModel::data(const QModelIndex& index, int role) const
             const auto formatted = Util::formatByteSize(cost, 1);
             if (cost > 1024) {
                 return i18nc("%1: the formatted byte size, e.g. \"1.2KB\", %2: the raw byte size, e.g. \"1300\"",
-                             "%1 (%2 bytes)", formatted, cost);
+                             "<b>%1</b> (%2 bytes)", formatted, cost);
             } else {
-                return formatted;
+                return QString("<b>%1</b>").arg(formatted);
             }
         };
         if (column == 0) {
             switch (m_type) {
             case Allocations:
-                return i18n("<qt>%1 allocations in total after %2</qt>", cost, time);
+                return i18n("<qt><b>%1</b> allocations in total after <b>%2</b></qt>", cost, time);
             case Temporary:
-                return i18n("<qt>%1 temporary allocations in total after %2</qt>", cost, time);
+                return i18n("<qt><b>%1</b> temporary allocations in total after <b>%2</b></qt>", cost, time);
             case Instances:
-                return i18n("<qt>%1 number of instances in total after %2</qt>", cost, time);
+                return i18n("<qt><b>%1</b> number of instances in total after <b>%2</b></qt>", cost, time);
             case Consumed:
-                return i18n("<qt>%1 consumed in total after %2</qt>",
+                return i18n("<qt>%1 consumed in total after <b>%2</b></qt>",
                             byteCost(), time);
             case Allocated:
-                return i18n("<qt>%1 allocated in total after %2</qt>",
+                return i18n("<qt>%1 allocated in total after <b>%2</b></qt>",
                             byteCost(), time);
             }
         } else {
-            const auto label = Util::wrapLabel(m_data.labels.value(column), 96);
+            auto label = m_data.labels.value(column);
+#ifdef QWT_FOUND
+            label = Util::wrapLabel(label, 96, 0, "&nbsp;<br>");
+#else
+            label = label.toHtmlEscaped(); // Qt wraps text in tooltips itself
+#endif
+            Util::wrapLabel(label, 96);
             switch (m_type) {
             case Allocations:
-                return i18n("<qt>%2 allocations after %3 from:<p "
-                            "style='margin-left:10px;'>%1</p></qt>",
+                return i18n("<qt><b>%2</b> allocations after <b>%3</b> from: "
+                            "<p style='margin-left:10px;'>%1</p></qt>",
                             label, cost, time);
             case Temporary:
-                return i18n("<qt>%2 temporary allocations after %3 from:<p "
-                            "style='margin-left:10px'>%1</p></qt>",
+                return i18n("<qt><b>%2</b> temporary allocations after <b>%3</b> from: "
+                            "<p style='margin-left:10px'>%1</p></qt>",
                             label, cost, time);
             case Instances:
-                return i18n("<qt>%2 number of instances after %3 from:<p "
-                            "style='margin-left:10px'>%1</p></qt>",
+                return i18n("<qt><b>%2</b> number of instances after <b>%3</b> from: "
+                            "<p style='margin-left:10px'>%1</p></qt>",
                             label, cost, time);
             case Consumed:
-                return i18n("<qt>%2 consumed after %3 from:<p "
-                            "style='margin-left:10px'>%1</p></qt>",
+                return i18n("<qt><b>%2</b> consumed after <b>%3</b> from: "
+                            "<p style='margin-left:10px'>%1</p></qt>",
                             label, byteCost(), time);
             case Allocated:
-                return i18n("<qt>%2 allocated after %3 from:<p "
-                            "style='margin-left:10px'>%1</p></qt>",
+                return i18n("<qt><b>%2</b> allocated after <b>%3</b> from: "
+                            "<p style='margin-left:10px'>%1</p></qt>",
                             label, byteCost(), time);
             }
         }
index f081a68a0a0ef93dbfda6e2ca029190823f4f348..b2410f266e18309134b764138167b283e74b5786 100644 (file)
@@ -46,7 +46,7 @@ public:
 protected:
     virtual QwtText trackerTextF(const QPointF &pos) const
     {
-//qDebug() << "pos.x=" << pos.x() << "; pos.y=" << pos.y();
+//        qDebug() << "Zoomer: (" << pos.x() << "; " << pos.y() << ")";
         if ((pos.x() < 0) || (pos.y() < 0))
         {
             return {};
@@ -54,6 +54,7 @@ protected:
         QString s;
         if (m_plot->getCurveTooltip(pos, s))
         {
+            s = "<p style='margin-left:4px'>" + s + "</p> ";
             m_plot->clearTooltip();
         }
         else // show default text
@@ -71,6 +72,7 @@ protected:
             m_plot->restoreTooltip();
         }
         QwtText text(s);
+        text.setRenderFlags(text.renderFlags() & ~Qt::AlignHorizontal_Mask | Qt::AlignLeft);
         text.setColor(Qt::white);
         QColor c = rubberBandPen().color();
         text.setBorderPen(QPen(c));
@@ -291,8 +293,7 @@ bool ChartWidgetQwtPlot::getCurveTooltip(const QPointF &position, QString &toolt
     {
 //qDebug() << "timestamp: " << timestamp << " ms; row timestamp: " << m_model->getTimestamp(row) << " ms; cost="
 //         << cost << "; row=" << row << "; minCostFound=" << minCostFound;
-        tooltip = QString(" %1 ").arg(
-            m_model->data(m_model->index(row, columnFound), Qt::ToolTipRole).toString());
+        tooltip = m_model->data(m_model->index(row, columnFound), Qt::ToolTipRole).toString();
         return true;
     }
     return false;
index d231e94470ccc0e868b6ae02dcda85ffb5932934..04c75fb9e03a0ad0e4e7ffc40e896a66c2dd91e2 100644 (file)
@@ -98,7 +98,11 @@ QVariant HistogramModel::data(const QModelIndex& index, int role) const
             tooltip = i18n("%1 allocations from %2 in %3", column.allocations, column.location->function,
                            column.location->module);
         }
-        return Util::wrapLabel(tooltip, 96);
+#ifdef QWT_FOUND
+        return Util::wrapLabel(tooltip, 96, 0, "&nbsp;<br>");
+#else
+        return tooltip.toHtmlEscaped(); // Qt wraps text in tooltips itself
+#endif
     }
     return column.allocations;
 }
index f974f6bfd66509d6dd995f07b9233139b9583842..e5beb5c93a0b81a9653153cd50901ba229b2fe6c 100644 (file)
@@ -85,7 +85,7 @@ inline uint qHash(const LocationData& location, uint seed_ = 0)
     boost::hash_combine(seed, qHash(location.file));
     boost::hash_combine(seed, qHash(location.module));
     boost::hash_combine(seed, location.line);
-    return seed;
+    return (uint)seed;
 }
 
 inline uint qHash(const LocationData::Ptr& location, uint seed = 0)