|
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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 |
|
51 QT_BEGIN_NAMESPACE |
|
52 |
|
53 class QScriptDebuggerScriptsWidgetPrivate |
|
54 : public QScriptDebuggerScriptsWidgetInterfacePrivate |
|
55 { |
|
56 Q_DECLARE_PUBLIC(QScriptDebuggerScriptsWidget) |
|
57 public: |
|
58 QScriptDebuggerScriptsWidgetPrivate(); |
|
59 ~QScriptDebuggerScriptsWidgetPrivate(); |
|
60 |
|
61 // private slots |
|
62 void _q_onCurrentChanged(const QModelIndex &index); |
|
63 |
|
64 QTreeView *view; |
|
65 qint64 currentScriptId; |
|
66 }; |
|
67 |
|
68 QScriptDebuggerScriptsWidgetPrivate::QScriptDebuggerScriptsWidgetPrivate() |
|
69 { |
|
70 currentScriptId = -1; |
|
71 } |
|
72 |
|
73 QScriptDebuggerScriptsWidgetPrivate::~QScriptDebuggerScriptsWidgetPrivate() |
|
74 { |
|
75 } |
|
76 |
|
77 void 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 |
|
98 QScriptDebuggerScriptsWidget::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 |
|
116 QScriptDebuggerScriptsWidget::~QScriptDebuggerScriptsWidget() |
|
117 { |
|
118 } |
|
119 |
|
120 /*! |
|
121 \reimp |
|
122 */ |
|
123 QScriptDebuggerScriptsModel *QScriptDebuggerScriptsWidget::scriptsModel() const |
|
124 { |
|
125 Q_D(const QScriptDebuggerScriptsWidget); |
|
126 return qobject_cast<QScriptDebuggerScriptsModel*>(d->view->model()); |
|
127 } |
|
128 |
|
129 /*! |
|
130 \reimp |
|
131 */ |
|
132 void 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 |
|
140 qint64 QScriptDebuggerScriptsWidget::currentScriptId() const |
|
141 { |
|
142 Q_D(const QScriptDebuggerScriptsWidget); |
|
143 return scriptsModel()->scriptIdFromIndex(d->view->currentIndex()); |
|
144 } |
|
145 |
|
146 void QScriptDebuggerScriptsWidget::setCurrentScript(qint64 id) |
|
147 { |
|
148 Q_D(QScriptDebuggerScriptsWidget); |
|
149 d->view->setCurrentIndex(scriptsModel()->indexFromScriptId(id)); |
|
150 } |
|
151 |
|
152 QT_END_NAMESPACE |
|
153 |
|
154 #include "moc_qscriptdebuggerscriptswidget_p.cpp" |