2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-10-05 11:50:16 +02:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
#include "console.h"
|
2022-07-05 15:37:08 +02:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
#include "consoleview.h"
|
|
|
|
|
#include "consoleproxymodel.h"
|
|
|
|
|
#include "consoleitemdelegate.h"
|
2022-07-05 15:37:08 +02:00
|
|
|
#include "../debuggertr.h"
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2014-06-13 11:19:54 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2012-10-04 14:54:59 +02:00
|
|
|
#include <coreplugin/findplaceholder.h>
|
2015-11-10 16:59:02 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2022-07-05 15:37:08 +02:00
|
|
|
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2022-07-05 15:37:08 +02:00
|
|
|
|
2012-10-04 14:54:59 +02:00
|
|
|
#include <aggregation/aggregate.h>
|
2014-07-31 18:15:19 +02:00
|
|
|
#include <coreplugin/find/itemviewfind.h>
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2021-03-01 08:59:44 +01:00
|
|
|
#include <QAction>
|
2012-10-04 14:54:59 +02:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
const char CONSOLE[] = "Console";
|
|
|
|
|
const char SHOW_LOG[] = "showLog";
|
|
|
|
|
const char SHOW_WARNING[] = "showWarning";
|
|
|
|
|
const char SHOW_ERROR[] = "showError";
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
namespace Debugger::Internal {
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2015-11-10 16:59:02 +01:00
|
|
|
// Console
|
2012-10-04 14:54:59 +02:00
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
Console::Console()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2023-09-13 11:46:00 +02:00
|
|
|
setDisplayName(Tr::tr("QML Debugger Console"));
|
2016-03-13 22:15:19 +02:00
|
|
|
m_consoleItemModel = new ConsoleItemModel(this);
|
2015-11-10 16:59:02 +01:00
|
|
|
|
2012-10-04 14:54:59 +02:00
|
|
|
m_consoleWidget = new QWidget;
|
|
|
|
|
m_consoleWidget->setWindowTitle(displayName());
|
|
|
|
|
m_consoleWidget->setEnabled(true);
|
|
|
|
|
|
2018-07-23 22:28:49 +02:00
|
|
|
auto vbox = new QVBoxLayout(m_consoleWidget);
|
2019-08-29 10:36:01 +02:00
|
|
|
vbox->setContentsMargins(0, 0, 0, 0);
|
2012-10-04 14:54:59 +02:00
|
|
|
vbox->setSpacing(0);
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
m_consoleView = new ConsoleView(m_consoleItemModel, m_consoleWidget);
|
|
|
|
|
auto proxyModel = new ConsoleProxyModel(this);
|
|
|
|
|
proxyModel->setSourceModel(m_consoleItemModel);
|
|
|
|
|
connect(m_consoleItemModel,
|
|
|
|
|
&ConsoleItemModel::selectEditableRow,
|
|
|
|
|
proxyModel,
|
|
|
|
|
&ConsoleProxyModel::selectEditableRow);
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
//Scroll to bottom when rows matching current filter settings are inserted
|
|
|
|
|
//Not connecting rowsRemoved as the only way to remove rows is to clear the
|
|
|
|
|
//model which will automatically reset the view.
|
2015-11-10 16:59:02 +01:00
|
|
|
connect(m_consoleItemModel, &QAbstractItemModel::rowsInserted,
|
|
|
|
|
proxyModel, &ConsoleProxyModel::onRowsInserted);
|
|
|
|
|
m_consoleView->setModel(proxyModel);
|
|
|
|
|
|
|
|
|
|
connect(proxyModel, &ConsoleProxyModel::setCurrentIndex,
|
|
|
|
|
m_consoleView->selectionModel(), &QItemSelectionModel::setCurrentIndex);
|
|
|
|
|
connect(proxyModel, &ConsoleProxyModel::scrollToBottom,
|
|
|
|
|
m_consoleView, &ConsoleView::onScrollToBottom);
|
|
|
|
|
|
|
|
|
|
auto itemDelegate = new ConsoleItemDelegate(m_consoleItemModel, this);
|
|
|
|
|
connect(m_consoleView->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
|
itemDelegate, &ConsoleItemDelegate::currentChanged);
|
|
|
|
|
m_consoleView->setItemDelegate(itemDelegate);
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2018-07-23 22:28:49 +02:00
|
|
|
auto aggregate = new Aggregation::Aggregate();
|
2012-10-04 14:54:59 +02:00
|
|
|
aggregate->add(m_consoleView);
|
2014-07-31 18:15:19 +02:00
|
|
|
aggregate->add(new Core::ItemViewFind(m_consoleView));
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
vbox->addWidget(m_consoleView);
|
|
|
|
|
vbox->addWidget(new Core::FindToolBarPlaceHolder(m_consoleWidget));
|
|
|
|
|
|
|
|
|
|
m_showDebugButton = new QToolButton(m_consoleWidget);
|
|
|
|
|
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showDebug.setDefaultValue(true);
|
|
|
|
|
m_showDebug.setSettingsKey(CONSOLE, SHOW_LOG);
|
2022-07-05 15:37:08 +02:00
|
|
|
m_showDebug.setLabelText(Tr::tr("Show debug, log, and info messages."));
|
|
|
|
|
m_showDebug.setToolTip(Tr::tr("Show debug, log, and info messages."));
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showDebug.setValue(true);
|
|
|
|
|
m_showDebug.action()->setIcon(Utils::Icons::INFO_TOOLBAR.icon());
|
2023-06-26 11:02:42 +02:00
|
|
|
connect(&m_showDebug, &Utils::BoolAspect::changed,
|
|
|
|
|
proxyModel, [this, proxyModel] { proxyModel->setShowLogs(m_showDebug()); });
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showDebugButton->setDefaultAction(m_showDebug.action());
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
m_showWarningButton = new QToolButton(m_consoleWidget);
|
|
|
|
|
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showWarning.setDefaultValue(true);
|
|
|
|
|
m_showWarning.setSettingsKey(CONSOLE, SHOW_WARNING);
|
2022-07-05 15:37:08 +02:00
|
|
|
m_showWarning.setLabelText(Tr::tr("Show warning messages."));
|
|
|
|
|
m_showWarning.setToolTip(Tr::tr("Show warning messages."));
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showWarning.setValue(true);
|
|
|
|
|
m_showWarning.action()->setIcon(Utils::Icons::WARNING_TOOLBAR.icon());
|
|
|
|
|
connect(m_showWarning.action(), &QAction::toggled,
|
2023-06-26 11:02:42 +02:00
|
|
|
proxyModel, [this, proxyModel] { proxyModel->setShowWarnings(m_showWarning()); });
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showWarningButton->setDefaultAction(m_showWarning.action());
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
m_showErrorButton = new QToolButton(m_consoleWidget);
|
|
|
|
|
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showError.setDefaultValue(true);
|
|
|
|
|
m_showError.setSettingsKey(CONSOLE, SHOW_ERROR);
|
2022-07-05 15:37:08 +02:00
|
|
|
m_showError.setLabelText(Tr::tr("Show error messages."));
|
|
|
|
|
m_showError.setToolTip(Tr::tr("Show error messages."));
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showError.setValue(true);
|
|
|
|
|
m_showError.action()->setIcon(Utils::Icons::CRITICAL_TOOLBAR.icon());
|
|
|
|
|
connect(m_showError.action(), &QAction::toggled,
|
2023-06-26 11:02:42 +02:00
|
|
|
proxyModel, [this, proxyModel] { proxyModel->setShowErrors(m_showError()); });
|
2021-03-01 08:59:44 +01:00
|
|
|
m_showErrorButton->setDefaultAction(m_showError.action());
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
m_spacer = new QWidget(m_consoleWidget);
|
|
|
|
|
m_spacer->setMinimumWidth(30);
|
|
|
|
|
|
2016-12-09 11:32:48 +01:00
|
|
|
m_statusLabel = new QLabel(m_consoleWidget);
|
|
|
|
|
|
2012-10-04 14:54:59 +02:00
|
|
|
readSettings();
|
2015-11-10 16:59:02 +01:00
|
|
|
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
|
|
|
|
|
this, &Console::writeSettings);
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
Console::~Console()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
writeSettings();
|
|
|
|
|
delete m_consoleWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
QWidget *Console::outputWidget(QWidget *)
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
return m_consoleWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
QList<QWidget *> Console::toolBarWidgets() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
return {m_showDebugButton, m_showWarningButton, m_showErrorButton,
|
|
|
|
|
m_spacer, m_statusLabel};
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
int Console::priorityInStatusBar() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
return 20;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::clearContents()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2015-11-10 16:59:02 +01:00
|
|
|
m_consoleItemModel->clear();
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
bool Console::canFocus() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
bool Console::hasFocus() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2018-07-23 22:28:49 +02:00
|
|
|
for (QWidget *widget = m_consoleWidget->window()->focusWidget(); widget != nullptr;
|
2015-10-28 13:32:53 +01:00
|
|
|
widget = widget->parentWidget()) {
|
|
|
|
|
if (widget == m_consoleWidget)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::setFocus()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2015-10-28 13:32:53 +01:00
|
|
|
m_consoleView->setFocus();
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
bool Console::canNext() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
bool Console::canPrevious() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::goToNext()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::goToPrev()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
bool Console::canNavigate() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::readSettings()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2023-07-06 09:57:16 +02:00
|
|
|
m_showDebug.readSettings();
|
|
|
|
|
m_showWarning.readSettings();
|
|
|
|
|
m_showError.readSettings();
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 11:32:48 +01:00
|
|
|
void Console::setContext(const QString &context)
|
|
|
|
|
{
|
|
|
|
|
m_statusLabel->setText(context);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::writeSettings() const
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2023-07-06 09:57:16 +02:00
|
|
|
m_showDebug.writeSettings();
|
|
|
|
|
m_showWarning.writeSettings();
|
|
|
|
|
m_showError.writeSettings();
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::setScriptEvaluator(const ScriptEvaluator &evaluator)
|
|
|
|
|
{
|
|
|
|
|
m_scriptEvaluator = evaluator;
|
2017-01-05 15:25:13 +01:00
|
|
|
m_consoleItemModel->setCanFetchMore(bool(m_scriptEvaluator));
|
2016-12-09 11:32:48 +01:00
|
|
|
if (!m_scriptEvaluator)
|
|
|
|
|
setContext(QString());
|
2015-11-10 16:59:02 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-12 10:44:10 +02:00
|
|
|
void Console::populateFileFinder()
|
|
|
|
|
{
|
|
|
|
|
m_consoleView->populateFileFinder();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void Console::printItem(ConsoleItem::ItemType itemType, const QString &text)
|
|
|
|
|
{
|
|
|
|
|
printItem(new ConsoleItem(itemType, text));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Console::printItem(ConsoleItem *item)
|
|
|
|
|
{
|
|
|
|
|
m_consoleItemModel->appendItem(item);
|
|
|
|
|
if (item->itemType() == ConsoleItem::ErrorType)
|
|
|
|
|
popup(Core::IOutputPane::ModeSwitch);
|
|
|
|
|
else if (item->itemType() == ConsoleItem::WarningType)
|
|
|
|
|
flash();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Console::evaluate(const QString &expression)
|
|
|
|
|
{
|
|
|
|
|
if (m_scriptEvaluator) {
|
|
|
|
|
m_consoleItemModel->shiftEditableRow();
|
|
|
|
|
m_scriptEvaluator(expression);
|
|
|
|
|
} else {
|
2022-07-05 15:37:08 +02:00
|
|
|
auto item = new ConsoleItem(
|
2023-02-09 11:43:49 +01:00
|
|
|
ConsoleItem::ErrorType, Tr::tr("Can only evaluate during a debug session."));
|
2015-11-10 16:59:02 +01:00
|
|
|
m_consoleItemModel->shiftEditableRow();
|
|
|
|
|
printItem(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
} // Debugger::Internal
|