ScriptConsole: Move from Debugger to QmlJSTools

The console is now a part of qmljstools plugin. The console
appears as an output pane. A dummy QScriptEngine evaluates
expressions when a declarative debug session is not in
progress. During a debug session, the expressions are
evaluated by the debug services.

Task-Number: QTCREATORBUG-7402

Change-Id: Ic2eeac44fb335c706be03b89f8672b0356efe984
Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Aurindam Jana
2012-10-04 14:54:59 +02:00
committed by hjk
parent 614bb33589
commit 9ac25a2932
54 changed files with 1779 additions and 1872 deletions

View File

@@ -70,12 +70,6 @@ HEADERS += \
debuggertooltipmanager.h \ debuggertooltipmanager.h \
debuggersourcepathmappingwidget.h \ debuggersourcepathmappingwidget.h \
memoryview.h \ memoryview.h \
qtmessagelogwindow.h \
qtmessagelogeditor.h \
qtmessagelogview.h \
qtmessagelogproxymodel.h \
qtmessagelogitemdelegate.h \
qtmessageloghandler.h \
localsandexpressionswindow.h localsandexpressionswindow.h
SOURCES += \ SOURCES += \
@@ -123,12 +117,6 @@ SOURCES += \
debuggertooltipmanager.cpp \ debuggertooltipmanager.cpp \
debuggersourcepathmappingwidget.cpp \ debuggersourcepathmappingwidget.cpp \
memoryview.cpp \ memoryview.cpp \
qtmessagelogwindow.cpp \
qtmessagelogproxymodel.cpp \
qtmessagelogview.cpp \
qtmessagelogitemdelegate.cpp \
qtmessageloghandler.cpp \
qtmessagelogeditor.cpp \
localsandexpressionswindow.cpp localsandexpressionswindow.cpp
FORMS += \ FORMS += \

View File

@@ -101,18 +101,6 @@ QtcPlugin {
"outputcollector.h", "outputcollector.h",
"procinterrupt.cpp", "procinterrupt.cpp",
"procinterrupt.h", "procinterrupt.h",
"qtmessagelogeditor.cpp",
"qtmessagelogeditor.h",
"qtmessageloghandler.cpp",
"qtmessageloghandler.h",
"qtmessagelogitemdelegate.cpp",
"qtmessagelogitemdelegate.h",
"qtmessagelogproxymodel.cpp",
"qtmessagelogproxymodel.h",
"qtmessagelogview.cpp",
"qtmessagelogview.h",
"qtmessagelogwindow.cpp",
"qtmessagelogwindow.h",
"registerhandler.cpp", "registerhandler.cpp",
"registerhandler.h", "registerhandler.h",
"registerwindow.cpp", "registerwindow.cpp",

View File

@@ -30,12 +30,6 @@
<file>images/location_16.png</file> <file>images/location_16.png</file>
<file>images/location_24.png</file> <file>images/location_24.png</file>
<file>images/pin.xpm</file> <file>images/pin.xpm</file>
<file>images/collapse.png</file>
<file>images/error.png</file>
<file>images/expand.png</file>
<file>images/log.png</file>
<file>images/prompt.png</file>
<file>images/warning.png</file>
<file>images/qml/zoom.png</file> <file>images/qml/zoom.png</file>
<file>images/qml/select.png</file> <file>images/qml/select.png</file>
<file>images/qml/app-on-top.png</file> <file>images/qml/app-on-top.png</file>

View File

@@ -3,6 +3,7 @@ include(../../plugins/cpptools/cpptools.pri)
include(../../plugins/find/find.pri) include(../../plugins/find/find.pri)
include(../../plugins/projectexplorer/projectexplorer.pri) include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../plugins/texteditor/texteditor.pri) include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/qmljstools/qmljstools.pri)
include(../../libs/cplusplus/cplusplus.pri) include(../../libs/cplusplus/cplusplus.pri)
include(../../libs/utils/utils.pri) include(../../libs/utils/utils.pri)
include(../../libs/qmljs/qmljs.pri) include(../../libs/qmljs/qmljs.pri)

View File

@@ -75,7 +75,6 @@ const char DOCKWIDGET_THREADS[] = "Debugger.Docks.Threads";
const char DOCKWIDGET_WATCHERS[] = "Debugger.Docks.LocalsAndWatchers"; const char DOCKWIDGET_WATCHERS[] = "Debugger.Docks.LocalsAndWatchers";
const char DOCKWIDGET_QML_INSPECTOR[] = "Debugger.Docks.QmlInspector"; const char DOCKWIDGET_QML_INSPECTOR[] = "Debugger.Docks.QmlInspector";
const char DOCKWIDGET_QML_SCRIPTCONSOLE[] = "Debugger.Docks.ScriptConsole";
const char DOCKWIDGET_DEFAULT_AREA[] = "Debugger.Docks.DefaultArea"; const char DOCKWIDGET_DEFAULT_AREA[] = "Debugger.Docks.DefaultArea";
} // namespace Constants } // namespace Constants
@@ -182,9 +181,8 @@ enum LogChannel
AppOutput, // stdout AppOutput, // stdout
AppError, // stderr AppError, // stderr
AppStuff, // (possibly) windows debug channel AppStuff, // (possibly) windows debug channel
StatusBar, // LogStatus and also put to the status bar StatusBar, // LogStatus and also put to the status bar
QtMessageLogOutput, ConsoleOutput // Used to output to console
QtMessageLogStatus
}; };
enum DebuggerEngineType enum DebuggerEngineType

View File

@@ -48,7 +48,6 @@
#include "stackhandler.h" #include "stackhandler.h"
#include "threadshandler.h" #include "threadshandler.h"
#include "watchhandler.h" #include "watchhandler.h"
#include "qtmessageloghandler.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
@@ -66,6 +65,8 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/fileinprojectfinder.h> #include <utils/fileinprojectfinder.h>
#include <qmljstools/qmlconsolemanager.h>
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
#include <QFile> #include <QFile>
@@ -297,7 +298,6 @@ public:
StackHandler m_stackHandler; StackHandler m_stackHandler;
ThreadsHandler m_threadsHandler; ThreadsHandler m_threadsHandler;
WatchHandler m_watchHandler; WatchHandler m_watchHandler;
QtMessageLogHandler m_qtMessageHandler;
QFutureInterface<void> m_progress; QFutureInterface<void> m_progress;
DisassemblerAgent m_disassemblerAgent; DisassemblerAgent m_disassemblerAgent;
@@ -428,11 +428,6 @@ WatchHandler *DebuggerEngine::watchHandler() const
: &d->m_watchHandler; : &d->m_watchHandler;
} }
QtMessageLogHandler *DebuggerEngine::qtMessageLogHandler() const
{
return &d->m_qtMessageHandler;
}
SourceFilesHandler *DebuggerEngine::sourceFilesHandler() const SourceFilesHandler *DebuggerEngine::sourceFilesHandler() const
{ {
return d->m_masterEngine return d->m_masterEngine
@@ -510,14 +505,6 @@ QAbstractItemModel *DebuggerEngine::sourceFilesModel() const
return model; return model;
} }
QAbstractItemModel *DebuggerEngine::qtMessageLogModel() const
{
QAbstractItemModel *model = qtMessageLogHandler()->model();
if (model->objectName().isEmpty()) // Make debugging easier.
model->setObjectName(objectName() + QLatin1String("QtMessageLogModel"));
return model;
}
void DebuggerEngine::fetchMemory(MemoryAgent *, QObject *, void DebuggerEngine::fetchMemory(MemoryAgent *, QObject *,
quint64 addr, quint64 length) quint64 addr, quint64 length)
{ {
@@ -546,8 +533,9 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
} }
//if (msg.size() && msg.at(0).isUpper() && msg.at(1).isUpper()) //if (msg.size() && msg.at(0).isUpper() && msg.at(1).isUpper())
// qDebug() << qPrintable(msg) << "IN STATE" << state(); // qDebug() << qPrintable(msg) << "IN STATE" << state();
if (channel == QtMessageLogOutput) QmlJSTools::QmlConsoleManager *consoleManager = QmlJSTools::QmlConsoleManager::instance();
qtMessageLogHandler()->appendMessage(QtMessageLogHandler::UndefinedType, msg); if (channel == ConsoleOutput && consoleManager)
consoleManager->printToConsolePane(QmlJSTools::QmlConsoleItem::UndefinedType, msg);
debuggerCore()->showMessage(msg, channel, timeout); debuggerCore()->showMessage(msg, channel, timeout);
if (d->m_runControl) { if (d->m_runControl) {

View File

@@ -77,7 +77,6 @@ class QmlAdapter;
class QmlCppEngine; class QmlCppEngine;
class DebuggerToolTipContext; class DebuggerToolTipContext;
class MemoryMarkup; class MemoryMarkup;
class QtMessageLogHandler;
struct WatchUpdateFlags struct WatchUpdateFlags
{ {
@@ -216,7 +215,6 @@ public:
virtual Internal::WatchHandler *watchHandler() const; virtual Internal::WatchHandler *watchHandler() const;
virtual Internal::SourceFilesHandler *sourceFilesHandler() const; virtual Internal::SourceFilesHandler *sourceFilesHandler() const;
virtual Internal::BreakHandler *breakHandler() const; virtual Internal::BreakHandler *breakHandler() const;
virtual Internal::QtMessageLogHandler *qtMessageLogHandler() const;
virtual QAbstractItemModel *modulesModel() const; virtual QAbstractItemModel *modulesModel() const;
virtual QAbstractItemModel *registerModel() const; virtual QAbstractItemModel *registerModel() const;
@@ -229,7 +227,6 @@ public:
virtual QAbstractItemModel *toolTipsModel() const; // Deprecated, FIXME: use watchModel virtual QAbstractItemModel *toolTipsModel() const; // Deprecated, FIXME: use watchModel
virtual QAbstractItemModel *watchModel() const; virtual QAbstractItemModel *watchModel() const;
virtual QAbstractItemModel *sourceFilesModel() const; virtual QAbstractItemModel *sourceFilesModel() const;
virtual QAbstractItemModel *qtMessageLogModel() const;
void progressPing(); void progressPing();
void handleFinished(); void handleFinished();
@@ -273,6 +270,8 @@ public:
QString toFileInProject(const QUrl &fileUrl); QString toFileInProject(const QUrl &fileUrl);
virtual bool evaluateScriptExpression(const QString &expression);
signals: signals:
void stateChanged(Debugger::DebuggerState state); void stateChanged(Debugger::DebuggerState state);
// A new stack frame is on display including locals. // A new stack frame is on display including locals.
@@ -354,7 +353,6 @@ protected:
virtual void executeRunToFunction(const QString &functionName); virtual void executeRunToFunction(const QString &functionName);
virtual void executeJumpToLine(const Internal::ContextData &data); virtual void executeJumpToLine(const Internal::ContextData &data);
virtual void executeDebuggerCommand(const QString &command, DebuggerLanguages languages); virtual void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
virtual bool evaluateScriptExpression(const QString &expression);
virtual void frameUp(); virtual void frameUp();
virtual void frameDown(); virtual void frameDown();

View File

@@ -690,7 +690,6 @@ void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
QDockWidget *threadsDock = q->dockWidget(QLatin1String(DOCKWIDGET_THREADS)); QDockWidget *threadsDock = q->dockWidget(QLatin1String(DOCKWIDGET_THREADS));
QDockWidget *outputDock = q->dockWidget(QLatin1String(DOCKWIDGET_OUTPUT)); QDockWidget *outputDock = q->dockWidget(QLatin1String(DOCKWIDGET_OUTPUT));
QDockWidget *qmlInspectorDock = q->dockWidget(QLatin1String(DOCKWIDGET_QML_INSPECTOR)); QDockWidget *qmlInspectorDock = q->dockWidget(QLatin1String(DOCKWIDGET_QML_INSPECTOR));
QDockWidget *consoleDock = q->dockWidget(QLatin1String(DOCKWIDGET_QML_SCRIPTCONSOLE));
QDockWidget *modulesDock = q->dockWidget(QLatin1String(DOCKWIDGET_MODULES)); QDockWidget *modulesDock = q->dockWidget(QLatin1String(DOCKWIDGET_MODULES));
QDockWidget *registerDock = q->dockWidget(QLatin1String(DOCKWIDGET_REGISTER)); QDockWidget *registerDock = q->dockWidget(QLatin1String(DOCKWIDGET_REGISTER));
QDockWidget *sourceFilesDock = q->dockWidget(QLatin1String(DOCKWIDGET_SOURCE_FILES)); QDockWidget *sourceFilesDock = q->dockWidget(QLatin1String(DOCKWIDGET_SOURCE_FILES));
@@ -701,7 +700,6 @@ void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
QTC_ASSERT(snapshotsDock, return); QTC_ASSERT(snapshotsDock, return);
QTC_ASSERT(threadsDock, return); QTC_ASSERT(threadsDock, return);
QTC_ASSERT(outputDock, return); QTC_ASSERT(outputDock, return);
QTC_ASSERT(consoleDock, return);
QTC_ASSERT(modulesDock, return); QTC_ASSERT(modulesDock, return);
QTC_ASSERT(registerDock, return); QTC_ASSERT(registerDock, return);
QTC_ASSERT(sourceFilesDock, return); QTC_ASSERT(sourceFilesDock, return);
@@ -714,7 +712,7 @@ void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
// toolBar // toolBar
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// stack,qmlinspector | breakpoints,modules,register,threads,sourceFiles,snapshots,scriptconsole // stack,qmlinspector | breakpoints,modules,register,threads,sourceFiles,snapshots
// //
q->splitDockWidget(toolBarDock, stackDock, Qt::Vertical); q->splitDockWidget(toolBarDock, stackDock, Qt::Vertical);
q->splitDockWidget(stackDock, breakDock, Qt::Horizontal); q->splitDockWidget(stackDock, breakDock, Qt::Horizontal);
@@ -727,13 +725,10 @@ void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
q->tabifyDockWidget(breakDock, threadsDock); q->tabifyDockWidget(breakDock, threadsDock);
q->tabifyDockWidget(breakDock, sourceFilesDock); q->tabifyDockWidget(breakDock, sourceFilesDock);
q->tabifyDockWidget(breakDock, snapshotsDock); q->tabifyDockWidget(breakDock, snapshotsDock);
q->tabifyDockWidget(breakDock, consoleDock);
if (m_activeDebugLanguages.testFlag(Debugger::QmlLanguage)) { if (m_activeDebugLanguages.testFlag(Debugger::QmlLanguage)) {
if (qmlInspectorDock) if (qmlInspectorDock)
qmlInspectorDock->show(); qmlInspectorDock->show();
if (consoleDock)
consoleDock->show();
} else { } else {
// CPP only // CPP only
threadsDock->show(); threadsDock->show();

View File

@@ -46,7 +46,6 @@
#include "breakpoint.h" #include "breakpoint.h"
#include "breakhandler.h" #include "breakhandler.h"
#include "breakwindow.h" #include "breakwindow.h"
#include "qtmessagelogwindow.h"
#include "disassemblerlines.h" #include "disassemblerlines.h"
#include "logwindow.h" #include "logwindow.h"
#include "moduleswindow.h" #include "moduleswindow.h"
@@ -126,6 +125,8 @@
# include <utils/winutils.h> # include <utils/winutils.h>
#endif #endif
#include <qmljstools/qmlconsolemanager.h>
#include <QComboBox> #include <QComboBox>
#include <QDockWidget> #include <QDockWidget>
#include <QFileDialog> #include <QFileDialog>
@@ -1283,7 +1284,6 @@ public:
BaseWindow *m_breakWindow; BaseWindow *m_breakWindow;
BreakHandler *m_breakHandler; BreakHandler *m_breakHandler;
QtMessageLogWindow *m_qtMessageLogWindow;
WatchWindow *m_returnWindow; WatchWindow *m_returnWindow;
WatchWindow *m_localsWindow; WatchWindow *m_localsWindow;
WatchWindow *m_watchersWindow; WatchWindow *m_watchersWindow;
@@ -1349,7 +1349,6 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin) :
m_threadsWindow = 0; m_threadsWindow = 0;
m_logWindow = 0; m_logWindow = 0;
m_localsAndExpressionsWindow = 0; m_localsAndExpressionsWindow = 0;
m_qtMessageLogWindow = 0;
m_mainWindow = 0; m_mainWindow = 0;
m_snapshotHandler = 0; m_snapshotHandler = 0;
@@ -2066,12 +2065,18 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine)
m_threadsWindow->setModel(engine->threadsModel()); m_threadsWindow->setModel(engine->threadsModel());
m_watchersWindow->setModel(engine->watchersModel()); m_watchersWindow->setModel(engine->watchersModel());
m_inspectorWindow->setModel(engine->inspectorModel()); m_inspectorWindow->setModel(engine->inspectorModel());
m_qtMessageLogWindow->setModel(engine->qtMessageLogModel());
engine->watchHandler()->rebuildModel(); engine->watchHandler()->rebuildModel();
mainWindow()->setEngineDebugLanguages(engine->startParameters().languages); mainWindow()->setEngineDebugLanguages(engine->startParameters().languages);
mainWindow()->setCurrentEngine(engine); mainWindow()->setCurrentEngine(engine);
QmlJSTools::QmlConsoleManager *consoleManager = QmlJSTools::QmlConsoleManager::instance();
if (consoleManager) {
if (engine->startParameters().languages & QmlLanguage)
consoleManager->setDebuggerEngine(engine);
else
consoleManager->setDebuggerEngine(0);
}
} }
static void changeFontSize(QWidget *widget, qreal size) static void changeFontSize(QWidget *widget, qreal size)
@@ -2194,7 +2199,6 @@ void DebuggerPluginPrivate::setInitialState()
action(AutoDerefPointers)->setEnabled(true); action(AutoDerefPointers)->setEnabled(true);
action(ExpandStack)->setEnabled(false); action(ExpandStack)->setEnabled(false);
m_qtMessageLogWindow->setEnabled(true);
} }
void DebuggerPluginPrivate::updateWatchersWindow(bool showWatch, bool showReturn) void DebuggerPluginPrivate::updateWatchersWindow(bool showWatch, bool showReturn)
@@ -2559,10 +2563,6 @@ void DebuggerPluginPrivate::showMessage(const QString &msg, int channel, int tim
m_logWindow->showInput(LogError, QLatin1String("ERROR: ") + msg); m_logWindow->showInput(LogError, QLatin1String("ERROR: ") + msg);
m_logWindow->showOutput(LogError, QLatin1String("ERROR: ") + msg); m_logWindow->showOutput(LogError, QLatin1String("ERROR: ") + msg);
break; break;
case QtMessageLogStatus:
QTC_ASSERT(m_qtMessageLogWindow, return);
m_qtMessageLogWindow->showStatus(msg, timeout);
break;
default: default:
m_logWindow->showOutput(channel, msg); m_logWindow->showOutput(channel, msg);
break; break;
@@ -2739,8 +2739,6 @@ void DebuggerPluginPrivate::extensionsInitialized()
m_breakWindow->setObjectName(QLatin1String(DOCKWIDGET_BREAK)); m_breakWindow->setObjectName(QLatin1String(DOCKWIDGET_BREAK));
m_breakWindow->setModel(m_breakHandler->model()); m_breakWindow->setModel(m_breakHandler->model());
m_qtMessageLogWindow = new QtMessageLogWindow();
m_qtMessageLogWindow->setObjectName(QLatin1String(DOCKWIDGET_QML_SCRIPTCONSOLE));
m_modulesWindow = new ModulesWindow; m_modulesWindow = new ModulesWindow;
m_modulesWindow->setObjectName(QLatin1String(DOCKWIDGET_MODULES)); m_modulesWindow->setObjectName(QLatin1String(DOCKWIDGET_MODULES));
m_logWindow = new LogWindow; m_logWindow = new LogWindow;
@@ -2885,7 +2883,6 @@ void DebuggerPluginPrivate::extensionsInitialized()
dock->setProperty(DOCKWIDGET_DEFAULT_AREA, Qt::TopDockWidgetArea); dock->setProperty(DOCKWIDGET_DEFAULT_AREA, Qt::TopDockWidgetArea);
m_mainWindow->createDockWidget(CppLanguage, m_breakWindow); m_mainWindow->createDockWidget(CppLanguage, m_breakWindow);
m_mainWindow->createDockWidget(QmlLanguage, m_qtMessageLogWindow);
m_mainWindow->createDockWidget(CppLanguage, m_snapshotWindow); m_mainWindow->createDockWidget(CppLanguage, m_snapshotWindow);
m_mainWindow->createDockWidget(CppLanguage, m_stackWindow); m_mainWindow->createDockWidget(CppLanguage, m_stackWindow);
m_mainWindow->createDockWidget(CppLanguage, m_threadsWindow); m_mainWindow->createDockWidget(CppLanguage, m_threadsWindow);

View File

@@ -34,7 +34,6 @@
#include "debuggerstartparameters.h" #include "debuggerstartparameters.h"
#include "stackhandler.h" #include "stackhandler.h"
#include "qmlengine.h" #include "qmlengine.h"
#include "qtmessageloghandler.h"
#include "watchdata.h" #include "watchdata.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -794,11 +793,6 @@ void QmlCppEngine::resetLocation()
DebuggerEngine::resetLocation(); DebuggerEngine::resetLocation();
} }
Internal::QtMessageLogHandler *QmlCppEngine::qtMessageLogHandler() const
{
return d->m_qmlEngine->qtMessageLogHandler();
}
DebuggerEngine *QmlCppEngine::cppEngine() const DebuggerEngine *QmlCppEngine::cppEngine() const
{ {
return d->m_cppEngine; return d->m_cppEngine;

View File

@@ -93,8 +93,6 @@ public:
int timeout = -1) const; int timeout = -1) const;
void resetLocation(); void resetLocation();
Internal::QtMessageLogHandler *qtMessageLogHandler() const;
void notifyInferiorIll(); void notifyInferiorIll();
protected: protected:

View File

@@ -50,7 +50,6 @@
#include "watchhandler.h" #include "watchhandler.h"
#include "sourcefileshandler.h" #include "sourcefileshandler.h"
#include "watchutils.h" #include "watchutils.h"
#include "qtmessageloghandler.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <qmldebug/baseenginedebugclient.h> #include <qmldebug/baseenginedebugclient.h>
@@ -68,6 +67,9 @@
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <qmljstools/qmlconsolemanager.h>
#include <qmljstools/qmlconsoleitem.h>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
@@ -330,8 +332,6 @@ QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters)
m_noDebugOutputTimer.setInterval(8000); m_noDebugOutputTimer.setInterval(8000);
connect(&m_noDebugOutputTimer, SIGNAL(timeout()), this, SLOT(tryToConnect())); connect(&m_noDebugOutputTimer, SIGNAL(timeout()), this, SLOT(tryToConnect()));
qtMessageLogHandler()->setHasEditableRow(true);
connect(ModelManagerInterface::instance(), connect(ModelManagerInterface::instance(),
SIGNAL(documentUpdated(QmlJS::Document::Ptr)), SIGNAL(documentUpdated(QmlJS::Document::Ptr)),
this, this,
@@ -1031,14 +1031,61 @@ void QmlEngine::synchronizeWatchers()
} }
} }
QmlJSTools::QmlConsoleItem *constructLogItemTree(QmlJSTools::QmlConsoleItem *parent,
const QVariant &result,
const QString &key = QString())
{
using namespace QmlJSTools;
bool sorted = debuggerCore()->boolSetting(SortStructMembers);
if (!result.isValid())
return 0;
QmlConsoleItem *item = new QmlConsoleItem(parent);
if (result.type() == QVariant::Map) {
if (key.isEmpty())
item->setText(_("Object"));
else
item->setText(key + _(" : Object"));
QMapIterator<QString, QVariant> i(result.toMap());
while (i.hasNext()) {
i.next();
QmlConsoleItem *child = constructLogItemTree(item, i.value(), i.key());
if (child)
item->insertChild(child, sorted);
}
} else if (result.type() == QVariant::List) {
if (key.isEmpty())
item->setText(_("List"));
else
item->setText(QString(_("[%1] : List")).arg(key));
QVariantList resultList = result.toList();
for (int i = 0; i < resultList.count(); i++) {
QmlConsoleItem *child = constructLogItemTree(item, resultList.at(i),
QString::number(i));
if (child)
item->insertChild(child, sorted);
}
} else if (result.canConvert(QVariant::String)) {
item->setText(result.toString());
} else {
item->setText(_("Unknown Value"));
}
return item;
}
void QmlEngine::expressionEvaluated(quint32 queryId, const QVariant &result) void QmlEngine::expressionEvaluated(quint32 queryId, const QVariant &result)
{ {
if (queryIds.contains(queryId)) { if (queryIds.contains(queryId)) {
queryIds.removeOne(queryId); queryIds.removeOne(queryId);
QtMessageLogItem *item = constructLogItemTree(qtMessageLogHandler()->root(), using namespace QmlJSTools;
result); QmlConsoleManager *consoleManager = QmlConsoleManager::instance();
if (item) if (consoleManager) {
qtMessageLogHandler()->appendItem(item); QmlConsoleItem *item = constructLogItemTree(consoleManager->rootItem(), result);
if (item)
consoleManager->printToConsolePane(item);
}
} }
} }
@@ -1092,35 +1139,40 @@ void QmlEngine::documentUpdated(QmlJS::Document::Ptr doc)
void QmlEngine::updateCurrentContext() void QmlEngine::updateCurrentContext()
{ {
const QString context = state() == InferiorStopOk ? const QString context = state() == InferiorStopOk ?
stackHandler()->currentFrame().function : stackHandler()->currentFrame().function
m_inspectorAdapter.currentSelectedDisplayName(); : m_inspectorAdapter.currentSelectedDisplayName();
showMessage(tr("Context: ").append(context), QtMessageLogStatus); QmlJSTools::QmlConsoleManager *consoleManager = QmlJSTools::QmlConsoleManager::instance();
if (consoleManager)
consoleManager->setContext(tr("Context: ").append(context));
} }
void QmlEngine::appendDebugOutput(QtMsgType type, const QString &message, void QmlEngine::appendDebugOutput(QtMsgType type, const QString &message,
const QmlDebug::QDebugContextInfo &info) const QmlDebug::QDebugContextInfo &info)
{ {
QtMessageLogHandler::ItemType itemType; using namespace QmlJSTools;
QmlConsoleItem::ItemType itemType;
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
itemType = QtMessageLogHandler::DebugType; itemType = QmlConsoleItem::DebugType;
break; break;
case QtWarningMsg: case QtWarningMsg:
itemType = QtMessageLogHandler::WarningType; itemType = QmlConsoleItem::WarningType;
break; break;
case QtCriticalMsg: case QtCriticalMsg:
case QtFatalMsg: case QtFatalMsg:
itemType = QtMessageLogHandler::ErrorType; itemType = QmlConsoleItem::ErrorType;
break; break;
default: default:
//This case is not possible //This case is not possible
return; return;
} }
QtMessageLogItem *item = new QtMessageLogItem(qtMessageLogHandler()->root(), QmlConsoleManager *consoleManager = QmlConsoleManager::instance();
itemType, message); if (consoleManager) {
item->file = info.file; QmlConsoleItem *item = new QmlConsoleItem(consoleManager->rootItem(), itemType, message);
item->line = info.line; item->file = info.file;
qtMessageLogHandler()->appendItem(item); item->line = info.line;
consoleManager->printToConsolePane(item);
}
} }
void QmlEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages) void QmlEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages languages)
@@ -1133,37 +1185,25 @@ void QmlEngine::executeDebuggerCommand(const QString &command, DebuggerLanguages
bool QmlEngine::evaluateScriptExpression(const QString &expression) bool QmlEngine::evaluateScriptExpression(const QString &expression)
{ {
bool didEvaluate = true; bool didEvaluate = true;
//Check if string is only white spaces // Evaluate expression based on engine state
if (!expression.trimmed().isEmpty()) { // When engine->state() == InferiorStopOk, the expression is sent to debuggerClient.
//check if it can be evaluated if (state() != InferiorStopOk) {
if (canEvaluateScript(expression)) { QmlInspectorAgent *agent = m_inspectorAdapter.agent();
//Evaluate expression based on engine state quint32 queryId = agent->queryExpressionResult(m_inspectorAdapter.currentSelectedDebugId(),
//When engine->state() == InferiorStopOk, the expression expression);
//is sent to V8DebugService. In all other cases, the if (queryId) {
//expression is evaluated by QDeclarativeEngine. queryIds << queryId;
if (state() != InferiorStopOk) {
QmlInspectorAgent *agent = m_inspectorAdapter.agent();
quint32 queryId
= agent->queryExpressionResult(
m_inspectorAdapter.currentSelectedDebugId(),
expression);
if (queryId) {
queryIds << queryId;
} else {
didEvaluate = false;
qtMessageLogHandler()->
appendItem(
new QtMessageLogItem(
qtMessageLogHandler()->root(),
QtMessageLogHandler::ErrorType,
_("Error evaluating expression.")));
}
} else {
executeDebuggerCommand(expression, QmlLanguage);
}
} else { } else {
didEvaluate = false; didEvaluate = false;
using namespace QmlJSTools;
QmlConsoleManager *consoleManager = QmlConsoleManager::instance();
if (consoleManager) {
consoleManager->printToConsolePane(QmlConsoleItem::ErrorType,
_("Error evaluating expression."));
}
} }
} else {
executeDebuggerCommand(expression, QmlLanguage);
} }
return didEvaluate; return didEvaluate;
} }
@@ -1270,48 +1310,6 @@ bool QmlEngine::canEvaluateScript(const QString &script)
return m_interpreter.canEvaluate(); return m_interpreter.canEvaluate();
} }
QtMessageLogItem *QmlEngine::constructLogItemTree(
QtMessageLogItem *parent, const QVariant &result, const QString &key)
{
if (!result.isValid())
return 0;
QtMessageLogItem *item = new QtMessageLogItem(parent);
if (result.type() == QVariant::Map) {
if (key.isEmpty())
item->setText(_("Object"));
else
item->setText(key + _(" : Object"));
QMapIterator<QString, QVariant> i(result.toMap());
while (i.hasNext()) {
i.next();
QtMessageLogItem *child = constructLogItemTree(item,
i.value(), i.key());
if (child)
item->insertChild(child);
}
} else if (result.type() == QVariant::List) {
if (key.isEmpty())
item->setText(_("List"));
else
item->setText(QString(_("[%1] : List")).arg(key));
QVariantList resultList = result.toList();
for (int i = 0; i < resultList.count(); i++) {
QtMessageLogItem *child = constructLogItemTree(item, resultList.at(i),
QString::number(i));
if (child)
item->insertChild(child);
}
} else if (result.canConvert(QVariant::String)) {
item->setText(result.toString());
} else {
item->setText(_("Unknown Value"));
}
return item;
}
bool QmlEngine::adjustBreakpointLineAndColumn( bool QmlEngine::adjustBreakpointLineAndColumn(
const QString &filePath, quint32 *line, quint32 *column, bool *valid) const QString &filePath, quint32 *line, quint32 *column, bool *valid)
{ {

View File

@@ -53,7 +53,6 @@ namespace Debugger {
namespace Internal { namespace Internal {
class QmlAdapter; class QmlAdapter;
class QtMessageLogItem;
class QmlEngine : public DebuggerEngine class QmlEngine : public DebuggerEngine
{ {
@@ -181,9 +180,6 @@ private:
void updateEditor(Core::IEditor *editor, const QTextDocument *document); void updateEditor(Core::IEditor *editor, const QTextDocument *document);
bool canEvaluateScript(const QString &script); bool canEvaluateScript(const QString &script);
QtMessageLogItem *constructLogItemTree(QtMessageLogItem *parent,
const QVariant &result,
const QString &key = QString());
bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line, bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
quint32 *column, bool *valid); quint32 *column, bool *valid);

View File

@@ -37,12 +37,16 @@
#include "breakhandler.h" #include "breakhandler.h"
#include "qmlengine.h" #include "qmlengine.h"
#include "stackhandler.h" #include "stackhandler.h"
#include "qtmessageloghandler.h" #include "debuggercore.h"
#include "debuggeractions.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <qmljstools/qmlconsoleitem.h>
#include <qmljstools/qmlconsolemanager.h>
#include <QTextBlock> #include <QTextBlock>
#include <QVariant> #include <QVariant>
#include <QStack> #include <QStack>
@@ -117,19 +121,14 @@ public:
void version(); void version();
//void profile(ProfileCommand command); //NOT SUPPORTED //void profile(ProfileCommand command); //NOT SUPPORTED
void gc(); void gc();
QmlV8ObjectData extractData(const QVariant &data, const QVariant &refsVal);
void clearCache(); void clearCache();
void logSendMessage(const QString &msg) const; void logSendMessage(const QString &msg) const;
void logReceiveMessage(const QString &msg) const; void logReceiveMessage(const QString &msg) const;
QtMessageLogItem *constructLogItemTree(QtMessageLogItem *parent,
const QmlV8ObjectData &objectData, const QVariant &refsVal);
private: private:
QByteArray packMessage(const QByteArray &type, const QByteArray &message = QByteArray()); QByteArray packMessage(const QByteArray &type, const QByteArray &message = QByteArray());
QScriptValue initObject(); QScriptValue initObject();
QVariant valueFromRef(int handle, const QVariant &refsVal, bool *success);
public: public:
QmlV8DebuggerClient *q; QmlV8DebuggerClient *q;
@@ -762,8 +761,23 @@ void QmlV8DebuggerClientPrivate::gc()
q->sendMessage(packMessage(V8REQUEST, jsonMessage.toString().toUtf8())); q->sendMessage(packMessage(V8REQUEST, jsonMessage.toString().toUtf8()));
} }
QmlV8ObjectData QmlV8DebuggerClientPrivate::extractData(const QVariant &data, QVariant valueFromRef(int handle, const QVariant &refsVal, bool *success)
const QVariant &refsVal) {
*success = false;
QVariant variant;
const QVariantList refs = refsVal.toList();
foreach (const QVariant &ref, refs) {
const QVariantMap refData = ref.toMap();
if (refData.value(_(HANDLE)).toInt() == handle) {
variant = refData;
*success = true;
break;
}
}
return variant;
}
QmlV8ObjectData extractData(const QVariant &data, const QVariant &refsVal)
{ {
// { "handle" : <handle>, // { "handle" : <handle>,
// "type" : <"undefined", "null", "boolean", "number", "string", "object", "function" or "frame"> // "type" : <"undefined", "null", "boolean", "number", "string", "object", "function" or "frame">
@@ -901,24 +915,6 @@ QScriptValue QmlV8DebuggerClientPrivate::initObject()
return jsonVal; return jsonVal;
} }
QVariant QmlV8DebuggerClientPrivate::valueFromRef(int handle,
const QVariant &refsVal,
bool *success)
{
*success = false;
QVariant variant;
const QVariantList refs = refsVal.toList();
foreach (const QVariant &ref, refs) {
const QVariantMap refData = ref.toMap();
if (refData.value(_(HANDLE)).toInt() == handle) {
variant = refData;
*success = true;
break;
}
}
return variant;
}
void QmlV8DebuggerClientPrivate::logSendMessage(const QString &msg) const void QmlV8DebuggerClientPrivate::logSendMessage(const QString &msg) const
{ {
if (engine) if (engine)
@@ -931,34 +927,6 @@ void QmlV8DebuggerClientPrivate::logReceiveMessage(const QString &msg) const
engine->logMessage(QLatin1String("V8DebuggerClient"), QmlEngine::LogReceive, msg); engine->logMessage(QLatin1String("V8DebuggerClient"), QmlEngine::LogReceive, msg);
} }
QtMessageLogItem *QmlV8DebuggerClientPrivate::constructLogItemTree(
QtMessageLogItem *parent,
const QmlV8ObjectData &objectData,
const QVariant &refsVal)
{
if (!objectData.value.isValid())
return 0;
QString text;
if (objectData.name.isEmpty())
text = objectData.value.toString();
else
text = QString(_("%1: %2")).arg(QString::fromLatin1(objectData.name))
.arg(objectData.value.toString());
QtMessageLogItem *item = new QtMessageLogItem(parent,
QtMessageLogHandler::UndefinedType, text);
foreach (const QVariant &property, objectData.properties) {
QtMessageLogItem *child = constructLogItemTree(
item, extractData(property, refsVal), refsVal);
if (child)
item->insertChild(child);
}
return item;
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
// QmlV8DebuggerClient // QmlV8DebuggerClient
@@ -1126,9 +1094,8 @@ void QmlV8DebuggerClient::assignValueInDebugger(const WatchData * /*data*/,
d->evaluate(expression, false, false, stackHandler->currentIndex()); d->evaluate(expression, false, false, stackHandler->currentIndex());
d->updateLocalsAndWatchers.append(d->sequence); d->updateLocalsAndWatchers.append(d->sequence);
} else { } else {
d->engine->showMessage(QString(_("Cannot evaluate" d->engine->showMessage(QString(_("Cannot evaluate %1 in current stack frame")).arg(
"%1 in current stack frame")). expression), ConsoleOutput);
arg(expression), QtMessageLogOutput);
} }
} }
@@ -1145,9 +1112,8 @@ void QmlV8DebuggerClient::executeDebuggerCommand(const QString &command)
d->debuggerCommands.append(d->sequence); d->debuggerCommands.append(d->sequence);
} else { } else {
//Currently cannot evaluate if not in a javascript break //Currently cannot evaluate if not in a javascript break
d->engine->showMessage(QString(_("Cannot evaluate %1" d->engine->showMessage(QString(_("Cannot evaluate %1 in current stack frame")).arg(
"in current stack frame")). command), ConsoleOutput);
arg(command), QtMessageLogOutput);
} }
} }
@@ -1630,17 +1596,17 @@ StackFrame QmlV8DebuggerClient::extractStackFrame(const QVariant &bodyVal, const
return stackFrame; return stackFrame;
} }
QmlV8ObjectData objectData = d->extractData(body.value(_("func")), refsVal); QmlV8ObjectData objectData = extractData(body.value(_("func")), refsVal);
QString functionName = objectData.value.toString(); QString functionName = objectData.value.toString();
if (functionName.isEmpty()) if (functionName.isEmpty())
functionName = tr("Anonymous Function"); functionName = tr("Anonymous Function");
stackFrame.function = functionName; stackFrame.function = functionName;
objectData = d->extractData(body.value(_("script")), refsVal); objectData = extractData(body.value(_("script")), refsVal);
stackFrame.file = d->engine->toFileInProject(objectData.value.toString()); stackFrame.file = d->engine->toFileInProject(objectData.value.toString());
stackFrame.usable = QFileInfo(stackFrame.file).isReadable(); stackFrame.usable = QFileInfo(stackFrame.file).isReadable();
objectData = d->extractData(body.value(_("receiver")), refsVal); objectData = extractData(body.value(_("receiver")), refsVal);
stackFrame.to = objectData.value.toString(); stackFrame.to = objectData.value.toString();
stackFrame.line = body.value(_("line")).toInt() + 1; stackFrame.line = body.value(_("line")).toInt() + 1;
@@ -1691,8 +1657,7 @@ void QmlV8DebuggerClient::setCurrentFrameDetails(const QVariant &bodyVal, const
data.exp = QByteArray("this"); data.exp = QByteArray("this");
data.name = QLatin1String(data.exp); data.name = QLatin1String(data.exp);
data.iname = QByteArray("local.") + data.exp; data.iname = QByteArray("local.") + data.exp;
QmlV8ObjectData objectData = d->extractData( QmlV8ObjectData objectData = extractData(currentFrame.value(_("receiver")), refsVal);
currentFrame.value(_("receiver")), refsVal);
data.id = objectData.handle; data.id = objectData.handle;
data.type = objectData.type; data.type = objectData.type;
data.value = objectData.value.toString(); data.value = objectData.value.toString();
@@ -1749,12 +1714,12 @@ void QmlV8DebuggerClient::updateScope(const QVariant &bodyVal, const QVariant &r
if (bodyMap.value(_("frameIndex")).toInt() != stackHandler->currentIndex()) if (bodyMap.value(_("frameIndex")).toInt() != stackHandler->currentIndex())
return; return;
QmlV8ObjectData objectData = d->extractData(bodyMap.value(_("object")), refsVal); QmlV8ObjectData objectData = extractData(bodyMap.value(_("object")), refsVal);
QList<int> handlesToLookup; QList<int> handlesToLookup;
QList<WatchData> locals; QList<WatchData> locals;
foreach (const QVariant &property, objectData.properties) { foreach (const QVariant &property, objectData.properties) {
QmlV8ObjectData localData = d->extractData(property, refsVal); QmlV8ObjectData localData = extractData(property, refsVal);
WatchData data; WatchData data;
data.exp = localData.name; data.exp = localData.name;
//Check for v8 specific local data //Check for v8 specific local data
@@ -1784,8 +1749,36 @@ void QmlV8DebuggerClient::updateScope(const QVariant &bodyVal, const QVariant &r
d->engine->watchHandler()->insertData(locals); d->engine->watchHandler()->insertData(locals);
} }
void QmlV8DebuggerClient::updateEvaluationResult(int sequence, bool success, const QVariant &bodyVal, QmlJSTools::QmlConsoleItem *constructLogItemTree(QmlJSTools::QmlConsoleItem *parent,
const QmlV8ObjectData &objectData,
const QVariant &refsVal) const QVariant &refsVal)
{
using namespace QmlJSTools;
bool sorted = debuggerCore()->boolSetting(SortStructMembers);
if (!objectData.value.isValid())
return 0;
QString text;
if (objectData.name.isEmpty())
text = objectData.value.toString();
else
text = QString(_("%1: %2")).arg(QString::fromAscii(objectData.name))
.arg(objectData.value.toString());
QmlConsoleItem *item = new QmlConsoleItem(parent, QmlConsoleItem::UndefinedType, text);
foreach (const QVariant &property, objectData.properties) {
QmlConsoleItem *child = constructLogItemTree(item, extractData(property, refsVal),
refsVal);
if (child)
item->insertChild(child, sorted);
}
return item;
}
void QmlV8DebuggerClient::updateEvaluationResult(int sequence, bool success,
const QVariant &bodyVal, const QVariant &refsVal)
{ {
// { "seq" : <number>, // { "seq" : <number>,
// "type" : "response", // "type" : "response",
@@ -1809,17 +1802,20 @@ void QmlV8DebuggerClient::updateEvaluationResult(int sequence, bool success, con
} else if (d->debuggerCommands.contains(sequence)) { } else if (d->debuggerCommands.contains(sequence)) {
d->updateLocalsAndWatchers.removeOne(sequence); d->updateLocalsAndWatchers.removeOne(sequence);
QmlV8ObjectData body = d->extractData(bodyVal, refsVal); QmlV8ObjectData body = extractData(bodyVal, refsVal);
QtMessageLogItem *item = d->constructLogItemTree(d->engine->qtMessageLogHandler()->root(), using namespace QmlJSTools;
body, refsVal); QmlConsoleManager *consoleManager = QmlConsoleManager::instance();
if (item) if (consoleManager) {
d->engine->qtMessageLogHandler()->appendItem(item); QmlConsoleItem *item = constructLogItemTree(consoleManager->rootItem(), body, refsVal);
if (item)
consoleManager->printToConsolePane(item);
}
//Update the locals //Update the locals
foreach (int index, d->currentFrameScopes) foreach (int index, d->currentFrameScopes)
d->scope(index); d->scope(index);
} else { } else {
QmlV8ObjectData body = d->extractData(bodyVal, refsVal); QmlV8ObjectData body = extractData(bodyVal, refsVal);
if (d->evaluatingExpression.contains(sequence)) { if (d->evaluatingExpression.contains(sequence)) {
QString exp = d->evaluatingExpression.take(sequence); QString exp = d->evaluatingExpression.take(sequence);
QList<WatchData> watchDataList; QList<WatchData> watchDataList;
@@ -1918,7 +1914,7 @@ void QmlV8DebuggerClient::expandLocalsAndWatchers(const QVariant &bodyVal, const
QStringList handlesList = body.keys(); QStringList handlesList = body.keys();
WatchHandler *watchHandler = d->engine->watchHandler(); WatchHandler *watchHandler = d->engine->watchHandler();
foreach (const QString &handle, handlesList) { foreach (const QString &handle, handlesList) {
QmlV8ObjectData bodyObjectData = d->extractData( QmlV8ObjectData bodyObjectData = extractData(
body.value(handle), refsVal); body.value(handle), refsVal);
QByteArray prepend = d->localsAndWatchers.take(handle.toInt()); QByteArray prepend = d->localsAndWatchers.take(handle.toInt());
@@ -1955,7 +1951,7 @@ QList<WatchData> QmlV8DebuggerClient::createWatchDataList(const WatchData *paren
if (properties.count()) { if (properties.count()) {
QTC_ASSERT(parent, return watchDataList); QTC_ASSERT(parent, return watchDataList);
foreach (const QVariant &property, properties) { foreach (const QVariant &property, properties) {
QmlV8ObjectData propertyData = d->extractData(property, refsVal); QmlV8ObjectData propertyData = extractData(property, refsVal);
WatchData data; WatchData data;
data.name = QString::fromUtf8(propertyData.name); data.name = QString::fromUtf8(propertyData.name);
@@ -2021,7 +2017,7 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
QString message = QString(_("%1: %2: %3")).arg(filePath).arg(lineNumber) QString message = QString(_("%1: %2: %3")).arg(filePath).arg(lineNumber)
.arg(errorMessage); .arg(errorMessage);
d->engine->showMessage(message, QtMessageLogOutput); d->engine->showMessage(message, ConsoleOutput);
} }
} }
} }

View File

@@ -514,7 +514,7 @@ void QScriptDebuggerClient::messageReceived(const QByteArray &data)
if (iname.startsWith("watch.")) { if (iname.startsWith("watch.")) {
watchHandler->insertIncompleteData(data); watchHandler->insertIncompleteData(data);
} else if (iname == "console") { } else if (iname == "console") {
d->engine->showMessage(data.value, QtMessageLogOutput); d->engine->showMessage(data.value, ConsoleOutput);
} else if (iname.startsWith("local.")) { } else if (iname.startsWith("local.")) {
data.name = data.name.left(data.name.indexOf(QLatin1Char(' '))); data.name = data.name.left(data.name.indexOf(QLatin1Char(' ')));
watchHandler->insertIncompleteData(data); watchHandler->insertIncompleteData(data);

View File

@@ -1,73 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef QTMESSAGELOGEDITOR_H
#define QTMESSAGELOGEDITOR_H
#include <QModelIndex>
#include <QTextEdit>
namespace Debugger {
namespace Internal {
class QtMessageLogEditor : public QTextEdit
{
Q_OBJECT
public:
explicit QtMessageLogEditor(const QModelIndex &index,
QWidget *parent = 0);
QString getCurrentScript() const;
protected:
void keyPressEvent(QKeyEvent *e);
void contextMenuEvent(QContextMenuEvent *event);
void focusOutEvent(QFocusEvent *e);
signals:
void editingFinished();
protected:
void handleUpKey();
void handleDownKey();
void replaceCurrentScript(const QString &script);
private:
QModelIndex m_historyIndex;
QString m_cachedScript;
QImage m_prompt;
int m_startOfEditableArea;
};
} //Internal
} //Debugger
#endif // QTMESSAGELOGEDITOR_H

View File

@@ -1,405 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qtmessageloghandler.h"
#include "debuggercore.h"
#include "debuggeractions.h"
#include <utils/qtcassert.h>
#include <QFontMetrics>
namespace Debugger {
namespace Internal {
///////////////////////////////////////////////////////////////////////
//
// QtMessageLogItem
//
///////////////////////////////////////////////////////////////////////
QtMessageLogItem::QtMessageLogItem(QtMessageLogItem *parent,
QtMessageLogHandler::ItemType itemType, const QString &text)
: m_parentItem(parent),
itemType(itemType),
line(-1)
{
setText(text);
}
QtMessageLogItem::~QtMessageLogItem()
{
qDeleteAll(m_childItems);
}
QtMessageLogItem *QtMessageLogItem::child(int number)
{
return m_childItems.value(number);
}
int QtMessageLogItem::childCount() const
{
return m_childItems.size();
}
int QtMessageLogItem::childNumber() const
{
if (m_parentItem)
return m_parentItem->m_childItems.indexOf(
const_cast<QtMessageLogItem *>(this));
return 0;
}
bool QtMessageLogItem::insertChildren(int position, int count)
{
if (position < 0 || position > m_childItems.size())
return false;
for (int row = 0; row < count; ++row) {
QtMessageLogItem *item = new
QtMessageLogItem(this , QtMessageLogHandler::UndefinedType,
QString());
m_childItems.insert(position, item);
}
return true;
}
void QtMessageLogItem::insertChild(QtMessageLogItem *item)
{
if (!debuggerCore()->boolSetting(SortStructMembers)) {
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 QtMessageLogItem::insertChild(int position, QtMessageLogItem *item)
{
if (position < 0 || position > m_childItems.size())
return false;
m_childItems.insert(position, item);
return true;
}
QtMessageLogItem *QtMessageLogItem::parent()
{
return m_parentItem;
}
bool QtMessageLogItem::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 QtMessageLogItem::detachChild(int position)
{
if (position < 0 || position > m_childItems.size())
return false;
m_childItems.removeAt(position);
return true;
}
void QtMessageLogItem::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 &QtMessageLogItem::text() const
{
return m_text;
}
///////////////////////////////////////////////////////////////////////
//
// QtMessageLogHandler
//
///////////////////////////////////////////////////////////////////////
QtMessageLogHandler::QtMessageLogHandler(QObject *parent) :
QAbstractItemModel(parent),
m_hasEditableRow(false),
m_rootItem(new QtMessageLogItem(0)),
m_maxSizeOfFileName(0)
{
}
QtMessageLogHandler::~QtMessageLogHandler()
{
delete m_rootItem;
}
void QtMessageLogHandler::clear()
{
beginResetModel();
delete m_rootItem;
m_rootItem = new QtMessageLogItem(0);
endResetModel();
if (m_hasEditableRow)
appendEditableRow();
}
bool QtMessageLogHandler::appendItem(QtMessageLogItem *item, int position)
{
if (position < 0)
position = m_rootItem->childCount() - 1;
beginInsertRows(QModelIndex(), position, position);
bool success = m_rootItem->insertChild(position, item);
endInsertRows();
return success;
}
bool QtMessageLogHandler::appendMessage(QtMessageLogHandler::ItemType itemType,
const QString &message, int position)
{
return appendItem(new QtMessageLogItem(m_rootItem, itemType, message), position);
}
void QtMessageLogHandler::setHasEditableRow(bool hasEditableRow)
{
if (m_hasEditableRow && !hasEditableRow)
removeEditableRow();
if (!m_hasEditableRow && hasEditableRow)
appendEditableRow();
m_hasEditableRow = hasEditableRow;
}
bool QtMessageLogHandler::hasEditableRow() const
{
return m_hasEditableRow;
}
void QtMessageLogHandler::appendEditableRow()
{
int position = m_rootItem->childCount();
if (appendItem(new QtMessageLogItem(m_rootItem, QtMessageLogHandler::InputType), position))
emit selectEditableRow(index(position, 0),
QItemSelectionModel::ClearAndSelect);
}
void QtMessageLogHandler::removeEditableRow()
{
if (m_rootItem->child(m_rootItem->childCount() - 1)->itemType ==
QtMessageLogHandler::InputType)
removeRow(m_rootItem->childCount() - 1);
}
int QtMessageLogHandler::sizeOfFile(const QFont &font)
{
int lastReadOnlyRow = m_rootItem->childCount();
if (m_hasEditableRow)
lastReadOnlyRow -= 2;
else
lastReadOnlyRow -= 1;
if (lastReadOnlyRow < 0)
return 0;
QString filename = m_rootItem->child(lastReadOnlyRow)->file;
const int pos = filename.lastIndexOf(QLatin1Char('/'));
if (pos != -1)
filename = filename.mid(pos + 1);
QFontMetrics fm(font);
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.width(filename));
return m_maxSizeOfFileName;
}
int QtMessageLogHandler::sizeOfLineNumber(const QFont &font)
{
QFontMetrics fm(font);
return fm.width(QLatin1String("88888"));
}
QVariant QtMessageLogHandler::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
QtMessageLogItem *item = getItem(index);
if (role == Qt::DisplayRole )
return item->text();
else if (role == QtMessageLogHandler::TypeRole)
return int(item->itemType);
else if (role == QtMessageLogHandler::FileRole)
return item->file;
else if (role == QtMessageLogHandler::LineRole)
return item->line;
else
return QVariant();
}
QModelIndex QtMessageLogHandler::index(int row, int column,
const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
if (column > 0)
return QModelIndex();
QtMessageLogItem *parentItem = getItem(parent);
QtMessageLogItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex QtMessageLogHandler::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
QtMessageLogItem *childItem = getItem(index);
QtMessageLogItem *parentItem = childItem->parent();
if (parentItem == m_rootItem)
return QModelIndex();
//can parentItem be 0?
if (!parentItem)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
}
int QtMessageLogHandler::rowCount(const QModelIndex &parent) const
{
QtMessageLogItem *parentItem = getItem(parent);
return parentItem->childCount();
}
int QtMessageLogHandler::columnCount(const QModelIndex & /* parent */) const
{
return 1;
}
Qt::ItemFlags QtMessageLogHandler::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
QtMessageLogItem *item = getItem(index);
if (m_hasEditableRow && item->parent() == m_rootItem
&& index.row() == m_rootItem->childCount() - 1)
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
bool QtMessageLogHandler::setData(const QModelIndex &index, const QVariant &value,
int role)
{
QtMessageLogItem *item = getItem(index);
bool result = false;
if (role == Qt::DisplayRole) {
item->setText(value.toString());
result = true;
} else if (role == QtMessageLogHandler::TypeRole) {
item->itemType = (QtMessageLogHandler::ItemType)value.toInt();
result = true;
} else if (role == QtMessageLogHandler::FileRole) {
item->file = value.toString();
result = true;
} else if (role == QtMessageLogHandler::LineRole) {
item->line = value.toInt();
result = true;
}
if (result)
emit dataChanged(index, index);
return result;
}
bool QtMessageLogHandler::insertRows(int position, int rows, const QModelIndex &parent)
{
QtMessageLogItem *parentItem = getItem(parent);
bool success;
beginInsertRows(parent, position, position + rows - 1);
success = parentItem->insertChildren(position, rows);
endInsertRows();
return success;
}
bool QtMessageLogHandler::removeRows(int position, int rows, const QModelIndex &parent)
{
QtMessageLogItem *parentItem = getItem(parent);
bool success = true;
beginRemoveRows(parent, position, position + rows - 1);
success = parentItem->removeChildren(position, rows);
endRemoveRows();
return success;
}
QtMessageLogItem *QtMessageLogHandler::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
QtMessageLogItem *item = static_cast<QtMessageLogItem*>(index.internalPointer());
if (item) return item;
}
return m_rootItem;
}
} //Internal
} //Debugger

View File

@@ -1,150 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef QTMESSAGELOGHANDLER_H
#define QTMESSAGELOGHANDLER_H
#include <QAbstractItemModel>
#include <QItemSelectionModel>
#include <QFont>
namespace Debugger {
namespace Internal {
class QtMessageLogItem;
class QtMessageLogHandler : public QAbstractItemModel
{
Q_OBJECT
public:
enum ItemType
{
InputType = 0x01,
DebugType = 0x02,
WarningType = 0x04,
ErrorType = 0x08,
UndefinedType = 0x10, //Can be used for unknown and for Return values
DefaultTypes = InputType | UndefinedType
};
Q_DECLARE_FLAGS(ItemTypes, ItemType)
enum Roles { TypeRole = Qt::UserRole, FileRole, LineRole };
explicit QtMessageLogHandler(QObject *parent = 0);
~QtMessageLogHandler();
void setHasEditableRow(bool hasEditableRow);
bool hasEditableRow() const;
void appendEditableRow();
void removeEditableRow();
bool appendItem(QtMessageLogItem *item, int position = -1);
bool appendMessage(QtMessageLogHandler::ItemType itemType,
const QString &message, int position = -1);
QAbstractItemModel *model() { return this; }
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int sizeOfFile(const QFont &font);
int sizeOfLineNumber(const QFont &font);
QtMessageLogItem *root() const { return m_rootItem; }
public slots:
void clear();
signals:
void selectEditableRow(const QModelIndex &index,
QItemSelectionModel::SelectionFlags flags);
void rowInserted(const QModelIndex &index);
protected:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole);
bool insertRows(int position, int rows,
const QModelIndex &parent = QModelIndex());
bool removeRows(int position, int rows,
const QModelIndex &parent = QModelIndex());
QtMessageLogItem *getItem(const QModelIndex &index) const;
private:
bool m_hasEditableRow;
QtMessageLogItem *m_rootItem;
int m_maxSizeOfFileName;
};
class QtMessageLogItem
{
public:
QtMessageLogItem(QtMessageLogItem *parent,
QtMessageLogHandler::ItemType type = QtMessageLogHandler::UndefinedType,
const QString &data = QString());
~QtMessageLogItem();
QtMessageLogItem *child(int number);
int childCount() const;
bool insertChildren(int position, int count);
void insertChild(QtMessageLogItem *item);
bool insertChild(int position, QtMessageLogItem *item);
QtMessageLogItem *parent();
bool removeChildren(int position, int count);
bool detachChild(int position);
int childNumber() const;
void setText(const QString &text);
const QString &text() const;
private:
QtMessageLogItem *m_parentItem;
QList<QtMessageLogItem *> m_childItems;
QString m_text;
public:
QtMessageLogHandler::ItemType itemType;
QString file;
int line;
};
} //Internal
} //Debugger
#endif // QTMESSAGELOGHANDLER_H

View File

@@ -1,90 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qtmessagelogproxymodel.h"
namespace Debugger {
namespace Internal {
QtMessageLogProxyModel::QtMessageLogProxyModel(QObject *parent) :
QSortFilterProxyModel(parent),
m_filter(QtMessageLogHandler::DefaultTypes)
{
}
void QtMessageLogProxyModel::setShowLogs(bool show)
{
m_filter = show ? m_filter | QtMessageLogHandler::DebugType :
m_filter & ~QtMessageLogHandler::DebugType;
setFilterRegExp(QString());
}
void QtMessageLogProxyModel::setShowWarnings(bool show)
{
m_filter = show ? m_filter | QtMessageLogHandler::WarningType :
m_filter & ~QtMessageLogHandler::WarningType;
setFilterRegExp(QString());
}
void QtMessageLogProxyModel::setShowErrors(bool show)
{
m_filter = show ? m_filter | QtMessageLogHandler::ErrorType :
m_filter & ~QtMessageLogHandler::ErrorType;
setFilterRegExp(QString());
}
void QtMessageLogProxyModel::selectEditableRow(const QModelIndex &index,
QItemSelectionModel::SelectionFlags command)
{
emit setCurrentIndex(mapFromSource(index), command);
}
bool QtMessageLogProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return m_filter.testFlag((QtMessageLogHandler::ItemType)
sourceModel()->data(
index, QtMessageLogHandler::TypeRole).toInt());
}
void QtMessageLogProxyModel::onRowsInserted(const QModelIndex &index, int start, int end)
{
int rowIndex = end;
do {
if (filterAcceptsRow(rowIndex, index)) {
emit scrollToBottom();
break;
}
} while (--rowIndex >= start);
}
} // namespace Internal
} // namespace Debugger

View File

@@ -1,71 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef QTMESSAGELOGPROXYMODEL_H
#define QTMESSAGELOGPROXYMODEL_H
#include "qtmessageloghandler.h"
#include <QSortFilterProxyModel>
#include <QItemSelectionModel>
namespace Debugger {
namespace Internal {
class QtMessageLogProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit QtMessageLogProxyModel(QObject *parent = 0);
public slots:
void setShowLogs(bool show);
void setShowWarnings(bool show);
void setShowErrors(bool show);
void selectEditableRow(const QModelIndex &index,
QItemSelectionModel::SelectionFlags command);
void onRowsInserted(const QModelIndex &index, int start, int end);
signals:
void scrollToBottom();
void setCurrentIndex(const QModelIndex &index,
QItemSelectionModel::SelectionFlags command);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
private:
QFlags<QtMessageLogHandler::ItemType> m_filter;
};
} // namespace Internal
} // namespace Debugger
#endif // QTMESSAGELOGPROXYMODEL_H

View File

@@ -1,67 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef QTMESSAGELOGVIEW_H
#define QTMESSAGELOGVIEW_H
#include <QTreeView>
namespace Debugger {
namespace Internal {
class QtMessageLogView : public QTreeView
{
Q_OBJECT
public:
explicit QtMessageLogView(QWidget *parent = 0);
public slots:
void onScrollToBottom();
protected:
void mousePressEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *e);
void resizeEvent(QResizeEvent *e);
void drawBranches(QPainter *painter, const QRect &rect,
const QModelIndex &index) const;
void contextMenuEvent(QContextMenuEvent *event);
private slots:
void onRowActivated(const QModelIndex &index);
private:
void copyToClipboard(const QModelIndex &index);
bool canShowItemInTextEditor(const QModelIndex &index);
};
} //Internal
} //Debugger
#endif // QTMESSAGELOGVIEW_H

View File

@@ -1,254 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qtmessagelogwindow.h"
#include "qtmessagelogview.h"
#include "qtmessageloghandler.h"
#include "qtmessagelogitemdelegate.h"
#include "debuggerstringutils.h"
#include "qtmessagelogproxymodel.h"
#include <utils/statuslabel.h>
#include <utils/styledbar.h>
#include <utils/savedaction.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/findplaceholder.h>
#include <aggregation/aggregate.h>
#include <find/treeviewfind.h>
#include <QSettings>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QToolButton>
static const char CONSOLE[] = "Console";
static const char SHOW_LOG[] = "showLog";
static const char SHOW_WARNING[] = "showWarning";
static const char SHOW_ERROR[] = "showError";
namespace Debugger {
namespace Internal {
/////////////////////////////////////////////////////////////////////
//
// QtMessageLogWindow
//
/////////////////////////////////////////////////////////////////////
QtMessageLogWindow::QtMessageLogWindow(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(tr(CONSOLE));
setObjectName(_(CONSOLE));
const int statusBarHeight = 25;
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
vbox->setSpacing(0);
QWidget *statusbarContainer = new Utils::StyledBar();
statusbarContainer->setStyleSheet(QLatin1String("background: #9B9B9B"));
statusbarContainer->setFixedHeight(statusBarHeight);
QHBoxLayout *hbox = new QHBoxLayout(statusbarContainer);
hbox->setMargin(0);
hbox->setSpacing(0);
hbox->addSpacing(5);
//Status Label
m_statusLabel = new Utils::StatusLabel;
hbox->addWidget(m_statusLabel);
hbox->addWidget(new Utils::StyledSeparator);
const int buttonWidth = 25;
//Filters
QToolButton *button = new QToolButton(this);
button->setAutoRaise(true);
button->setFixedWidth(buttonWidth);
m_showLogAction = new Utils::SavedAction(this);
m_showLogAction->setDefaultValue(true);
m_showLogAction->setSettingsKey(_(CONSOLE), _(SHOW_LOG));
m_showLogAction->setText(tr("Log"));
m_showLogAction->setToolTip(tr("Show debug, log, and info messages."));
m_showLogAction->setCheckable(true);
m_showLogAction->setIcon(QIcon(_(":/debugger/images/log.png")));
button->setDefaultAction(m_showLogAction);
hbox->addWidget(button);
button = new QToolButton(this);
button->setAutoRaise(true);
button->setFixedWidth(buttonWidth);
m_showWarningAction = new Utils::SavedAction(this);
m_showWarningAction->setDefaultValue(true);
m_showWarningAction->setSettingsKey(_(CONSOLE), _(SHOW_WARNING));
m_showWarningAction->setText(tr("Warning"));
m_showWarningAction->setToolTip(tr("Show warning messages."));
m_showWarningAction->setCheckable(true);
m_showWarningAction->setIcon(QIcon(_(":/debugger/images/warning.png")));
button->setDefaultAction(m_showWarningAction);
hbox->addWidget(button);
button = new QToolButton(this);
button->setAutoRaise(true);
button->setFixedWidth(buttonWidth);
m_showErrorAction = new Utils::SavedAction(this);
m_showErrorAction->setDefaultValue(true);
m_showErrorAction->setSettingsKey(_(CONSOLE), _(SHOW_ERROR));
m_showErrorAction->setText(tr("Error"));
m_showErrorAction->setToolTip(tr("Show error and fatal messages."));
m_showErrorAction->setCheckable(true);
m_showErrorAction->setIcon(QIcon(_(":/debugger/images/error.png")));
button->setDefaultAction(m_showErrorAction);
hbox->addWidget(button);
hbox->addWidget(new Utils::StyledSeparator);
//Clear Button
button = new QToolButton;
button->setAutoRaise(true);
button->setFixedWidth(buttonWidth);
m_clearAction = new QAction(tr("Clear Console"), this);
m_clearAction->setIcon(QIcon(_(Core::Constants::ICON_CLEAN_PANE)));
button->setDefaultAction(m_clearAction);
hbox->addWidget(button);
hbox->addWidget(new Utils::StyledSeparator);
m_treeView = new QtMessageLogView(this);
m_treeView->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
m_proxyModel = new QtMessageLogProxyModel(this);
connect(m_showLogAction, SIGNAL(toggled(bool)),
m_proxyModel, SLOT(setShowLogs(bool)));
connect(m_showWarningAction, SIGNAL(toggled(bool)),
m_proxyModel, SLOT(setShowWarnings(bool)));
connect(m_showErrorAction, SIGNAL(toggled(bool)),
m_proxyModel, SLOT(setShowErrors(bool)));
m_treeView->setModel(m_proxyModel);
connect(m_proxyModel,
SIGNAL(setCurrentIndex(QModelIndex,QItemSelectionModel::SelectionFlags)),
m_treeView->selectionModel(),
SLOT(setCurrentIndex(QModelIndex,QItemSelectionModel::SelectionFlags)));
connect(m_proxyModel,
SIGNAL(scrollToBottom()),
m_treeView,
SLOT(onScrollToBottom()));
m_itemDelegate = new QtMessageLogItemDelegate(this);
connect(m_treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
m_itemDelegate, SLOT(currentChanged(QModelIndex,QModelIndex)));
m_treeView->setItemDelegate(m_itemDelegate);
vbox->addWidget(statusbarContainer);
vbox->addWidget(m_treeView);
vbox->addWidget(new Core::FindToolBarPlaceHolder(this));
readSettings();
connect(Core::ICore::instance(),
SIGNAL(saveSettingsRequested()), SLOT(writeSettings()));
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate();
aggregate->add(m_treeView);
aggregate->add(new Find::TreeViewFind(m_treeView));
}
QtMessageLogWindow::~QtMessageLogWindow()
{
writeSettings();
}
void QtMessageLogWindow::readSettings()
{
QSettings *settings = Core::ICore::settings();
m_showLogAction->readSettings(settings);
m_showWarningAction->readSettings(settings);
m_showErrorAction->readSettings(settings);
}
void QtMessageLogWindow::showStatus(const QString &context, int timeout)
{
m_statusLabel->showStatusMessage(context, timeout);
}
void QtMessageLogWindow::writeSettings() const
{
QSettings *settings = Core::ICore::settings();
m_showLogAction->writeSettings(settings);
m_showWarningAction->writeSettings(settings);
m_showErrorAction->writeSettings(settings);
}
void QtMessageLogWindow::setModel(QAbstractItemModel *model)
{
QtMessageLogHandler *oldHandler = qobject_cast<QtMessageLogHandler *>(
m_proxyModel->sourceModel());
if (oldHandler) {
disconnect(m_clearAction, SIGNAL(triggered()), oldHandler, SLOT(clear()));
disconnect(oldHandler,
SIGNAL(selectEditableRow(
QModelIndex,QItemSelectionModel::SelectionFlags)),
m_proxyModel,
SLOT(selectEditableRow(
QModelIndex,QItemSelectionModel::SelectionFlags)));
disconnect(oldHandler,
SIGNAL(rowsInserted(QModelIndex,int,int)),
m_proxyModel,
SLOT(onRowsInserted(QModelIndex,int,int)));
}
QtMessageLogHandler *newHandler = qobject_cast<QtMessageLogHandler *>(model);
m_proxyModel->setSourceModel(newHandler);
m_itemDelegate->setItemModel(newHandler);
if (newHandler) {
connect(m_clearAction, SIGNAL(triggered()), newHandler, SLOT(clear()));
connect(newHandler,
SIGNAL(selectEditableRow(
QModelIndex,QItemSelectionModel::SelectionFlags)),
m_proxyModel,
SLOT(selectEditableRow(
QModelIndex,QItemSelectionModel::SelectionFlags)));
//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.
connect(newHandler,
SIGNAL(rowsInserted(QModelIndex,int,int)),
m_proxyModel,
SLOT(onRowsInserted(QModelIndex,int,int)));
}
}
} // namespace Internal
} // namespace Debugger

View File

@@ -1,82 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef QTMESSAGELOGWINDOW_H
#define QTMESSAGELOGWINDOW_H
#include <QWidget>
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
class QAction;
QT_END_NAMESPACE
namespace Utils {
class StatusLabel;
class SavedAction;
}
namespace Debugger {
namespace Internal {
class QtMessageLogView;
class QtMessageLogItemDelegate;
class QtMessageLogProxyModel;
class QtMessageLogWindow : public QWidget
{
Q_OBJECT
public:
QtMessageLogWindow(QWidget *parent = 0);
~QtMessageLogWindow();
void setModel(QAbstractItemModel *model);
void readSettings();
void showStatus(const QString &context, int timeout);
public slots:
void writeSettings() const;
private:
Utils::StatusLabel *m_statusLabel;
Utils::SavedAction *m_showLogAction;
Utils::SavedAction *m_showWarningAction;
Utils::SavedAction *m_showErrorAction;
QAction *m_clearAction;
QtMessageLogView *m_treeView;
QtMessageLogItemDelegate *m_itemDelegate;
QtMessageLogProxyModel *m_proxyModel;
};
} // namespace Internal
} // namespace Debugger
#endif // QTMESSAGELOGWINDOW_H

View File

Before

Width:  |  Height:  |  Size: 986 B

After

Width:  |  Height:  |  Size: 986 B

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 997 B

After

Width:  |  Height:  |  Size: 997 B

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -1,38 +1,6 @@
/************************************************************************** #include "qmlconsoleedit.h"
** #include "qmlconsoleitemmodel.h"
** This file is part of Qt Creator #include "qmlconsolemanager.h"
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qtmessagelogeditor.h"
#include "qtmessageloghandler.h"
#include "debuggerstringutils.h"
#include "debuggercore.h"
#include "debuggerengine.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -40,54 +8,56 @@
#include <QMenu> #include <QMenu>
#include <QKeyEvent> #include <QKeyEvent>
namespace Debugger { namespace QmlJSTools {
namespace Internal { namespace Internal {
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
// QtMessageLogEditor // QmlConsoleEdit
// //
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
QtMessageLogEditor::QtMessageLogEditor(const QModelIndex &index, QmlConsoleEdit::QmlConsoleEdit(const QModelIndex &index, QWidget *parent) :
QWidget *parent) :
QTextEdit(parent), QTextEdit(parent),
m_historyIndex(index), m_historyIndex(index),
m_prompt(_(":/debugger/images/prompt.png")), m_prompt(QLatin1String(":/qmljstools/images/prompt.png")),
m_startOfEditableArea(0) m_startOfEditableArea(0)
{ {
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
setUndoRedoEnabled(false); setUndoRedoEnabled(false);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
document()->addResource(QTextDocument::ImageResource, document()->addResource(QTextDocument::ImageResource, QUrl(QLatin1String("prompt")), m_prompt);
QUrl(_("prompt")), m_prompt);
QTextImageFormat format; QTextImageFormat format;
format.setName(_("prompt")); format.setName(QLatin1String("prompt"));
format.setHeight(9); format.setHeight(9);
format.setWidth(9); format.setWidth(9);
textCursor().insertText(_(" ")); textCursor().insertText(QLatin1String(" "));
textCursor().insertImage(format); textCursor().insertImage(format);
textCursor().insertText(_(" ")); textCursor().insertText(QLatin1String(" "));
m_startOfEditableArea = textCursor().position(); m_startOfEditableArea = textCursor().position();
ensureCursorVisible(); ensureCursorVisible();
setTextInteractionFlags(Qt::TextEditorInteraction); setTextInteractionFlags(Qt::TextEditorInteraction);
} }
void QtMessageLogEditor::keyPressEvent(QKeyEvent *e) void QmlConsoleEdit::keyPressEvent(QKeyEvent *e)
{ {
bool keyConsumed = false; bool keyConsumed = false;
switch (e->key()) { switch (e->key()) {
case Qt::Key_Return: case Qt::Key_Return:
case Qt::Key_Enter: { case Qt::Key_Enter: {
keyConsumed = debuggerCore()->evaluateScriptExpression(getCurrentScript()); m_interpreter.clearText();
if (keyConsumed) { QString currentScript = getCurrentScript();
m_interpreter.appendText(currentScript);
if (currentScript.isEmpty()) {
emit editingFinished();
} else if (m_interpreter.canEvaluate()) {
QmlConsoleModel::evaluate(currentScript);
emit editingFinished(); emit editingFinished();
debuggerCore()->currentEngine()->qtMessageLogHandler()->appendEditableRow();
} }
}
break; break;
}
case Qt::Key_Backspace: case Qt::Key_Backspace:
if (textCursor().selectionStart() <= m_startOfEditableArea) if (textCursor().selectionStart() <= m_startOfEditableArea)
@@ -99,14 +69,13 @@ void QtMessageLogEditor::keyPressEvent(QKeyEvent *e)
keyConsumed = true; keyConsumed = true;
break; break;
case Qt::Key_Home: case Qt::Key_Home: {
{
QTextCursor c(textCursor()); QTextCursor c(textCursor());
c.setPosition(m_startOfEditableArea); c.setPosition(m_startOfEditableArea);
setTextCursor(c); setTextCursor(c);
keyConsumed = true; keyConsumed = true;
}
break; break;
}
case Qt::Key_Up: case Qt::Key_Up:
handleUpKey(); handleUpKey();
@@ -161,10 +130,9 @@ void QtMessageLogEditor::keyPressEvent(QKeyEvent *e)
QTextEdit::keyPressEvent(e); QTextEdit::keyPressEvent(e);
} }
void QtMessageLogEditor::contextMenuEvent(QContextMenuEvent *event) void QmlConsoleEdit::contextMenuEvent(QContextMenuEvent *event)
{ {
//TODO:: on right click the editor closes // TODO:: on right click the editor closes
//FIXIT
return QTextEdit::contextMenuEvent(event); return QTextEdit::contextMenuEvent(event);
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
@@ -193,12 +161,12 @@ void QtMessageLogEditor::contextMenuEvent(QContextMenuEvent *event)
delete menu; delete menu;
} }
void QtMessageLogEditor::focusOutEvent(QFocusEvent * /*e*/) void QmlConsoleEdit::focusOutEvent(QFocusEvent * /*e*/)
{ {
emit editingFinished(); emit editingFinished();
} }
void QtMessageLogEditor::handleUpKey() void QmlConsoleEdit::handleUpKey()
{ {
QTC_ASSERT(m_historyIndex.isValid(), return); QTC_ASSERT(m_historyIndex.isValid(), return);
int currentRow = m_historyIndex.row(); int currentRow = m_historyIndex.row();
@@ -210,19 +178,17 @@ void QtMessageLogEditor::handleUpKey()
currentRow--; currentRow--;
if (model->hasIndex(currentRow, 0)) { if (model->hasIndex(currentRow, 0)) {
QModelIndex index = model->index(currentRow, 0); QModelIndex index = model->index(currentRow, 0);
if (QtMessageLogHandler::InputType == (QtMessageLogHandler::ItemType)model->data( if (QmlConsoleItem::InputType == (QmlConsoleItem::ItemType)model->data(
index, QtMessageLogHandler::TypeRole).toInt()) { index, QmlConsoleItemModel::TypeRole).toInt()) {
m_historyIndex = index; m_historyIndex = index;
replaceCurrentScript(model->data( replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
index, Qt::DisplayRole).
toString());
break; break;
} }
} }
} }
} }
void QtMessageLogEditor::handleDownKey() void QmlConsoleEdit::handleDownKey()
{ {
QTC_ASSERT(m_historyIndex.isValid(), return); QTC_ASSERT(m_historyIndex.isValid(), return);
int currentRow = m_historyIndex.row(); int currentRow = m_historyIndex.row();
@@ -231,32 +197,29 @@ void QtMessageLogEditor::handleDownKey()
currentRow++; currentRow++;
if (model->hasIndex(currentRow, 0)) { if (model->hasIndex(currentRow, 0)) {
QModelIndex index = model->index(currentRow, 0); QModelIndex index = model->index(currentRow, 0);
if (QtMessageLogHandler::InputType == (QtMessageLogHandler::ItemType)model->data( if (QmlConsoleItem::InputType == (QmlConsoleItem::ItemType)model->data(
index, QtMessageLogHandler::TypeRole).toInt()) { index, QmlConsoleItemModel::TypeRole).toInt()) {
m_historyIndex = index; m_historyIndex = index;
if (currentRow == model->rowCount() - 1) if (currentRow == model->rowCount() - 1)
replaceCurrentScript(m_cachedScript); replaceCurrentScript(m_cachedScript);
else else
replaceCurrentScript(model->data( replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
index, Qt::DisplayRole).
toString());
break; break;
} }
} }
} }
} }
QString QtMessageLogEditor::getCurrentScript() const QString QmlConsoleEdit::getCurrentScript() const
{ {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
cursor.setPosition(m_startOfEditableArea); cursor.setPosition(m_startOfEditableArea);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
QString script = cursor.selectedText(); QString script = cursor.selectedText();
//remove WS
return script.trimmed(); return script.trimmed();
} }
void QtMessageLogEditor::replaceCurrentScript(const QString &script) void QmlConsoleEdit::replaceCurrentScript(const QString &script)
{ {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
cursor.setPosition(m_startOfEditableArea); cursor.setPosition(m_startOfEditableArea);
@@ -266,5 +229,5 @@ void QtMessageLogEditor::replaceCurrentScript(const QString &script)
setTextCursor(cursor); setTextCursor(cursor);
} }
} //Internal } // Internal
} //Debugger } // QmlJSTools

View File

@@ -0,0 +1,45 @@
#ifndef QMLCONSOLEEDIT_H
#define QMLCONSOLEEDIT_H
#include "qmljsinterpreter.h"
#include <QTextEdit>
#include <QModelIndex>
namespace QmlJSTools {
namespace Internal {
class QmlConsoleEdit : public QTextEdit
{
Q_OBJECT
public:
QmlConsoleEdit(const QModelIndex &index, QWidget *parent);
QString getCurrentScript() const;
protected:
void keyPressEvent(QKeyEvent *e);
void contextMenuEvent(QContextMenuEvent *event);
void focusOutEvent(QFocusEvent *e);
signals:
void editingFinished();
protected:
void handleUpKey();
void handleDownKey();
void replaceCurrentScript(const QString &script);
private:
QModelIndex m_historyIndex;
QString m_cachedScript;
QImage m_prompt;
int m_startOfEditableArea;
QmlJSInterpreter m_interpreter;
};
} // QmlJSTools
} // Internal
#endif // QMLCONSOLEEDIT_H

View File

@@ -0,0 +1,123 @@
#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

View File

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

View File

@@ -1,35 +1,5 @@
/************************************************************************** #include "qmlconsoleitemdelegate.h"
** #include "qmlconsoleedit.h"
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qtmessagelogitemdelegate.h"
#include "qtmessagelogeditor.h"
#include <QPainter> #include <QPainter>
#include <QTreeView> #include <QTreeView>
@@ -54,55 +24,54 @@ const char CONSOLE_BORDER_COLOR[] = "#C9C9C9";
const int ELLIPSIS_GRADIENT_WIDTH = 16; const int ELLIPSIS_GRADIENT_WIDTH = 16;
namespace Debugger { namespace QmlJSTools {
namespace Internal { namespace Internal {
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
// QtMessageLogItemDelegate // QmlConsoleItemDelegate
// //
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
QtMessageLogItemDelegate::QtMessageLogItemDelegate(QObject *parent) : QmlConsoleItemDelegate::QmlConsoleItemDelegate(QObject *parent) :
QStyledItemDelegate(parent), QStyledItemDelegate(parent),
m_logIcon(QLatin1String(":/debugger/images/log.png")), m_logIcon(QLatin1String(":/qmljstools/images/log.png")),
m_warningIcon(QLatin1String(":/debugger/images/warning.png")), m_warningIcon(QLatin1String(":/qmljstools/images/warning.png")),
m_errorIcon(QLatin1String(":/debugger/images/error.png")), m_errorIcon(QLatin1String(":/qmljstools/images/error.png")),
m_expandIcon(QLatin1String(":/debugger/images/expand.png")), m_expandIcon(QLatin1String(":/qmljstools/images/expand.png")),
m_collapseIcon(QLatin1String(":/debugger/images/collapse.png")), m_collapseIcon(QLatin1String(":/qmljstools/images/collapse.png")),
m_prompt(QLatin1String(":/debugger/images/prompt.png")), m_prompt(QLatin1String(":/qmljstools/images/prompt.png")),
m_itemModel(0),
m_cachedHeight(0) m_cachedHeight(0)
{ {
} }
void QtMessageLogItemDelegate::emitSizeHintChanged(const QModelIndex &index) void QmlConsoleItemDelegate::emitSizeHintChanged(const QModelIndex &index)
{ {
emit sizeHintChanged(index); emit sizeHintChanged(index);
} }
QColor QtMessageLogItemDelegate::drawBackground(QPainter *painter, const QRect &rect, QColor QmlConsoleItemDelegate::drawBackground(QPainter *painter, const QRect &rect,
const QModelIndex &index, const QModelIndex &index,
bool selected) const bool selected) const
{ {
painter->save(); painter->save();
QtMessageLogHandler::ItemType itemType = (QtMessageLogHandler::ItemType)index.data( QmlConsoleItem::ItemType itemType = (QmlConsoleItem::ItemType)index.data(
QtMessageLogHandler::TypeRole).toInt(); QmlConsoleItemModel::TypeRole).toInt();
QColor backgroundColor; QColor backgroundColor;
switch (itemType) { switch (itemType) {
case QtMessageLogHandler::DebugType: case QmlConsoleItem::DebugType:
backgroundColor = selected ? QColor(CONSOLE_LOG_BACKGROUND_SELECTED_COLOR) : backgroundColor = selected ? QColor(CONSOLE_LOG_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_LOG_BACKGROUND_COLOR); QColor(CONSOLE_LOG_BACKGROUND_COLOR);
break; break;
case QtMessageLogHandler::WarningType: case QmlConsoleItem::WarningType:
backgroundColor = selected ? QColor(CONSOLE_WARNING_BACKGROUND_SELECTED_COLOR) : backgroundColor = selected ? QColor(CONSOLE_WARNING_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_WARNING_BACKGROUND_COLOR); QColor(CONSOLE_WARNING_BACKGROUND_COLOR);
break; break;
case QtMessageLogHandler::ErrorType: case QmlConsoleItem::ErrorType:
backgroundColor = selected ? QColor(CONSOLE_ERROR_BACKGROUND_SELECTED_COLOR) : backgroundColor = selected ? QColor(CONSOLE_ERROR_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_ERROR_BACKGROUND_COLOR); QColor(CONSOLE_ERROR_BACKGROUND_COLOR);
break; break;
case QtMessageLogHandler::InputType: case QmlConsoleItem::InputType:
default: default:
backgroundColor = selected ? QColor(CONSOLE_EDITOR_BACKGROUND_SELECTED_COLOR) : backgroundColor = selected ? QColor(CONSOLE_EDITOR_BACKGROUND_SELECTED_COLOR) :
QColor(CONSOLE_EDITOR_BACKGROUND_COLOR); QColor(CONSOLE_EDITOR_BACKGROUND_COLOR);
@@ -117,37 +86,37 @@ QColor QtMessageLogItemDelegate::drawBackground(QPainter *painter, const QRect &
painter->setPen(QColor(CONSOLE_BORDER_COLOR)); painter->setPen(QColor(CONSOLE_BORDER_COLOR));
if (!(index.flags() & Qt::ItemIsEditable)) if (!(index.flags() & Qt::ItemIsEditable))
painter->drawLine(0, rect.bottom(), rect.right(), painter->drawLine(0, rect.bottom(), rect.right(),
rect.bottom()); rect.bottom());
painter->restore(); painter->restore();
return backgroundColor; return backgroundColor;
} }
void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, void QmlConsoleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const const QModelIndex &index) const
{ {
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
painter->save(); painter->save();
//Set Colors // Set Colors
QColor textColor; QColor textColor;
QIcon taskIcon; QIcon taskIcon;
QtMessageLogHandler::ItemType type = (QtMessageLogHandler::ItemType)index.data( QmlConsoleItem::ItemType type = (QmlConsoleItem::ItemType)index.data(
QtMessageLogHandler::TypeRole).toInt(); QmlConsoleItemModel::TypeRole).toInt();
switch (type) { switch (type) {
case QtMessageLogHandler::DebugType: case QmlConsoleItem::DebugType:
textColor = QColor(CONSOLE_LOG_TEXT_COLOR); textColor = QColor(CONSOLE_LOG_TEXT_COLOR);
taskIcon = m_logIcon; taskIcon = m_logIcon;
break; break;
case QtMessageLogHandler::WarningType: case QmlConsoleItem::WarningType:
textColor = QColor(CONSOLE_WARNING_TEXT_COLOR); textColor = QColor(CONSOLE_WARNING_TEXT_COLOR);
taskIcon = m_warningIcon; taskIcon = m_warningIcon;
break; break;
case QtMessageLogHandler::ErrorType: case QmlConsoleItem::ErrorType:
textColor = QColor(CONSOLE_ERROR_TEXT_COLOR); textColor = QColor(CONSOLE_ERROR_TEXT_COLOR);
taskIcon = m_errorIcon; taskIcon = m_errorIcon;
break; break;
case QtMessageLogHandler::InputType: case QmlConsoleItem::InputType:
textColor = QColor(CONSOLE_EDITOR_TEXT_COLOR); textColor = QColor(CONSOLE_EDITOR_TEXT_COLOR);
taskIcon = m_prompt; taskIcon = m_prompt;
break; break;
@@ -156,11 +125,11 @@ void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
break; break;
} }
//Paint background // Paint background
QColor backgroundColor = drawBackground(painter, opt.rect, index, QColor backgroundColor = drawBackground(painter, opt.rect, index,
bool(opt.state & QStyle::State_Selected)); bool(opt.state & QStyle::State_Selected));
//Calculate positions // Calculate positions
const QTreeView *view = qobject_cast<const QTreeView *>(opt.widget); const QTreeView *view = qobject_cast<const QTreeView *>(opt.widget);
int level = 0; int level = 0;
QModelIndex idx(index); QModelIndex idx(index);
@@ -168,14 +137,12 @@ void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
idx = idx.parent(); idx = idx.parent();
level++; level++;
} }
int width = view->width() - level * view->indentation() - int width = view->width() - level * view->indentation() - view->verticalScrollBar()->width();
view->verticalScrollBar()->width();
bool showTypeIcon = index.parent() == QModelIndex(); bool showTypeIcon = index.parent() == QModelIndex();
bool showExpandableIcon = type == QtMessageLogHandler::UndefinedType; bool showExpandableIcon = type == QmlConsoleItem::UndefinedType;
QRect rect(opt.rect.x(), opt.rect.top(), width, opt.rect.height()); QRect rect(opt.rect.x(), opt.rect.top(), width, opt.rect.height());
ConsoleItemPositions positions(rect, opt.font, showTypeIcon, ConsoleItemPositions positions(rect, opt.font, showTypeIcon, showExpandableIcon);
showExpandableIcon, m_itemModel);
// Paint TaskIconArea: // Paint TaskIconArea:
if (showTypeIcon) if (showTypeIcon)
@@ -196,11 +163,10 @@ void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
tl.draw(painter, QPoint(positions.textAreaLeft(), positions.adjustedTop())); tl.draw(painter, QPoint(positions.textAreaLeft(), positions.adjustedTop()));
} else { } else {
QFontMetrics fm(opt.font); QFontMetrics fm(opt.font);
painter->drawText(positions.textArea(), painter->drawText(positions.textArea(), fm.elidedText(str, Qt::ElideRight,
fm.elidedText(str, Qt::ElideRight, positions.textAreaWidth()));
positions.textAreaWidth()));
} }
//skip if area is editable // skip if area is editable
if (showExpandableIcon) { if (showExpandableIcon) {
// Paint ExpandableIconArea: // Paint ExpandableIconArea:
QIcon expandCollapseIcon; QIcon expandCollapseIcon;
@@ -210,16 +176,14 @@ void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
else else
expandCollapseIcon = m_expandIcon; expandCollapseIcon = m_expandIcon;
} }
painter->drawPixmap(positions.expandCollapseIconLeft(), painter->drawPixmap(positions.expandCollapseIconLeft(), positions.adjustedTop(),
positions.adjustedTop(), expandCollapseIcon.pixmap(positions.expandCollapseIconWidth(),
expandCollapseIcon.pixmap( positions.expandCollapseIconHeight()));
positions.expandCollapseIconWidth(),
positions.expandCollapseIconHeight()));
} }
if (showFileLineInfo) { if (showFileLineInfo) {
//Check for file info // Check for file info
QString file = index.data(QtMessageLogHandler::FileRole).toString(); QString file = index.data(QmlConsoleItemModel::FileRole).toString();
if (!file.isEmpty()) { if (!file.isEmpty()) {
QFontMetrics fm(option.font); QFontMetrics fm(option.font);
// Paint FileArea // Paint FileArea
@@ -228,22 +192,20 @@ void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
file = file.mid(pos +1); file = file.mid(pos +1);
const int realFileWidth = fm.width(file); const int realFileWidth = fm.width(file);
painter->setClipRect(positions.fileArea()); painter->setClipRect(positions.fileArea());
painter->drawText(positions.fileAreaLeft(), painter->drawText(positions.fileAreaLeft(), positions.adjustedTop() + fm.ascent(),
positions.adjustedTop() + fm.ascent(), file); file);
if (realFileWidth > positions.fileAreaWidth()) { if (realFileWidth > positions.fileAreaWidth()) {
// draw a gradient to mask the text // draw a gradient to mask the text
int gradientStart = positions.fileAreaLeft() - 1; int gradientStart = positions.fileAreaLeft() - 1;
QLinearGradient lg(gradientStart + QLinearGradient lg(gradientStart + ELLIPSIS_GRADIENT_WIDTH, 0, gradientStart, 0);
ELLIPSIS_GRADIENT_WIDTH, 0, gradientStart, 0);
lg.setColorAt(0, Qt::transparent); lg.setColorAt(0, Qt::transparent);
lg.setColorAt(1, backgroundColor); lg.setColorAt(1, backgroundColor);
painter->fillRect(gradientStart, positions.adjustedTop(), painter->fillRect(gradientStart, positions.adjustedTop(),
ELLIPSIS_GRADIENT_WIDTH, positions.lineHeight(), ELLIPSIS_GRADIENT_WIDTH, positions.lineHeight(), lg);
lg);
} }
// Paint LineArea // Paint LineArea
QString lineText = index.data(QtMessageLogHandler::LineRole).toString(); QString lineText = index.data(QmlConsoleItemModel::LineRole).toString();
painter->setClipRect(positions.lineArea()); painter->setClipRect(positions.lineArea());
const int realLineWidth = fm.width(lineText); const int realLineWidth = fm.width(lineText);
painter->drawText(positions.lineAreaRight() - realLineWidth, painter->drawText(positions.lineAreaRight() - realLineWidth,
@@ -254,8 +216,8 @@ void QtMessageLogItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
painter->restore(); painter->restore();
} }
QSize QtMessageLogItemDelegate::sizeHint(const QStyleOptionViewItem &option, QSize QmlConsoleItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const const QModelIndex &index) const
{ {
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
@@ -267,8 +229,7 @@ QSize QtMessageLogItemDelegate::sizeHint(const QStyleOptionViewItem &option,
idx = idx.parent(); idx = idx.parent();
level++; level++;
} }
int width = view->width() - level * view->indentation() - int width = view->width() - level * view->indentation() - view->verticalScrollBar()->width();
view->verticalScrollBar()->width();
if (index.flags() & Qt::ItemIsEditable) if (index.flags() & Qt::ItemIsEditable)
return QSize(width, view->height() * 1/2); return QSize(width, view->height() * 1/2);
@@ -276,14 +237,13 @@ QSize QtMessageLogItemDelegate::sizeHint(const QStyleOptionViewItem &option,
if (!selected && option.font == m_cachedFont && m_cachedHeight > 0) if (!selected && option.font == m_cachedFont && m_cachedHeight > 0)
return QSize(width, m_cachedHeight); return QSize(width, m_cachedHeight);
QtMessageLogHandler::ItemType type = (QtMessageLogHandler::ItemType)index.data( QmlConsoleItem::ItemType type = (QmlConsoleItem::ItemType)index.data(
QtMessageLogHandler::TypeRole).toInt(); QmlConsoleItemModel::TypeRole).toInt();
bool showTypeIcon = index.parent() == QModelIndex(); bool showTypeIcon = index.parent() == QModelIndex();
bool showExpandableIcon = type == QtMessageLogHandler::UndefinedType; bool showExpandableIcon = type == QmlConsoleItem::UndefinedType;
QRect rect(level * view->indentation(), 0, width, 0); QRect rect(level * view->indentation(), 0, width, 0);
ConsoleItemPositions positions(rect, opt.font, ConsoleItemPositions positions(rect, opt.font, showTypeIcon, showExpandableIcon);
showTypeIcon, showExpandableIcon, m_itemModel);
QFontMetrics fm(option.font); QFontMetrics fm(option.font);
qreal height = fm.height(); qreal height = fm.height();
@@ -308,58 +268,56 @@ QSize QtMessageLogItemDelegate::sizeHint(const QStyleOptionViewItem &option,
return QSize(width, height); return QSize(width, height);
} }
QWidget *QtMessageLogItemDelegate::createEditor(QWidget *parent, QWidget *QmlConsoleItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/*option*/, const QStyleOptionViewItem &/*option*/,
const QModelIndex &index) const const QModelIndex &index) const
{ {
QtMessageLogEditor *editor = new QtMessageLogEditor(index, parent); QmlConsoleEdit *editor = new QmlConsoleEdit(index, parent);
connect(editor, SIGNAL(editingFinished()), connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
this, SLOT(commitAndCloseEditor()));
return editor; return editor;
} }
void QtMessageLogItemDelegate::setEditorData(QWidget *editor, void QmlConsoleItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const const QModelIndex &index) const
{ {
QtMessageLogEditor *edtr = qobject_cast<QtMessageLogEditor *>(editor); QmlConsoleEdit *edtr = qobject_cast<QmlConsoleEdit *>(editor);
edtr->insertPlainText(index.data(Qt::DisplayRole).toString()); edtr->insertPlainText(index.data(Qt::DisplayRole).toString());
} }
void QtMessageLogItemDelegate::setModelData(QWidget *editor, void QmlConsoleItemDelegate::setModelData(QWidget *editor,
QAbstractItemModel *model, QAbstractItemModel *model,
const QModelIndex &index) const const QModelIndex &index) const
{ {
QtMessageLogEditor *edtr = qobject_cast<QtMessageLogEditor *>(editor); QmlConsoleEdit *edtr = qobject_cast<QmlConsoleEdit *>(editor);
model->setData(index, edtr->getCurrentScript(), Qt::DisplayRole); model->setData(index, edtr->getCurrentScript(), Qt::DisplayRole);
model->setData(index, QtMessageLogHandler::InputType, QtMessageLogHandler::TypeRole); model->setData(index, QmlConsoleItem::InputType, QmlConsoleItemModel::TypeRole);
} }
void QtMessageLogItemDelegate::updateEditorGeometry(QWidget *editor, void QmlConsoleItemDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QStyleOptionViewItem &option,
const QModelIndex &/*index*/) const const QModelIndex &/*index*/) const
{ {
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
editor->setGeometry(QRect(opt.rect.x(), opt.rect.top(), editor->setGeometry(QRect(opt.rect.x(), opt.rect.top(), opt.rect.width(), opt.rect.bottom()));
opt.rect.width(), opt.rect.bottom()));
} }
void QtMessageLogItemDelegate::currentChanged(const QModelIndex &current, void QmlConsoleItemDelegate::currentChanged(const QModelIndex &current,
const QModelIndex &previous) const QModelIndex &previous)
{ {
emit sizeHintChanged(current); emit sizeHintChanged(current);
emit sizeHintChanged(previous); emit sizeHintChanged(previous);
} }
void QtMessageLogItemDelegate::commitAndCloseEditor() void QmlConsoleItemDelegate::commitAndCloseEditor()
{ {
QtMessageLogEditor *editor = qobject_cast<QtMessageLogEditor *>(sender()); QmlConsoleEdit *editor = qobject_cast<QmlConsoleEdit *>(sender());
emit commitData(editor); emit commitData(editor);
emit closeEditor(editor); emit closeEditor(editor);
} }
qreal QtMessageLogItemDelegate::layoutText(QTextLayout &tl, int width, qreal QmlConsoleItemDelegate::layoutText(QTextLayout &tl, int width,
bool *showFileLineInfo) const bool *showFileLineInfo) const
{ {
qreal height = 0; qreal height = 0;
tl.beginLayout(); tl.beginLayout();
@@ -379,10 +337,5 @@ qreal QtMessageLogItemDelegate::layoutText(QTextLayout &tl, int width,
return height; return height;
} }
void QtMessageLogItemDelegate::setItemModel(QtMessageLogHandler *model) } // Internal
{ } // QmlJSTools
m_itemModel = model;
}
} //Internal
} //Debugger

View File

@@ -1,55 +1,24 @@
/************************************************************************** #ifndef QMLCONSOLEITEMDELEGATE_H
** #define QMLCONSOLEITEMDELEGATE_H
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef QTMESSAGELOGITEMDELEGATE_H #include "qmlconsoleitemmodel.h"
#define QTMESSAGELOGITEMDELEGATE_H #include "qmlconsolemanager.h"
#include "qtmessageloghandler.h"
#include <QTextLayout>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTextLayout>
namespace Debugger { namespace QmlJSTools {
namespace Internal { namespace Internal {
class QtMessageLogItemDelegate : public QStyledItemDelegate class QmlConsoleItemDelegate : public QStyledItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QtMessageLogItemDelegate(QObject *parent = 0); QmlConsoleItemDelegate(QObject *parent);
void emitSizeHintChanged(const QModelIndex &index);
QColor drawBackground(QPainter *painter, const QRect &rect,
const QModelIndex &index,
bool selected) const;
void setItemModel(QtMessageLogHandler *model); void emitSizeHintChanged(const QModelIndex &index);
QColor drawBackground(QPainter *painter, const QRect &rect, const QModelIndex &index,
bool selected) const;
public slots: public slots:
void currentChanged(const QModelIndex &current, const QModelIndex &previous); void currentChanged(const QModelIndex &current, const QModelIndex &previous);
@@ -62,11 +31,9 @@ protected:
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const; const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QStyleOptionViewItem &option,
const QModelIndex &index) const; const QModelIndex &index) const;
private slots: private slots:
@@ -82,7 +49,6 @@ private:
const QIcon m_expandIcon; const QIcon m_expandIcon;
const QIcon m_collapseIcon; const QIcon m_collapseIcon;
const QIcon m_prompt; const QIcon m_prompt;
QtMessageLogHandler *m_itemModel;
mutable int m_cachedHeight; mutable int m_cachedHeight;
mutable QFont m_cachedFont; mutable QFont m_cachedFont;
}; };
@@ -102,11 +68,8 @@ private:
class ConsoleItemPositions class ConsoleItemPositions
{ {
public: public:
ConsoleItemPositions(const QRect &rect, ConsoleItemPositions(const QRect &rect, const QFont &font, bool showTaskIconArea,
const QFont &font, bool showExpandableIconArea)
bool showTaskIconArea,
bool showExpandableIconArea,
QtMessageLogHandler *model = 0)
: m_x(rect.x()), : m_x(rect.x()),
m_width(rect.width()), m_width(rect.width()),
m_top(rect.top()), m_top(rect.top()),
@@ -117,10 +80,9 @@ public:
m_showExpandableIconArea(showExpandableIconArea) m_showExpandableIconArea(showExpandableIconArea)
{ {
m_fontHeight = QFontMetrics(font).height(); m_fontHeight = QFontMetrics(font).height();
if (model) { QmlConsoleItemModel *model = QmlConsoleModel::qmlConsoleItemModel();
m_maxFileLength = model->sizeOfFile(font); m_maxFileLength = model->sizeOfFile(font);
m_maxLineLength = model->sizeOfLineNumber(font); m_maxLineLength = model->sizeOfLineNumber(font);
}
} }
int adjustedTop() const { return m_top + ITEM_PADDING; } int adjustedTop() const { return m_top + ITEM_PADDING; }
@@ -130,44 +92,41 @@ public:
int lineHeight() const { return m_fontHeight + 1; } int lineHeight() const { return m_fontHeight + 1; }
int minimumHeight() const { return typeIconHeight() + 2 * ITEM_PADDING; } int minimumHeight() const { return typeIconHeight() + 2 * ITEM_PADDING; }
//PROMPTAREA is same as TYPEICONAREA // PROMPTAREA is same as TYPEICONAREA
int typeIconLeft() const { return adjustedLeft(); } int typeIconLeft() const { return adjustedLeft(); }
int typeIconWidth() const { return TASK_ICON_SIZE; } int typeIconWidth() const { return TASK_ICON_SIZE; }
int typeIconHeight() const { return TASK_ICON_SIZE; } int typeIconHeight() const { return TASK_ICON_SIZE; }
int typeIconRight() const { return m_showTaskIconArea ? int typeIconRight() const { return m_showTaskIconArea ? typeIconLeft() + typeIconWidth()
typeIconLeft() + typeIconWidth() : adjustedLeft(); } : adjustedLeft(); }
QRect typeIcon() const { return QRect typeIcon() const { return QRect(typeIconLeft(), adjustedTop(), typeIconWidth(),
QRect(typeIconLeft(), adjustedTop(), typeIconHeight()); }
typeIconWidth(), typeIconHeight()); }
int expandCollapseIconLeft() const { return typeIconRight() + int expandCollapseIconLeft() const { return typeIconRight() + ITEM_SPACING; }
ITEM_SPACING; }
int expandCollapseIconWidth() const { return TASK_ICON_SIZE; } int expandCollapseIconWidth() const { return TASK_ICON_SIZE; }
int expandCollapseIconHeight() const { return TASK_ICON_SIZE; } int expandCollapseIconHeight() const { return TASK_ICON_SIZE; }
int expandCollapseIconRight() const { return m_showExpandableIconArea ? int expandCollapseIconRight() const { return m_showExpandableIconArea ?
expandCollapseIconLeft() + expandCollapseIconWidth() : expandCollapseIconLeft() + expandCollapseIconWidth() : typeIconRight(); }
typeIconRight(); } QRect expandCollapseIcon() const { return QRect(expandCollapseIconLeft(), adjustedTop(),
QRect expandCollapseIcon() const { return expandCollapseIconWidth(),
QRect(expandCollapseIconLeft(), adjustedTop(), expandCollapseIconHeight()); }
expandCollapseIconWidth(), expandCollapseIconHeight()); }
int textAreaLeft() const { return expandCollapseIconRight() + ITEM_SPACING; } int textAreaLeft() const { return expandCollapseIconRight() + ITEM_SPACING; }
int textAreaWidth() const { return textAreaRight() - textAreaLeft(); } int textAreaWidth() const { return textAreaRight() - textAreaLeft(); }
int textAreaRight() const { return fileAreaLeft() - ITEM_SPACING; } int textAreaRight() const { return fileAreaLeft() - ITEM_SPACING; }
QRect textArea() const { return QRect textArea() const { return QRect(textAreaLeft(), adjustedTop(), textAreaWidth(),
QRect(textAreaLeft(), adjustedTop(), textAreaWidth(), lineHeight()); } lineHeight()); }
int fileAreaLeft() const { return fileAreaRight() - fileAreaWidth(); } int fileAreaLeft() const { return fileAreaRight() - fileAreaWidth(); }
int fileAreaWidth() const { return m_maxFileLength; } int fileAreaWidth() const { return m_maxFileLength; }
int fileAreaRight() const { return lineAreaLeft() - ITEM_SPACING; } int fileAreaRight() const { return lineAreaLeft() - ITEM_SPACING; }
QRect fileArea() const { return QRect fileArea() const { return QRect(fileAreaLeft(), adjustedTop(), fileAreaWidth(),
QRect(fileAreaLeft(), adjustedTop(), fileAreaWidth(), lineHeight()); } lineHeight()); }
int lineAreaLeft() const { return lineAreaRight() - lineAreaWidth(); } int lineAreaLeft() const { return lineAreaRight() - lineAreaWidth(); }
int lineAreaWidth() const { return m_maxLineLength; } int lineAreaWidth() const { return m_maxLineLength; }
int lineAreaRight() const { return adjustedRight() - ITEM_SPACING; } int lineAreaRight() const { return adjustedRight() - ITEM_SPACING; }
QRect lineArea() const { return QRect lineArea() const { return QRect(lineAreaLeft(), adjustedTop(), lineAreaWidth(),
QRect(lineAreaLeft(), adjustedTop(), lineAreaWidth(), lineHeight()); } lineHeight()); }
private: private:
int m_x; int m_x;
@@ -186,7 +145,8 @@ public:
static const int ITEM_SPACING = 4; static const int ITEM_SPACING = 4;
}; };
} //Internal
} //Debugger
#endif // QTMESSAGELOGITEMDELEGATE_H } // namespace Internal
} // namespace QmlJSTools
#endif // QMLCONSOLEITEMDELEGATE_H

View File

@@ -0,0 +1,252 @@
#include "qmlconsoleitemmodel.h"
#include <utils/qtcassert.h>
#include <QFontMetrics>
namespace QmlJSTools {
namespace Internal {
///////////////////////////////////////////////////////////////////////
//
// QmlConsoleItemModel
//
///////////////////////////////////////////////////////////////////////
QmlConsoleItemModel::QmlConsoleItemModel(QObject *parent) :
QAbstractItemModel(parent),
m_hasEditableRow(false),
m_rootItem(new QmlConsoleItem(0)),
m_maxSizeOfFileName(0)
{
}
QmlConsoleItemModel::~QmlConsoleItemModel()
{
delete m_rootItem;
}
void QmlConsoleItemModel::clear()
{
beginResetModel();
reset();
delete m_rootItem;
m_rootItem = new QmlConsoleItem(0);
endResetModel();
if (m_hasEditableRow)
appendEditableRow();
}
bool QmlConsoleItemModel::appendItem(QmlConsoleItem *item, int position)
{
if (position < 0)
position = m_rootItem->childCount() - 1;
if (position < 0)
position = 0;
beginInsertRows(QModelIndex(), position, position);
bool success = m_rootItem->insertChild(position, item);
endInsertRows();
return success;
}
bool QmlConsoleItemModel::appendMessage(QmlConsoleItem::ItemType itemType,
const QString &message, int position)
{
return appendItem(new QmlConsoleItem(m_rootItem, itemType, message), position);
}
void QmlConsoleItemModel::setHasEditableRow(bool hasEditableRow)
{
if (m_hasEditableRow && !hasEditableRow)
removeEditableRow();
if (!m_hasEditableRow && hasEditableRow)
appendEditableRow();
m_hasEditableRow = hasEditableRow;
}
bool QmlConsoleItemModel::hasEditableRow() const
{
return m_hasEditableRow;
}
void QmlConsoleItemModel::appendEditableRow()
{
int position = m_rootItem->childCount();
if (appendItem(new QmlConsoleItem(m_rootItem, QmlConsoleItem::InputType), position))
emit selectEditableRow(index(position, 0), QItemSelectionModel::ClearAndSelect);
}
void QmlConsoleItemModel::removeEditableRow()
{
if (m_rootItem->child(m_rootItem->childCount() - 1)->itemType == QmlConsoleItem::InputType)
removeRow(m_rootItem->childCount() - 1);
}
int QmlConsoleItemModel::sizeOfFile(const QFont &font)
{
int lastReadOnlyRow = m_rootItem->childCount();
if (m_hasEditableRow)
lastReadOnlyRow -= 2;
else
lastReadOnlyRow -= 1;
if (lastReadOnlyRow < 0)
return 0;
QString filename = m_rootItem->child(lastReadOnlyRow)->file;
const int pos = filename.lastIndexOf(QLatin1Char('/'));
if (pos != -1)
filename = filename.mid(pos + 1);
QFontMetrics fm(font);
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.width(filename));
return m_maxSizeOfFileName;
}
int QmlConsoleItemModel::sizeOfLineNumber(const QFont &font)
{
QFontMetrics fm(font);
return fm.width(QLatin1String("88888"));
}
QVariant QmlConsoleItemModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
QmlConsoleItem *item = getItem(index);
if (role == Qt::DisplayRole )
return item->text();
else if (role == QmlConsoleItemModel::TypeRole)
return int(item->itemType);
else if (role == QmlConsoleItemModel::FileRole)
return item->file;
else if (role == QmlConsoleItemModel::LineRole)
return item->line;
else
return QVariant();
}
QModelIndex QmlConsoleItemModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
if (column > 0)
return QModelIndex();
QmlConsoleItem *parentItem = getItem(parent);
QmlConsoleItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex QmlConsoleItemModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
QmlConsoleItem *childItem = getItem(index);
QmlConsoleItem *parentItem = childItem->parent();
if (parentItem == m_rootItem)
return QModelIndex();
if (!parentItem)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
}
int QmlConsoleItemModel::rowCount(const QModelIndex &parent) const
{
QmlConsoleItem *parentItem = getItem(parent);
return parentItem->childCount();
}
int QmlConsoleItemModel::columnCount(const QModelIndex & /* parent */) const
{
return 1;
}
Qt::ItemFlags QmlConsoleItemModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
QmlConsoleItem *item = getItem(index);
if (m_hasEditableRow && item->parent() == m_rootItem
&& index.row() == m_rootItem->childCount() - 1)
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
bool QmlConsoleItemModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
QmlConsoleItem *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();
result = true;
} else if (role == QmlConsoleItemModel::FileRole) {
item->file = value.toString();
result = true;
} else if (role == QmlConsoleItemModel::LineRole) {
item->line = value.toInt();
result = true;
}
if (result)
emit dataChanged(index, index);
return result;
}
bool QmlConsoleItemModel::insertRows(int position, int rows, const QModelIndex &parent)
{
QmlConsoleItem *parentItem = getItem(parent);
bool success;
beginInsertRows(parent, position, position + rows - 1);
success = parentItem->insertChildren(position, rows);
endInsertRows();
return success;
}
bool QmlConsoleItemModel::removeRows(int position, int rows, const QModelIndex &parent)
{
QmlConsoleItem *parentItem = getItem(parent);
bool success = true;
beginRemoveRows(parent, position, position + rows - 1);
success = parentItem->removeChildren(position, rows);
endRemoveRows();
return success;
}
QmlConsoleItem *QmlConsoleItemModel::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
QmlConsoleItem *item = static_cast<QmlConsoleItem*>(index.internalPointer());
if (item)
return item;
}
return m_rootItem;
}
} // Internal
} // QmlJSTools

View File

@@ -0,0 +1,73 @@
#ifndef QMLCONSOLEITEMMODEL_H
#define QMLCONSOLEITEMMODEL_H
#include "qmlconsoleitem.h"
#include <QAbstractItemModel>
#include <QItemSelectionModel>
#include <QFont>
namespace QmlJSTools {
namespace Internal {
class QmlConsoleItemModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum Roles { TypeRole = Qt::UserRole, FileRole, LineRole };
explicit QmlConsoleItemModel(QObject *parent = 0);
~QmlConsoleItemModel();
void setHasEditableRow(bool hasEditableRow);
bool hasEditableRow() const;
void appendEditableRow();
void removeEditableRow();
bool appendItem(QmlConsoleItem *item, int position = -1);
bool appendMessage(QmlConsoleItem::ItemType itemType, const QString &message,
int position = -1);
QAbstractItemModel *model() { return this; }
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int sizeOfFile(const QFont &font);
int sizeOfLineNumber(const QFont &font);
QmlConsoleItem *root() const { return m_rootItem; }
public slots:
void clear();
signals:
void selectEditableRow(const QModelIndex &index, QItemSelectionModel::SelectionFlags flags);
void rowInserted(const QModelIndex &index);
protected:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
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;
private:
bool m_hasEditableRow;
QmlConsoleItem *m_rootItem;
int m_maxSizeOfFileName;
};
} // Internal
} // QmlJSTools
#endif // QMLCONSOLEITEMMODEL_H

View File

@@ -0,0 +1,162 @@
#include "qmlconsolemanager.h"
#include "qmlconsolepane.h"
#include "qmlconsoleitemmodel.h"
#include <extensionsystem/pluginmanager.h>
#include <debugger/debuggerengine.h>
#include <QScriptEngine>
#include <QVariant>
namespace QmlJSTools {
QmlConsoleManager *QmlConsoleManager::m_instance = 0;
class QmlConsoleManagerPrivate
{
public:
QScriptEngine *scriptEngine;
Internal::QmlConsoleItemModel *qmlConsoleItemModel;
Internal::QmlConsolePane *qmlConsolePane;
Debugger::DebuggerEngine *debuggerEngine;
};
QmlConsoleManager::QmlConsoleManager(QObject *parent)
: QObject(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);
ExtensionSystem::PluginManager::addObject(d->qmlConsolePane);
d->debuggerEngine = 0;
}
QmlConsoleManager::~QmlConsoleManager()
{
if (d->qmlConsolePane) {
ExtensionSystem::PluginManager::removeObject(d->qmlConsolePane);
}
delete d;
m_instance = 0;
}
void QmlConsoleManager::showConsolePane()
{
if (d->qmlConsolePane)
d->qmlConsolePane->popup(Core::IOutputPane::ModeSwitch);
}
QmlConsoleItem *QmlConsoleManager::rootItem() const
{
return d->qmlConsoleItemModel->root();
}
void QmlConsoleManager::setDebuggerEngine(Debugger::DebuggerEngine *debuggerEngine)
{
d->debuggerEngine = debuggerEngine;
}
void QmlConsoleManager::setContext(const QString &context)
{
d->qmlConsolePane->setContext(context);
}
void QmlConsoleManager::printToConsolePane(QmlConsoleItem::ItemType itemType,
const QString &text, bool bringToForeground)
{
if (!d->qmlConsolePane)
return;
if (itemType == QmlConsoleItem::ErrorType)
bringToForeground = true;
if (bringToForeground)
d->qmlConsolePane->popup(Core::IOutputPane::ModeSwitch);
d->qmlConsoleItemModel->appendMessage(itemType, text);
}
void QmlConsoleManager::printToConsolePane(QmlConsoleItem *item, bool bringToForeground)
{
if (!d->qmlConsolePane)
return;
if (item->itemType == QmlConsoleItem::ErrorType)
bringToForeground = true;
if (bringToForeground)
d->qmlConsolePane->popup(Core::IOutputPane::ModeSwitch);
d->qmlConsoleItemModel->appendItem(item);
}
namespace Internal {
QmlConsoleItem *constructLogItemTree(QmlConsoleItem *parent, const QVariant &result,
const QString &key = QString())
{
if (!result.isValid())
return 0;
QmlConsoleItem *item = new QmlConsoleItem(parent);
if (result.type() == QVariant::Map) {
if (key.isEmpty())
item->setText(QLatin1String("Object"));
else
item->setText(key + QLatin1String(" : Object"));
QMapIterator<QString, QVariant> i(result.toMap());
while (i.hasNext()) {
i.next();
QmlConsoleItem *child = constructLogItemTree(item, i.value(), i.key());
if (child)
item->insertChild(child, true);
}
} else if (result.type() == QVariant::List) {
if (key.isEmpty())
item->setText(QLatin1String("List"));
else
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),
QString::number(i));
if (child)
item->insertChild(child, true);
}
} else if (result.canConvert(QVariant::String)) {
item->setText(result.toString());
} else {
item->setText(QLatin1String("Unknown Value"));
}
return item;
}
QmlConsoleItemModel *QmlConsoleModel::qmlConsoleItemModel()
{
QmlConsoleManager *manager = QmlConsoleManager::instance();
if (manager)
return manager->d->qmlConsoleItemModel;
return 0;
}
void QmlConsoleModel::evaluate(const QString &expression)
{
QmlConsoleManager *manager = QmlConsoleManager::instance();
if (manager) {
if (manager->d->debuggerEngine) {
QmlConsoleModel::qmlConsoleItemModel()->appendEditableRow();
manager->d->debuggerEngine->evaluateScriptExpression(expression);
} else {
QVariant result = manager->d->scriptEngine->evaluate(expression).toVariant();
QmlConsoleItem *root = manager->rootItem();
QmlConsoleItem *item = constructLogItemTree(root, result);
if (item) {
QmlConsoleModel::qmlConsoleItemModel()->appendEditableRow();
manager->printToConsolePane(item);
}
}
}
}
} // Internal
} // QmlJSTools

View File

@@ -0,0 +1,59 @@
#ifndef QMLCONSOLEMANAGER_H
#define QMLCONSOLEMANAGER_H
#include "qmljstools_global.h"
#include "qmlconsoleitem.h"
#include <QObject>
namespace Debugger {
class DebuggerEngine;
}
namespace QmlJSTools {
namespace Internal {
class QmlConsoleItemModel;
class QmlConsoleModel;
}
class QmlConsoleManagerPrivate;
class QMLJSTOOLS_EXPORT QmlConsoleManager : public QObject
{
Q_OBJECT
public:
QmlConsoleManager(QObject *parent);
~QmlConsoleManager();
static QmlConsoleManager *instance() { return m_instance; }
void showConsolePane();
QmlConsoleItem *rootItem() const;
void setDebuggerEngine(Debugger::DebuggerEngine *debuggerEngine);
void setContext(const QString &context);
void printToConsolePane(QmlConsoleItem::ItemType itemType, const QString &text,
bool bringToForeground = false);
void printToConsolePane(QmlConsoleItem *item, bool bringToForeground = false);
private:
QmlConsoleManagerPrivate *d;
static QmlConsoleManager *m_instance;
friend class Internal::QmlConsoleModel;
};
namespace Internal {
class QmlConsoleModel
{
public:
static QmlConsoleItemModel *qmlConsoleItemModel();
static void evaluate(const QString &expression);
};
}
} // namespace QmlJSTools
#endif // QMLCONSOLEMANAGER_H

View File

@@ -0,0 +1,215 @@
#include "qmlconsolepane.h"
#include "qmlconsoleview.h"
#include "qmlconsoleproxymodel.h"
#include "qmlconsoleitemmodel.h"
#include "qmlconsolemanager.h"
#include "qmlconsoleitemdelegate.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/findplaceholder.h>
#include <utils/savedaction.h>
#include <aggregation/aggregate.h>
#include <find/treeviewfind.h>
#include <QToolButton>
#include <QLabel>
#include <QVBoxLayout>
static const char CONSOLE[] = "Console";
static const char SHOW_LOG[] = "showLog";
static const char SHOW_WARNING[] = "showWarning";
static const char SHOW_ERROR[] = "showError";
namespace QmlJSTools {
namespace Internal {
/////////////////////////////////////////////////////////////////////
//
// QmlConsolePane
//
/////////////////////////////////////////////////////////////////////
QmlConsolePane::QmlConsolePane(QObject *parent)
: Core::IOutputPane(parent)
{
m_consoleWidget = new QWidget;
m_consoleWidget->setWindowTitle(displayName());
m_consoleWidget->setEnabled(true);
QVBoxLayout *vbox = new QVBoxLayout(m_consoleWidget);
vbox->setMargin(0);
vbox->setSpacing(0);
m_consoleView = new QmlConsoleView(m_consoleWidget);
m_proxyModel = new QmlConsoleProxyModel(this);
m_proxyModel->setSourceModel(QmlConsoleModel::qmlConsoleItemModel());
connect(QmlConsoleModel::qmlConsoleItemModel(),
SIGNAL(selectEditableRow(QModelIndex, QItemSelectionModel::SelectionFlags)),
m_proxyModel,
SLOT(selectEditableRow(QModelIndex,QItemSelectionModel::SelectionFlags)));
//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.
connect(QmlConsoleModel::qmlConsoleItemModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
m_proxyModel, SLOT(onRowsInserted(QModelIndex,int,int)));
m_consoleView->setModel(m_proxyModel);
connect(m_proxyModel,
SIGNAL(setCurrentIndex(QModelIndex,QItemSelectionModel::SelectionFlags)),
m_consoleView->selectionModel(),
SLOT(setCurrentIndex(QModelIndex,QItemSelectionModel::SelectionFlags)));
connect(m_proxyModel, SIGNAL(scrollToBottom()), m_consoleView, SLOT(onScrollToBottom()));
m_itemDelegate = new QmlConsoleItemDelegate(this);
connect(m_consoleView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
m_itemDelegate, SLOT(currentChanged(QModelIndex,QModelIndex)));
m_consoleView->setItemDelegate(m_itemDelegate);
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate();
aggregate->add(m_consoleView);
aggregate->add(new Find::TreeViewFind(m_consoleView));
vbox->addWidget(m_consoleView);
vbox->addWidget(new Core::FindToolBarPlaceHolder(m_consoleWidget));
m_showDebugButton = new QToolButton(m_consoleWidget);
m_showDebugButton->setAutoRaise(true);
m_showDebugButtonAction = new Utils::SavedAction(this);
m_showDebugButtonAction->setDefaultValue(true);
m_showDebugButtonAction->setSettingsKey(QLatin1String(CONSOLE), QLatin1String(SHOW_LOG));
m_showDebugButtonAction->setToolTip(tr("Show debug, log, and info messages."));
m_showDebugButtonAction->setCheckable(true);
m_showDebugButtonAction->setIcon(QIcon(QLatin1String(":/qmljstools/images/log.png")));
connect(m_showDebugButtonAction, SIGNAL(toggled(bool)), m_proxyModel, SLOT(setShowLogs(bool)));
m_showDebugButton->setDefaultAction(m_showDebugButtonAction);
m_showWarningButton = new QToolButton(m_consoleWidget);
m_showWarningButton->setAutoRaise(true);
m_showWarningButtonAction = new Utils::SavedAction(this);
m_showWarningButtonAction->setDefaultValue(true);
m_showWarningButtonAction->setSettingsKey(QLatin1String(CONSOLE), QLatin1String(SHOW_WARNING));
m_showWarningButtonAction->setToolTip(tr("Show debug, log, and info messages."));
m_showWarningButtonAction->setCheckable(true);
m_showWarningButtonAction->setIcon(QIcon(QLatin1String(":/qmljstools/images/warning.png")));
connect(m_showWarningButtonAction, SIGNAL(toggled(bool)), m_proxyModel,
SLOT(setShowWarnings(bool)));
m_showWarningButton->setDefaultAction(m_showWarningButtonAction);
m_showErrorButton = new QToolButton(m_consoleWidget);
m_showErrorButton->setAutoRaise(true);
m_showErrorButtonAction = new Utils::SavedAction(this);
m_showErrorButtonAction->setDefaultValue(true);
m_showErrorButtonAction->setSettingsKey(QLatin1String(CONSOLE), QLatin1String(SHOW_ERROR));
m_showErrorButtonAction->setToolTip(tr("Show debug, log, and info messages."));
m_showErrorButtonAction->setCheckable(true);
m_showErrorButtonAction->setIcon(QIcon(QLatin1String(":/qmljstools/images/error.png")));
connect(m_showErrorButtonAction, SIGNAL(toggled(bool)), m_proxyModel,
SLOT(setShowErrors(bool)));
m_showErrorButton->setDefaultAction(m_showErrorButtonAction);
m_spacer = new QWidget(m_consoleWidget);
m_spacer->setMinimumWidth(30);
m_statusLabel = new QLabel(m_consoleWidget);
readSettings();
connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), SLOT(writeSettings()));
}
QmlConsolePane::~QmlConsolePane()
{
writeSettings();
delete m_consoleWidget;
}
QWidget *QmlConsolePane::outputWidget(QWidget *)
{
return m_consoleWidget;
}
QList<QWidget *> QmlConsolePane::toolBarWidgets() const
{
return QList<QWidget *>() << m_showDebugButton << m_showWarningButton << m_showErrorButton
<< m_spacer << m_statusLabel;
}
int QmlConsolePane::priorityInStatusBar() const
{
return 20;
}
void QmlConsolePane::clearContents()
{
QmlConsoleModel::qmlConsoleItemModel()->clear();
}
void QmlConsolePane::visibilityChanged(bool /*visible*/)
{
}
bool QmlConsolePane::canFocus() const
{
return true;
}
bool QmlConsolePane::hasFocus() const
{
return m_consoleWidget->hasFocus();
}
void QmlConsolePane::setFocus()
{
m_consoleWidget->setFocus();
}
bool QmlConsolePane::canNext() const
{
return false;
}
bool QmlConsolePane::canPrevious() const
{
return false;
}
void QmlConsolePane::goToNext()
{
}
void QmlConsolePane::goToPrev()
{
}
bool QmlConsolePane::canNavigate() const
{
return false;
}
void QmlConsolePane::readSettings()
{
QSettings *settings = Core::ICore::settings();
m_showDebugButtonAction->readSettings(settings);
m_showWarningButtonAction->readSettings(settings);
m_showErrorButtonAction->readSettings(settings);
}
void QmlConsolePane::setContext(const QString &context)
{
m_statusLabel->setText(context);
}
void QmlConsolePane::writeSettings() const
{
QSettings *settings = Core::ICore::settings();
m_showDebugButtonAction->writeSettings(settings);
m_showWarningButtonAction->writeSettings(settings);
m_showErrorButtonAction->writeSettings(settings);
}
} // Internal
} // QmlJSTools

View File

@@ -0,0 +1,71 @@
#ifndef QMLCONSOLEPANE_H
#define QMLCONSOLEPANE_H
#include <coreplugin/ioutputpane.h>
QT_BEGIN_NAMESPACE
class QToolButton;
class QLabel;
QT_END_NAMESPACE
namespace Utils {
class SavedAction;
}
namespace QmlJSTools {
namespace Internal {
class QmlConsoleView;
class QmlConsoleItemDelegate;
class QmlConsoleProxyModel;
class QmlConsoleItemModel;
class QmlConsolePane : public Core::IOutputPane
{
Q_OBJECT
public:
QmlConsolePane(QObject *parent);
~QmlConsolePane();
QWidget *outputWidget(QWidget *);
QList<QWidget *> toolBarWidgets() const;
QString displayName() const { return tr("Console"); }
int priorityInStatusBar() const;
void clearContents();
void visibilityChanged(bool visible);
bool canFocus() const;
bool hasFocus() const;
void setFocus();
bool canNext() const;
bool canPrevious() const;
void goToNext();
void goToPrev();
bool canNavigate() const;
void readSettings();
void setContext(const QString &context);
public slots:
void writeSettings() const;
private:
QToolButton *m_showDebugButton;
QToolButton *m_showWarningButton;
QToolButton *m_showErrorButton;
Utils::SavedAction *m_showDebugButtonAction;
Utils::SavedAction *m_showWarningButtonAction;
Utils::SavedAction *m_showErrorButtonAction;
QWidget *m_spacer;
QLabel *m_statusLabel;
QmlConsoleView *m_consoleView;
QmlConsoleItemDelegate *m_itemDelegate;
QmlConsoleProxyModel *m_proxyModel;
QWidget *m_consoleWidget;
};
} // namespace Internal
} // namespace QmlJSTools
#endif // QMLCONSOLEPANE_H

View File

@@ -0,0 +1,58 @@
#include "qmlconsoleproxymodel.h"
#include "qmlconsoleitemmodel.h"
namespace QmlJSTools {
namespace Internal {
QmlConsoleProxyModel::QmlConsoleProxyModel(QObject *parent) :
QSortFilterProxyModel(parent),
m_filter(QmlConsoleItem::DefaultTypes)
{
}
void QmlConsoleProxyModel::setShowLogs(bool show)
{
m_filter = show ? m_filter | QmlConsoleItem::DebugType : m_filter & ~QmlConsoleItem::DebugType;
setFilterRegExp(QString());
}
void QmlConsoleProxyModel::setShowWarnings(bool show)
{
m_filter = show ? m_filter | QmlConsoleItem::WarningType
: m_filter & ~QmlConsoleItem::WarningType;
setFilterRegExp(QString());
}
void QmlConsoleProxyModel::setShowErrors(bool show)
{
m_filter = show ? m_filter | QmlConsoleItem::ErrorType : m_filter & ~QmlConsoleItem::ErrorType;
setFilterRegExp(QString());
}
void QmlConsoleProxyModel::selectEditableRow(const QModelIndex &index,
QItemSelectionModel::SelectionFlags command)
{
emit setCurrentIndex(mapFromSource(index), command);
}
bool QmlConsoleProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return m_filter.testFlag((QmlConsoleItem::ItemType)sourceModel()->data(
index, QmlConsoleItemModel::TypeRole).toInt());
}
void QmlConsoleProxyModel::onRowsInserted(const QModelIndex &index, int start, int end)
{
int rowIndex = end;
do {
if (filterAcceptsRow(rowIndex, index)) {
emit scrollToBottom();
break;
}
} while (--rowIndex >= start);
}
} // Internal
} // QmlJSTools

View File

@@ -0,0 +1,41 @@
#ifndef QMLCONSOLEPROXYMODEL_H
#define QMLCONSOLEPROXYMODEL_H
#include "qmlconsoleitem.h"
#include <QSortFilterProxyModel>
#include <QItemSelectionModel>
namespace QmlJSTools {
namespace Internal {
class QmlConsoleProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit QmlConsoleProxyModel(QObject *parent);
public slots:
void setShowLogs(bool show);
void setShowWarnings(bool show);
void setShowErrors(bool show);
void selectEditableRow(const QModelIndex &index,
QItemSelectionModel::SelectionFlags command);
void onRowsInserted(const QModelIndex &index, int start, int end);
signals:
void scrollToBottom();
void setCurrentIndex(const QModelIndex &index,
QItemSelectionModel::SelectionFlags command);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
private:
QFlags<QmlConsoleItem::ItemType> m_filter;
};
} // Internal
} // QmlJSTools
#endif // QMLCONSOLEPROXYMODEL_H

View File

@@ -1,39 +1,6 @@
/************************************************************************** #include "qmlconsoleview.h"
** #include "qmlconsoleitemdelegate.h"
** This file is part of Qt Creator #include "qmlconsoleitemmodel.h"
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "qtmessagelogview.h"
#include "qtmessagelogitemdelegate.h"
#include "qtmessageloghandler.h"
#include "debuggerstringutils.h"
#include "debuggercore.h"
#include "debuggerengine.h"
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
@@ -47,24 +14,20 @@
#include <QUrl> #include <QUrl>
#include <QScrollBar> #include <QScrollBar>
namespace Debugger { namespace QmlJSTools {
namespace Internal { namespace Internal {
class QtMessageLogViewViewStyle : public QProxyStyle class QmlConsoleViewStyle : public QProxyStyle
{ {
public: public:
void drawPrimitive(PrimitiveElement element, void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter,
const QStyleOption *option,
QPainter *painter,
const QWidget *widget = 0) const const QWidget *widget = 0) const
{ {
if (element != QStyle::PE_PanelItemViewRow) if (element != QStyle::PE_PanelItemViewRow)
QProxyStyle::drawPrimitive(element, option, painter, widget); QProxyStyle::drawPrimitive(element, option, painter, widget);
} }
int styleHint(StyleHint hint, int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0,
const QStyleOption *option = 0,
const QWidget *widget = 0,
QStyleHintReturn *returnData = 0) const { QStyleHintReturn *returnData = 0) const {
if (hint == SH_ItemView_ShowDecorationSelected) if (hint == SH_ItemView_ShowDecorationSelected)
return 0; return 0;
@@ -75,11 +38,11 @@ public:
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
// QtMessageLogView // QmlConsoleView
// //
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
QtMessageLogView::QtMessageLogView(QWidget *parent) : QmlConsoleView::QmlConsoleView(QWidget *parent) :
QTreeView(parent) QTreeView(parent)
{ {
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
@@ -103,36 +66,35 @@ QtMessageLogView::QtMessageLogView(QWidget *parent) :
"QTreeView::branch:open:has-children:has-siblings {" "QTreeView::branch:open:has-children:has-siblings {"
"border-image: none;" "border-image: none;"
"image: none; }")); "image: none; }"));
QtMessageLogViewViewStyle *style = new QtMessageLogViewViewStyle; QmlConsoleViewStyle *style = new QmlConsoleViewStyle;
setStyle(style); setStyle(style);
style->setParent(this); style->setParent(this);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
connect(this, SIGNAL(activated(QModelIndex)), connect(this, SIGNAL(activated(QModelIndex)), SLOT(onRowActivated(QModelIndex)));
SLOT(onRowActivated(QModelIndex)));
} }
void QtMessageLogView::onScrollToBottom() void QmlConsoleView::onScrollToBottom()
{ {
//Keep scrolling to bottom if scroll bar is at maximum() // Keep scrolling to bottom if scroll bar is at maximum()
if (verticalScrollBar()->value() == verticalScrollBar()->maximum()) if (verticalScrollBar()->value() == verticalScrollBar()->maximum())
scrollToBottom(); scrollToBottom();
} }
void QtMessageLogView::mousePressEvent(QMouseEvent *event) void QmlConsoleView::mousePressEvent(QMouseEvent *event)
{ {
QPoint pos = event->pos(); QPoint pos = event->pos();
QModelIndex index = indexAt(pos); QModelIndex index = indexAt(pos);
if (index.isValid()) { if (index.isValid()) {
QtMessageLogHandler::ItemType type = (QtMessageLogHandler::ItemType)index.data( QmlConsoleItem::ItemType type = (QmlConsoleItem::ItemType)index.data(
QtMessageLogHandler::TypeRole).toInt(); QmlConsoleItemModel::TypeRole).toInt();
bool handled = false; bool handled = false;
if (type == QtMessageLogHandler::UndefinedType) { if (type == QmlConsoleItem::UndefinedType) {
bool showTypeIcon = index.parent() == QModelIndex(); bool showTypeIcon = index.parent() == QModelIndex();
ConsoleItemPositions positions(visualRect(index), viewOptions().font, ConsoleItemPositions positions(visualRect(index), viewOptions().font, showTypeIcon,
showTypeIcon, true); true);
if (positions.expandCollapseIcon().contains(pos)) { if (positions.expandCollapseIcon().contains(pos)) {
if (isExpanded(index)) if (isExpanded(index))
@@ -145,13 +107,12 @@ void QtMessageLogView::mousePressEvent(QMouseEvent *event)
if (!handled) if (!handled)
QTreeView::mousePressEvent(event); QTreeView::mousePressEvent(event);
} else { } else {
selectionModel()->setCurrentIndex(model()->index( selectionModel()->setCurrentIndex(model()->index(model()->rowCount() - 1, 0),
model()->rowCount() - 1, 0), QItemSelectionModel::ClearAndSelect);
QItemSelectionModel::ClearAndSelect);
} }
} }
void QtMessageLogView::keyPressEvent(QKeyEvent *e) void QmlConsoleView::keyPressEvent(QKeyEvent *e)
{ {
if (!e->modifiers() && e->key() == Qt::Key_Return) { if (!e->modifiers() && e->key() == Qt::Key_Return) {
emit activated(currentIndex()); emit activated(currentIndex());
@@ -161,22 +122,22 @@ void QtMessageLogView::keyPressEvent(QKeyEvent *e)
QTreeView::keyPressEvent(e); QTreeView::keyPressEvent(e);
} }
void QtMessageLogView::resizeEvent(QResizeEvent *e) void QmlConsoleView::resizeEvent(QResizeEvent *e)
{ {
static_cast<QtMessageLogItemDelegate *>(itemDelegate())->emitSizeHintChanged( static_cast<QmlConsoleItemDelegate *>(itemDelegate())->emitSizeHintChanged(
selectionModel()->currentIndex()); selectionModel()->currentIndex());
QTreeView::resizeEvent(e); QTreeView::resizeEvent(e);
} }
void QtMessageLogView::drawBranches(QPainter *painter, const QRect &rect, void QmlConsoleView::drawBranches(QPainter *painter, const QRect &rect,
const QModelIndex &index) const const QModelIndex &index) const
{ {
static_cast<QtMessageLogItemDelegate *>(itemDelegate())->drawBackground( static_cast<QmlConsoleItemDelegate *>(itemDelegate())->drawBackground(painter, rect, index,
painter, rect, index, false); false);
QTreeView::drawBranches(painter, rect, index); QTreeView::drawBranches(painter, rect, index);
} }
void QtMessageLogView::contextMenuEvent(QContextMenuEvent *event) void QmlConsoleView::contextMenuEvent(QContextMenuEvent *event)
{ {
QModelIndex itemIndex = indexAt(event->pos()); QModelIndex itemIndex = indexAt(event->pos());
QMenu menu; QMenu menu;
@@ -195,69 +156,59 @@ void QtMessageLogView::contextMenuEvent(QContextMenuEvent *event)
if (a == 0) if (a == 0)
return; return;
if (a == copy) if (a == copy) {
copyToClipboard(itemIndex); copyToClipboard(itemIndex);
else if (a == show) } else if (a == show) {
onRowActivated(itemIndex); onRowActivated(itemIndex);
else if (a == clear) { } else if (a == clear) {
QAbstractProxyModel *proxyModel = QAbstractProxyModel *proxyModel = qobject_cast<QAbstractProxyModel *>(model());
qobject_cast<QAbstractProxyModel *>(model()); QmlConsoleItemModel *handler = qobject_cast<QmlConsoleItemModel *>(
QtMessageLogHandler *handler = proxyModel->sourceModel());
qobject_cast<QtMessageLogHandler *>(proxyModel->sourceModel());
handler->clear(); handler->clear();
} }
} }
void QtMessageLogView::onRowActivated(const QModelIndex &index) void QmlConsoleView::onRowActivated(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid())
return; return;
//See if we have file and line Info // See if we have file and line Info
QString filePath = model()->data(index, QString filePath = model()->data(index,
QtMessageLogHandler::FileRole).toString(); QmlConsoleItemModel::FileRole).toString();
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {
filePath = debuggerCore()->currentEngine()->toFileInProject(
QUrl(filePath));
QFileInfo fi(filePath); QFileInfo fi(filePath);
if (fi.exists() && fi.isFile() && fi.isReadable()) { if (fi.exists() && fi.isFile() && fi.isReadable()) {
int line = model()->data(index, int line = model()->data(index, QmlConsoleItemModel::LineRole).toInt();
QtMessageLogHandler::LineRole).toInt(); TextEditor::BaseTextEditorWidget::openEditorAt(fi.canonicalFilePath(), line);
TextEditor::BaseTextEditorWidget::openEditorAt(
fi.canonicalFilePath(), line);
} }
} }
} }
void QtMessageLogView::copyToClipboard(const QModelIndex &index) void QmlConsoleView::copyToClipboard(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid())
return; return;
QString contents = model()->data(index).toString(); QString contents = model()->data(index).toString();
//See if we have file and line Info // See if we have file and line Info
QString filePath = model()->data(index, QString filePath = model()->data(index, QmlConsoleItemModel::FileRole).toString();
QtMessageLogHandler::FileRole).toString();
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {
contents = QString(_("%1 %2: %3")).arg(contents).arg(filePath).arg( contents = QString(QLatin1String("%1 %2: %3")).arg(contents).arg(filePath).arg(
model()->data(index, model()->data(index, QmlConsoleItemModel::LineRole).toString());
QtMessageLogHandler::LineRole).toString());
} }
QClipboard *cb = QApplication::clipboard(); QClipboard *cb = QApplication::clipboard();
cb->setText(contents); cb->setText(contents);
} }
bool QtMessageLogView::canShowItemInTextEditor(const QModelIndex &index) bool QmlConsoleView::canShowItemInTextEditor(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid())
return false; return false;
//See if we have file and line Info // See if we have file and line Info
QString filePath = model()->data(index, QString filePath = model()->data(index, QmlConsoleItemModel::FileRole).toString();
QtMessageLogHandler::FileRole).toString();
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {
filePath = debuggerCore()->currentEngine()->toFileInProject(
QUrl(filePath));
QFileInfo fi(filePath); QFileInfo fi(filePath);
if (fi.exists() && fi.isFile() && fi.isReadable()) { if (fi.exists() && fi.isFile() && fi.isReadable()) {
return true; return true;
@@ -266,5 +217,5 @@ bool QtMessageLogView::canShowItemInTextEditor(const QModelIndex &index)
return false; return false;
} }
} //Internal } // Internal
} //Debugger } // QmlJSTools

View File

@@ -0,0 +1,37 @@
#ifndef QMLCONSOLEVIEW_H
#define QMLCONSOLEVIEW_H
#include <QTreeView>
namespace QmlJSTools {
namespace Internal {
class QmlConsoleView : public QTreeView
{
Q_OBJECT
public:
QmlConsoleView(QWidget *parent);
public slots:
void onScrollToBottom();
protected:
void mousePressEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *e);
void resizeEvent(QResizeEvent *e);
void drawBranches(QPainter *painter, const QRect &rect,
const QModelIndex &index) const;
void contextMenuEvent(QContextMenuEvent *event);
private slots:
void onRowActivated(const QModelIndex &index);
private:
void copyToClipboard(const QModelIndex &index);
bool canShowItemInTextEditor(const QModelIndex &index);
};
} // Internal
} // QmlJSTools
#endif // QMLCONSOLEVIEW_H

View File

@@ -0,0 +1,58 @@
#include "qmljsinterpreter.h"
namespace QmlJSTools {
namespace Internal {
bool QmlJSInterpreter::canEvaluate()
{
int yyaction = 0;
int yytoken = -1;
int yytos = -1;
setCode(m_code, 1);
m_tokens.append(T_FEED_JS_PROGRAM);
do {
if (++yytos == m_stateStack.size())
m_stateStack.resize(m_stateStack.size() * 2);
m_stateStack[yytos] = yyaction;
again:
if (yytoken == -1 && action_index[yyaction] != -TERMINAL_COUNT) {
if (m_tokens.isEmpty())
yytoken = lex();
else
yytoken = m_tokens.takeFirst();
}
yyaction = t_action(yyaction, yytoken);
if (yyaction > 0) {
if (yyaction == ACCEPT_STATE) {
--yytos;
return true;
}
yytoken = -1;
} else if (yyaction < 0) {
const int ruleno = -yyaction - 1;
yytos -= rhs[ruleno];
yyaction = nt_action(m_stateStack[yytos], lhs[ruleno] - TERMINAL_COUNT);
}
} while (yyaction);
const int errorState = m_stateStack[yytos];
if (t_action(errorState, T_AUTOMATIC_SEMICOLON) && canInsertAutomaticSemicolon(yytoken)) {
yyaction = errorState;
m_tokens.prepend(yytoken);
yytoken = T_SEMICOLON;
goto again;
}
if (yytoken != EOF_SYMBOL)
return true;
return false;
}
} // namespace Internal
} // namespace QmlJSTools

View File

@@ -0,0 +1,40 @@
#ifndef QMLJSINTERPRETER_H
#define QMLJSINTERPRETER_H
#include <qmljs/parser/qmljslexer_p.h>
#include <qmljs/parser/qmljsengine_p.h>
#include <QVector>
#include <QString>
#include <QList>
namespace QmlJSTools {
namespace Internal {
class QmlJSInterpreter: QmlJS::Lexer
{
public:
QmlJSInterpreter()
: Lexer(&m_engine),
m_stateStack(128)
{
}
void clearText() { m_code.clear(); }
void appendText(const QString &text) { m_code += text; }
QString code() const { return m_code; }
bool canEvaluate();
private:
QmlJS::Engine m_engine;
QVector<int> m_stateStack;
QList<int> m_tokens;
QString m_code;
};
} // namespace Internal
} // namespace QmlJSTools
#endif // QMLJSINTERPRETER_H

View File

@@ -1,45 +0,0 @@
!dll {
DEFINES += QMLJSTOOLS_STATIC
}
INCLUDEPATH += $$PWD/..
HEADERS += \
$$PWD/qmljstools_global.h \
$$PWD/qmljstoolsplugin.h \
$$PWD/qmljstoolsconstants.h \
$$PWD/qmljstoolssettings.h \
$$PWD/qmljscodestylepreferencesfactory.h \
$$PWD/qmljsmodelmanager.h \
$$PWD/qmljsqtstylecodeformatter.h \
$$PWD/qmljsrefactoringchanges.h \
$$PWD/qmljsplugindumper.h \
$$PWD/qmljsfunctionfilter.h \
$$PWD/qmljslocatordata.h \
$$PWD/qmljsindenter.h \
$$PWD/qmljscodestylesettingspage.h \
$$PWD/qmljsfindexportedcpptypes.h \
$$PWD/qmljssemanticinfo.h
SOURCES += \
$$PWD/qmljstoolsplugin.cpp \
$$PWD/qmljstoolssettings.cpp \
$$PWD/qmljscodestylepreferencesfactory.cpp \
$$PWD/qmljsmodelmanager.cpp \
$$PWD/qmljsqtstylecodeformatter.cpp \
$$PWD/qmljsrefactoringchanges.cpp \
$$PWD/qmljsplugindumper.cpp \
$$PWD/qmljsfunctionfilter.cpp \
$$PWD/qmljslocatordata.cpp \
$$PWD/qmljsindenter.cpp \
$$PWD/qmljscodestylesettingspage.cpp \
$$PWD/qmljsfindexportedcpptypes.cpp \
$$PWD/qmljssemanticinfo.cpp
FORMS += \
$$PWD/qmljscodestylesettingspage.ui
equals(TEST, 1) {
SOURCES += \
$$PWD/qmljstools_test.cpp
}

View File

@@ -1,5 +1,3 @@
include(qmljstools_dependencies.pri) include(qmljstools_dependencies.pri)
INCLUDEPATH *= $$PWD/..
LIBS *= -l$$qtLibraryName(QmlJSTools) LIBS *= -l$$qtLibraryName(QmlJSTools)

View File

@@ -7,4 +7,69 @@ include(qmljstools_dependencies.pri)
DEFINES += QT_NO_CAST_TO_ASCII DEFINES += QT_NO_CAST_TO_ASCII
DEFINES += QMLJSTOOLS_LIBRARY DEFINES += QMLJSTOOLS_LIBRARY
include(qmljstools-lib.pri) !dll {
DEFINES += QMLJSTOOLS_STATIC
}
QT += script
HEADERS += \
$$PWD/qmljstoolsplugin.h \
$$PWD/qmljstoolsconstants.h \
$$PWD/qmljstoolssettings.h \
$$PWD/qmljscodestylepreferencesfactory.h \
$$PWD/qmljsmodelmanager.h \
$$PWD/qmljsqtstylecodeformatter.h \
$$PWD/qmljsrefactoringchanges.h \
$$PWD/qmljsplugindumper.h \
$$PWD/qmljsfunctionfilter.h \
$$PWD/qmljslocatordata.h \
$$PWD/qmljsindenter.h \
$$PWD/qmljscodestylesettingspage.h \
$$PWD/qmljsfindexportedcpptypes.h \
$$PWD/qmljssemanticinfo.h \
$$PWD/qmljstools_global.h \
$$PWD/qmlconsolemanager.h \
$$PWD/qmlconsoleitem.h \
$$PWD/qmlconsoleitemmodel.h \
$$PWD/qmlconsolepane.h \
$$PWD/qmlconsoleview.h \
$$PWD/qmlconsoleitemdelegate.h \
$$PWD/qmlconsoleedit.h \
$$PWD/qmljsinterpreter.h \
$$PWD/qmlconsoleproxymodel.h
SOURCES += \
$$PWD/qmljstoolsplugin.cpp \
$$PWD/qmljstoolssettings.cpp \
$$PWD/qmljscodestylepreferencesfactory.cpp \
$$PWD/qmljsmodelmanager.cpp \
$$PWD/qmljsqtstylecodeformatter.cpp \
$$PWD/qmljsrefactoringchanges.cpp \
$$PWD/qmljsplugindumper.cpp \
$$PWD/qmljsfunctionfilter.cpp \
$$PWD/qmljslocatordata.cpp \
$$PWD/qmljsindenter.cpp \
$$PWD/qmljscodestylesettingspage.cpp \
$$PWD/qmljsfindexportedcpptypes.cpp \
$$PWD/qmljssemanticinfo.cpp \
$$PWD/qmlconsolemanager.cpp \
$$PWD/qmlconsoleitem.cpp \
$$PWD/qmlconsoleitemmodel.cpp \
$$PWD/qmlconsolepane.cpp \
$$PWD/qmlconsoleview.cpp \
$$PWD/qmlconsoleitemdelegate.cpp \
$$PWD/qmlconsoleedit.cpp \
$$PWD/qmljsinterpreter.cpp \
$$PWD/qmlconsoleproxymodel.cpp
RESOURCES += \
qmljstools.qrc
FORMS += \
$$PWD/qmljscodestylesettingspage.ui
equals(TEST, 1) {
SOURCES += \
$$PWD/qmljstools_test.cpp
}

View File

@@ -53,6 +53,25 @@ QtcPlugin {
"qmljstoolsplugin.h", "qmljstoolsplugin.h",
"qmljstoolssettings.cpp", "qmljstoolssettings.cpp",
"qmljstoolssettings.h", "qmljstoolssettings.h",
"qmlconsolemanager.cpp",
"qmlconsolemanager.h",
"qmlconsoleitem.cpp",
"qmlconsoleitem.h",
"qmlcomsoleitemmodel.cpp",
"qmlconsoleitemmodel.h",
"qmlconsolepane.cpp",
"qmlconsolepane.h",
"qmlconsoleview.cpp",
"qmlconsoleview.h",
"qmlconsoleitemdelegate.cpp",
"qmlconsoleitemdelegate.h",
"qmlconsoleedit.cpp",
"qmlconsoleedit.h",
"qmljsinterpreter.cpp",
"qmljsinterpreter.h",
"qmljsconsoleproxymodel.cpp",
"qmljsconsoleproxymodel.h",
"qmljstools.qrc"
] ]
Group { Group {

View File

@@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/qmljstools">
<file>images/prompt.png</file>
<file>images/collapse.png</file>
<file>images/warning.png</file>
<file>images/log.png</file>
<file>images/expand.png</file>
<file>images/error.png</file>
</qresource>
</RCC>

View File

@@ -35,6 +35,7 @@
#include "qmljscodestylesettingspage.h" #include "qmljscodestylesettingspage.h"
#include "qmljstoolsconstants.h" #include "qmljstoolsconstants.h"
#include "qmljstoolssettings.h" #include "qmljstoolssettings.h"
#include "qmlconsolemanager.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
@@ -52,6 +53,7 @@
#include <QSettings> #include <QSettings>
#include <QMenu> #include <QMenu>
using namespace QmlJSTools;
using namespace QmlJSTools::Internal; using namespace QmlJSTools::Internal;
enum { debug = 0 }; enum { debug = 0 };
@@ -68,6 +70,7 @@ QmlJSToolsPlugin::~QmlJSToolsPlugin()
{ {
m_instance = 0; m_instance = 0;
m_modelManager = 0; // deleted automatically m_modelManager = 0; // deleted automatically
m_consoleManager = 0; // deleted automatically
} }
bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error) bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
@@ -79,6 +82,8 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
// Objects // Objects
m_modelManager = new ModelManager(this); m_modelManager = new ModelManager(this);
m_consoleManager = new QmlConsoleManager(this);
// Core::VCSManager *vcsManager = core->vcsManager(); // Core::VCSManager *vcsManager = core->vcsManager();
// Core::DocumentManager *fileManager = core->fileManager(); // Core::DocumentManager *fileManager = core->fileManager();
// connect(vcsManager, SIGNAL(repositoryChanged(QString)), // connect(vcsManager, SIGNAL(repositoryChanged(QString)),

View File

@@ -46,6 +46,7 @@ QT_END_NAMESPACE
namespace QmlJSTools { namespace QmlJSTools {
class QmlJSToolsSettings; class QmlJSToolsSettings;
class QmlConsoleManager;
namespace Internal { namespace Internal {
@@ -77,6 +78,7 @@ private slots:
private: private:
ModelManager *m_modelManager; ModelManager *m_modelManager;
QmlConsoleManager *m_consoleManager;
QmlJSToolsSettings *m_settings; QmlJSToolsSettings *m_settings;
QAction *m_resetCodeModelAction; QAction *m_resetCodeModelAction;