1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtSCriptTools module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
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.
|
---|
15 | **
|
---|
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.
|
---|
23 | **
|
---|
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.
|
---|
27 | **
|
---|
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.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qscriptdebuggerstackmodel_p.h"
|
---|
43 |
|
---|
44 | #include "private/qabstractitemmodel_p.h"
|
---|
45 |
|
---|
46 | #include <QtScript/qscriptcontextinfo.h>
|
---|
47 | #include <QtCore/qfileinfo.h>
|
---|
48 | #include <QtCore/qcoreapplication.h>
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 | class QScriptDebuggerStackModelPrivate
|
---|
53 | : public QAbstractItemModelPrivate
|
---|
54 | {
|
---|
55 | Q_DECLARE_PUBLIC(QScriptDebuggerStackModel)
|
---|
56 | public:
|
---|
57 | QScriptDebuggerStackModelPrivate();
|
---|
58 | ~QScriptDebuggerStackModelPrivate();
|
---|
59 |
|
---|
60 | QList<QScriptContextInfo> contextInfos;
|
---|
61 | };
|
---|
62 |
|
---|
63 | QScriptDebuggerStackModelPrivate::QScriptDebuggerStackModelPrivate()
|
---|
64 | {
|
---|
65 | }
|
---|
66 |
|
---|
67 | QScriptDebuggerStackModelPrivate::~QScriptDebuggerStackModelPrivate()
|
---|
68 | {
|
---|
69 | }
|
---|
70 |
|
---|
71 | QScriptDebuggerStackModel::QScriptDebuggerStackModel(QObject *parent)
|
---|
72 | : QAbstractTableModel(*new QScriptDebuggerStackModelPrivate, parent)
|
---|
73 | {
|
---|
74 | }
|
---|
75 |
|
---|
76 | QScriptDebuggerStackModel::~QScriptDebuggerStackModel()
|
---|
77 | {
|
---|
78 | }
|
---|
79 |
|
---|
80 | QList<QScriptContextInfo> QScriptDebuggerStackModel::contextInfos() const
|
---|
81 | {
|
---|
82 | Q_D(const QScriptDebuggerStackModel);
|
---|
83 | return d->contextInfos;
|
---|
84 | }
|
---|
85 |
|
---|
86 | void QScriptDebuggerStackModel::setContextInfos(const QList<QScriptContextInfo> &infos)
|
---|
87 | {
|
---|
88 | Q_D(QScriptDebuggerStackModel);
|
---|
89 | layoutAboutToBeChanged();
|
---|
90 | d->contextInfos = infos;
|
---|
91 | layoutChanged();
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*!
|
---|
95 | \reimp
|
---|
96 | */
|
---|
97 | int QScriptDebuggerStackModel::columnCount(const QModelIndex &parent) const
|
---|
98 | {
|
---|
99 | if (!parent.isValid())
|
---|
100 | return 3;
|
---|
101 | return 0;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /*!
|
---|
105 | \reimp
|
---|
106 | */
|
---|
107 | int QScriptDebuggerStackModel::rowCount(const QModelIndex &parent) const
|
---|
108 | {
|
---|
109 | Q_D(const QScriptDebuggerStackModel);
|
---|
110 | if (!parent.isValid())
|
---|
111 | return d->contextInfos.count();
|
---|
112 | return 0;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*!
|
---|
116 | \reimp
|
---|
117 | */
|
---|
118 | QVariant QScriptDebuggerStackModel::data(const QModelIndex &index, int role) const
|
---|
119 | {
|
---|
120 | Q_D(const QScriptDebuggerStackModel);
|
---|
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()) {
|
---|
137 | if (info.functionType() == QScriptContextInfo::ScriptFunction)
|
---|
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 |
|
---|
152 | /*!
|
---|
153 | \reimp
|
---|
154 | */
|
---|
155 | QVariant QScriptDebuggerStackModel::headerData(int section, Qt::Orientation orient, int role) const
|
---|
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 |
|
---|
170 | QT_END_NAMESPACE
|
---|