diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-01-29 11:43:43 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-02-01 11:00:55 +0000 |
commit | 32429e11c90ec035d10f23aa079a18869cf546a0 (patch) | |
tree | d49747aadf0f6854ad53b916a89b791c15751076 /src/libs/utils/tooltip | |
parent | 4e8c2c4b13f7518b4c3d27c12daaa42d0442f606 (diff) |
Help: Avoid double lookup for help tooltips
Save the HelpItem directly in the tooltip instead of the help ID which
would need to be looked up again.
Change-Id: I107e82e89d9ea26cad9d6532ad4c687d1ac8f1ec
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/libs/utils/tooltip')
-rw-r--r-- | src/libs/utils/tooltip/tips.cpp | 23 | ||||
-rw-r--r-- | src/libs/utils/tooltip/tips.h | 14 | ||||
-rw-r--r-- | src/libs/utils/tooltip/tooltip.cpp | 36 | ||||
-rw-r--r-- | src/libs/utils/tooltip/tooltip.h | 19 |
4 files changed, 47 insertions, 45 deletions
diff --git a/src/libs/utils/tooltip/tips.cpp b/src/libs/utils/tooltip/tips.cpp index 2dfbe277526..d882bdb1d88 100644 --- a/src/libs/utils/tooltip/tips.cpp +++ b/src/libs/utils/tooltip/tips.cpp @@ -53,15 +53,15 @@ TipLabel::TipLabel(QWidget *parent) : { } -void TipLabel::setHelpId(const QString &id) +void TipLabel::setContextHelp(const QVariant &help) { - m_helpId = id; + m_contextHelp = help; update(); } -QString TipLabel::helpId() const +QVariant TipLabel::contextHelp() const { - return m_helpId; + return m_contextHelp; } const QMetaObject *TipLabel::metaObject() const @@ -113,9 +113,9 @@ bool ColorTip::canHandleContentReplacement(int typeId) const return typeId == ToolTip::ColorContent; } -bool ColorTip::equals(int typeId, const QVariant &other, const QString &otherHelpId) const +bool ColorTip::equals(int typeId, const QVariant &other, const QVariant &otherContextHelp) const { - return typeId == ToolTip::ColorContent && otherHelpId == helpId() && other == m_color; + return typeId == ToolTip::ColorContent && otherContextHelp == contextHelp() && other == m_color; } void ColorTip::paintEvent(QPaintEvent *event) @@ -165,7 +165,7 @@ bool TextTip::isInteractive() const void TextTip::configure(const QPoint &pos, QWidget *w) { - if (helpId().isEmpty()) + if (contextHelp().isNull()) setText(m_text); else setText(QString::fromLatin1("<table><tr><td valign=middle>%1</td><td> " @@ -201,9 +201,10 @@ int TextTip::showTime() const return 10000 + 40 * qMax(0, m_text.size() - 100); } -bool TextTip::equals(int typeId, const QVariant &other, const QString &otherHelpId) const +bool TextTip::equals(int typeId, const QVariant &other, const QVariant &otherContextHelp) const { - return typeId == ToolTip::TextContent && otherHelpId == helpId() && other.toString() == m_text; + return typeId == ToolTip::TextContent && otherContextHelp == contextHelp() + && other.toString() == m_text; } void TextTip::paintEvent(QPaintEvent *event) @@ -280,9 +281,9 @@ bool WidgetTip::canHandleContentReplacement(int typeId) const return false; } -bool WidgetTip::equals(int typeId, const QVariant &other, const QString &otherHelpId) const +bool WidgetTip::equals(int typeId, const QVariant &other, const QVariant &otherContextHelp) const { - return typeId == ToolTip::WidgetContent && otherHelpId == helpId() + return typeId == ToolTip::WidgetContent && otherContextHelp == contextHelp() && other.value<QWidget *>() == m_widget; } diff --git a/src/libs/utils/tooltip/tips.h b/src/libs/utils/tooltip/tips.h index 764e10eb8ae..22415075ab8 100644 --- a/src/libs/utils/tooltip/tips.h +++ b/src/libs/utils/tooltip/tips.h @@ -46,15 +46,15 @@ public: virtual int showTime() const = 0; virtual void configure(const QPoint &pos, QWidget *w) = 0; virtual bool canHandleContentReplacement(int typeId) const = 0; - virtual bool equals(int typeId, const QVariant &other, const QString &helpId) const = 0; - virtual void setHelpId(const QString &id); - virtual QString helpId() const; + virtual bool equals(int typeId, const QVariant &other, const QVariant &contextHelp) const = 0; + virtual void setContextHelp(const QVariant &help); + virtual QVariant contextHelp() const; protected: const QMetaObject *metaObject() const override; private: - QString m_helpId; + QVariant m_contextHelp; }; class TextTip : public TipLabel @@ -67,7 +67,7 @@ public: void configure(const QPoint &pos, QWidget *w) override; bool canHandleContentReplacement(int typeId) const override; int showTime() const override; - bool equals(int typeId, const QVariant &other, const QString &otherHelpId) const override; + bool equals(int typeId, const QVariant &other, const QVariant &otherContextHelp) const override; void paintEvent(QPaintEvent *event) override; void resizeEvent(QResizeEvent *event) override; @@ -84,7 +84,7 @@ public: void configure(const QPoint &pos, QWidget *w) override; bool canHandleContentReplacement(int typeId) const override; int showTime() const override { return 4000; } - bool equals(int typeId, const QVariant &other, const QString &otherHelpId) const override; + bool equals(int typeId, const QVariant &other, const QVariant &otherContextHelp) const override; void paintEvent(QPaintEvent *event) override; private: @@ -104,7 +104,7 @@ public: void configure(const QPoint &pos, QWidget *w) override; bool canHandleContentReplacement(int typeId) const override; int showTime() const override { return 30000; } - bool equals(int typeId, const QVariant &other, const QString &otherHelpId) const override; + bool equals(int typeId, const QVariant &other, const QVariant &otherContextHelp) const override; bool isInteractive() const override { return true; } private: diff --git a/src/libs/utils/tooltip/tooltip.cpp b/src/libs/utils/tooltip/tooltip.cpp index 42ce6b5c565..de3c536c5fe 100644 --- a/src/libs/utils/tooltip/tooltip.cpp +++ b/src/libs/utils/tooltip/tooltip.cpp @@ -62,36 +62,36 @@ ToolTip *ToolTip::instance() return &tooltip; } -void ToolTip::show(const QPoint &pos, const QString &content, QWidget *w, const QString &helpId, const QRect &rect) +void ToolTip::show(const QPoint &pos, const QString &content, QWidget *w, const QVariant &contextHelp, const QRect &rect) { if (content.isEmpty()) instance()->hideTipWithDelay(); else - instance()->showInternal(pos, QVariant(content), TextContent, w, helpId, rect); + instance()->showInternal(pos, QVariant(content), TextContent, w, contextHelp, rect); } -void ToolTip::show(const QPoint &pos, const QColor &color, QWidget *w, const QString &helpId, const QRect &rect) +void ToolTip::show(const QPoint &pos, const QColor &color, QWidget *w, const QVariant &contextHelp, const QRect &rect) { if (!color.isValid()) instance()->hideTipWithDelay(); else - instance()->showInternal(pos, QVariant(color), ColorContent, w, helpId, rect); + instance()->showInternal(pos, QVariant(color), ColorContent, w, contextHelp, rect); } -void ToolTip::show(const QPoint &pos, QWidget *content, QWidget *w, const QString &helpId, const QRect &rect) +void ToolTip::show(const QPoint &pos, QWidget *content, QWidget *w, const QVariant &contextHelp, const QRect &rect) { if (!content) instance()->hideTipWithDelay(); else - instance()->showInternal(pos, QVariant::fromValue(content), WidgetContent, w, helpId, rect); + instance()->showInternal(pos, QVariant::fromValue(content), WidgetContent, w, contextHelp, rect); } -void ToolTip::show(const QPoint &pos, QLayout *content, QWidget *w, const QString &helpId, const QRect &rect) +void ToolTip::show(const QPoint &pos, QLayout *content, QWidget *w, const QVariant &contextHelp, const QRect &rect) { if (content && content->count()) { auto tooltipWidget = new FakeToolTip; tooltipWidget->setLayout(content); - instance()->showInternal(pos, QVariant::fromValue(tooltipWidget), WidgetContent, w, helpId, rect); + instance()->showInternal(pos, QVariant::fromValue(tooltipWidget), WidgetContent, w, contextHelp, rect); } else { instance()->hideTipWithDelay(); } @@ -118,15 +118,15 @@ bool ToolTip::pinToolTip(QWidget *w, QWidget *parent) return false; } -QString ToolTip::contextHelpId() +QVariant ToolTip::contextHelp() { - return instance()->m_tip ? instance()->m_tip->helpId() : QString(); + return instance()->m_tip ? instance()->m_tip->contextHelp() : QVariant(); } bool ToolTip::acceptShow(const QVariant &content, int typeId, const QPoint &pos, - QWidget *w, const QString &helpId, + QWidget *w, const QVariant &contextHelp, const QRect &rect) { if (isVisible()) { @@ -135,9 +135,9 @@ bool ToolTip::acceptShow(const QVariant &content, QPoint localPos = pos; if (w) localPos = w->mapFromGlobal(pos); - if (tipChanged(localPos, content, typeId, w, helpId)) { + if (tipChanged(localPos, content, typeId, w, contextHelp)) { m_tip->setContent(content); - m_tip->setHelpId(helpId); + m_tip->setContextHelp(contextHelp); setUp(pos, w, rect); } return false; @@ -169,9 +169,9 @@ void ToolTip::setUp(const QPoint &pos, QWidget *w, const QRect &rect) } bool ToolTip::tipChanged(const QPoint &pos, const QVariant &content, int typeId, QWidget *w, - const QString &helpId) const + const QVariant &contextHelp) const { - if (!m_tip->equals(typeId, content, helpId) || m_widget != w) + if (!m_tip->equals(typeId, content, contextHelp) || m_widget != w) return true; if (!m_rect.isNull()) return !m_rect.contains(pos); @@ -243,9 +243,9 @@ void ToolTip::hideTipImmediately() } void ToolTip::showInternal(const QPoint &pos, const QVariant &content, - int typeId, QWidget *w, const QString &helpId, const QRect &rect) + int typeId, QWidget *w, const QVariant &contextHelp, const QRect &rect) { - if (acceptShow(content, typeId, pos, w, helpId, rect)) { + if (acceptShow(content, typeId, pos, w, contextHelp, rect)) { QWidget *target = nullptr; if (HostOsInfo::isWindowsHost()) target = QApplication::desktop()->screen(Internal::screenNumber(pos, w)); @@ -264,7 +264,7 @@ void ToolTip::showInternal(const QPoint &pos, const QVariant &content, break; } m_tip->setContent(content); - m_tip->setHelpId(helpId); + m_tip->setContextHelp(contextHelp); setUp(pos, w, rect); qApp->installEventFilter(this); showTip(); diff --git a/src/libs/utils/tooltip/tooltip.h b/src/libs/utils/tooltip/tooltip.h index d78623b41ff..8a4a0e83096 100644 --- a/src/libs/utils/tooltip/tooltip.h +++ b/src/libs/utils/tooltip/tooltip.h @@ -32,6 +32,7 @@ #include <QPointer> #include <QTimer> #include <QRect> +#include <QVariant> /* * In its current form QToolTip is not extensible. So this is an attempt to provide a more @@ -72,13 +73,13 @@ public: static ToolTip *instance(); static void show(const QPoint &pos, const QString &content, QWidget *w = nullptr, - const QString &helpId = QString(), const QRect &rect = QRect()); + const QVariant &contextHelp = {}, const QRect &rect = QRect()); static void show(const QPoint &pos, const QColor &color, QWidget *w = nullptr, - const QString &helpId = QString(), const QRect &rect = QRect()); + const QVariant &contextHelp = {}, const QRect &rect = QRect()); static void show(const QPoint &pos, QWidget *content, QWidget *w = nullptr, - const QString &helpId = QString(), const QRect &rect = QRect()); + const QVariant &contextHelp = {}, const QRect &rect = QRect()); static void show(const QPoint &pos, QLayout *content, QWidget *w = nullptr, - const QString &helpId = QString(), const QRect &rect = QRect()); + const QVariant &contextHelp = {}, const QRect &rect = QRect()); static void move(const QPoint &pos, QWidget *w); static void hide(); static void hideImmediately(); @@ -90,7 +91,7 @@ public: // using WidgetContent static bool pinToolTip(QWidget *w, QWidget *parent); - static QString contextHelpId(); + static QVariant contextHelp(); signals: void shown(); @@ -98,13 +99,13 @@ signals: private: void showInternal(const QPoint &pos, const QVariant &content, int typeId, QWidget *w, - const QString &helpId, const QRect &rect); + const QVariant &contextHelp, const QRect &rect); void hideTipImmediately(); bool acceptShow(const QVariant &content, int typeId, const QPoint &pos, QWidget *w, - const QString &helpId, const QRect &rect); + const QVariant &contextHelp, const QRect &rect); void setUp(const QPoint &pos, QWidget *w, const QRect &rect); bool tipChanged(const QPoint &pos, const QVariant &content, int typeId, QWidget *w, - const QString &helpId) const; + const QVariant &contextHelp) const; void setTipRect(QWidget *w, const QRect &rect); void placeTip(const QPoint &pos, QWidget *w); void showTip(); @@ -115,7 +116,7 @@ private: QRect m_rect; QTimer m_showTimer; QTimer m_hideDelayTimer; - QString m_helpId; + QVariant m_contextHelp; }; } // namespace Utils |