hoverhandler: add priority system to determine which tooltip is shown

Hover handlers now have a priority which is used to determine which
handler's tooltip is shown. The handler with the highest priority is
used, or, in the case of equal rankings, the first registered handler.

The base handler implements a default basic priority system based on the
diagnostic and help properties. Derived handlers can manually set the
ranking value as part of the identifyMatch() call.

A new checkToolTip() method is added so the handler can analyze whether a
tooltip is valid without it being shown.

Change-Id: I9d82fb9cc52f1d3cd53a8b197d75cd923651b79d
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Marc Reilly
2016-01-04 09:17:59 +11:00
committed by David Schulz
parent 8c6b31f3d8
commit 64b172ae73
3 changed files with 61 additions and 4 deletions

View File

@@ -3107,11 +3107,24 @@ void TextEditorWidgetPrivate::processTooltipRequest(const QTextCursor &c)
emit q->tooltipOverrideRequested(q, toolTipPoint, c.position(), &handled);
if (handled)
return;
if (!m_hoverHandlers.isEmpty()) {
m_hoverHandlers.first()->showToolTip(q, toolTipPoint, c.position());
if (m_hoverHandlers.isEmpty()) {
emit q->tooltipRequested(toolTipPoint, c.position());
return;
}
emit q->tooltipRequested(toolTipPoint, c.position());
int highestPriority = -1;
BaseHoverHandler *highest = 0;
foreach (BaseHoverHandler *handler, m_hoverHandlers) {
int priority = handler->checkToolTip(q, c.position());
if (priority > highestPriority) {
highestPriority = priority;
highest = handler;
}
}
if (highest)
highest->showToolTip(q, toolTipPoint, c.position());
}
bool TextEditorWidget::viewportEvent(QEvent *event)