source: trunk/src/scripttools/debugging/qscriptdebuggerstackmodel.cpp@ 342

Last change on this file since 342 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtSCriptTools module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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
49QT_BEGIN_NAMESPACE
50
51class QScriptDebuggerStackModelPrivate
52 : public QAbstractItemModelPrivate
53{
54 Q_DECLARE_PUBLIC(QScriptDebuggerStackModel)
55public:
56 QScriptDebuggerStackModelPrivate();
57 ~QScriptDebuggerStackModelPrivate();
58
59 QList<QScriptContextInfo> contextInfos;
60};
61
62QScriptDebuggerStackModelPrivate::QScriptDebuggerStackModelPrivate()
63{
64}
65
66QScriptDebuggerStackModelPrivate::~QScriptDebuggerStackModelPrivate()
67{
68}
69
70QScriptDebuggerStackModel::QScriptDebuggerStackModel(QObject *parent)
71 : QAbstractTableModel(*new QScriptDebuggerStackModelPrivate, parent)
72{
73}
74
75QScriptDebuggerStackModel::~QScriptDebuggerStackModel()
76{
77}
78
79QList<QScriptContextInfo> QScriptDebuggerStackModel::contextInfos() const
80{
81 Q_D(const QScriptDebuggerStackModel);
82 return d->contextInfos;
83}
84
85void QScriptDebuggerStackModel::setContextInfos(const QList<QScriptContextInfo> &infos)
86{
87 Q_D(QScriptDebuggerStackModel);
88 layoutAboutToBeChanged();
89 d->contextInfos = infos;
90 layoutChanged();
91}
92
93/*!
94 \reimp
95*/
96int QScriptDebuggerStackModel::columnCount(const QModelIndex &parent) const
97{
98 if (!parent.isValid())
99 return 3;
100 return 0;
101}
102
103/*!
104 \reimp
105*/
106int QScriptDebuggerStackModel::rowCount(const QModelIndex &parent) const
107{
108 Q_D(const QScriptDebuggerStackModel);
109 if (!parent.isValid())
110 return d->contextInfos.count();
111 return 0;
112}
113
114/*!
115 \reimp
116*/
117QVariant QScriptDebuggerStackModel::data(const QModelIndex &index, int role) const
118{
119 Q_D(const QScriptDebuggerStackModel);
120 if (!index.isValid())
121 return QVariant();
122 if (index.row() >= d->contextInfos.count())
123 return QVariant();
124 const QScriptContextInfo &info = d->contextInfos.at(index.row());
125 if (role == Qt::DisplayRole) {
126 if (index.column() == 0) {
127 return index.row();
128 } else if (index.column() == 1) {
129 QString name = info.functionName();
130 if (name.isEmpty())
131 name = QString::fromLatin1("<anonymous>");
132 return name;
133 } else if (index.column() == 2) {
134 if (info.lineNumber() == -1)
135 return QString::fromLatin1("<native>");
136 QString fn = QFileInfo(info.fileName()).fileName();
137 if (fn.isEmpty())
138 fn = QString::fromLatin1("<anonymous script, id=%0>").arg(info.scriptId());
139 return QString::fromLatin1("%0:%1").arg(fn).arg(info.lineNumber());
140 }
141 } else if (role == Qt::ToolTipRole) {
142 if (QFileInfo(info.fileName()).fileName() != info.fileName())
143 return info.fileName();
144 }
145 return QVariant();
146}
147
148/*!
149 \reimp
150*/
151QVariant QScriptDebuggerStackModel::headerData(int section, Qt::Orientation orient, int role) const
152{
153 if (orient != Qt::Horizontal)
154 return QVariant();
155 if (role == Qt::DisplayRole) {
156 if (section == 0)
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");
162 }
163 return QVariant();
164}
165
166QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.