Commit 7862e312 authored by dt's avatar dt

Refactor OutputFormatter

Move link handling code to outputwindow from OutputFormatter

Move createOutputFormatter to the RunConfiguration

That makes it easier for Qt4RunConfiguration et all.
This also fixes that each time a runcontrol was rerun a new
OutputFormatter was created without deleting the old one, thus
increasing the memory usage.
parent 4e6c8e38
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace TextEditor; using namespace TextEditor;
OutputFormatter::OutputFormatter(QObject *parent) OutputFormatter::OutputFormatter()
: QObject(parent) : QObject()
, m_formats(0) , m_formats(0)
{ {
initFormats(); initFormats();
...@@ -58,7 +58,6 @@ QPlainTextEdit *OutputFormatter::plainTextEdit() const ...@@ -58,7 +58,6 @@ QPlainTextEdit *OutputFormatter::plainTextEdit() const
void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText) void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
{ {
m_plainTextEdit = plainText; m_plainTextEdit = plainText;
setParent(m_plainTextEdit);
} }
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr) void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
...@@ -83,15 +82,6 @@ void OutputFormatter::append(const QString &text, const QTextCharFormat &format) ...@@ -83,15 +82,6 @@ void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
cursor.insertText(text, format); cursor.insertText(text, format);
} }
void OutputFormatter::mousePressEvent(QMouseEvent * /*e*/)
{}
void OutputFormatter::mouseReleaseEvent(QMouseEvent * /*e*/)
{}
void OutputFormatter::mouseMoveEvent(QMouseEvent * /*e*/)
{}
void OutputFormatter::initFormats() void OutputFormatter::initFormats()
{ {
FontSettings fs = TextEditorSettings::instance()->fontSettings(); FontSettings fs = TextEditorSettings::instance()->fontSettings();
...@@ -117,3 +107,8 @@ void OutputFormatter::initFormats() ...@@ -117,3 +107,8 @@ void OutputFormatter::initFormats()
m_formats[StdErrFormat].setFont(font); m_formats[StdErrFormat].setFont(font);
m_formats[StdErrFormat].setForeground(QColor(200, 0, 0)); m_formats[StdErrFormat].setForeground(QColor(200, 0, 0));
} }
void OutputFormatter::handleLink(const QString &href)
{
Q_UNUSED(href);
}
...@@ -46,7 +46,7 @@ class PROJECTEXPLORER_EXPORT OutputFormatter: public QObject ...@@ -46,7 +46,7 @@ class PROJECTEXPLORER_EXPORT OutputFormatter: public QObject
Q_OBJECT Q_OBJECT
public: public:
OutputFormatter(QObject *parent = 0); OutputFormatter();
virtual ~OutputFormatter(); virtual ~OutputFormatter();
QPlainTextEdit *plainTextEdit() const; QPlainTextEdit *plainTextEdit() const;
...@@ -55,9 +55,7 @@ public: ...@@ -55,9 +55,7 @@ public:
virtual void appendApplicationOutput(const QString &text, bool onStdErr); virtual void appendApplicationOutput(const QString &text, bool onStdErr);
virtual void appendMessage(const QString &text, bool isError); virtual void appendMessage(const QString &text, bool isError);
virtual void mousePressEvent(QMouseEvent *e); virtual void handleLink(const QString &href);
virtual void mouseReleaseEvent(QMouseEvent *e);
virtual void mouseMoveEvent(QMouseEvent *e);
protected: protected:
enum Format { enum Format {
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <find/basetextfind.h> #include <find/basetextfind.h>
#include <aggregation/aggregate.h> #include <aggregation/aggregate.h>
#include <texteditor/basetexteditor.h>
#include <projectexplorer/project.h>
#include <QtGui/QIcon> #include <QtGui/QIcon>
#include <QtGui/QScrollBar> #include <QtGui/QScrollBar>
...@@ -211,7 +213,7 @@ void OutputPane::createNewOutputWindow(RunControl *rc) ...@@ -211,7 +213,7 @@ void OutputPane::createNewOutputWindow(RunControl *rc)
OutputWindow *ow = static_cast<OutputWindow *>(m_tabWidget->widget(i)); OutputWindow *ow = static_cast<OutputWindow *>(m_tabWidget->widget(i));
ow->grayOutOldContent(); ow->grayOutOldContent();
ow->verticalScrollBar()->setValue(ow->verticalScrollBar()->maximum()); ow->verticalScrollBar()->setValue(ow->verticalScrollBar()->maximum());
ow->setFormatter(rc->createOutputFormatter(ow)); ow->setFormatter(rc->outputFormatter());
m_outputWindows.insert(rc, ow); m_outputWindows.insert(rc, ow);
found = true; found = true;
break; break;
...@@ -219,7 +221,7 @@ void OutputPane::createNewOutputWindow(RunControl *rc) ...@@ -219,7 +221,7 @@ void OutputPane::createNewOutputWindow(RunControl *rc)
} }
if (!found) { if (!found) {
OutputWindow *ow = new OutputWindow(m_tabWidget); OutputWindow *ow = new OutputWindow(m_tabWidget);
ow->setFormatter(rc->createOutputFormatter(ow)); ow->setFormatter(rc->outputFormatter());
Aggregation::Aggregate *agg = new Aggregation::Aggregate; Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(ow); agg->add(ow);
agg->add(new Find::BaseTextFind(ow)); agg->add(new Find::BaseTextFind(ow));
...@@ -376,6 +378,8 @@ OutputWindow::OutputWindow(QWidget *parent) ...@@ -376,6 +378,8 @@ OutputWindow::OutputWindow(QWidget *parent)
: QPlainTextEdit(parent) : QPlainTextEdit(parent)
, m_enforceNewline(false) , m_enforceNewline(false)
, m_scrollToBottom(false) , m_scrollToBottom(false)
, m_linksActive(true)
, m_mousePressed(false)
{ {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
//setCenterOnScroll(false); //setCenterOnScroll(false);
...@@ -429,6 +433,42 @@ OutputWindow::~OutputWindow() ...@@ -429,6 +433,42 @@ OutputWindow::~OutputWindow()
delete m_outputWindowContext; delete m_outputWindowContext;
} }
void OutputWindow::mousePressEvent(QMouseEvent *e)
{
m_mousePressed = true;
QPlainTextEdit::mousePressEvent(e);
}
void OutputWindow::mouseReleaseEvent(QMouseEvent *e)
{
m_mousePressed = false;
if (!m_linksActive) {
// Mouse was released, activate links again
m_linksActive = true;
return;
}
const QString href = anchorAt(e->pos());
if (m_formatter)
m_formatter->handleLink(href);
QPlainTextEdit::mouseReleaseEvent(e);
}
void OutputWindow::mouseMoveEvent(QMouseEvent *e)
{
// Cursor was dragged to make a selection, deactivate links
if (m_mousePressed && textCursor().hasSelection())
m_linksActive = false;
if (!m_linksActive || anchorAt(e->pos()).isEmpty())
viewport()->setCursor(Qt::IBeamCursor);
else
viewport()->setCursor(Qt::PointingHandCursor);
QPlainTextEdit::mouseMoveEvent(e);
}
OutputFormatter *OutputWindow::formatter() const OutputFormatter *OutputWindow::formatter() const
{ {
return m_formatter; return m_formatter;
...@@ -554,21 +594,3 @@ void OutputWindow::enableUndoRedo() ...@@ -554,21 +594,3 @@ void OutputWindow::enableUndoRedo()
setMaximumBlockCount(0); setMaximumBlockCount(0);
setUndoRedoEnabled(true); setUndoRedoEnabled(true);
} }
void OutputWindow::mousePressEvent(QMouseEvent *e)
{
QPlainTextEdit::mousePressEvent(e);
m_formatter->mousePressEvent(e);
}
void OutputWindow::mouseReleaseEvent(QMouseEvent *e)
{
QPlainTextEdit::mouseReleaseEvent(e);
m_formatter->mouseReleaseEvent(e);
}
void OutputWindow::mouseMoveEvent(QMouseEvent *e)
{
QPlainTextEdit::mouseMoveEvent(e);
m_formatter->mouseMoveEvent(e);
}
...@@ -49,6 +49,7 @@ namespace Core { ...@@ -49,6 +49,7 @@ namespace Core {
namespace ProjectExplorer { namespace ProjectExplorer {
class OutputFormatter; class OutputFormatter;
class RunControl; class RunControl;
class Project;
namespace Constants { namespace Constants {
const char * const C_APP_OUTPUT = "Application Output"; const char * const C_APP_OUTPUT = "Application Output";
...@@ -140,23 +141,24 @@ public: ...@@ -140,23 +141,24 @@ public:
void showEvent(QShowEvent *); void showEvent(QShowEvent *);
protected: protected:
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
bool isScrollbarAtBottom() const; bool isScrollbarAtBottom() const;
void scrollToBottom(); void scrollToBottom();
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e);
virtual void mouseMoveEvent(QMouseEvent *e);
private: private:
void enableUndoRedo(); void enableUndoRedo();
QString doNewlineEnfocement(const QString &out); QString doNewlineEnfocement(const QString &out);
private:
Core::BaseContext *m_outputWindowContext; Core::BaseContext *m_outputWindowContext;
OutputFormatter *m_formatter; OutputFormatter *m_formatter;
bool m_enforceNewline; bool m_enforceNewline;
bool m_scrollToBottom; bool m_scrollToBottom;
bool m_linksActive;
bool m_mousePressed;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -179,6 +179,11 @@ Target *RunConfiguration::target() const ...@@ -179,6 +179,11 @@ Target *RunConfiguration::target() const
return m_target; return m_target;
} }
ProjectExplorer::OutputFormatter *RunConfiguration::createOutputFormatter() const
{
return new OutputFormatter();
}
IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) : IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) :
QObject(parent) QObject(parent)
{ {
...@@ -218,13 +223,23 @@ IRunControlFactory::~IRunControlFactory() ...@@ -218,13 +223,23 @@ IRunControlFactory::~IRunControlFactory()
RunControl::RunControl(RunConfiguration *runConfiguration, QString mode) RunControl::RunControl(RunConfiguration *runConfiguration, QString mode)
: m_runMode(mode), m_runConfiguration(runConfiguration) : m_runMode(mode), m_runConfiguration(runConfiguration)
{ {
if (runConfiguration) if (runConfiguration) {
m_displayName = runConfiguration->displayName(); m_displayName = runConfiguration->displayName();
m_outputFormatter = runConfiguration->createOutputFormatter();
}
// We need to ensure that there's always a OutputFormatter
if (!m_outputFormatter)
m_outputFormatter = new OutputFormatter();
} }
RunControl::~RunControl() RunControl::~RunControl()
{ {
delete m_outputFormatter;
}
OutputFormatter *RunControl::outputFormatter()
{
return m_outputFormatter;
} }
QString RunControl::runMode() const QString RunControl::runMode() const
...@@ -242,11 +257,6 @@ bool RunControl::sameRunConfiguration(RunControl *other) ...@@ -242,11 +257,6 @@ bool RunControl::sameRunConfiguration(RunControl *other)
return other->m_runConfiguration.data() == m_runConfiguration.data(); return other->m_runConfiguration.data() == m_runConfiguration.data();
} }
OutputFormatter *RunControl::createOutputFormatter(QObject *parent)
{
return new OutputFormatter(parent);
}
void RunControl::bringApplicationToForeground(qint64 pid) void RunControl::bringApplicationToForeground(qint64 pid)
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
......
...@@ -85,6 +85,8 @@ public: ...@@ -85,6 +85,8 @@ public:
Target *target() const; Target *target() const;
virtual ProjectExplorer::OutputFormatter *createOutputFormatter() const;
signals: signals:
void isEnabledChanged(bool value); void isEnabledChanged(bool value);
...@@ -169,7 +171,7 @@ public: ...@@ -169,7 +171,7 @@ public:
bool sameRunConfiguration(RunControl *other); bool sameRunConfiguration(RunControl *other);
virtual OutputFormatter *createOutputFormatter(QObject *parent = 0); OutputFormatter *outputFormatter();
QString runMode() const; QString runMode() const;
signals: signals:
...@@ -189,6 +191,7 @@ private: ...@@ -189,6 +191,7 @@ private:
QString m_displayName; QString m_displayName;
QString m_runMode; QString m_runMode;
const QWeakPointer<RunConfiguration> m_runConfiguration; const QWeakPointer<RunConfiguration> m_runConfiguration;
OutputFormatter *m_outputFormatter;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
//these two are used to bring apps in the foreground on Mac //these two are used to bring apps in the foreground on Mac
......
...@@ -22,8 +22,7 @@ HEADERS += qmlproject.h \ ...@@ -22,8 +22,7 @@ HEADERS += qmlproject.h \
qmltaskmanager.h \ qmltaskmanager.h \
qmlprojectmanager_global.h \ qmlprojectmanager_global.h \
qmlprojectmanagerconstants.h \ qmlprojectmanagerconstants.h \
qmlprojecttarget.h \ qmlprojecttarget.h
qmloutputformatter.h
SOURCES += qmlproject.cpp \ SOURCES += qmlproject.cpp \
qmlprojectplugin.cpp \ qmlprojectplugin.cpp \
qmlprojectmanager.cpp \ qmlprojectmanager.cpp \
...@@ -35,8 +34,7 @@ SOURCES += qmlproject.cpp \ ...@@ -35,8 +34,7 @@ SOURCES += qmlproject.cpp \
qmlprojectrunconfigurationfactory.cpp \ qmlprojectrunconfigurationfactory.cpp \
qmlprojectapplicationwizard.cpp \ qmlprojectapplicationwizard.cpp \
qmltaskmanager.cpp \ qmltaskmanager.cpp \
qmlprojecttarget.cpp \ qmlprojecttarget.cpp
qmloutputformatter.cpp
RESOURCES += qmlproject.qrc RESOURCES += qmlproject.qrc
OTHER_FILES += QmlProjectManager.pluginspec \ OTHER_FILES += QmlProjectManager.pluginspec \
......
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
** **
**************************************************************************/ **************************************************************************/
#include "qmlprojectrunconfiguration.h"
#include "qmlproject.h" #include "qmlproject.h"
#include "qmlprojectmanagerconstants.h" #include "qmlprojectmanagerconstants.h"
#include "qmlprojectrunconfiguration.h"
#include "qmlprojecttarget.h" #include "qmlprojecttarget.h"
#include "projectexplorer/projectexplorer.h" #include "projectexplorer/projectexplorer.h"
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
** **
**************************************************************************/ **************************************************************************/
#include "qmloutputformatter.h"
#include "qmlprojectruncontrol.h" #include "qmlprojectruncontrol.h"
#include "qmlprojectrunconfiguration.h" #include "qmlprojectrunconfiguration.h"
#include "qmlprojectconstants.h" #include "qmlprojectconstants.h"
...@@ -103,11 +102,6 @@ bool QmlRunControl::isRunning() const ...@@ -103,11 +102,6 @@ bool QmlRunControl::isRunning() const
return m_applicationLauncher.isRunning(); return m_applicationLauncher.isRunning();
} }
ProjectExplorer::OutputFormatter *QmlRunControl::createOutputFormatter(QObject *parent)
{
return new QmlOutputFormatter(parent);
}
void QmlRunControl::slotBringApplicationToForeground(qint64 pid) void QmlRunControl::slotBringApplicationToForeground(qint64 pid)
{ {
bringApplicationToForeground(pid); bringApplicationToForeground(pid);
......
...@@ -51,8 +51,6 @@ public: ...@@ -51,8 +51,6 @@ public:
virtual void stop(); virtual void stop();
virtual bool isRunning() const; virtual bool isRunning() const;
virtual ProjectExplorer::OutputFormatter *createOutputFormatter(QObject *parent = 0);
private slots: private slots:
void processExited(int exitCode); void processExited(int exitCode);
void slotBringApplicationToForeground(qint64 pid); void slotBringApplicationToForeground(qint64 pid);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "maemorunconfigurationwidget.h" #include "maemorunconfigurationwidget.h"
#include "maemotoolchain.h" #include "maemotoolchain.h"
#include "qemuruntimemanager.h" #include "qemuruntimemanager.h"
#include "qtoutputformatter.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
...@@ -113,6 +114,11 @@ QWidget *MaemoRunConfiguration::createConfigurationWidget() ...@@ -113,6 +114,11 @@ QWidget *MaemoRunConfiguration::createConfigurationWidget()
return new MaemoRunConfigurationWidget(this); return new MaemoRunConfigurationWidget(this);
} }
ProjectExplorer::OutputFormatter *MaemoRunConfiguration::createConfigurationWidget() const
{
return new QtOutputFormatter(qt4Target()->qt4Project());
}
void MaemoRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro) void MaemoRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro)
{ {
if (m_proFilePath == pro->path()) if (m_proFilePath == pro->path())
......
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
bool isEnabled(ProjectExplorer::BuildConfiguration *config) const; bool isEnabled(ProjectExplorer::BuildConfiguration *config) const;
QWidget *createConfigurationWidget(); QWidget *createConfigurationWidget();
ProjectExplorer::OutputFormatter *createConfigurationWidget() const;
Qt4Target *qt4Target() const; Qt4Target *qt4Target() const;
Qt4BuildConfiguration *activeQt4BuildConfiguration() const; Qt4BuildConfiguration *activeQt4BuildConfiguration() const;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "qt4buildconfiguration.h" #include "qt4buildconfiguration.h"
#include "qt4projectmanagerconstants.h" #include "qt4projectmanagerconstants.h"
#include "s60createpackagestep.h" #include "s60createpackagestep.h"
#include "qtoutputformatter.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
...@@ -207,6 +208,11 @@ QWidget *S60DeviceRunConfiguration::createConfigurationWidget() ...@@ -207,6 +208,11 @@ QWidget *S60DeviceRunConfiguration::createConfigurationWidget()
return new S60DeviceRunConfigurationWidget(this); return new S60DeviceRunConfigurationWidget(this);
} }
ProjectExplorer::OutputFormatter *S60DeviceRunConfiguration::createOutputFormatter() const
{
return new QtOutputFormatter(qt4Target()->qt4Project());
}
QVariantMap S60DeviceRunConfiguration::toMap() const QVariantMap S60DeviceRunConfiguration::toMap() const
{ {
QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
......
...@@ -74,6 +74,8 @@ public: ...@@ -74,6 +74,8 @@ public:
bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const; bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const;
QWidget *createConfigurationWidget(); QWidget *createConfigurationWidget();
ProjectExplorer::OutputFormatter *createOutputFormatter() const;
QString serialPortName() const; QString serialPortName() const;
void setSerialPortName(const QString &name); void setSerialPortName(const QString &name);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "s60devices.h" #include "s60devices.h"
#include "qt4buildconfiguration.h" #include "qt4buildconfiguration.h"
#include "qt4projectmanagerconstants.h" #include "qt4projectmanagerconstants.h"
#include "qtoutputformatter.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
...@@ -131,6 +132,11 @@ QWidget *S60EmulatorRunConfiguration::createConfigurationWidget() ...@@ -131,6 +132,11 @@ QWidget *S60EmulatorRunConfiguration::createConfigurationWidget()
return new S60EmulatorRunConfigurationWidget(this); return new S60EmulatorRunConfigurationWidget(this);
} }
ProjectExplorer::OutputFormatter *S60EmulatorRunConfiguration::createOutputFormatter() const
{
return new QtOutputFormatter(qt4Target()->qt4Project());
}
QVariantMap S60EmulatorRunConfiguration::toMap() const QVariantMap S60EmulatorRunConfiguration::toMap() const
{ {
QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
......
...@@ -67,6 +67,8 @@ public: ...@@ -67,6 +67,8 @@ public:
bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const; bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const;
QWidget *createConfigurationWidget(); QWidget *createConfigurationWidget();