Commit 33651877 authored by hjk's avatar hjk Committed by Ulf Hermann

Move QmlConsole to Debugger

Now it is closer to its only user and possibly reusable for no-QML uses
there.  We also drop the QML/JS syntax checker. The application being
debugged can already tell us about syntax errors. There is no need to
duplicate that functionality.

Change-Id: I2ba151f9f4c854c6119ba5462c21be40bddcebf9
Reviewed-by: default avatarUlf Hermann <ulf.hermann@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 0e76b991
......@@ -84,7 +84,7 @@
\image qtquick-example-setting-breakpoint3.png
\li To execute JavaScript commands in the current context, open the
\uicontrol {QML/JS Console} output pane.
\uicontrol {Debugger Console} output pane.
\li To change the score to 1000, enter \c{gameCanvas.score = 1000}
in the console.
......@@ -108,7 +108,7 @@
\inlineimage qml-inspector-select-button.png
(\uicontrol Select) to activate selection mode and then click the
\uicontrol {Quit} button to move into the \uicontrol ButtonLabel component
in the \uicontrol {QML/JS Console} and the code editor.
in the \uicontrol {Locals and Expressions} and the code editor.
\li In the \uicontrol {Locals and Expressions} view, double-click the value of
the \c text property to change it temporarily from \uicontrol {Quit} to
......
......@@ -158,17 +158,17 @@
\section1 Executing JavaScript Expressions
When the application is interrupted by a breakpoint, you can use the
\uicontrol {QML/JS Console} to execute JavaScript expressions in the current
\uicontrol {Debugger Console} to execute JavaScript expressions in the current
context. To open it, choose \uicontrol Window > \uicontrol {Output Panes}
> \uicontrol {QML/JS Console}.
> \uicontrol {Debugger Console}.
\image qml-script-console.png "QML/JS Console"
\image qml-script-console.png "Debugger Console"
For more information about using the console, see \l{QML/JS Console}.
For more information about using the console, see \l{Debugger Console}.
\section1 Applying QML Changes at Runtime
When you change property values in the \uicontrol {QML/JS Console} or in the
When you change property values in the \uicontrol {Debugger Console} or in the
\uicontrol {Locals and Expressions} view, they are immediately updated in the running
application, but not in the source code.
......
......@@ -335,7 +335,7 @@
\li \uicontrol{Compile Output}
\li \uicontrol {QML/JS Console}
\li \uicontrol {Debugger Console}
\li \uicontrol {To-Do Entries}
......@@ -460,14 +460,14 @@
Select the \uicontrol {Cancel Build} button to cancel the build.
\section2 QML/JS Console
\section2 Debugger Console
In the \uicontrol {QML/JS Console}, you can type JavaScript expressions and use them to get
In the \uicontrol {Debugger Console}, you can type JavaScript expressions and use them to get
information about the state of your application during debugging. You can change property
values temporarily, without editing the source, and view the results in the running
application.
\image qml-script-console.png "QML/JS Console"
\image qml-script-console.png "Debugger Console"
You can change the property values permanently in the code editor.
......
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "consolemanagerinterface.h"
namespace QmlJS {
static ConsoleManagerInterface *g_instance = 0;
ConsoleManagerInterface::ConsoleManagerInterface(QObject *parent)
: QObject(parent)
{
Q_ASSERT(!g_instance);
g_instance = this;
}
ConsoleManagerInterface::~ConsoleManagerInterface()
{
Q_ASSERT(g_instance == this);
g_instance = 0;
}
ConsoleManagerInterface *ConsoleManagerInterface::instance()
{
return g_instance;
}
} // QmlJS
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CONSOLEMANAGERINTERFACE_H
#define CONSOLEMANAGERINTERFACE_H
#include "qmljs_global.h"
#include "consoleitem.h"
#include <QObject>
namespace QmlJS {
class IScriptEvaluator;
class QMLJS_EXPORT ConsoleManagerInterface : public QObject
{
Q_OBJECT
public:
ConsoleManagerInterface(QObject *parent = 0);
~ConsoleManagerInterface();
static ConsoleManagerInterface *instance();
virtual void showConsolePane() = 0;
virtual void setScriptEvaluator(IScriptEvaluator *scriptEvaluator) = 0;
virtual void setContext(const QString &context) = 0;
virtual void printToConsolePane(ConsoleItem::ItemType itemType, const QString &text,
bool bringToForeground = false) = 0;
virtual void printToConsolePane(ConsoleItem *item, bool bringToForeground = false) = 0;
};
} // QmlJS
#endif // CONSOLEMANAGERINTERFACE_H
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef ISCRIPTEVALUATOR_H
#define ISCRIPTEVALUATOR_H
#include "qmljs_global.h"
#include <QString>
namespace QmlJS {
class IScriptEvaluator
{
public:
IScriptEvaluator() {}
virtual bool evaluateScript(const QString &script) = 0;
};
} // QmlJS
#endif // ISCRIPTEVALUATOR_H
......@@ -34,9 +34,6 @@ HEADERS += \
$$PWD/qmljsutils.h \
$$PWD/qmljsstaticanalysismessage.h \
$$PWD/jsoncheck.h \
$$PWD/consolemanagerinterface.h \
$$PWD/consoleitem.h \
$$PWD/iscriptevaluator.h \
$$PWD/qmljssimplereader.h \
$$PWD/persistenttrie.h \
$$PWD/qmljsqrcparser.h \
......@@ -72,8 +69,6 @@ SOURCES += \
$$PWD/qmljsutils.cpp \
$$PWD/qmljsstaticanalysismessage.cpp \
$$PWD/jsoncheck.cpp \
$$PWD/consolemanagerinterface.cpp \
$$PWD/consoleitem.cpp \
$$PWD/qmljssimplereader.cpp \
$$PWD/persistenttrie.cpp \
$$PWD/qmljsqrcparser.cpp \
......
......@@ -17,9 +17,6 @@ QtcLibrary {
Group {
name: "General"
files: [
"consoleitem.cpp", "consoleitem.h",
"consolemanagerinterface.cpp", "consolemanagerinterface.h",
"iscriptevaluator.h",
"jsoncheck.cpp", "jsoncheck.h",
"persistenttrie.cpp", "persistenttrie.h",
"qmljs.qrc",
......
......@@ -28,11 +28,17 @@
**
****************************************************************************/
#ifndef QMLCONSOLEPANE_H
#define QMLCONSOLEPANE_H
#ifndef DEBUGGER_CONSOLE_H
#define DEBUGGER_CONSOLE_H
#include "consoleitem.h"
#include <coreplugin/ioutputpane.h>
#include <functional>
#include <QObject>
QT_BEGIN_NAMESPACE
class QToolButton;
class QLabel;
......@@ -40,25 +46,25 @@ QT_END_NAMESPACE
namespace Utils { class SavedAction; }
namespace QmlJSTools {
namespace Debugger {
namespace Internal {
class QmlConsoleView;
class QmlConsoleItemDelegate;
class QmlConsoleProxyModel;
class QmlConsoleItemModel;
typedef std::function<bool(QString)> ScriptEvaluator;
class ConsoleItemModel;
class ConsoleView;
class QmlConsolePane : public Core::IOutputPane
class Console : public Core::IOutputPane
{
Q_OBJECT
public:
QmlConsolePane(QObject *parent);
~QmlConsolePane();
Console();
~Console();
QWidget *outputWidget(QWidget *);
QList<QWidget *> toolBarWidgets() const;
QString displayName() const { return tr("QML/JS Console"); }
QString displayName() const { return tr("Debugger Console"); }
int priorityInStatusBar() const;
void clearContents();
void visibilityChanged(bool visible);
......@@ -75,7 +81,12 @@ public:
void readSettings();
void setContext(const QString &context);
public slots:
void setScriptEvaluator(const ScriptEvaluator &evaluator);
void evaluate(const QString &expression);
void printItem(ConsoleItem *item);
void printItem(ConsoleItem::ItemType itemType, const QString &text);
void writeSettings() const;
private:
......@@ -87,13 +98,15 @@ private:
Utils::SavedAction *m_showErrorButtonAction;
QWidget *m_spacer;
QLabel *m_statusLabel;
QmlConsoleView *m_consoleView;
QmlConsoleItemDelegate *m_itemDelegate;
QmlConsoleProxyModel *m_proxyModel;
ConsoleItemModel *m_consoleItemModel;
ConsoleView *m_consoleView;
QWidget *m_consoleWidget;
ScriptEvaluator m_scriptEvaluator;
};
Console *debuggerConsole();
} // namespace Internal
} // namespace QmlJSTools
} // namespace Debugger
#endif // QMLCONSOLEPANE_H
#endif // DEBUGGER_CONSOLE_H
HEADERS += \
$$PWD/consoleitem.h \
$$PWD/consoleedit.h \
$$PWD/consoleitemdelegate.h \
$$PWD/consoleitemmodel.h \
$$PWD/console.h \
$$PWD/consoleproxymodel.h \
$$PWD/consoleview.h
SOURCES += \
$$PWD/consoleitem.cpp \
$$PWD/consoleedit.cpp \
$$PWD/consoleitemdelegate.cpp \
$$PWD/consoleitemmodel.cpp \
$$PWD/console.cpp \
$$PWD/consoleproxymodel.cpp \
$$PWD/consoleview.cpp
......@@ -28,28 +28,25 @@
**
****************************************************************************/
#include "qmlconsoleedit.h"
#include "qmlconsoleitemmodel.h"
#include "qmlconsolemodel.h"
#include "consoleedit.h"
#include "consoleitemmodel.h"
#include "console.h"
#include <utils/qtcassert.h>
#include <QUrl>
#include <QMenu>
#include <QKeyEvent>
using namespace QmlJS;
namespace QmlJSTools {
namespace Debugger {
namespace Internal {
///////////////////////////////////////////////////////////////////////
//
// QmlConsoleEdit
// ConsoleEdit
//
///////////////////////////////////////////////////////////////////////
QmlConsoleEdit::QmlConsoleEdit(const QModelIndex &index, QWidget *parent) :
ConsoleEdit::ConsoleEdit(const QModelIndex &index, QWidget *parent) :
QTextEdit(parent),
m_historyIndex(index)
{
......@@ -60,7 +57,7 @@ QmlConsoleEdit::QmlConsoleEdit(const QModelIndex &index, QWidget *parent) :
setTextInteractionFlags(Qt::TextEditorInteraction);
}
void QmlConsoleEdit::keyPressEvent(QKeyEvent *e)
void ConsoleEdit::keyPressEvent(QKeyEvent *e)
{
bool keyConsumed = false;
......@@ -68,10 +65,8 @@ void QmlConsoleEdit::keyPressEvent(QKeyEvent *e)
case Qt::Key_Return:
case Qt::Key_Enter: {
QString currentScript = getCurrentScript();
if (m_interpreter.canEvaluate(currentScript)) {
QmlConsoleModel::evaluate(currentScript);
emit editingFinished();
}
debuggerConsole()->evaluate(currentScript);
emit editingFinished();
keyConsumed = true;
break;
}
......@@ -94,12 +89,12 @@ void QmlConsoleEdit::keyPressEvent(QKeyEvent *e)
QTextEdit::keyPressEvent(e);
}
void QmlConsoleEdit::focusOutEvent(QFocusEvent * /*e*/)
void ConsoleEdit::focusOutEvent(QFocusEvent * /*e*/)
{
emit editingFinished();
}
void QmlConsoleEdit::handleUpKey()
void ConsoleEdit::handleUpKey()
{
QTC_ASSERT(m_historyIndex.isValid(), return);
int currentRow = m_historyIndex.row();
......@@ -122,7 +117,7 @@ void QmlConsoleEdit::handleUpKey()
}
}
void QmlConsoleEdit::handleDownKey()
void ConsoleEdit::handleDownKey()
{
QTC_ASSERT(m_historyIndex.isValid(), return);
int currentRow = m_historyIndex.row();
......@@ -146,7 +141,7 @@ void QmlConsoleEdit::handleDownKey()
}
}
QString QmlConsoleEdit::getCurrentScript() const
QString ConsoleEdit::getCurrentScript() const
{
QTextCursor cursor = textCursor();
cursor.setPosition(0);
......@@ -154,7 +149,7 @@ QString QmlConsoleEdit::getCurrentScript() const
return cursor.selectedText();
}
void QmlConsoleEdit::replaceCurrentScript(const QString &script)
void ConsoleEdit::replaceCurrentScript(const QString &script)
{
QTextCursor cursor = textCursor();
cursor.setPosition(0);
......@@ -165,4 +160,4 @@ void QmlConsoleEdit::replaceCurrentScript(const QString &script)
}
} // Internal
} // QmlJSTools
} // Debugger
......@@ -28,23 +28,22 @@
**
****************************************************************************/
#ifndef QMLCONSOLEEDIT_H
#define QMLCONSOLEEDIT_H
#ifndef DEBUGGER_CONSOLEEDIT_H
#define DEBUGGER_CONSOLEEDIT_H
#include "qmljsinterpreter.h"
#include <QTextEdit>
#include <QModelIndex>
#include <QString>
#include <QTextEdit>
namespace QmlJSTools {
namespace Debugger {
namespace Internal {
class QmlConsoleEdit : public QTextEdit
class ConsoleEdit : public QTextEdit
{
Q_OBJECT
public:
QmlConsoleEdit(const QModelIndex &index, QWidget *parent);
public:
ConsoleEdit(const QModelIndex &index, QWidget *parent);
QString getCurrentScript() const;
protected:
......@@ -57,16 +56,14 @@ signals:
protected:
void handleUpKey();
void handleDownKey();
void replaceCurrentScript(const QString &script);
private:
QModelIndex m_historyIndex;
QString m_cachedScript;
QmlJSInterpreter m_interpreter;
};
} // QmlJSTools
} // Debugger
} // Internal
#endif // QMLCONSOLEEDIT_H
#endif // DEBUGGER_CONSOLEEDIT_H
......@@ -30,15 +30,10 @@
#include "consoleitem.h"
namespace QmlJS {
namespace Debugger {
namespace Internal {
///////////////////////////////////////////////////////////////////////
//
// ConsoleItem
//
///////////////////////////////////////////////////////////////////////
QString addZeroWidthSpace(QString text)
static QString addZeroWidthSpace(QString text)
{
for (int i = 0; i < text.length(); ++i) {
if (text.at(i).isPunct())
......@@ -164,4 +159,5 @@ QString ConsoleItem::expression() const
return text().remove(QChar(0x200b)); // ZERO WIDTH SPACE
}
} // QmlJS
} // Internal
} // Debugger
......@@ -31,15 +31,15 @@
#ifndef CONSOLEITEM_H
#define CONSOLEITEM_H
#include "qmljs_global.h"
#include <utils/treemodel.h>
#include <QString>
#include <functional>
namespace QmlJS {
namespace Debugger {
namespace Internal {
class QMLJS_EXPORT ConsoleItem : public Utils::TreeItem
class ConsoleItem : public Utils::TreeItem
{
public:
enum Roles {
......@@ -85,6 +85,7 @@ private:
std::function<void(ConsoleItem *)> m_doFetch;
};
} // QmlJS
} // Internal
} // Debugger
#endif // CONSOLEITEM_H
......@@ -28,8 +28,8 @@
**
****************************************************************************/
#include "qmlconsoleitemdelegate.h"
#include "qmlconsoleedit.h"
#include "consoleitemdelegate.h"
#include "consoleedit.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/coreicons.h>
......@@ -59,19 +59,18 @@ const char CONSOLE_BORDER_COLOR[] = "#C9C9C9";
const int ELLIPSIS_GRADIENT_WIDTH = 16;
using namespace QmlJS;
namespace QmlJSTools {
namespace Debugger {
namespace Internal {
///////////////////////////////////////////////////////////////////////
//
// QmlConsoleItemDelegate
// ConsoleItemDelegate
//
///////////////////////////////////////////////////////////////////////
QmlConsoleItemDelegate::QmlConsoleItemDelegate(QObject *parent) :
ConsoleItemDelegate::ConsoleItemDelegate(ConsoleItemModel *model, QObject *parent) :
QStyledItemDelegate(parent),
m_model(model),
m_logIcon(Core::Icons::INFO.icon()),
m_warningIcon(Core::Icons::WARNING.icon()),
m_errorIcon(Core::Icons::ERROR.icon()),
......@@ -82,12 +81,12 @@ QmlConsoleItemDelegate::QmlConsoleItemDelegate(QObject *parent) :
{
}
void QmlConsoleItemDelegate::emitSizeHintChanged(const QModelIndex &index)
void ConsoleItemDelegate::emitSizeHintChanged(const QModelIndex &index)
{
emit sizeHintChanged(index);
}
QColor QmlConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
QColor ConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
const QModelIndex &index,
bool selected) const
{
......@@ -128,7 +127,7 @@ QColor QmlConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &re
return backgroundColor;
}
void QmlConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,