2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "watchwindow.h"
|
|
|
|
|
|
2009-03-17 17:00:06 +01:00
|
|
|
#include "debuggeractions.h"
|
2011-04-21 15:52:51 +02:00
|
|
|
#include "debuggerinternalconstants.h"
|
2010-11-10 11:39:01 +01:00
|
|
|
#include "debuggercore.h"
|
2010-11-05 19:38:40 +01:00
|
|
|
#include "watchhandler.h"
|
2011-11-11 17:17:57 +01:00
|
|
|
|
2009-03-19 15:24:18 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <utils/savedaction.h>
|
2009-03-19 15:24:18 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHeaderView>
|
2014-07-01 10:55:24 +02:00
|
|
|
#include <QScrollBar>
|
|
|
|
|
#include <QTimer>
|
2009-03-19 15:24:18 +01:00
|
|
|
|
2010-11-05 19:38:40 +01:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-06-04 14:45:10 +02:00
|
|
|
WatchTreeView::WatchTreeView(WatchType type)
|
2014-08-20 10:35:57 +02:00
|
|
|
: m_type(type), m_sliderPosition(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
setObjectName("WatchWindow");
|
2011-05-10 15:57:33 +02:00
|
|
|
setWindowTitle(tr("Locals and Expressions"));
|
2012-03-29 14:20:45 +02:00
|
|
|
setIndentation(indentation() * 9/10);
|
|
|
|
|
setUniformRowHeights(true);
|
|
|
|
|
setDragEnabled(true);
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
setDropIndicatorShown(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-01-29 23:55:10 +01:00
|
|
|
connect(this, &QTreeView::expanded, this, &WatchTreeView::expandNode);
|
|
|
|
|
connect(this, &QTreeView::collapsed, this, &WatchTreeView::collapseNode);
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-29 14:20:45 +02:00
|
|
|
void WatchTreeView::expandNode(const QModelIndex &idx)
|
2010-01-29 21:33:57 +01:00
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
model()->setData(idx, true, LocalsExpandedRole);
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-29 14:20:45 +02:00
|
|
|
void WatchTreeView::collapseNode(const QModelIndex &idx)
|
2010-01-29 21:33:57 +01:00
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
model()->setData(idx, false, LocalsExpandedRole);
|
2009-07-01 12:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 22:39:39 +03:00
|
|
|
void WatchTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
2012-10-05 13:42:14 +02:00
|
|
|
{
|
|
|
|
|
emit currentIndexChanged(current);
|
2013-08-15 22:39:39 +03:00
|
|
|
BaseTreeView::currentChanged(current, previous);
|
2012-10-05 13:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-03-29 14:20:45 +02:00
|
|
|
void WatchTreeView::setModel(QAbstractItemModel *model)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-03-29 14:20:45 +02:00
|
|
|
BaseTreeView::setModel(model);
|
2012-05-18 02:28:41 +02:00
|
|
|
setRootIndex(model->index(m_type, 0, QModelIndex()));
|
2012-03-29 14:20:45 +02:00
|
|
|
setRootIsDecorated(true);
|
2011-03-16 18:48:14 +01:00
|
|
|
if (header()) {
|
|
|
|
|
header()->setDefaultAlignment(Qt::AlignLeft);
|
2017-10-26 16:32:48 +02:00
|
|
|
if (m_type == ReturnType && m_type == TooltipType)
|
2011-03-16 18:48:14 +01:00
|
|
|
header()->hide();
|
|
|
|
|
}
|
2009-03-25 13:05:12 +01:00
|
|
|
|
2015-01-29 23:55:10 +01:00
|
|
|
auto watchModel = qobject_cast<WatchModelBase *>(model);
|
|
|
|
|
QTC_ASSERT(watchModel, return);
|
|
|
|
|
connect(model, &QAbstractItemModel::layoutChanged,
|
|
|
|
|
this, &WatchTreeView::resetHelper);
|
|
|
|
|
connect(watchModel, &WatchModelBase::currentIndexRequested,
|
|
|
|
|
this, &QAbstractItemView::setCurrentIndex);
|
|
|
|
|
connect(watchModel, &WatchModelBase::itemIsExpanded,
|
|
|
|
|
this, &WatchTreeView::handleItemIsExpanded);
|
2015-03-06 09:14:40 +01:00
|
|
|
if (m_type == LocalsType) {
|
2015-03-17 13:26:20 +01:00
|
|
|
connect(watchModel, &WatchModelBase::updateStarted,
|
2015-03-06 09:14:40 +01:00
|
|
|
this, &WatchTreeView::showProgressIndicator);
|
|
|
|
|
connect(watchModel, &WatchModelBase::updateFinished,
|
|
|
|
|
this, &WatchTreeView::hideProgressIndicator);
|
|
|
|
|
}
|
2012-05-18 02:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchTreeView::handleItemIsExpanded(const QModelIndex &idx)
|
|
|
|
|
{
|
|
|
|
|
bool on = idx.data(LocalsExpandedRole).toBool();
|
|
|
|
|
QTC_ASSERT(on, return);
|
|
|
|
|
if (!isExpanded(idx))
|
|
|
|
|
expand(idx);
|
2009-03-25 13:05:12 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-10 18:10:56 +02:00
|
|
|
void WatchTreeView::reexpand(QTreeView *view, const QModelIndex &idx)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-06-16 11:08:54 +02:00
|
|
|
if (idx.data(LocalsExpandedRole).toBool()) {
|
2014-07-10 18:10:56 +02:00
|
|
|
//qDebug() << "EXPANDING " << view->model()->data(idx, LocalsINameRole);
|
|
|
|
|
if (!view->isExpanded(idx)) {
|
|
|
|
|
view->expand(idx);
|
|
|
|
|
for (int i = 0, n = view->model()->rowCount(idx); i != n; ++i) {
|
|
|
|
|
QModelIndex idx1 = view->model()->index(i, 0, idx);
|
|
|
|
|
reexpand(view, idx1);
|
2010-11-25 18:44:07 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-03-25 13:05:12 +01:00
|
|
|
} else {
|
2014-07-10 18:10:56 +02:00
|
|
|
//qDebug() << "COLLAPSING " << view->model()->data(idx, LocalsINameRole);
|
|
|
|
|
if (view->isExpanded(idx))
|
|
|
|
|
view->collapse(idx);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2014-07-10 18:10:56 +02:00
|
|
|
void WatchTreeView::resetHelper()
|
|
|
|
|
{
|
|
|
|
|
QModelIndex idx = model()->index(m_type, 0);
|
|
|
|
|
reexpand(this, idx);
|
|
|
|
|
expand(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:28:41 +02:00
|
|
|
void WatchTreeView::reset()
|
|
|
|
|
{
|
|
|
|
|
BaseTreeView::reset();
|
2015-02-10 11:02:13 +01:00
|
|
|
if (model()) {
|
|
|
|
|
setRootIndex(model()->index(m_type, 0));
|
|
|
|
|
resetHelper();
|
|
|
|
|
}
|
2012-05-18 02:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 10:55:24 +02:00
|
|
|
void WatchTreeView::doItemsLayout()
|
|
|
|
|
{
|
|
|
|
|
if (m_sliderPosition == 0)
|
|
|
|
|
m_sliderPosition = verticalScrollBar()->sliderPosition();
|
|
|
|
|
Utils::BaseTreeView::doItemsLayout();
|
|
|
|
|
if (m_sliderPosition)
|
2016-04-19 22:49:23 +02:00
|
|
|
QTimer::singleShot(0, this, &WatchTreeView::adjustSlider);
|
2014-07-01 10:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchTreeView::adjustSlider()
|
|
|
|
|
{
|
|
|
|
|
if (m_sliderPosition) {
|
|
|
|
|
verticalScrollBar()->setSliderPosition(m_sliderPosition);
|
|
|
|
|
m_sliderPosition = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:38:40 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|