1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtSCriptTools module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qscriptdebuggerstackmodel_p.h"
44 #include "private/qabstractitemmodel_p.h"
46 #include <QtScript/qscriptcontextinfo.h>
47 #include <QtCore/qfileinfo.h>
51 class QScriptDebuggerStackModelPrivate
52 : public QAbstractItemModelPrivate
54 Q_DECLARE_PUBLIC(QScriptDebuggerStackModel
)
56 QScriptDebuggerStackModelPrivate();
57 ~QScriptDebuggerStackModelPrivate();
59 QList
<QScriptContextInfo
> contextInfos
;
62 QScriptDebuggerStackModelPrivate::QScriptDebuggerStackModelPrivate()
66 QScriptDebuggerStackModelPrivate::~QScriptDebuggerStackModelPrivate()
70 QScriptDebuggerStackModel::QScriptDebuggerStackModel(QObject
*parent
)
71 : QAbstractTableModel(*new QScriptDebuggerStackModelPrivate
, parent
)
75 QScriptDebuggerStackModel::~QScriptDebuggerStackModel()
79 QList
<QScriptContextInfo
> QScriptDebuggerStackModel::contextInfos() const
81 Q_D(const QScriptDebuggerStackModel
);
82 return d
->contextInfos
;
85 void QScriptDebuggerStackModel::setContextInfos(const QList
<QScriptContextInfo
> &infos
)
87 Q_D(QScriptDebuggerStackModel
);
88 layoutAboutToBeChanged();
89 d
->contextInfos
= infos
;
96 int QScriptDebuggerStackModel::columnCount(const QModelIndex
&parent
) const
98 if (!parent
.isValid())
106 int QScriptDebuggerStackModel::rowCount(const QModelIndex
&parent
) const
108 Q_D(const QScriptDebuggerStackModel
);
109 if (!parent
.isValid())
110 return d
->contextInfos
.count();
117 QVariant
QScriptDebuggerStackModel::data(const QModelIndex
&index
, int role
) const
119 Q_D(const QScriptDebuggerStackModel
);
120 if (!index
.isValid())
122 if (index
.row() >= d
->contextInfos
.count())
124 const QScriptContextInfo
&info
= d
->contextInfos
.at(index
.row());
125 if (role
== Qt::DisplayRole
) {
126 if (index
.column() == 0) {
128 } else if (index
.column() == 1) {
129 QString name
= info
.functionName();
131 name
= QString::fromLatin1("<anonymous>");
133 } else if (index
.column() == 2) {
134 if (info
.lineNumber() == -1)
135 return QString::fromLatin1("<native>");
136 QString fn
= QFileInfo(info
.fileName()).fileName();
138 fn
= QString::fromLatin1("<anonymous script, id=%0>").arg(info
.scriptId());
139 return QString::fromLatin1("%0:%1").arg(fn
).arg(info
.lineNumber());
141 } else if (role
== Qt::ToolTipRole
) {
142 if (QFileInfo(info
.fileName()).fileName() != info
.fileName())
143 return info
.fileName();
151 QVariant
QScriptDebuggerStackModel::headerData(int section
, Qt::Orientation orient
, int role
) const
153 if (orient
!= Qt::Horizontal
)
155 if (role
== Qt::DisplayRole
) {
157 return QObject::tr("Level");
158 else if (section
== 1)
159 return QObject::tr("Name");
160 else if (section
== 2)
161 return QObject::tr("Location");