forked from qt-creator/qt-creator
Debugger: Remove the dependence on QmlJSTools
Change-Id: I26765134c19b9a6cf1e7ad26f313e2d4f8faf258 Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <QMenu>
|
||||
#include <QKeyEvent>
|
||||
|
||||
using namespace QmlJS;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
@@ -207,7 +209,7 @@ void QmlConsoleEdit::handleUpKey()
|
||||
currentRow--;
|
||||
if (model->hasIndex(currentRow, 0)) {
|
||||
QModelIndex index = model->index(currentRow, 0);
|
||||
if (QmlConsoleItem::InputType == (QmlConsoleItem::ItemType)model->data(
|
||||
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
|
||||
index, QmlConsoleItemModel::TypeRole).toInt()) {
|
||||
m_historyIndex = index;
|
||||
replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
|
||||
@@ -226,7 +228,7 @@ void QmlConsoleEdit::handleDownKey()
|
||||
currentRow++;
|
||||
if (model->hasIndex(currentRow, 0)) {
|
||||
QModelIndex index = model->index(currentRow, 0);
|
||||
if (QmlConsoleItem::InputType == (QmlConsoleItem::ItemType)model->data(
|
||||
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
|
||||
index, QmlConsoleItemModel::TypeRole).toInt()) {
|
||||
m_historyIndex = index;
|
||||
if (currentRow == model->rowCount() - 1)
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/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 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmlconsoleitem.h"
|
||||
|
||||
namespace QmlJSTools {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// QmlConsoleItem
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
QmlConsoleItem::QmlConsoleItem(QmlConsoleItem *parent, QmlConsoleItem::ItemType itemType,
|
||||
const QString &text)
|
||||
: m_parentItem(parent),
|
||||
itemType(itemType),
|
||||
line(-1)
|
||||
|
||||
{
|
||||
setText(text);
|
||||
}
|
||||
|
||||
QmlConsoleItem::~QmlConsoleItem()
|
||||
{
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
QmlConsoleItem *QmlConsoleItem::child(int number)
|
||||
{
|
||||
return m_childItems.value(number);
|
||||
}
|
||||
|
||||
int QmlConsoleItem::childCount() const
|
||||
{
|
||||
return m_childItems.size();
|
||||
}
|
||||
|
||||
int QmlConsoleItem::childNumber() const
|
||||
{
|
||||
if (m_parentItem)
|
||||
return m_parentItem->m_childItems.indexOf(const_cast<QmlConsoleItem *>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool QmlConsoleItem::insertChildren(int position, int count)
|
||||
{
|
||||
if (position < 0 || position > m_childItems.size())
|
||||
return false;
|
||||
|
||||
for (int row = 0; row < count; ++row) {
|
||||
QmlConsoleItem *item = new QmlConsoleItem(this, QmlConsoleItem::UndefinedType,
|
||||
QString());
|
||||
m_childItems.insert(position, item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QmlConsoleItem::insertChild(QmlConsoleItem *item, bool sorted)
|
||||
{
|
||||
if (!sorted) {
|
||||
m_childItems.insert(m_childItems.count(), item);
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (; i < m_childItems.count(); i++) {
|
||||
if (item->m_text < m_childItems[i]->m_text)
|
||||
break;
|
||||
}
|
||||
m_childItems.insert(i, item);
|
||||
}
|
||||
|
||||
bool QmlConsoleItem::insertChild(int position, QmlConsoleItem *item)
|
||||
{
|
||||
if (position < 0 || position > m_childItems.size())
|
||||
return false;
|
||||
|
||||
m_childItems.insert(position, item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QmlConsoleItem *QmlConsoleItem::parent()
|
||||
{
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
bool QmlConsoleItem::removeChildren(int position, int count)
|
||||
{
|
||||
if (position < 0 || position + count > m_childItems.size())
|
||||
return false;
|
||||
|
||||
for (int row = 0; row < count; ++row)
|
||||
delete m_childItems.takeAt(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QmlConsoleItem::detachChild(int position)
|
||||
{
|
||||
if (position < 0 || position > m_childItems.size())
|
||||
return false;
|
||||
|
||||
m_childItems.removeAt(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QmlConsoleItem::setText(const QString &text)
|
||||
{
|
||||
m_text = text;
|
||||
for (int i = 0; i < m_text.length(); ++i) {
|
||||
if (m_text.at(i).isPunct())
|
||||
m_text.insert(++i, QChar(0x200b)); // ZERO WIDTH SPACE
|
||||
}
|
||||
}
|
||||
|
||||
const QString &QmlConsoleItem::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
} // QmlJSTools
|
||||
@@ -1,84 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/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 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMLCONSOLEITEM_H
|
||||
#define QMLCONSOLEITEM_H
|
||||
|
||||
#include "qmljstools_global.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
namespace QmlJSTools {
|
||||
|
||||
class QMLJSTOOLS_EXPORT QmlConsoleItem
|
||||
{
|
||||
public:
|
||||
enum ItemType
|
||||
{
|
||||
UndefinedType = 0x01, // Can be used for unknown and for Return values
|
||||
DebugType = 0x02,
|
||||
WarningType = 0x04,
|
||||
ErrorType = 0x08,
|
||||
InputType = 0x10,
|
||||
DefaultTypes = InputType | UndefinedType
|
||||
};
|
||||
Q_DECLARE_FLAGS(ItemTypes, ItemType)
|
||||
|
||||
QmlConsoleItem(QmlConsoleItem *parent,
|
||||
QmlConsoleItem::ItemType type = QmlConsoleItem::UndefinedType,
|
||||
const QString &data = QString());
|
||||
~QmlConsoleItem();
|
||||
|
||||
QmlConsoleItem *child(int number);
|
||||
int childCount() const;
|
||||
bool insertChildren(int position, int count);
|
||||
void insertChild(QmlConsoleItem *item, bool sorted);
|
||||
bool insertChild(int position, QmlConsoleItem *item);
|
||||
QmlConsoleItem *parent();
|
||||
bool removeChildren(int position, int count);
|
||||
bool detachChild(int position);
|
||||
int childNumber() const;
|
||||
void setText(const QString &text);
|
||||
const QString &text() const;
|
||||
|
||||
private:
|
||||
QmlConsoleItem *m_parentItem;
|
||||
QList<QmlConsoleItem *> m_childItems;
|
||||
QString m_text;
|
||||
|
||||
public:
|
||||
QmlConsoleItem::ItemType itemType;
|
||||
QString file;
|
||||
int line;
|
||||
};
|
||||
|
||||
} // QmlJSTools
|
||||
|
||||
#endif // QMLCONSOLEITEM_H
|
||||
@@ -53,6 +53,8 @@ const char CONSOLE_BORDER_COLOR[] = "#C9C9C9";
|
||||
|
||||
const int ELLIPSIS_GRADIENT_WIDTH = 16;
|
||||
|
||||
using namespace QmlJS;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
@@ -84,23 +86,23 @@ QColor QmlConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &re
|
||||
bool selected) const
|
||||
{
|
||||
painter->save();
|
||||
QmlConsoleItem::ItemType itemType = (QmlConsoleItem::ItemType)index.data(
|
||||
ConsoleItem::ItemType itemType = (ConsoleItem::ItemType)index.data(
|
||||
QmlConsoleItemModel::TypeRole).toInt();
|
||||
QColor backgroundColor;
|
||||
switch (itemType) {
|
||||
case QmlConsoleItem::DebugType:
|
||||
case ConsoleItem::DebugType:
|
||||
backgroundColor = selected ? QColor(CONSOLE_LOG_BACKGROUND_SELECTED_COLOR) :
|
||||
QColor(CONSOLE_LOG_BACKGROUND_COLOR);
|
||||
break;
|
||||
case QmlConsoleItem::WarningType:
|
||||
case ConsoleItem::WarningType:
|
||||
backgroundColor = selected ? QColor(CONSOLE_WARNING_BACKGROUND_SELECTED_COLOR) :
|
||||
QColor(CONSOLE_WARNING_BACKGROUND_COLOR);
|
||||
break;
|
||||
case QmlConsoleItem::ErrorType:
|
||||
case ConsoleItem::ErrorType:
|
||||
backgroundColor = selected ? QColor(CONSOLE_ERROR_BACKGROUND_SELECTED_COLOR) :
|
||||
QColor(CONSOLE_ERROR_BACKGROUND_COLOR);
|
||||
break;
|
||||
case QmlConsoleItem::InputType:
|
||||
case ConsoleItem::InputType:
|
||||
default:
|
||||
backgroundColor = selected ? QColor(CONSOLE_EDITOR_BACKGROUND_SELECTED_COLOR) :
|
||||
QColor(CONSOLE_EDITOR_BACKGROUND_COLOR);
|
||||
@@ -130,22 +132,22 @@ void QmlConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||
// Set Colors
|
||||
QColor textColor;
|
||||
QIcon taskIcon;
|
||||
QmlConsoleItem::ItemType type = (QmlConsoleItem::ItemType)index.data(
|
||||
ConsoleItem::ItemType type = (ConsoleItem::ItemType)index.data(
|
||||
QmlConsoleItemModel::TypeRole).toInt();
|
||||
switch (type) {
|
||||
case QmlConsoleItem::DebugType:
|
||||
case ConsoleItem::DebugType:
|
||||
textColor = QColor(CONSOLE_LOG_TEXT_COLOR);
|
||||
taskIcon = m_logIcon;
|
||||
break;
|
||||
case QmlConsoleItem::WarningType:
|
||||
case ConsoleItem::WarningType:
|
||||
textColor = QColor(CONSOLE_WARNING_TEXT_COLOR);
|
||||
taskIcon = m_warningIcon;
|
||||
break;
|
||||
case QmlConsoleItem::ErrorType:
|
||||
case ConsoleItem::ErrorType:
|
||||
textColor = QColor(CONSOLE_ERROR_TEXT_COLOR);
|
||||
taskIcon = m_errorIcon;
|
||||
break;
|
||||
case QmlConsoleItem::InputType:
|
||||
case ConsoleItem::InputType:
|
||||
textColor = QColor(CONSOLE_EDITOR_TEXT_COLOR);
|
||||
taskIcon = m_prompt;
|
||||
break;
|
||||
@@ -168,7 +170,7 @@ void QmlConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||
}
|
||||
int width = view->width() - level * view->indentation() - view->verticalScrollBar()->width();
|
||||
bool showTypeIcon = index.parent() == QModelIndex();
|
||||
bool showExpandableIcon = type == QmlConsoleItem::UndefinedType;
|
||||
bool showExpandableIcon = type == ConsoleItem::UndefinedType;
|
||||
|
||||
QRect rect(opt.rect.x(), opt.rect.top(), width, opt.rect.height());
|
||||
ConsoleItemPositions positions(rect, opt.font, showTypeIcon, showExpandableIcon);
|
||||
@@ -266,10 +268,10 @@ QSize QmlConsoleItemDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
if (!selected && option.font == m_cachedFont && m_cachedHeight > 0)
|
||||
return QSize(width, m_cachedHeight);
|
||||
|
||||
QmlConsoleItem::ItemType type = (QmlConsoleItem::ItemType)index.data(
|
||||
ConsoleItem::ItemType type = (ConsoleItem::ItemType)index.data(
|
||||
QmlConsoleItemModel::TypeRole).toInt();
|
||||
bool showTypeIcon = index.parent() == QModelIndex();
|
||||
bool showExpandableIcon = type == QmlConsoleItem::UndefinedType;
|
||||
bool showExpandableIcon = type == ConsoleItem::UndefinedType;
|
||||
|
||||
QRect rect(level * view->indentation(), 0, width, 0);
|
||||
ConsoleItemPositions positions(rect, opt.font, showTypeIcon, showExpandableIcon);
|
||||
@@ -320,7 +322,7 @@ void QmlConsoleItemDelegate::setModelData(QWidget *editor,
|
||||
{
|
||||
QmlConsoleEdit *edtr = qobject_cast<QmlConsoleEdit *>(editor);
|
||||
model->setData(index, edtr->getCurrentScript(), Qt::DisplayRole);
|
||||
model->setData(index, QmlConsoleItem::InputType, QmlConsoleItemModel::TypeRole);
|
||||
model->setData(index, ConsoleItem::InputType, QmlConsoleItemModel::TypeRole);
|
||||
}
|
||||
|
||||
void QmlConsoleItemDelegate::updateEditorGeometry(QWidget *editor,
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
||||
using namespace QmlJS;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
@@ -45,7 +47,7 @@ namespace Internal {
|
||||
QmlConsoleItemModel::QmlConsoleItemModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),
|
||||
m_hasEditableRow(false),
|
||||
m_rootItem(new QmlConsoleItem(0)),
|
||||
m_rootItem(new ConsoleItem(0)),
|
||||
m_maxSizeOfFileName(0)
|
||||
{
|
||||
}
|
||||
@@ -60,14 +62,14 @@ void QmlConsoleItemModel::clear()
|
||||
beginResetModel();
|
||||
reset();
|
||||
delete m_rootItem;
|
||||
m_rootItem = new QmlConsoleItem(0);
|
||||
m_rootItem = new ConsoleItem(0);
|
||||
endResetModel();
|
||||
|
||||
if (m_hasEditableRow)
|
||||
appendEditableRow();
|
||||
}
|
||||
|
||||
bool QmlConsoleItemModel::appendItem(QmlConsoleItem *item, int position)
|
||||
bool QmlConsoleItemModel::appendItem(ConsoleItem *item, int position)
|
||||
{
|
||||
if (position < 0)
|
||||
position = m_rootItem->childCount() - 1;
|
||||
@@ -82,10 +84,10 @@ bool QmlConsoleItemModel::appendItem(QmlConsoleItem *item, int position)
|
||||
return success;
|
||||
}
|
||||
|
||||
bool QmlConsoleItemModel::appendMessage(QmlConsoleItem::ItemType itemType,
|
||||
bool QmlConsoleItemModel::appendMessage(ConsoleItem::ItemType itemType,
|
||||
const QString &message, int position)
|
||||
{
|
||||
return appendItem(new QmlConsoleItem(m_rootItem, itemType, message), position);
|
||||
return appendItem(new ConsoleItem(m_rootItem, itemType, message), position);
|
||||
}
|
||||
|
||||
void QmlConsoleItemModel::setHasEditableRow(bool hasEditableRow)
|
||||
@@ -107,13 +109,13 @@ bool QmlConsoleItemModel::hasEditableRow() const
|
||||
void QmlConsoleItemModel::appendEditableRow()
|
||||
{
|
||||
int position = m_rootItem->childCount();
|
||||
if (appendItem(new QmlConsoleItem(m_rootItem, QmlConsoleItem::InputType), position))
|
||||
if (appendItem(new ConsoleItem(m_rootItem, ConsoleItem::InputType), position))
|
||||
emit selectEditableRow(index(position, 0), QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
void QmlConsoleItemModel::removeEditableRow()
|
||||
{
|
||||
if (m_rootItem->child(m_rootItem->childCount() - 1)->itemType == QmlConsoleItem::InputType)
|
||||
if (m_rootItem->child(m_rootItem->childCount() - 1)->itemType == ConsoleItem::InputType)
|
||||
removeRow(m_rootItem->childCount() - 1);
|
||||
}
|
||||
|
||||
@@ -148,7 +150,7 @@ QVariant QmlConsoleItemModel::data(const QModelIndex &index, int role) const
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
QmlConsoleItem *item = getItem(index);
|
||||
ConsoleItem *item = getItem(index);
|
||||
|
||||
if (role == Qt::DisplayRole )
|
||||
return item->text();
|
||||
@@ -170,9 +172,9 @@ QModelIndex QmlConsoleItemModel::index(int row, int column, const QModelIndex &p
|
||||
if (column > 0)
|
||||
return QModelIndex();
|
||||
|
||||
QmlConsoleItem *parentItem = getItem(parent);
|
||||
ConsoleItem *parentItem = getItem(parent);
|
||||
|
||||
QmlConsoleItem *childItem = parentItem->child(row);
|
||||
ConsoleItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
@@ -184,8 +186,8 @@ QModelIndex QmlConsoleItemModel::parent(const QModelIndex &index) const
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
QmlConsoleItem *childItem = getItem(index);
|
||||
QmlConsoleItem *parentItem = childItem->parent();
|
||||
ConsoleItem *childItem = getItem(index);
|
||||
ConsoleItem *parentItem = childItem->parent();
|
||||
|
||||
if (parentItem == m_rootItem)
|
||||
return QModelIndex();
|
||||
@@ -197,7 +199,7 @@ QModelIndex QmlConsoleItemModel::parent(const QModelIndex &index) const
|
||||
|
||||
int QmlConsoleItemModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
QmlConsoleItem *parentItem = getItem(parent);
|
||||
ConsoleItem *parentItem = getItem(parent);
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
@@ -212,7 +214,7 @@ Qt::ItemFlags QmlConsoleItemModel::flags(const QModelIndex &index) const
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
QmlConsoleItem *item = getItem(index);
|
||||
ConsoleItem *item = getItem(index);
|
||||
if (m_hasEditableRow && item->parent() == m_rootItem
|
||||
&& index.row() == m_rootItem->childCount() - 1)
|
||||
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
@@ -221,13 +223,13 @@ Qt::ItemFlags QmlConsoleItemModel::flags(const QModelIndex &index) const
|
||||
|
||||
bool QmlConsoleItemModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
QmlConsoleItem *item = getItem(index);
|
||||
ConsoleItem *item = getItem(index);
|
||||
bool result = false;
|
||||
if (role == Qt::DisplayRole) {
|
||||
item->setText(value.toString());
|
||||
result = true;
|
||||
} else if (role == QmlConsoleItemModel::TypeRole) {
|
||||
item->itemType = (QmlConsoleItem::ItemType)value.toInt();
|
||||
item->itemType = (ConsoleItem::ItemType)value.toInt();
|
||||
result = true;
|
||||
} else if (role == QmlConsoleItemModel::FileRole) {
|
||||
item->file = value.toString();
|
||||
@@ -245,7 +247,7 @@ bool QmlConsoleItemModel::setData(const QModelIndex &index, const QVariant &valu
|
||||
|
||||
bool QmlConsoleItemModel::insertRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
QmlConsoleItem *parentItem = getItem(parent);
|
||||
ConsoleItem *parentItem = getItem(parent);
|
||||
bool success;
|
||||
|
||||
beginInsertRows(parent, position, position + rows - 1);
|
||||
@@ -257,7 +259,7 @@ bool QmlConsoleItemModel::insertRows(int position, int rows, const QModelIndex &
|
||||
|
||||
bool QmlConsoleItemModel::removeRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
QmlConsoleItem *parentItem = getItem(parent);
|
||||
ConsoleItem *parentItem = getItem(parent);
|
||||
bool success = true;
|
||||
|
||||
beginRemoveRows(parent, position, position + rows - 1);
|
||||
@@ -267,10 +269,10 @@ bool QmlConsoleItemModel::removeRows(int position, int rows, const QModelIndex &
|
||||
return success;
|
||||
}
|
||||
|
||||
QmlConsoleItem *QmlConsoleItemModel::getItem(const QModelIndex &index) const
|
||||
ConsoleItem *QmlConsoleItemModel::getItem(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid()) {
|
||||
QmlConsoleItem *item = static_cast<QmlConsoleItem*>(index.internalPointer());
|
||||
ConsoleItem *item = static_cast<ConsoleItem*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifndef QMLCONSOLEITEMMODEL_H
|
||||
#define QMLCONSOLEITEMMODEL_H
|
||||
|
||||
#include "qmlconsoleitem.h"
|
||||
#include <qmljs/consoleitem.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QItemSelectionModel>
|
||||
@@ -53,8 +53,8 @@ public:
|
||||
void appendEditableRow();
|
||||
void removeEditableRow();
|
||||
|
||||
bool appendItem(QmlConsoleItem *item, int position = -1);
|
||||
bool appendMessage(QmlConsoleItem::ItemType itemType, const QString &message,
|
||||
bool appendItem(QmlJS::ConsoleItem *item, int position = -1);
|
||||
bool appendMessage(QmlJS::ConsoleItem::ItemType itemType, const QString &message,
|
||||
int position = -1);
|
||||
|
||||
QAbstractItemModel *model() { return this; }
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
int sizeOfFile(const QFont &font);
|
||||
int sizeOfLineNumber(const QFont &font);
|
||||
|
||||
QmlConsoleItem *root() const { return m_rootItem; }
|
||||
QmlJS::ConsoleItem *root() const { return m_rootItem; }
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
@@ -88,11 +88,11 @@ protected:
|
||||
bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||
bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||
|
||||
QmlConsoleItem *getItem(const QModelIndex &index) const;
|
||||
QmlJS::ConsoleItem *getItem(const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
bool m_hasEditableRow;
|
||||
QmlConsoleItem *m_rootItem;
|
||||
QmlJS::ConsoleItem *m_rootItem;
|
||||
int m_maxSizeOfFileName;
|
||||
};
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <debugger/debuggerengine.h>
|
||||
#include <qmljs/iscriptevaluator.h>
|
||||
|
||||
#include <QScriptEngine>
|
||||
#include <QVariant>
|
||||
|
||||
namespace QmlJSTools {
|
||||
using namespace QmlJS;
|
||||
|
||||
QmlConsoleManager *QmlConsoleManager::m_instance = 0;
|
||||
namespace QmlJSTools {
|
||||
|
||||
class QmlConsoleManagerPrivate
|
||||
{
|
||||
@@ -48,29 +48,26 @@ public:
|
||||
QScriptEngine *scriptEngine;
|
||||
Internal::QmlConsoleItemModel *qmlConsoleItemModel;
|
||||
Internal::QmlConsolePane *qmlConsolePane;
|
||||
Debugger::DebuggerEngine *debuggerEngine;
|
||||
QmlJS::IScriptEvaluator *scriptEvaluator;
|
||||
};
|
||||
|
||||
QmlConsoleManager::QmlConsoleManager(QObject *parent)
|
||||
: QObject(parent),
|
||||
: ConsoleManagerInterface(parent),
|
||||
d(new QmlConsoleManagerPrivate)
|
||||
{
|
||||
m_instance = this;
|
||||
d->scriptEngine = new QScriptEngine(this);
|
||||
d->qmlConsoleItemModel = new Internal::QmlConsoleItemModel(this);
|
||||
d->qmlConsoleItemModel->setHasEditableRow(true);
|
||||
d->qmlConsolePane = new Internal::QmlConsolePane(this);
|
||||
d->scriptEvaluator = 0;
|
||||
ExtensionSystem::PluginManager::addObject(d->qmlConsolePane);
|
||||
d->debuggerEngine = 0;
|
||||
}
|
||||
|
||||
QmlConsoleManager::~QmlConsoleManager()
|
||||
{
|
||||
if (d->qmlConsolePane) {
|
||||
if (d->qmlConsolePane)
|
||||
ExtensionSystem::PluginManager::removeObject(d->qmlConsolePane);
|
||||
}
|
||||
delete d;
|
||||
m_instance = 0;
|
||||
}
|
||||
|
||||
void QmlConsoleManager::showConsolePane()
|
||||
@@ -79,15 +76,15 @@ void QmlConsoleManager::showConsolePane()
|
||||
d->qmlConsolePane->popup(Core::IOutputPane::ModeSwitch);
|
||||
}
|
||||
|
||||
QmlConsoleItem *QmlConsoleManager::rootItem() const
|
||||
ConsoleItem *QmlConsoleManager::rootItem() const
|
||||
{
|
||||
return d->qmlConsoleItemModel->root();
|
||||
}
|
||||
|
||||
void QmlConsoleManager::setDebuggerEngine(Debugger::DebuggerEngine *debuggerEngine)
|
||||
void QmlConsoleManager::setScriptEvaluator(QmlJS::IScriptEvaluator *scriptEvaluator)
|
||||
{
|
||||
d->debuggerEngine = debuggerEngine;
|
||||
if (!debuggerEngine)
|
||||
d->scriptEvaluator = scriptEvaluator;
|
||||
if (!scriptEvaluator)
|
||||
setContext(QString());
|
||||
}
|
||||
|
||||
@@ -96,23 +93,23 @@ void QmlConsoleManager::setContext(const QString &context)
|
||||
d->qmlConsolePane->setContext(context);
|
||||
}
|
||||
|
||||
void QmlConsoleManager::printToConsolePane(QmlConsoleItem::ItemType itemType,
|
||||
void QmlConsoleManager::printToConsolePane(ConsoleItem::ItemType itemType,
|
||||
const QString &text, bool bringToForeground)
|
||||
{
|
||||
if (!d->qmlConsolePane)
|
||||
return;
|
||||
if (itemType == QmlConsoleItem::ErrorType)
|
||||
if (itemType == ConsoleItem::ErrorType)
|
||||
bringToForeground = true;
|
||||
if (bringToForeground)
|
||||
d->qmlConsolePane->popup(Core::IOutputPane::ModeSwitch);
|
||||
d->qmlConsoleItemModel->appendMessage(itemType, text);
|
||||
}
|
||||
|
||||
void QmlConsoleManager::printToConsolePane(QmlConsoleItem *item, bool bringToForeground)
|
||||
void QmlConsoleManager::printToConsolePane(ConsoleItem *item, bool bringToForeground)
|
||||
{
|
||||
if (!d->qmlConsolePane)
|
||||
return;
|
||||
if (item->itemType == QmlConsoleItem::ErrorType)
|
||||
if (item->itemType == ConsoleItem::ErrorType)
|
||||
bringToForeground = true;
|
||||
if (bringToForeground)
|
||||
d->qmlConsolePane->popup(Core::IOutputPane::ModeSwitch);
|
||||
@@ -121,13 +118,13 @@ void QmlConsoleManager::printToConsolePane(QmlConsoleItem *item, bool bringToFor
|
||||
|
||||
namespace Internal {
|
||||
|
||||
QmlConsoleItem *constructLogItemTree(QmlConsoleItem *parent, const QVariant &result,
|
||||
ConsoleItem *constructLogItemTree(ConsoleItem *parent, const QVariant &result,
|
||||
const QString &key = QString())
|
||||
{
|
||||
if (!result.isValid())
|
||||
return 0;
|
||||
|
||||
QmlConsoleItem *item = new QmlConsoleItem(parent);
|
||||
ConsoleItem *item = new ConsoleItem(parent);
|
||||
if (result.type() == QVariant::Map) {
|
||||
if (key.isEmpty())
|
||||
item->setText(QLatin1String("Object"));
|
||||
@@ -137,7 +134,7 @@ QmlConsoleItem *constructLogItemTree(QmlConsoleItem *parent, const QVariant &res
|
||||
QMapIterator<QString, QVariant> i(result.toMap());
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
QmlConsoleItem *child = constructLogItemTree(item, i.value(), i.key());
|
||||
ConsoleItem *child = constructLogItemTree(item, i.value(), i.key());
|
||||
if (child)
|
||||
item->insertChild(child, true);
|
||||
}
|
||||
@@ -148,7 +145,7 @@ QmlConsoleItem *constructLogItemTree(QmlConsoleItem *parent, const QVariant &res
|
||||
item->setText(QString(QLatin1String("[%1] : List")).arg(key));
|
||||
QVariantList resultList = result.toList();
|
||||
for (int i = 0; i < resultList.count(); i++) {
|
||||
QmlConsoleItem *child = constructLogItemTree(item, resultList.at(i),
|
||||
ConsoleItem *child = constructLogItemTree(item, resultList.at(i),
|
||||
QString::number(i));
|
||||
if (child)
|
||||
item->insertChild(child, true);
|
||||
@@ -164,7 +161,7 @@ QmlConsoleItem *constructLogItemTree(QmlConsoleItem *parent, const QVariant &res
|
||||
|
||||
QmlConsoleItemModel *QmlConsoleModel::qmlConsoleItemModel()
|
||||
{
|
||||
QmlConsoleManager *manager = QmlConsoleManager::instance();
|
||||
QmlConsoleManager *manager = qobject_cast<QmlConsoleManager *>(QmlConsoleManager::instance());
|
||||
if (manager)
|
||||
return manager->d->qmlConsoleItemModel;
|
||||
return 0;
|
||||
@@ -172,15 +169,15 @@ QmlConsoleItemModel *QmlConsoleModel::qmlConsoleItemModel()
|
||||
|
||||
void QmlConsoleModel::evaluate(const QString &expression)
|
||||
{
|
||||
QmlConsoleManager *manager = QmlConsoleManager::instance();
|
||||
QmlConsoleManager *manager = qobject_cast<QmlConsoleManager *>(QmlConsoleManager::instance());
|
||||
if (manager) {
|
||||
if (manager->d->debuggerEngine) {
|
||||
if (manager->d->scriptEvaluator) {
|
||||
QmlConsoleModel::qmlConsoleItemModel()->appendEditableRow();
|
||||
manager->d->debuggerEngine->evaluateScriptExpression(expression);
|
||||
manager->d->scriptEvaluator->evaluateScript(expression);
|
||||
} else {
|
||||
QVariant result = manager->d->scriptEngine->evaluate(expression).toVariant();
|
||||
QmlConsoleItem *root = manager->rootItem();
|
||||
QmlConsoleItem *item = constructLogItemTree(root, result);
|
||||
ConsoleItem *root = manager->rootItem();
|
||||
ConsoleItem *item = constructLogItemTree(root, result);
|
||||
if (item) {
|
||||
QmlConsoleModel::qmlConsoleItemModel()->appendEditableRow();
|
||||
manager->printToConsolePane(item);
|
||||
|
||||
@@ -31,12 +31,13 @@
|
||||
#define QMLCONSOLEMANAGER_H
|
||||
|
||||
#include "qmljstools_global.h"
|
||||
#include "qmlconsoleitem.h"
|
||||
|
||||
#include <qmljs/consolemanagerinterface.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Debugger {
|
||||
class DebuggerEngine;
|
||||
namespace QmlJS {
|
||||
class IScriptEvaluator;
|
||||
}
|
||||
namespace QmlJSTools {
|
||||
|
||||
@@ -46,29 +47,26 @@ class QmlConsoleModel;
|
||||
}
|
||||
|
||||
class QmlConsoleManagerPrivate;
|
||||
class QMLJSTOOLS_EXPORT QmlConsoleManager : public QObject
|
||||
class QMLJSTOOLS_EXPORT QmlConsoleManager : public QmlJS::ConsoleManagerInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QmlConsoleManager(QObject *parent);
|
||||
~QmlConsoleManager();
|
||||
|
||||
static QmlConsoleManager *instance() { return m_instance; }
|
||||
|
||||
void showConsolePane();
|
||||
|
||||
QmlConsoleItem *rootItem() const;
|
||||
QmlJS::ConsoleItem *rootItem() const;
|
||||
|
||||
void setDebuggerEngine(Debugger::DebuggerEngine *debuggerEngine);
|
||||
void setScriptEvaluator(QmlJS::IScriptEvaluator *scriptEvaluator);
|
||||
void setContext(const QString &context);
|
||||
|
||||
void printToConsolePane(QmlConsoleItem::ItemType itemType, const QString &text,
|
||||
void printToConsolePane(QmlJS::ConsoleItem::ItemType itemType, const QString &text,
|
||||
bool bringToForeground = false);
|
||||
void printToConsolePane(QmlConsoleItem *item, bool bringToForeground = false);
|
||||
void printToConsolePane(QmlJS::ConsoleItem *item, bool bringToForeground = false);
|
||||
|
||||
private:
|
||||
QmlConsoleManagerPrivate *d;
|
||||
static QmlConsoleManager *m_instance;
|
||||
friend class Internal::QmlConsoleModel;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,31 +30,33 @@
|
||||
#include "qmlconsoleproxymodel.h"
|
||||
#include "qmlconsoleitemmodel.h"
|
||||
|
||||
using namespace QmlJS;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
QmlConsoleProxyModel::QmlConsoleProxyModel(QObject *parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
m_filter(QmlConsoleItem::DefaultTypes)
|
||||
m_filter(ConsoleItem::DefaultTypes)
|
||||
{
|
||||
}
|
||||
|
||||
void QmlConsoleProxyModel::setShowLogs(bool show)
|
||||
{
|
||||
m_filter = show ? m_filter | QmlConsoleItem::DebugType : m_filter & ~QmlConsoleItem::DebugType;
|
||||
m_filter = show ? m_filter | ConsoleItem::DebugType : m_filter & ~ConsoleItem::DebugType;
|
||||
setFilterRegExp(QString());
|
||||
}
|
||||
|
||||
void QmlConsoleProxyModel::setShowWarnings(bool show)
|
||||
{
|
||||
m_filter = show ? m_filter | QmlConsoleItem::WarningType
|
||||
: m_filter & ~QmlConsoleItem::WarningType;
|
||||
m_filter = show ? m_filter | ConsoleItem::WarningType
|
||||
: m_filter & ~ConsoleItem::WarningType;
|
||||
setFilterRegExp(QString());
|
||||
}
|
||||
|
||||
void QmlConsoleProxyModel::setShowErrors(bool show)
|
||||
{
|
||||
m_filter = show ? m_filter | QmlConsoleItem::ErrorType : m_filter & ~QmlConsoleItem::ErrorType;
|
||||
m_filter = show ? m_filter | ConsoleItem::ErrorType : m_filter & ~ConsoleItem::ErrorType;
|
||||
setFilterRegExp(QString());
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ bool QmlConsoleProxyModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
return m_filter.testFlag((QmlConsoleItem::ItemType)sourceModel()->data(
|
||||
return m_filter.testFlag((ConsoleItem::ItemType)sourceModel()->data(
|
||||
index, QmlConsoleItemModel::TypeRole).toInt());
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifndef QMLCONSOLEPROXYMODEL_H
|
||||
#define QMLCONSOLEPROXYMODEL_H
|
||||
|
||||
#include "qmlconsoleitem.h"
|
||||
#include <qmljs/consoleitem.h>
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QItemSelectionModel>
|
||||
@@ -61,7 +61,7 @@ protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
||||
|
||||
private:
|
||||
QFlags<QmlConsoleItem::ItemType> m_filter;
|
||||
QFlags<QmlJS::ConsoleItem::ItemType> m_filter;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include <QUrl>
|
||||
#include <QScrollBar>
|
||||
|
||||
using namespace QmlJS;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
@@ -117,10 +119,10 @@ void QmlConsoleView::mousePressEvent(QMouseEvent *event)
|
||||
QPoint pos = event->pos();
|
||||
QModelIndex index = indexAt(pos);
|
||||
if (index.isValid()) {
|
||||
QmlConsoleItem::ItemType type = (QmlConsoleItem::ItemType)index.data(
|
||||
ConsoleItem::ItemType type = (ConsoleItem::ItemType)index.data(
|
||||
QmlConsoleItemModel::TypeRole).toInt();
|
||||
bool handled = false;
|
||||
if (type == QmlConsoleItem::UndefinedType) {
|
||||
if (type == ConsoleItem::UndefinedType) {
|
||||
bool showTypeIcon = index.parent() == QModelIndex();
|
||||
ConsoleItemPositions positions(visualRect(index), viewOptions().font, showTypeIcon,
|
||||
true);
|
||||
|
||||
@@ -30,7 +30,6 @@ HEADERS += \
|
||||
$$PWD/qmljssemanticinfo.h \
|
||||
$$PWD/qmljstools_global.h \
|
||||
$$PWD/qmlconsolemanager.h \
|
||||
$$PWD/qmlconsoleitem.h \
|
||||
$$PWD/qmlconsoleitemmodel.h \
|
||||
$$PWD/qmlconsolepane.h \
|
||||
$$PWD/qmlconsoleview.h \
|
||||
@@ -54,7 +53,6 @@ SOURCES += \
|
||||
$$PWD/qmljsfindexportedcpptypes.cpp \
|
||||
$$PWD/qmljssemanticinfo.cpp \
|
||||
$$PWD/qmlconsolemanager.cpp \
|
||||
$$PWD/qmlconsoleitem.cpp \
|
||||
$$PWD/qmlconsoleitemmodel.cpp \
|
||||
$$PWD/qmlconsolepane.cpp \
|
||||
$$PWD/qmlconsoleview.cpp \
|
||||
|
||||
@@ -55,8 +55,6 @@ QtcPlugin {
|
||||
"qmljstoolssettings.h",
|
||||
"qmlconsolemanager.cpp",
|
||||
"qmlconsolemanager.h",
|
||||
"qmlconsoleitem.cpp",
|
||||
"qmlconsoleitem.h",
|
||||
"qmlconsoleitemmodel.cpp",
|
||||
"qmlconsoleitemmodel.h",
|
||||
"qmlconsolepane.cpp",
|
||||
|
||||
Reference in New Issue
Block a user