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: Ulf Hermann <ulf.hermann@theqtcompany.com>
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
hjk
2015-11-10 16:59:02 +01:00
committed by Ulf Hermann
parent 0e76b99108
commit 33651877d8
41 changed files with 381 additions and 804 deletions

View File

@@ -1,167 +0,0 @@
/****************************************************************************
**
** 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 "consoleitem.h"
namespace QmlJS {
///////////////////////////////////////////////////////////////////////
//
// ConsoleItem
//
///////////////////////////////////////////////////////////////////////
QString addZeroWidthSpace(QString text)
{
for (int i = 0; i < text.length(); ++i) {
if (text.at(i).isPunct())
text.insert(++i, QChar(0x200b)); // ZERO WIDTH SPACE
}
return text;
}
ConsoleItem::ConsoleItem(ItemType itemType, const QString &expression, const QString &file,
int line) :
m_itemType(itemType), m_text(addZeroWidthSpace(expression)), m_file(file), m_line(line)
{
setFlags(Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable |
(itemType == InputType ? Qt::ItemIsEditable : Qt::NoItemFlags)));
}
ConsoleItem::ConsoleItem(ConsoleItem::ItemType itemType, const QString &expression,
std::function<void(ConsoleItem *)> doFetch) :
m_itemType(itemType), m_text(addZeroWidthSpace(expression)), m_line(-1), m_doFetch(doFetch)
{
setFlags(Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable |
(itemType == InputType ? Qt::ItemIsEditable : Qt::NoItemFlags)));
}
ConsoleItem::ItemType ConsoleItem::itemType() const
{
return m_itemType;
}
QString ConsoleItem::text() const
{
return m_text;
}
QString ConsoleItem::file() const
{
return m_file;
}
int ConsoleItem::line() const
{
return m_line;
}
QVariant ConsoleItem::data(int column, int role) const
{
if (column != 0)
return QVariant();
switch (role)
{
case TypeRole:
return m_itemType;
case FileRole:
return m_file;
case LineRole:
return m_line;
case ExpressionRole:
return expression();
case Qt::DisplayRole:
return m_text;
default:
return TreeItem::data(column, role);
}
}
bool ConsoleItem::setData(int column, const QVariant &data, int role)
{
if (column != 0)
return false;
switch (role)
{
case TypeRole:
m_itemType = ItemType(data.toInt());
return true;
case FileRole:
m_file = data.toString();
return true;
case LineRole:
m_line = data.toInt();
return true;
case ExpressionRole:
m_text = addZeroWidthSpace(data.toString());
return true;
case Qt::DisplayRole:
m_text = data.toString();
return true;
default:
return TreeItem::setData(column, data, role);
}
}
bool ConsoleItem::canFetchMore() const
{
// Always fetch all children, too, as the labels depend on them.
foreach (TreeItem *child, children()) {
if (static_cast<ConsoleItem *>(child)->m_doFetch)
return true;
}
return bool(m_doFetch);
}
void ConsoleItem::fetchMore()
{
if (m_doFetch) {
m_doFetch(this);
m_doFetch = std::function<void(ConsoleItem *)>();
}
foreach (TreeItem *child, children()) {
ConsoleItem *item = static_cast<ConsoleItem *>(child);
if (item->m_doFetch) {
item->m_doFetch(item);
item->m_doFetch = m_doFetch;
}
}
}
QString ConsoleItem::expression() const
{
return text().remove(QChar(0x200b)); // ZERO WIDTH SPACE
}
} // QmlJS

View File

@@ -1,90 +0,0 @@
/****************************************************************************
**
** 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 CONSOLEITEM_H
#define CONSOLEITEM_H
#include "qmljs_global.h"
#include <utils/treemodel.h>
#include <QString>
#include <functional>
namespace QmlJS {
class QMLJS_EXPORT ConsoleItem : public Utils::TreeItem
{
public:
enum Roles {
TypeRole = Qt::UserRole,
FileRole,
LineRole,
ExpressionRole
};
enum ItemType
{
DefaultType = 0x01, // Can be used for unknown and for Return values
DebugType = 0x02,
WarningType = 0x04,
ErrorType = 0x08,
InputType = 0x10,
AllTypes = DefaultType | DebugType | WarningType | ErrorType | InputType
};
Q_DECLARE_FLAGS(ItemTypes, ItemType)
ConsoleItem(ItemType itemType = ConsoleItem::DefaultType, const QString &expression = QString(),
const QString &file = QString(), int line = -1);
ConsoleItem(ItemType itemType, const QString &expression,
std::function<void(ConsoleItem *)> doFetch);
ItemType itemType() const;
QString expression() const;
QString text() const;
QString file() const;
int line() const;
QVariant data(int column, int role) const;
bool setData(int column, const QVariant &data, int role);
bool canFetchMore() const;
void fetchMore();
private:
ItemType m_itemType;
QString m_text;
QString m_file;
int m_line;
std::function<void(ConsoleItem *)> m_doFetch;
};
} // QmlJS
#endif // CONSOLEITEM_H

View File

@@ -1,55 +0,0 @@
/****************************************************************************
**
** 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

View File

@@ -1,63 +0,0 @@
/****************************************************************************
**
** 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

View File

@@ -1,49 +0,0 @@
/****************************************************************************
**
** 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

View File

@@ -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 \

View File

@@ -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",