1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSCriptTools module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qscriptdebuggerstackwidget_p.h"
41#include "qscriptdebuggerstackwidgetinterface_p_p.h"
42
43#include <QtCore/qdebug.h>
44#include <QtWidgets/qheaderview.h>
45#include <QtWidgets/qtreeview.h>
46#include <QtWidgets/qboxlayout.h>
47
48QT_BEGIN_NAMESPACE
49
50class QScriptDebuggerStackWidgetPrivate
51 : public QScriptDebuggerStackWidgetInterfacePrivate
52{
53 Q_DECLARE_PUBLIC(QScriptDebuggerStackWidget)
54public:
55 QScriptDebuggerStackWidgetPrivate();
56 ~QScriptDebuggerStackWidgetPrivate();
57
58 // private slots
59 void _q_onCurrentChanged(const QModelIndex &index);
60
61 QTreeView *view;
62};
63
64QScriptDebuggerStackWidgetPrivate::QScriptDebuggerStackWidgetPrivate()
65{
66}
67
68QScriptDebuggerStackWidgetPrivate::~QScriptDebuggerStackWidgetPrivate()
69{
70}
71
72void QScriptDebuggerStackWidgetPrivate::_q_onCurrentChanged(const QModelIndex &index)
73{
74 Q_Q(QScriptDebuggerStackWidget);
75 emit q->currentFrameChanged(newFrameIndex: index.row());
76}
77
78QScriptDebuggerStackWidget::QScriptDebuggerStackWidget(QWidget *parent)
79 : QScriptDebuggerStackWidgetInterface(*new QScriptDebuggerStackWidgetPrivate, parent, {})
80{
81 Q_D(QScriptDebuggerStackWidget);
82 d->view = new QTreeView();
83 d->view->setEditTriggers(QAbstractItemView::NoEditTriggers);
84 d->view->setAlternatingRowColors(true);
85 d->view->setRootIsDecorated(false);
86 d->view->setSelectionBehavior(QAbstractItemView::SelectRows);
87 d->view->header()->setDefaultAlignment(Qt::AlignLeft);
88// d->view->header()->setResizeMode(QHeaderView::ResizeToContents);
89
90 QVBoxLayout *vbox = new QVBoxLayout(this);
91 vbox->setContentsMargins(left: 0, top: 0, right: 0, bottom: 0);
92 vbox->addWidget(d->view);
93}
94
95QScriptDebuggerStackWidget::~QScriptDebuggerStackWidget()
96{
97}
98
99/*!
100 \reimp
101*/
102QAbstractItemModel *QScriptDebuggerStackWidget::stackModel() const
103{
104 Q_D(const QScriptDebuggerStackWidget);
105 return d->view->model();
106}
107
108/*!
109 \reimp
110*/
111void QScriptDebuggerStackWidget::setStackModel(QAbstractItemModel *model)
112{
113 Q_D(QScriptDebuggerStackWidget);
114 d->view->setModel(model);
115 QObject::connect(sender: d->view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
116 receiver: this, SLOT(_q_onCurrentChanged(QModelIndex)));
117 d->view->header()->resizeSection(logicalIndex: 0, size: 50);
118}
119
120/*!
121 \reimp
122*/
123int QScriptDebuggerStackWidget::currentFrameIndex() const
124{
125 Q_D(const QScriptDebuggerStackWidget);
126 return d->view->currentIndex().row();
127}
128
129/*!
130 \reimp
131*/
132void QScriptDebuggerStackWidget::setCurrentFrameIndex(int frameIndex)
133{
134 Q_D(QScriptDebuggerStackWidget);
135 d->view->setCurrentIndex(d->view->model()->index(row: frameIndex, column: 0));
136}
137
138QT_END_NAMESPACE
139
140#include "moc_qscriptdebuggerstackwidget_p.cpp"
141

source code of qtscript/src/scripttools/debugging/qscriptdebuggerstackwidget.cpp