Qt 4.8
qscriptdebuggerstackmodel.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 
43 
44 #include "private/qabstractitemmodel_p.h"
45 
46 #include <QtScript/qscriptcontextinfo.h>
47 #include <QtCore/qfileinfo.h>
48 #include <QtCore/qcoreapplication.h>
49 
51 
54 {
56 public:
59 
61 };
62 
64 {
65 }
66 
68 {
69 }
70 
73 {
74 }
75 
77 {
78 }
79 
81 {
83  return d->contextInfos;
84 }
85 
87 {
90  d->contextInfos = infos;
91  layoutChanged();
92 }
93 
98 {
99  if (!parent.isValid())
100  return 3;
101  return 0;
102 }
103 
108 {
110  if (!parent.isValid())
111  return d->contextInfos.count();
112  return 0;
113 }
114 
119 {
121  if (!index.isValid())
122  return QVariant();
123  if (index.row() >= d->contextInfos.count())
124  return QVariant();
125  const QScriptContextInfo &info = d->contextInfos.at(index.row());
126  if (role == Qt::DisplayRole) {
127  if (index.column() == 0) {
128  return index.row();
129  } else if (index.column() == 1) {
130  QString name = info.functionName();
131  if (name.isEmpty())
132  name = QString::fromLatin1("<anonymous>");
133  return name;
134  } else if (index.column() == 2) {
135  QString fn = QFileInfo(info.fileName()).fileName();
136  if (fn.isEmpty()) {
138  fn = QString::fromLatin1("<anonymous script, id=%0>").arg(info.scriptId());
139  else
140  fn = QString::fromLatin1("<native>");
141 
142  }
143  return QString::fromLatin1("%0:%1").arg(fn).arg(info.lineNumber());
144  }
145  } else if (role == Qt::ToolTipRole) {
146  if (QFileInfo(info.fileName()).fileName() != info.fileName())
147  return info.fileName();
148  }
149  return QVariant();
150 }
151 
156 {
157  if (orient != Qt::Horizontal)
158  return QVariant();
159  if (role == Qt::DisplayRole) {
160  if (section == 0)
161  return QCoreApplication::translate("QScriptDebuggerStackModel", "Level");
162  else if (section == 1)
163  return QCoreApplication::translate("QScriptDebuggerStackModel", "Name");
164  else if (section == 2)
165  return QCoreApplication::translate("QScriptDebuggerStackModel", "Location");
166  }
167  return QVariant();
168 }
169 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
int rowCount(const QModelIndex &parent) const
Reimplemented Function
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QVariant data(const QModelIndex &index, int role) const
Reimplemented Function
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
QVariant headerData(int section, Qt::Orientation, int role) const
Reimplemented Function
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QString fileName() const
Returns the name of the file where the code being executed was defined, if available; otherwise retur...
int columnCount(const QModelIndex &parent) const
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int lineNumber() const
Returns the line number corresponding to the statement being executed, or -1 if the line number is no...
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int row() const
Returns the row this model index refers to.
const char * name
QScriptDebuggerStackModel(QObject *parent=0)
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
void setContextInfos(const QList< QScriptContextInfo > &infos)
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QScriptContextInfo class provides additional information about a QScriptContext.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
FunctionType functionType() const
Returns the type of the called function.
qint64 scriptId() const
Returns the ID of the script where the code being executed was defined, or -1 if the ID is not availa...
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
Orientation
Definition: qnamespace.h:174
static QString fileName(const QString &fileUrl)
QList< QScriptContextInfo > contextInfos() const
QList< QScriptContextInfo > contextInfos
The QAbstractTableModel class provides an abstract model that can be subclassed to create table model...
int column() const
Returns the column this model index refers to.
QString functionName() const
Returns the name of the called function, or an empty string if the name is not available.