OSDN Git Service

Port the compile output window away from HTML to QTextCharFormat
authordt <qtc-committer@nokia.com>
Tue, 8 Jun 2010 13:04:42 +0000 (15:04 +0200)
committerdt <qtc-committer@nokia.com>
Tue, 8 Jun 2010 13:23:58 +0000 (15:23 +0200)
Is more then twice as fast

14 files changed:
src/plugins/projectexplorer/abstractprocessstep.cpp
src/plugins/projectexplorer/abstractprocessstep.h
src/plugins/projectexplorer/buildmanager.cpp
src/plugins/projectexplorer/buildmanager.h
src/plugins/projectexplorer/buildstep.h
src/plugins/projectexplorer/compileoutputwindow.cpp
src/plugins/projectexplorer/compileoutputwindow.h
src/plugins/projectexplorer/ioutputparser.cpp
src/plugins/projectexplorer/ioutputparser.h
src/plugins/projectexplorer/outputparser_test.cpp
src/plugins/projectexplorer/outputparser_test.h
src/plugins/qt4projectmanager/makestep.cpp
src/plugins/qt4projectmanager/qmakestep.cpp
src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp

index 55d94dd..a6d5c13 100644 (file)
@@ -82,8 +82,8 @@ void AbstractProcessStep::setOutputParser(ProjectExplorer::IOutputParser *parser
     m_outputParserChain = parser;
 
     if (m_outputParserChain) {
-        connect(parser, SIGNAL(addOutput(QString)),
-                this, SLOT(outputAdded(QString)));
+        connect(parser, SIGNAL(addOutput(QString, QTextCharFormat)),
+                this, SLOT(outputAdded(QString, QTextCharFormat)));
         connect(parser, SIGNAL(addTask(ProjectExplorer::Task)),
                 this, SLOT(taskAdded(ProjectExplorer::Task)));
     }
@@ -199,22 +199,34 @@ void AbstractProcessStep::run(QFutureInterface<bool> &fi)
 
 void AbstractProcessStep::processStarted()
 {
-    emit addOutput(tr("<font color=\"#0000ff\">Starting: \"%1\" %2</font>\n").arg(m_command, Qt::escape(m_arguments.join(" "))));
+    QTextCharFormat textCharFormat;
+    textCharFormat.setForeground(Qt::blue);
+    emit addOutput(tr("Starting: \"%1\" %2\n").arg(m_command, m_arguments.join(" ")), textCharFormat);
 }
 
 void AbstractProcessStep::processFinished(int exitCode, QProcess::ExitStatus status)
 {
-    if (status == QProcess::NormalExit && exitCode == 0)
-        emit addOutput(tr("<font color=\"#0000ff\">The process \"%1\" exited normally.</font>").arg(m_command));
-    else if (status == QProcess::NormalExit)
-        emit addOutput(tr("<font color=\"#ff0000\"><b>The process \"%1\" exited with code %2.</b></font>").arg(m_command, m_process->exitCode()));
-    else
-        emit addOutput(tr("<font color=\"#ff0000\"><b>The process \"%1\" crashed.</b></font>").arg(m_command));
+    QTextCharFormat textCharFormat;
+    if (status == QProcess::NormalExit && exitCode == 0) {
+        textCharFormat.setForeground(Qt::blue);
+        emit addOutput(tr("The process \"%1\" exited normally.").arg(m_command), textCharFormat);
+    } else if (status == QProcess::NormalExit) {
+        textCharFormat.setForeground(Qt::red);
+        textCharFormat.setFontWeight(QFont::Bold);
+        emit addOutput(tr("The process \"%1\" exited with code %2.").arg(m_command, m_process->exitCode()), textCharFormat);
+    } else {
+        textCharFormat.setForeground(Qt::red);
+        textCharFormat.setFontWeight(QFont::Bold);
+        emit addOutput(tr("The process \"%1\" crashed.").arg(m_command), textCharFormat);
+    }
 }
 
 void AbstractProcessStep::processStartupFailed()
 {
-   emit addOutput(tr("<font color=\"#ff0000\"><b>Could not start process \"%1\"</b></font>").arg(m_command));
+    QTextCharFormat textCharFormat;
+    textCharFormat.setForeground(Qt::red);
+    textCharFormat.setFontWeight(QFont::Bold);
+    emit addOutput(tr("Could not start process \"%1\"").arg(m_command), textCharFormat);
 }
 
 bool AbstractProcessStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
@@ -235,7 +247,8 @@ void AbstractProcessStep::stdOutput(const QString &line)
 {
     if (m_outputParserChain)
         m_outputParserChain->stdOutput(line);
-    emit addOutput(Qt::escape(line));
+    QTextCharFormat textCharFormat;
+    emit addOutput(Qt::escape(line), textCharFormat);
 }
 
 void AbstractProcessStep::processReadyReadStdError()
@@ -251,7 +264,9 @@ void AbstractProcessStep::stdError(const QString &line)
 {
     if (m_outputParserChain)
         m_outputParserChain->stdError(line);
-    emit addOutput(QLatin1String("<font color=\"#ff0000\">") + Qt::escape(line) + QLatin1String("</font>"));
+    QTextCharFormat textCharFormat;
+    textCharFormat.setForeground(Qt::red);
+    emit addOutput(line, textCharFormat);
 }
 
 void AbstractProcessStep::checkForCancel()
@@ -312,9 +327,9 @@ void AbstractProcessStep::taskAdded(const ProjectExplorer::Task &task)
     emit addTask(editable);
 }
 
-void AbstractProcessStep::outputAdded(const QString &string)
+void AbstractProcessStep::outputAdded(const QString &string, const QTextCharFormat &textCharFormat)
 {
-    emit addOutput(string);
+    emit addOutput(string, textCharFormat);
 }
 
 void AbstractProcessStep::slotProcessFinished(int, QProcess::ExitStatus)
index 98399fd..de4498a 100644 (file)
@@ -147,8 +147,8 @@ private slots:
     void checkForCancel();
 
     void taskAdded(const ProjectExplorer::Task &task);
-    void outputAdded(const QString &string);
 
+    void outputAdded(const QString &string, const QTextCharFormat &format);
 private:
     QTimer *m_timer;
     QFutureInterface<bool> *m_futureInterface;
index f538d8d..a2f3070 100644 (file)
@@ -180,7 +180,9 @@ void BuildManager::finish()
 
 void BuildManager::emitCancelMessage()
 {
-    emit addToOutputWindow(tr("<font color=\"#ff0000\">Canceled build.</font>"));
+    QTextCharFormat textCharFormat;
+    textCharFormat.setForeground(Qt::red);
+    emit addToOutputWindow(tr("Canceled build."), textCharFormat);
 }
 
 void BuildManager::clearBuildQueue()
@@ -282,9 +284,9 @@ void BuildManager::addToTaskWindow(const ProjectExplorer::Task &task)
     m_taskWindow->addTask(task);
 }
 
-void BuildManager::addToOutputWindow(const QString &string)
+void BuildManager::addToOutputWindow(const QString &string, const QTextCharFormat &format)
 {
-    m_outputWindow->appendText(string);
+    m_outputWindow->appendText(string, format);
 }
 
 void BuildManager::nextBuildQueue()
@@ -294,8 +296,8 @@ void BuildManager::nextBuildQueue()
 
     disconnect(m_currentBuildStep, SIGNAL(addTask(ProjectExplorer::Task)),
                this, SLOT(addToTaskWindow(ProjectExplorer::Task)));
-    disconnect(m_currentBuildStep, SIGNAL(addOutput(QString)),
-               this, SLOT(addToOutputWindow(QString)));
+    disconnect(m_currentBuildStep, SIGNAL(addOutput(QString, QTextCharFormat)),
+               this, SLOT(addToOutputWindow(QString, QTextCharFormat)));
 
     ++m_progress;
     m_progressFutureInterface->setProgressValueAndText(m_progress*100, msgProgress(m_progress, m_maxProgress));
@@ -306,8 +308,10 @@ void BuildManager::nextBuildQueue()
         // Build Failure
         const QString projectName = m_currentBuildStep->buildConfiguration()->target()->project()->displayName();
         const QString targetName = m_currentBuildStep->buildConfiguration()->target()->displayName();
-        addToOutputWindow(tr("<font color=\"#ff0000\">Error while building project %1 (target: %2)</font>").arg(projectName, targetName));
-        addToOutputWindow(tr("<font color=\"#ff0000\">When executing build step '%1'</font>").arg(m_currentBuildStep->displayName()));
+        QTextCharFormat textCharFormat;
+        textCharFormat.setForeground(Qt::red);
+        addToOutputWindow(tr("Error while building project %1 (target: %2)").arg(projectName, targetName), textCharFormat);
+        addToOutputWindow(tr("When executing build step '%1'").arg(m_currentBuildStep->displayName()), textCharFormat);
         // NBS TODO fix in qtconcurrent
         m_progressFutureInterface->setProgressValueAndText(m_progress*100, tr("Error while building project %1 (target: %2)").arg(projectName, targetName));
     }
@@ -337,8 +341,10 @@ void BuildManager::nextStep()
 
         if (m_currentBuildStep->buildConfiguration()->target()->project() != m_previousBuildStepProject) {
             const QString projectName = m_currentBuildStep->buildConfiguration()->target()->project()->displayName();
-            addToOutputWindow(tr("<b>Running build steps for project %2...</b>")
-                              .arg(projectName));
+            QTextCharFormat textCharFormat;
+            textCharFormat.setFontWeight(QFont::Bold);
+            addToOutputWindow(tr("Running build steps for project %2...")
+                              .arg(projectName), textCharFormat);
             m_previousBuildStepProject = m_currentBuildStep->buildConfiguration()->target()->project();
         }
         m_watcher.setFuture(QtConcurrent::run(&BuildStep::run, m_currentBuildStep));
@@ -363,8 +369,8 @@ bool BuildManager::buildQueueAppend(QList<BuildStep *> steps)
         BuildStep *bs = steps.at(i);
         connect(bs, SIGNAL(addTask(ProjectExplorer::Task)),
                 this, SLOT(addToTaskWindow(ProjectExplorer::Task)));
-        connect(bs, SIGNAL(addOutput(QString)),
-                this, SLOT(addToOutputWindow(QString)));
+        connect(bs, SIGNAL(addOutput(QString, QTextCharFormat)),
+                this, SLOT(addToOutputWindow(QString, QTextCharFormat)));
         init = bs->init();
         if (!init)
             break;
@@ -376,16 +382,18 @@ bool BuildManager::buildQueueAppend(QList<BuildStep *> steps)
         // print something for the user
         const QString projectName = bs->buildConfiguration()->target()->project()->displayName();
         const QString targetName = bs->buildConfiguration()->target()->displayName();
-        addToOutputWindow(tr("<font color=\"#ff0000\">Error while building project %1 (target: %2)</font>").arg(projectName, targetName));
-        addToOutputWindow(tr("<font color=\"#ff0000\">When executing build step '%1'</font>").arg(bs->displayName()));
+        QTextCharFormat textCharFormat;
+        textCharFormat.setForeground(Qt::red);
+        addToOutputWindow(tr("Error while building project %1 (target: %2)").arg(projectName, targetName), textCharFormat);
+        addToOutputWindow(tr("When executing build step '%1'").arg(bs->displayName()), textCharFormat);
 
         // disconnect the buildsteps again
         for (int j = 0; j <= i; ++j) {
             BuildStep *bs = steps.at(j);
             disconnect(bs, SIGNAL(addTask(ProjectExplorer::Task)),
                        this, SLOT(addToTaskWindow(ProjectExplorer::Task)));
-            disconnect(bs, SIGNAL(addOutput(QString)),
-                       this, SLOT(addToOutputWindow(QString)));
+            disconnect(bs, SIGNAL(addOutput(QString, QTextCharFormat)),
+                       this, SLOT(addToOutputWindow(QString, QTextCharFormat)));
         }
         return false;
     }
index dda5c10..648790b 100644 (file)
@@ -95,7 +95,7 @@ signals:
 
 private slots:
     void addToTaskWindow(const ProjectExplorer::Task &task);
-    void addToOutputWindow(const QString &string);
+    void addToOutputWindow(const QString &string, const QTextCharFormat &textCharFormat);
 
     void nextBuildQueue();
     void progressChanged();
index fb92427..9a8739c 100644 (file)
@@ -105,8 +105,8 @@ signals:
     void addTask(const ProjectExplorer::Task &task);
     // The string is added to the generated output, usually in the output
     // window.
-    // It should be in html format, that is properly escaped
-    void addOutput(const QString &string);
+    // It should be in plain text, with the format in the parameter
+    void addOutput(const QString &string, const QTextCharFormat &textCharFormat);
 
 private:
     BuildConfiguration *m_buildConfiguration;
index 8bbfe18..a0856c7 100644 (file)
@@ -52,6 +52,8 @@ CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/)
     Aggregation::Aggregate *agg = new Aggregation::Aggregate;
     agg->add(m_textEdit);
     agg->add(new Find::BaseTextFind(m_textEdit));
+
+    qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
 }
 
 bool CompileOutputWindow::hasFocus()
@@ -74,9 +76,16 @@ QWidget *CompileOutputWindow::outputWidget(QWidget *)
     return m_textEdit;
 }
 
-void CompileOutputWindow::appendText(const QString &text)
+void CompileOutputWindow::appendText(const QString &text, const QTextCharFormat &textCharFormat)
 {
-    m_textEdit->appendHtml(text);
+    QString textWithNewline = text;
+    if (!textWithNewline.endsWith("\n"))
+        textWithNewline.append("\n");
+    QTextCursor cursor = QTextCursor(m_textEdit->document());
+    cursor.movePosition(QTextCursor::End);
+    cursor.beginEditBlock();
+    cursor.insertText(textWithNewline, textCharFormat);
+    cursor.endEditBlock();
 }
 
 void CompileOutputWindow::clearContents()
index e74d4e4..1bdd118 100644 (file)
@@ -31,6 +31,8 @@
 #define COMPILEOUTPUTWINDOW_H
 
 #include <coreplugin/ioutputpane.h>
+#include <QtGui/QColor>
+#include <QtGui/QTextCharFormat>
 
 QT_BEGIN_NAMESPACE
 class QPlainTextEdit;
@@ -54,7 +56,7 @@ public:
     int priorityInStatusBar() const;
     void clearContents();
     void visibilityChanged(bool visible);
-    void appendText(const QString &text);
+    void appendText(const QString &text, const QTextCharFormat &textCharFormat);
     bool canFocus();
     bool hasFocus();
     void setFocus();
index 6cf1a4d..ca5b8ba 100644 (file)
@@ -50,8 +50,8 @@ void IOutputParser::appendOutputParser(IOutputParser *parser)
     }
 
     m_parser = parser;
-    connect(parser, SIGNAL(addOutput(QString)),
-            this, SLOT(outputAdded(QString)), Qt::DirectConnection);
+    connect(parser, SIGNAL(addOutput(QString, QTextCharFormat)),
+            this, SLOT(outputAdded(QString, QTextCharFormat)), Qt::DirectConnection);
     connect(parser, SIGNAL(addTask(ProjectExplorer::Task)),
             this, SLOT(taskAdded(ProjectExplorer::Task)), Qt::DirectConnection);
 }
@@ -59,8 +59,8 @@ void IOutputParser::appendOutputParser(IOutputParser *parser)
 IOutputParser *IOutputParser::takeOutputParserChain()
 {
     IOutputParser *parser = m_parser;
-    disconnect(parser, SIGNAL(addOutput(QString)),
-            this, SLOT(outputAdded(QString)));
+    disconnect(parser, SIGNAL(addOutput(QString, QTextCharFormat)),
+            this, SLOT(outputAdded(QString, QTextCharFormat)));
     disconnect(parser, SIGNAL(addTask(ProjectExplorer::Task)),
             this, SLOT(taskAdded(ProjectExplorer::Task)));
     m_parser = 0;
@@ -84,9 +84,9 @@ void IOutputParser::stdError(const QString &line)
         m_parser->stdError(line);
 }
 
-void IOutputParser::outputAdded(const QString &string)
+void IOutputParser::outputAdded(const QString &string, const QTextCharFormat &textCharFormat)
 {
-    emit addOutput(string);
+    emit addOutput(string, textCharFormat);
 }
 
 void IOutputParser::taskAdded(const ProjectExplorer::Task &task)
index da76133..058b5a7 100644 (file)
@@ -67,14 +67,14 @@ signals:
     /// added to the output.
     /// Note: This is additional information. There is no need to add each
     /// line!
-    void addOutput(const QString &string);
+    void addOutput(const QString &string, const QTextCharFormat &format);
     /// Should be emitted for each task seen in the output.
     void addTask(const ProjectExplorer::Task &task);
 
 public slots:
     /// Subparsers have their addOutput signal connected to this slot.
     /// This method can be overwritten to change the string.
-    virtual void outputAdded(const QString &string);
+    virtual void outputAdded(const QString &string, const QTextCharFormat &color);
     /// Subparsers have their addTask signal connected to this slot.
     /// This method can be overwritten to change the task.
     virtual void taskAdded(const ProjectExplorer::Task &task);
index 28a83b5..7bf6c66 100644 (file)
@@ -104,7 +104,8 @@ void OutputParserTester::testOutputMangling(const QString &input,
 {
     reset();
 
-    childParser()->outputAdded(input);
+    QTextCharFormat textCharFormat;
+    childParser()->outputAdded(input, textCharFormat);
 
     QCOMPARE(m_receivedOutput, output);
     QVERIFY(m_receivedStdErrChildLine.isNull());
@@ -139,7 +140,7 @@ void OutputParserTester::appendOutputParser(IOutputParser *parser)
     parser->appendOutputParser(this);
 }
 
-void OutputParserTester::outputAdded(const QString &line)
+void OutputParserTester::outputAdded(const QString &line, const QTextCharFormat &textCharFormat)
 {
     if (!m_receivedOutput.isEmpty())
         m_receivedOutput.append(QChar('\n'));
index 8241766..5d3a4d2 100644 (file)
@@ -71,7 +71,7 @@ public:
     void appendOutputParser(IOutputParser *parser);
 
 private slots:
-    void outputAdded(const QString &line);
+    void outputAdded(const QString &line, const QTextCharFormat &textCharFormat);
     void taskAdded(const ProjectExplorer::Task &task);
 
 private:
index fb3184a..02eaf98 100644 (file)
@@ -135,8 +135,9 @@ bool MakeStep::init()
         // Try to detect command in environment
         const QString tmp = environment.searchInPath(makeCmd);
         if (tmp.isEmpty()) {
-            emit addOutput(tr("<font color=\"#ff0000\">Could not find make command: %1 "\
-                              "in the build environment</font>").arg(makeCmd));
+            QTextCharFormat textCharFormat;
+            textCharFormat.setForeground(Qt::red);
+            emit addOutput(tr("Could not find make command: %1 in the build environment").arg(makeCmd), textCharFormat);
             return false;
         }
         makeCmd = tmp;
index 9b42e38..12629bf 100644 (file)
@@ -198,13 +198,17 @@ void QMakeStep::run(QFutureInterface<bool> &fi)
             canContinue = false;
     }
     if (!canContinue) {
-        emit addOutput(tr("<font color=\"#0000ff\">Configuration is faulty, please check the Build Issues view for details.</font>"));
+        QTextCharFormat textCharFormat;
+        textCharFormat.setForeground(Qt::blue);
+        emit addOutput(tr("Configuration is faulty, please check the Build Issues view for details."), textCharFormat);
         fi.reportResult(false);
         return;
     }
 
     if (!m_needToRunQMake) {
-        emit addOutput(tr("<font color=\"#0000ff\">Configuration unchanged, skipping qmake step.</font>"));
+        QTextCharFormat textCharFormat;
+        textCharFormat.setForeground(Qt::blue);
+        emit addOutput(tr("Configuration unchanged, skipping qmake step."), textCharFormat);
         fi.reportResult(true);
         return;
     }
index c43a2f1..0a00779 100644 (file)
@@ -114,7 +114,8 @@ bool MaemoPackageCreationStep::createPackage()
     if (!packagingNeeded())
         return true;
 
-    emit addOutput(tr("Creating package file ..."));
+    QTextCharFormat textCharFormat;
+    emit addOutput(tr("Creating package file ..."), textCharFormat);
     QFile configFile(targetRoot() % QLatin1String("/config.sh"));
     if (!configFile.open(QIODevice::ReadOnly)) {
         raiseError(tr("Cannot open MADDE config file '%1'.")
@@ -213,14 +214,15 @@ bool MaemoPackageCreationStep::createPackage()
             return false;
     }
 
-    emit addOutput(tr("Package created."));
+    emit addOutput(tr("Package created."), textCharFormat);
     m_packageContents->setUnModified();
     return true;
 }
 
 bool MaemoPackageCreationStep::runCommand(QProcess &proc, const QString &command)
 {
-    emit addOutput(tr("Package Creation: Running command '%1'.").arg(command));
+    QTextCharFormat textCharFormat;
+    emit addOutput(tr("Package Creation: Running command '%1'.").arg(command), textCharFormat);
     QString perl;
 #ifdef Q_OS_WIN
     perl = maddeRoot() + QLatin1String("/bin/perl.exe ");
@@ -323,7 +325,8 @@ QString MaemoPackageCreationStep::nativePath(const QFile &file) const
 void MaemoPackageCreationStep::raiseError(const QString &shortMsg,
                                           const QString &detailedMsg)
 {
-    emit addOutput(detailedMsg.isNull() ? shortMsg : detailedMsg);
+    QTextCharFormat textCharFormat;
+    emit addOutput(detailedMsg.isNull() ? shortMsg : detailedMsg, textCharFormat);
     emit addTask(Task(Task::Error, shortMsg, QString(), -1,
                       TASK_CATEGORY_BUILDSYSTEM));
 }