Qt 4.8
qscriptdebuggerfrontend.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSCriptTools module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
45 #include "qscriptdebuggerevent_p.h"
49 
50 #include <QtCore/qcoreevent.h>
51 #include <QtCore/qcoreapplication.h>
52 
54 
66 // helper class that's used to handle our custom Qt events
68 {
69 public:
71  QObject *parent = 0);
73 
74  bool event(QEvent *);
75 
76 private:
78 };
79 
82  : QObject(parent), m_frontend(frontend)
83 {
84 }
85 
87 {
88 }
89 
91 {
92  return m_frontend->event(e);
93 }
94 
95 
97 {
98  eventHandler = 0;
99  nextCommandId = 0;
100  eventReceiver = new QScriptDebuggerFrontendEventReceiver(this);
101 }
102 
104 {
105  delete eventReceiver;
106 }
107 
109 {
110  QCoreApplication::postEvent(eventReceiver, e);
111 }
112 
114 {
116  if (e->type() == QEvent::User+1) {
118  bool handled = q->notifyEvent(de->event());
119  if (handled) {
120  q->scheduleCommand(QScriptDebuggerCommand::resumeCommand(),
121  /*responseHandler=*/0);
122  }
123  return true;
124  } else if (e->type() == QEvent::User+2) {
125  processCommands();
126  return true;
127  }
128  return false;
129 }
130 
132 {
134  while (!pendingCommands.isEmpty()) {
135  QScriptDebuggerCommand command(pendingCommands.takeFirst());
136  int id = pendingCommandIds.takeFirst();
137  q->processCommand(id, command);
138  }
139 }
140 
143 {
144  d_ptr->q_ptr = this;
145 }
146 
148 {
149 }
150 
152  : d_ptr(&dd)
153 {
154  d_ptr->q_ptr = this;
155 }
156 
158 {
160  return d->eventHandler;
161 }
162 
164 {
166  d->eventHandler = eventHandler;
167 }
168 
178  const QScriptDebuggerCommand &command,
180 {
182  int id = ++d->nextCommandId;
183  d->pendingCommands.append(command);
184  d->pendingCommandIds.append(id);
185  if (responseHandler)
186  d->responseHandlers.insert(id, responseHandler);
187  if (d->pendingCommands.size() == 1) {
188  QEvent *e = new QEvent(QEvent::Type(QEvent::User+2)); // ProcessCommands
189  d->postEvent(e);
190  }
191  return id;
192 }
193 
201 {
203  if (d->responseHandlers.contains(id)) {
204  QScriptDebuggerResponseHandlerInterface *handler = d->responseHandlers.take(id);
205  Q_ASSERT(handler != 0);
206  handler->handleResponse(response, id);
207  }
208 }
209 
217 {
219  if (d->eventHandler)
220  return d->eventHandler->debuggerEvent(event);
221  return false;
222 }
223 
225 {
227  return d->nextCommandId;
228 }
229 
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
The QScriptDebuggerFrontend class is the base class of debugger front-ends.
The QScriptDebuggerResponse class represents a front-end&#39;s response to a QScriptDebuggerCommand.
void notifyCommandFinished(int id, const QScriptDebuggerResponse &response)
Subclasses should call this function when the command identified by the given id has finished and pro...
bool notifyEvent(const QScriptDebuggerEvent &event)
Subclasses should call this function when the given event is received from the back-end.
QScriptDebuggerFrontendEventReceiver(QScriptDebuggerFrontendPrivate *frontend, QObject *parent=0)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
#define Q_D(Class)
Definition: qglobal.h:2482
static QScriptDebuggerCommand resumeCommand()
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void handleResponse(const QScriptDebuggerResponse &response, int commandId)=0
QScriptDebuggerEventHandlerInterface * eventHandler() const
QScopedPointer< QScriptDebuggerFrontendPrivate > d_ptr
QScriptDebuggerFrontendPrivate * m_frontend
The QScriptDebuggerCommand class represents a command issued to a QScriptDebuggerFrontend.
const QScriptDebuggerEvent & event() const
int scheduleCommand(const QScriptDebuggerCommand &command, QScriptDebuggerResponseHandlerInterface *responseHandler)
Schedules the given command for execution by this front-end, and returns a unique identifier associat...
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
QImageIOHandler * handler
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setEventHandler(QScriptDebuggerEventHandlerInterface *eventHandler)