forked from qt-creator/qt-creator
Core: Prepare de-virtualization of IContext::contextHelp
... by providing a way to specify modified implementation by setting a functor. Change-Id: Ib0907dd00fdb2ef15242a7ec2e25a5f8a9cc6979 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -9,6 +9,24 @@
|
||||
|
||||
namespace Core {
|
||||
|
||||
void IContext::contextHelp(const HelpCallback &callback) const
|
||||
{
|
||||
if (m_contextHelpProvider) {
|
||||
m_contextHelpProvider(callback);
|
||||
} else {
|
||||
// This is important as this triggers the continued iteration
|
||||
// through other contexts that may provide items.
|
||||
callback({});
|
||||
}
|
||||
}
|
||||
|
||||
void IContext::setContextHelp(const HelpItem &item)
|
||||
{
|
||||
m_contextHelpProvider = [item](const HelpCallback &callback) {
|
||||
callback(item);
|
||||
};
|
||||
}
|
||||
|
||||
void IContext::attach(QWidget *widget, const Context &context, const HelpItem &help)
|
||||
{
|
||||
auto icontext = new IContext(widget); // As QObject parent.
|
||||
|
@@ -60,9 +60,10 @@ public:
|
||||
void setContext(const Context &context) { m_context = context; }
|
||||
|
||||
using HelpCallback = std::function<void(const HelpItem &item)>;
|
||||
virtual void contextHelp(const HelpCallback &callback) const { callback(m_contextHelp); }
|
||||
using HelpProvider = std::function<void(const HelpCallback &item)>;
|
||||
|
||||
virtual void setContextHelp(const HelpItem &id) { m_contextHelp = id; }
|
||||
virtual void contextHelp(const HelpCallback &callback) const;
|
||||
void setContextHelp(const HelpItem &id);
|
||||
|
||||
static void attach(QWidget *widget,
|
||||
const Context &context,
|
||||
@@ -71,7 +72,7 @@ public:
|
||||
protected:
|
||||
Context m_context;
|
||||
QPointer<QWidget> m_widget;
|
||||
HelpItem m_contextHelp;
|
||||
HelpProvider m_contextHelpProvider;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
Reference in New Issue
Block a user