OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / icontext.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef ICONTEXT_H
34 #define ICONTEXT_H
35
36 #include <coreplugin/core_global.h>
37
38 #include <QtCore/QList>
39 #include <QtCore/QObject>
40
41 QT_BEGIN_NAMESPACE
42 class QWidget;
43 QT_END_NAMESPACE
44
45 namespace Core {
46
47 class CORE_EXPORT Context
48 {
49 public:
50     Context() {}
51
52     explicit Context(const char *c1) { add(c1); }
53     Context(const char *c1, const char *c2) { add(c1); add(c2); }
54     Context(const char *c1, const char *c2, const char *c3) { add(c1); add(c2); add(c3); }
55     Context(const char *base, int offset);
56     void add(const char *c);
57     bool contains(const char *c) const;
58     bool contains(int c) const { return d.contains(c); }
59     int size() const { return d.size(); }
60     bool isEmpty() const { return d.isEmpty(); }
61     int at(int i) const { return d.at(i); }
62
63     // FIXME: Make interface slimmer.
64     typedef QList<int>::const_iterator const_iterator;
65     const_iterator begin() const { return d.begin(); }
66     const_iterator end() const { return d.end(); }
67     int indexOf(int c) const { return d.indexOf(c); }
68     void removeAt(int i) { d.removeAt(i); }
69     void prepend(int c) { d.prepend(c); }
70     void add(const Context &c) { d += c.d; }
71     void add(int c) { d.append(c); }
72     bool operator==(const Context &c) const { return d == c.d; }
73
74 private:
75     QList<int> d;
76 };
77
78 class CORE_EXPORT IContext : public QObject
79 {
80     Q_OBJECT
81 public:
82     IContext(QObject *parent = 0) : QObject(parent) {}
83     virtual ~IContext() {}
84
85     virtual Context context() const = 0;
86     virtual QWidget *widget() = 0;
87     virtual QString contextHelpId() const { return QString(); }
88 };
89
90 class BaseContext : public Core::IContext
91 {
92 public:
93     BaseContext(QWidget *widget, const Context &context, QObject *parent = 0)
94         : Core::IContext(parent),
95         m_widget(widget),
96         m_context(context)
97     {
98     }
99
100     Context context() const { return m_context; }
101
102     QWidget *widget() { return m_widget; }
103
104 private:
105     QWidget *m_widget;
106     Context m_context;
107 };
108
109 } // namespace Core
110
111 #endif //ICONTEXT_H