Qt 4.8
qscriptdebuggerconsolecommandmanager.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 
46 #include <QtCore/qlist.h>
47 #include <QtCore/qstringlist.h>
48 
50 
61 {
63 public:
66 
69 
71 };
72 
74 {
75  groups[QLatin1String("breakpoints")] =
76  QScriptDebuggerConsoleCommandGroupData(QLatin1String("Making program stop at certain points"),
77  QLatin1String(""));
78  groups[QLatin1String("files")] =
80  QLatin1String(""));
81  groups[QLatin1String("stack")] =
83  QLatin1String(""));
84  groups[QLatin1String("running")] =
86  QLatin1String(""));
87  groups[QLatin1String("status")] =
89  QLatin1String(""));
90  groups[QLatin1String("void")] =
92  QLatin1String("It's a secret to everyone"));
93 }
94 
96 {
98 }
99 
102 {
103  d_ptr->q_ptr = this;
104 }
105 
107 {
108 }
109 
115 {
117  Q_ASSERT(command != 0);
118  if (command->name().isEmpty()) {
119  qWarning("addCommand(): nameless command ignored");
120  return;
121  }
122  if (command->group().isEmpty()) {
123  qWarning("addCommand(): groupless command '%s' ignored",
124  qPrintable(command->name()));
125  return;
126  }
127  if (findCommand(command->name()) != 0) {
128  qWarning("addCommand(): duplicate command '%s' (group '%s') ignored",
129  qPrintable(command->name()), qPrintable(command->group()));
130  return;
131  }
132  if (!d->groups.contains(command->group())) {
133  qWarning("addCommand(): group '%s' for command '%s' is unknown!",
134  qPrintable(command->group()), qPrintable(command->name()));
135  }
136  d->commands.append(command);
137 }
138 
144 {
146  if (name.isEmpty()) {
147  qWarning("addCommandGroup(): nameless group ignored");
148  return;
149  }
150  if (d->groups.contains(name)) {
151  qWarning("addCommandGroup(): group '%s' already defined",
152  qPrintable(name));
153  return;
154  }
155  d->groups[name] = data;
156 }
157 
163 {
165  for (int i = 0; i < d->commands.size(); ++i) {
166  QScriptDebuggerConsoleCommand *cmd = d->commands.at(i);
167  if (cmd->name() == name)
168  return cmd;
169  else if (cmd->aliases().contains(name))
170  return cmd;
171  }
172  return 0;
173 }
174 
179 {
182  for (int i = 0; i < d->commands.size(); ++i) {
183  QScriptDebuggerConsoleCommand *cmd = d->commands.at(i);
184  result[cmd->group()].append(cmd);
185  }
186  return result;
187 }
188 
193 {
196  for (int i = 0; i < d->commands.size(); ++i) {
197  QScriptDebuggerConsoleCommand *cmd = d->commands.at(i);
198  if (cmd->group() == name)
199  result.append(cmd);
200  }
201  return result;
202 }
203 
208 {
210  return d->groups.value(name);
211 }
212 
217 {
219  return d->groups;
220 }
221 
226 {
228  QStringList result;
229  for (int i = 0; i < d->commands.size(); ++i) {
230  QScriptDebuggerConsoleCommand *cmd = d->commands.at(i);
231  QStringList names;
232  names.append(cmd->name());
233 // names += cmd->aliases();
234  for (int j = 0; j < names.size(); ++j) {
235  const QString &name = names.at(j);
236  if ((name.length() > prefix.length()) && name.startsWith(prefix))
237  result.append(name);
238  }
239  }
240  qStableSort(result);
241  return result;
242 }
243 
double d
Definition: qnumeric_p.h:62
virtual QString group() const =0
Returns the group that this console command belongs to.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void addCommand(QScriptDebuggerConsoleCommand *command)
Adds the given command.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QMap< QString, QList< QScriptDebuggerConsoleCommand * > > commands() const
Returns the commands organized into groups.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual QString name() const =0
Returns the name of this console command.
#define Q_D(Class)
Definition: qglobal.h:2482
QStringList completions(const QString &prefix) const
Returns the possible completions for the given prefix.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QScopedPointer< QScriptDebuggerConsoleCommandManagerPrivate > d_ptr
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QMap< QString, QScriptDebuggerConsoleCommandGroupData > groups
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
void qStableSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:202
QScriptDebuggerConsoleCommand * findCommand(const QString &name) const
Returns the command with the given name if one exists, otherwise returns 0.
The QScriptDebuggerConsoleCommandGroupData class holds data associated with a console command group...
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QScriptDebuggerConsoleCommand class is the base class of console commands.
QScriptDebuggerConsoleCommandGroupData commandGroupData(const QString &name) const
Returns data associated with the group of the given name.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QScriptDebuggerConsoleCommand * > commandsInGroup(const QString &name) const
Returns commands in the group of the given name.
QScriptDebuggerConsoleCommandGroupMap commandGroups() const
Returns all command groups.
#define qPrintable(string)
Definition: qglobal.h:1750
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
virtual QStringList aliases() const
Returns a list of aliases for this command.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void addCommandGroup(const QString &name, const QScriptDebuggerConsoleCommandGroupData &data)
Registers a command group with the given name and data.