Fixes a crash in QDoubleSpinBox
[qt-netbsd.git] / src / scripttools / debugging / qscriptdebuggerstackmodel.cpp
blobd26029510519a54e9a734292d3f736fa1476828b
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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.
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.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "qscriptdebuggerstackmodel_p.h"
44 #include "private/qabstractitemmodel_p.h"
46 #include <QtScript/qscriptcontextinfo.h>
47 #include <QtCore/qfileinfo.h>
49 QT_BEGIN_NAMESPACE
51 class QScriptDebuggerStackModelPrivate
52 : public QAbstractItemModelPrivate
54 Q_DECLARE_PUBLIC(QScriptDebuggerStackModel)
55 public:
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;
90 layoutChanged();
93 /*!
94 \reimp
96 int QScriptDebuggerStackModel::columnCount(const QModelIndex &parent) const
98 if (!parent.isValid())
99 return 3;
100 return 0;
104 \reimp
106 int QScriptDebuggerStackModel::rowCount(const QModelIndex &parent) const
108 Q_D(const QScriptDebuggerStackModel);
109 if (!parent.isValid())
110 return d->contextInfos.count();
111 return 0;
115 \reimp
117 QVariant QScriptDebuggerStackModel::data(const QModelIndex &index, int role) const
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());
141 } else if (role == Qt::ToolTipRole) {
142 if (QFileInfo(info.fileName()).fileName() != info.fileName())
143 return info.fileName();
145 return QVariant();
149 \reimp
151 QVariant QScriptDebuggerStackModel::headerData(int section, Qt::Orientation orient, int role) const
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");
163 return QVariant();
166 QT_END_NAMESPACE