2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-10-05 11:50:16 +02: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.
|
2012-10-05 11:50:16 +02: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.
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-10-05 11:50:16 +02:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
#include "consoleview.h"
|
|
|
|
|
#include "consoleitemdelegate.h"
|
|
|
|
|
#include "consoleitemmodel.h"
|
2012-02-22 11:50:05 +01:00
|
|
|
|
2013-05-30 17:26:51 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2012-11-21 14:00:41 +01:00
|
|
|
#include <coreplugin/manhattanstyle.h>
|
2018-06-12 10:44:10 +02:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
2013-03-14 12:20:43 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2012-02-08 15:54:59 +01:00
|
|
|
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QMenu>
|
2012-02-17 22:33:40 +02:00
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QPainter>
|
2012-02-22 11:50:05 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QAbstractProxyModel>
|
|
|
|
|
#include <QFileInfo>
|
2012-02-27 11:25:30 +01:00
|
|
|
#include <QScrollBar>
|
2012-11-21 14:00:41 +01:00
|
|
|
#include <QStyleFactory>
|
|
|
|
|
#include <QString>
|
2013-06-05 12:11:08 +02:00
|
|
|
#include <QUrl>
|
2012-02-08 15:54:59 +01:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
namespace Debugger {
|
2012-02-08 15:54:59 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
class ConsoleViewStyle : public ManhattanStyle
|
2012-02-08 15:54:59 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2015-11-10 16:59:02 +01:00
|
|
|
ConsoleViewStyle(const QString &baseStyleName) : ManhattanStyle(baseStyleName) {}
|
2012-11-21 14:00:41 +01:00
|
|
|
|
2012-10-04 14:54:59 +02:00
|
|
|
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter,
|
2018-02-01 10:59:24 +01:00
|
|
|
const QWidget *widget = nullptr) const final
|
2012-02-08 15:54:59 +01:00
|
|
|
{
|
|
|
|
|
if (element != QStyle::PE_PanelItemViewRow)
|
2012-11-21 14:00:41 +01:00
|
|
|
ManhattanStyle::drawPrimitive(element, option, painter, widget);
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-01 10:59:24 +01:00
|
|
|
int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
|
|
|
|
|
const QWidget *widget = nullptr,
|
|
|
|
|
QStyleHintReturn *returnData = nullptr) const final
|
|
|
|
|
{
|
2012-02-08 15:54:59 +01:00
|
|
|
if (hint == SH_ItemView_ShowDecorationSelected)
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
2012-11-21 14:00:41 +01:00
|
|
|
return ManhattanStyle::styleHint(hint, option, widget, returnData);
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2015-11-10 16:59:02 +01:00
|
|
|
// ConsoleView
|
2012-02-08 15:54:59 +01:00
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
ConsoleView::ConsoleView(ConsoleItemModel *model, QWidget *parent) :
|
|
|
|
|
Utils::TreeView(parent), m_model(model)
|
2012-02-08 15:54:59 +01:00
|
|
|
{
|
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
setHeaderHidden(true);
|
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
|
setEditTriggers(QAbstractItemView::AllEditTriggers);
|
2018-10-07 22:38:47 +03:00
|
|
|
setStyleSheet("QTreeView::branch:has-siblings:!adjoins-item {"
|
|
|
|
|
"border-image: none;"
|
|
|
|
|
"image: none; }"
|
|
|
|
|
"QTreeView::branch:has-siblings:adjoins-item {"
|
|
|
|
|
"border-image: none;"
|
|
|
|
|
"image: none; }"
|
|
|
|
|
"QTreeView::branch:!has-children:!has-siblings:adjoins-item {"
|
|
|
|
|
"border-image: none;"
|
|
|
|
|
"image: none; }"
|
|
|
|
|
"QTreeView::branch:has-children:!has-siblings:closed,"
|
|
|
|
|
"QTreeView::branch:closed:has-children:has-siblings {"
|
|
|
|
|
"border-image: none;"
|
|
|
|
|
"image: none; }"
|
|
|
|
|
"QTreeView::branch:open:has-children:!has-siblings,"
|
|
|
|
|
"QTreeView::branch:open:has-children:has-siblings {"
|
|
|
|
|
"border-image: none;"
|
|
|
|
|
"image: none; }");
|
2012-11-21 14:00:41 +01:00
|
|
|
|
|
|
|
|
QString baseName = QApplication::style()->objectName();
|
2013-03-14 12:20:43 +01:00
|
|
|
if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost()
|
2018-10-07 22:38:47 +03:00
|
|
|
&& baseName == "windows") {
|
2012-11-21 14:00:41 +01:00
|
|
|
// Sometimes we get the standard windows 95 style as a fallback
|
2018-10-07 22:38:47 +03:00
|
|
|
if (QStyleFactory::keys().contains("Fusion")) {
|
|
|
|
|
baseName = "fusion"; // Qt5
|
2012-11-21 14:00:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-23 22:28:49 +02:00
|
|
|
auto style = new ConsoleViewStyle(baseName);
|
2012-02-08 15:54:59 +01:00
|
|
|
setStyle(style);
|
|
|
|
|
style->setParent(this);
|
2012-02-22 11:50:05 +01:00
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
|
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
2013-10-24 17:57:29 +02:00
|
|
|
horizontalScrollBar()->setSingleStep(20);
|
|
|
|
|
verticalScrollBar()->setSingleStep(20);
|
2012-02-22 11:50:05 +01:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
connect(this, &ConsoleView::activated, this, &ConsoleView::onRowActivated);
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::onScrollToBottom()
|
2012-02-27 11:25:30 +01:00
|
|
|
{
|
2014-02-18 14:56:19 +01:00
|
|
|
// Keep scrolling to bottom if scroll bar is not at maximum()
|
|
|
|
|
if (verticalScrollBar()->value() != verticalScrollBar()->maximum())
|
2012-02-27 11:25:30 +01:00
|
|
|
scrollToBottom();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-12 10:44:10 +02:00
|
|
|
void ConsoleView::populateFileFinder()
|
|
|
|
|
{
|
|
|
|
|
QtSupport::BaseQtVersion::populateQmlFileFinder(&m_finder, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::mousePressEvent(QMouseEvent *event)
|
2012-02-08 15:54:59 +01:00
|
|
|
{
|
|
|
|
|
QPoint pos = event->pos();
|
|
|
|
|
QModelIndex index = indexAt(pos);
|
|
|
|
|
if (index.isValid()) {
|
2012-10-08 13:17:10 +02:00
|
|
|
ConsoleItem::ItemType type = (ConsoleItem::ItemType)index.data(
|
2015-08-21 17:33:53 +02:00
|
|
|
ConsoleItem::TypeRole).toInt();
|
2012-02-22 11:50:05 +01:00
|
|
|
bool handled = false;
|
2015-08-21 17:33:53 +02:00
|
|
|
if (type == ConsoleItem::DefaultType) {
|
2012-02-22 11:50:05 +01:00
|
|
|
bool showTypeIcon = index.parent() == QModelIndex();
|
2015-11-10 16:59:02 +01:00
|
|
|
ConsoleItemPositions positions(m_model, visualRect(index), viewOptions().font, showTypeIcon,
|
2012-10-04 14:54:59 +02:00
|
|
|
true);
|
2012-02-22 11:50:05 +01:00
|
|
|
|
|
|
|
|
if (positions.expandCollapseIcon().contains(pos)) {
|
|
|
|
|
if (isExpanded(index))
|
|
|
|
|
setExpanded(index, false);
|
|
|
|
|
else
|
|
|
|
|
setExpanded(index, true);
|
|
|
|
|
handled = true;
|
|
|
|
|
}
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
2012-02-22 11:50:05 +01:00
|
|
|
if (!handled)
|
2014-04-09 18:22:54 +02:00
|
|
|
Utils::TreeView::mousePressEvent(event);
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::resizeEvent(QResizeEvent *e)
|
2012-02-08 15:54:59 +01:00
|
|
|
{
|
2015-11-10 16:59:02 +01:00
|
|
|
static_cast<ConsoleItemDelegate *>(itemDelegate())->emitSizeHintChanged(
|
2012-02-08 15:54:59 +01:00
|
|
|
selectionModel()->currentIndex());
|
2014-04-09 18:22:54 +02:00
|
|
|
Utils::TreeView::resizeEvent(e);
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::drawBranches(QPainter *painter, const QRect &rect,
|
2012-10-04 14:54:59 +02:00
|
|
|
const QModelIndex &index) const
|
2012-02-08 15:54:59 +01:00
|
|
|
{
|
2015-11-10 16:59:02 +01:00
|
|
|
static_cast<ConsoleItemDelegate *>(itemDelegate())->drawBackground(painter, rect, index,
|
2012-10-04 14:54:59 +02:00
|
|
|
false);
|
2014-04-09 18:22:54 +02:00
|
|
|
Utils::TreeView::drawBranches(painter, rect, index);
|
2012-02-08 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::contextMenuEvent(QContextMenuEvent *event)
|
2012-02-22 11:50:05 +01:00
|
|
|
{
|
|
|
|
|
QModelIndex itemIndex = indexAt(event->pos());
|
|
|
|
|
QMenu menu;
|
|
|
|
|
|
2018-07-23 22:28:49 +02:00
|
|
|
auto copy = new QAction(tr("&Copy"), this);
|
2012-02-22 11:50:05 +01:00
|
|
|
copy->setEnabled(itemIndex.isValid());
|
|
|
|
|
menu.addAction(copy);
|
2018-07-23 22:28:49 +02:00
|
|
|
auto show = new QAction(tr("&Show in Editor"), this);
|
2012-02-22 11:50:05 +01:00
|
|
|
show->setEnabled(canShowItemInTextEditor(itemIndex));
|
|
|
|
|
menu.addAction(show);
|
|
|
|
|
menu.addSeparator();
|
2018-07-23 22:28:49 +02:00
|
|
|
auto clear = new QAction(tr("C&lear"), this);
|
2012-02-22 11:50:05 +01:00
|
|
|
menu.addAction(clear);
|
|
|
|
|
|
|
|
|
|
QAction *a = menu.exec(event->globalPos());
|
2018-07-23 22:28:49 +02:00
|
|
|
if (a == nullptr)
|
2012-02-22 11:50:05 +01:00
|
|
|
return;
|
|
|
|
|
|
2012-10-04 14:54:59 +02:00
|
|
|
if (a == copy) {
|
2012-02-22 11:50:05 +01:00
|
|
|
copyToClipboard(itemIndex);
|
2012-10-04 14:54:59 +02:00
|
|
|
} else if (a == show) {
|
2012-02-22 11:50:05 +01:00
|
|
|
onRowActivated(itemIndex);
|
2012-10-04 14:54:59 +02:00
|
|
|
} else if (a == clear) {
|
2018-07-23 22:28:49 +02:00
|
|
|
auto proxyModel = qobject_cast<QAbstractProxyModel*>(model());
|
|
|
|
|
auto handler = qobject_cast<ConsoleItemModel*>(
|
2012-10-04 14:54:59 +02:00
|
|
|
proxyModel->sourceModel());
|
2012-02-22 11:50:05 +01:00
|
|
|
handler->clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::focusInEvent(QFocusEvent *event)
|
2015-10-28 13:32:53 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
selectionModel()->setCurrentIndex(model()->index(model()->rowCount() - 1, 0),
|
|
|
|
|
QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::onRowActivated(const QModelIndex &index)
|
2012-02-22 11:50:05 +01:00
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2019-02-25 17:45:39 +01:00
|
|
|
const QFileInfo fi = m_finder.findFile(model()->data(index, ConsoleItem::FileRole).toString())
|
|
|
|
|
.first().toFileInfo();
|
2018-06-12 10:44:10 +02:00
|
|
|
if (fi.exists() && fi.isFile() && fi.isReadable()) {
|
|
|
|
|
Core::EditorManager::openEditorAt(fi.canonicalFilePath(),
|
|
|
|
|
model()->data(index, ConsoleItem::LineRole).toInt());
|
2012-02-22 11:50:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleView::copyToClipboard(const QModelIndex &index)
|
2012-02-22 11:50:05 +01:00
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2015-08-21 17:33:53 +02:00
|
|
|
QString contents = model()->data(index, ConsoleItem::ExpressionRole).toString();
|
2012-10-04 14:54:59 +02:00
|
|
|
// See if we have file and line Info
|
2015-08-21 17:33:53 +02:00
|
|
|
QString filePath = model()->data(index, ConsoleItem::FileRole).toString();
|
2013-05-24 16:31:01 +02:00
|
|
|
const QUrl fileUrl = QUrl(filePath);
|
|
|
|
|
if (fileUrl.isLocalFile())
|
|
|
|
|
filePath = fileUrl.toLocalFile();
|
2012-02-22 11:50:05 +01:00
|
|
|
if (!filePath.isEmpty()) {
|
2014-05-08 22:12:53 +02:00
|
|
|
contents = QString::fromLatin1("%1 %2: %3").arg(contents).arg(filePath).arg(
|
2015-08-21 17:33:53 +02:00
|
|
|
model()->data(index, ConsoleItem::LineRole).toString());
|
2012-02-22 11:50:05 +01:00
|
|
|
}
|
|
|
|
|
QClipboard *cb = QApplication::clipboard();
|
|
|
|
|
cb->setText(contents);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
bool ConsoleView::canShowItemInTextEditor(const QModelIndex &index)
|
2012-02-22 11:50:05 +01:00
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
2018-06-12 10:44:10 +02:00
|
|
|
bool success = false;
|
|
|
|
|
m_finder.findFile(model()->data(index, ConsoleItem::FileRole).toString(), &success);
|
|
|
|
|
return success;
|
2012-02-22 11:50:05 +01:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 14:54:59 +02:00
|
|
|
} // Internal
|
2015-11-10 16:59:02 +01:00
|
|
|
} // Debugger
|