summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin/icontext.cpp
blob: 300fe62704a02bfff84c83b53aa153cd74e9c4d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/

#include "icontext.h"

#include <QDebug>

QDebug operator<<(QDebug debug, const Core::Context &context)
{
    debug.nospace() << "Context(";
    Core::Context::const_iterator it = context.begin();
    Core::Context::const_iterator end = context.end();
    if (it != end) {
        debug << *it;
        ++it;
    }
    while (it != end) {
        debug << ", " << *it;
        ++it;
    }
    debug << ')';

    return debug;
}

/*!
    \class Core::Context
    \inmodule QtCreator
    \ingroup mainclasses
    \brief The Context class implements a list of context IDs.

    Contexts are used for registering actions with Core::ActionManager, and
    when creating UI elements that provide a context for actions.

    See \l{The Action Manager and Commands} for an overview of how contexts are
    used.

    \sa Core::IContext
    \sa Core::ActionManager
    \sa {The Action Manager and Commands}
*/

/*!
    \typedef Core::Context::const_iterator

    \brief The Context::const_iterator provides an STL-style const interator for
    Context.
*/

/*!
    \fn Core::Context::Context()

    Creates a context list that represents the global context.
*/

/*!
    \fn Core::Context::Context(Core::Id c1)

    Creates a context list with a single ID \a c1.
*/

/*!
    \fn Core::Context::Context(Core::Id c1, Core::Id c2)

    Creates a context list with IDs \a c1 and \a c2.
*/

/*!
    \fn Core::Context::Context(Core::Id c1, Core::Id c2, Core::Id c3)

    Creates a context list with IDs \a c1, \a c2 and \a c3.
*/

/*!
    \fn bool Core::Context::contains(Core::Id c) const

    Returns whether this context list contains the ID \a c.
*/

/*!
    \fn int Core::Context::size() const

    Returns the number of IDs in the context list.
*/

/*!
    \fn bool Core::Context::isEmpty() const

    Returns whether this context list is empty and therefore default
    constructed.
*/

/*!
    \fn Core::Id Core::Context::at(int i) const

    Returns the ID at index \a i in the context list.
*/

/*!
    \fn Core::Context::const_iterator Core::Context::begin() const

    Returns an STL-style iterator pointing to the first ID in the context list.
*/

/*!
    \fn Core::Context::const_iterator Core::Context::end() const

    Returns an STL-style iterator pointing to the imaginary item after the last
    ID in the context list.
*/

/*!
    \fn int Core::Context::indexOf(Core::Id c) const

    Returns the index position of the ID \a c in the context list. Returns -1
    if no item matched.
*/

/*!
    \fn void Core::Context::removeAt(int i)

    Removes the ID at index \a i from the context list.
*/

/*!
    \fn void Core::Context::prepend(Core::Id c)

    Adds the ID \a c as the first item to the context list.
*/

/*!
    \fn void Core::Context::add(const Core::Context &c)

    Adds the context list \a c at the end of this context list.
*/

/*!
    \fn void Core::Context::add(Core::Id c)

    Adds the ID \a c at the end of the context list.
*/

/*!
    \fn bool Core::Context::operator==(const Core::Context &c) const
    \internal
*/

/*!
    \class Core::IContext
    \inmodule QtCreator
    \ingroup mainclasses

    \brief The IContext class associates a widget with a context list and
    context help.

    An instance of IContext must be registered with
    Core::ICore::addContextObject() to have an effect. For many subclasses of
    IContext, like Core::IEditor and Core::IMode, this is done automatically.
    But instances of IContext can be created manually to associate a context
    and context help for an arbitrary widget, too. IContext instances are
    automatically unregistered when they are deleted. Use
    Core::ICore::removeContextObject() if you need to unregister an IContext
    instance manually.

    Whenever the widget is part of the application wide focus widget's parent
    chain, the associated context list is made active. This makes actions active
    that were registered for any of the included context IDs. If the user
    requests context help, the top-most IContext instance in the focus widget's
    parent hierarchy is asked to provide it.

    See \l{The Action Manager and Commands} for an overview of how contexts are
    used for managing actions.

    \sa Core::ICore
    \sa Core::Context
    \sa Core::ActionManager
    \sa {The Action Manager and Commands}
*/

/*!
    \fn Core::IContext::IContext(QObject *parent)

    Creates an IContext with an optional \a parent.
*/

/*!
    \fn Core::Context Core::IContext::context() const

    Returns the context list associated with this IContext.

    \sa setContext()
*/

/*!
    \fn QWidget *Core::IContext::widget() const

    Returns the widget associated with this IContext.

    \sa setWidget()
*/

/*!
    \typedef Core::IContext::HelpCallback

    The HelpCallback class defines the callback function that is used to report
    the help item to show when the user requests context help.
*/

/*!
    \fn void Core::IContext::contextHelp(const Core::IContext::HelpCallback &callback) const

    Called when the user requests context help and this IContext is the top-most
    in the application focus widget's parent hierarchy. Implementations must
    call the passed \a callback with the resulting help item.
    The default implementation returns an help item with the help ID that was
    set with setContextHelp().

    \sa setContextHelp()
*/

/*!
    \fn void Core::IContext::setContext(const Core::Context &context)

    Sets the context list associated with this IContext to \a context.

    \sa context()
*/

/*!
    \fn void Core::IContext::setWidget(QWidget *widget)

    Sets the widget associated with this IContext to \a widget.

    \sa widget()
*/

/*!
    \fn void Core::IContext::setContextHelp(const Core::HelpItem &id)

    Sets the context help item associated with this IContext to \a id.

    \sa contextHelp()
*/