source: branches/4.5.1/src/scripttools/debugging/qscriptdebuggerscriptswidget.cpp

Last change on this file 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.2 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 "qscriptdebuggerscriptswidget_p.h"
43#include "qscriptdebuggerscriptswidgetinterface_p_p.h"
44#include "qscriptdebuggerscriptsmodel_p.h"
45
46#include <QtCore/qdebug.h>
47#include <QtGui/qheaderview.h>
48#include <QtGui/qtreeview.h>
49#include <QtGui/qboxlayout.h>
50
51QT_BEGIN_NAMESPACE
52
53class QScriptDebuggerScriptsWidgetPrivate
54 : public QScriptDebuggerScriptsWidgetInterfacePrivate
55{
56 Q_DECLARE_PUBLIC(QScriptDebuggerScriptsWidget)
57public:
58 QScriptDebuggerScriptsWidgetPrivate();
59 ~QScriptDebuggerScriptsWidgetPrivate();
60
61 // private slots
62 void _q_onCurrentChanged(const QModelIndex &index);
63
64 QTreeView *view;
65 qint64 currentScriptId;
66};
67
68QScriptDebuggerScriptsWidgetPrivate::QScriptDebuggerScriptsWidgetPrivate()
69{
70 currentScriptId = -1;
71}
72
73QScriptDebuggerScriptsWidgetPrivate::~QScriptDebuggerScriptsWidgetPrivate()
74{
75}
76
77void QScriptDebuggerScriptsWidgetPrivate::_q_onCurrentChanged(const QModelIndex &index)
78{
79 Q_Q(QScriptDebuggerScriptsWidget);
80 if (!index.isValid())
81 return;
82 qint64 sid = q->scriptsModel()->scriptIdFromIndex(index);
83 if (sid != -1) {
84 if (currentScriptId != sid) {
85 currentScriptId = sid;
86 emit q->currentScriptChanged(sid);
87 }
88 } else {
89 qint64 sid = q->scriptsModel()->scriptIdFromIndex(index.parent());
90 Q_ASSERT(sid != -1);
91 currentScriptId = sid;
92 emit q->currentScriptChanged(sid);
93 QPair<QString, int> info = q->scriptsModel()->scriptFunctionInfoFromIndex(index);
94 emit q->scriptLocationSelected(info.second);
95 }
96}
97
98QScriptDebuggerScriptsWidget::QScriptDebuggerScriptsWidget(QWidget *parent)
99 : QScriptDebuggerScriptsWidgetInterface(*new QScriptDebuggerScriptsWidgetPrivate, parent, 0)
100{
101 Q_D(QScriptDebuggerScriptsWidget);
102 d->view = new QTreeView();
103 d->view->setEditTriggers(QAbstractItemView::NoEditTriggers);
104// d->view->setAlternatingRowColors(true);
105// d->view->setRootIsDecorated(false);
106 d->view->setSelectionBehavior(QAbstractItemView::SelectRows);
107 d->view->header()->hide();
108// d->view->header()->setDefaultAlignment(Qt::AlignLeft);
109// d->view->header()->setResizeMode(QHeaderView::ResizeToContents);
110
111 QVBoxLayout *vbox = new QVBoxLayout(this);
112 vbox->setMargin(0);
113 vbox->addWidget(d->view);
114}
115
116QScriptDebuggerScriptsWidget::~QScriptDebuggerScriptsWidget()
117{
118}
119
120/*!
121 \reimp
122*/
123QScriptDebuggerScriptsModel *QScriptDebuggerScriptsWidget::scriptsModel() const
124{
125 Q_D(const QScriptDebuggerScriptsWidget);
126 return qobject_cast<QScriptDebuggerScriptsModel*>(d->view->model());
127}
128
129/*!
130 \reimp
131*/
132void QScriptDebuggerScriptsWidget::setScriptsModel(QScriptDebuggerScriptsModel *model)
133{
134 Q_D(QScriptDebuggerScriptsWidget);
135 d->view->setModel(model);
136 QObject::connect(d->view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
137 this, SLOT(_q_onCurrentChanged(QModelIndex)));
138}
139
140qint64 QScriptDebuggerScriptsWidget::currentScriptId() const
141{
142 Q_D(const QScriptDebuggerScriptsWidget);
143 return scriptsModel()->scriptIdFromIndex(d->view->currentIndex());
144}
145
146void QScriptDebuggerScriptsWidget::setCurrentScript(qint64 id)
147{
148 Q_D(QScriptDebuggerScriptsWidget);
149 d->view->setCurrentIndex(scriptsModel()->indexFromScriptId(id));
150}
151
152QT_END_NAMESPACE
153
154#include "moc_qscriptdebuggerscriptswidget_p.cpp"
Note: See TracBrowser for help on using the repository browser.