2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2019-01-25 15:04:50 +01:00
|
|
|
#include "core_global.h"
|
|
|
|
|
#include "helpitem.h"
|
|
|
|
|
#include "id.h"
|
2010-06-25 17:37:59 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QList>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QWidget>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-01-17 16:06:13 +01:00
|
|
|
#include <functional>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Core {
|
|
|
|
|
|
2010-06-25 17:37:59 +02:00
|
|
|
class CORE_EXPORT Context
|
2010-06-25 12:56:16 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-07-21 21:11:46 +02:00
|
|
|
Context() = default;
|
2010-06-25 17:37:59 +02:00
|
|
|
|
2013-01-11 13:34:31 +01:00
|
|
|
explicit Context(Id c1) { add(c1); }
|
|
|
|
|
Context(Id c1, Id c2) { add(c1); add(c2); }
|
|
|
|
|
Context(Id c1, Id c2, Id c3) { add(c1); add(c2); add(c3); }
|
|
|
|
|
bool contains(Id c) const { return d.contains(c); }
|
2010-06-25 17:37:59 +02:00
|
|
|
int size() const { return d.size(); }
|
|
|
|
|
bool isEmpty() const { return d.isEmpty(); }
|
2013-01-11 13:34:31 +01:00
|
|
|
Id at(int i) const { return d.at(i); }
|
2010-06-25 18:05:09 +02:00
|
|
|
|
|
|
|
|
// FIXME: Make interface slimmer.
|
2018-07-21 21:11:46 +02:00
|
|
|
using const_iterator = QList<Id>::const_iterator;
|
2010-06-25 18:05:09 +02:00
|
|
|
const_iterator begin() const { return d.begin(); }
|
|
|
|
|
const_iterator end() const { return d.end(); }
|
2013-01-11 13:34:31 +01:00
|
|
|
int indexOf(Id c) const { return d.indexOf(c); }
|
2010-06-25 18:05:09 +02:00
|
|
|
void removeAt(int i) { d.removeAt(i); }
|
2013-01-11 13:34:31 +01:00
|
|
|
void prepend(Id c) { d.prepend(c); }
|
2010-06-25 18:05:09 +02:00
|
|
|
void add(const Context &c) { d += c.d; }
|
2013-01-11 13:34:31 +01:00
|
|
|
void add(Id c) { d.append(c); }
|
2010-10-30 21:13:16 +02:00
|
|
|
bool operator==(const Context &c) const { return d == c.d; }
|
2010-06-25 18:05:09 +02:00
|
|
|
|
|
|
|
|
private:
|
2013-01-11 13:34:31 +01:00
|
|
|
QList<Id> d;
|
2010-06-25 12:56:16 +02:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
class CORE_EXPORT IContext : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2018-05-07 17:34:42 +02:00
|
|
|
IContext(QObject *parent = nullptr) : QObject(parent) {}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-13 13:00:30 +02:00
|
|
|
virtual Context context() const { return m_context; }
|
|
|
|
|
virtual QWidget *widget() const { return m_widget; }
|
2019-01-28 11:47:50 +01:00
|
|
|
using HelpCallback = std::function<void(const HelpItem &item)>;
|
|
|
|
|
virtual void contextHelp(const HelpCallback &callback) const { callback(m_contextHelp); }
|
2011-04-13 13:00:30 +02:00
|
|
|
|
|
|
|
|
virtual void setContext(const Context &context) { m_context = context; }
|
|
|
|
|
virtual void setWidget(QWidget *widget) { m_widget = widget; }
|
2019-01-25 15:04:50 +01:00
|
|
|
virtual void setContextHelp(const HelpItem &id) { m_contextHelp = id; }
|
2011-04-13 16:09:04 +02:00
|
|
|
|
2011-04-13 13:00:30 +02:00
|
|
|
protected:
|
|
|
|
|
Context m_context;
|
|
|
|
|
QPointer<QWidget> m_widget;
|
2019-01-25 15:04:50 +01:00
|
|
|
HelpItem m_contextHelp;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|
2017-01-26 16:56:31 +01:00
|
|
|
CORE_EXPORT QDebug operator<<(QDebug debug, const Core::Context &context);
|