messagedock.cpp
---------------
begin : Tue Mar 11 2014
copyright : (C) 2014 by Guilherme Brondani Torri
email : guitorri AT gmail DOT com
***************************************************************************/
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "messagedock.h"
#include "main.h"
#include "qucsdoc.h"
#include "textdoc.h"
#include <QDockWidget>
#include <QTextBlock>
#include <QDebug>
* \file messagedock.cpp
* \brief Definition of the MessageDock class.
*/
* \brief MessageDock::MessageDock constructor
* \param App_ is the parent class
* It creates two docked text fields to hold the output of make called
* over admsXml and the C++ compiler used to build the Verilog-A
* dynamic loaded libraries.
* \see QucsApp::slotBuildModule() for the make output assignment.
*/
MessageDock::MessageDock(QucsApp *App_): QWidget()
{
builderTabs = new QTabWidget();
builderTabs->setTabPosition(QTabWidget::South);
admsOutput = new QPlainTextEdit();
admsOutput->setReadOnly(true);
builderTabs->insertTab(0,admsOutput,tr("admsXml"));
cppOutput = new QPlainTextEdit();
cppOutput->setReadOnly(true);
builderTabs->insertTab(1,cppOutput,tr("Compiler"));
msgDock = new QDockWidget(tr("admsXml Dock"));
msgDock->setWidget(builderTabs);
App_->addDockWidget(Qt::BottomDockWidgetArea, msgDock);
msgDock->hide();
connect(admsOutput,SIGNAL(textChanged()), this, SLOT(slotAdmsChanged()));
connect(cppOutput,SIGNAL(textChanged()), this, SLOT(slotCppChanged()));
connect(admsOutput, SIGNAL(cursorPositionChanged()), this, SLOT(slotCursor()));
}
* \brief MessageDock::reset clear the text and tab icons
*/
void MessageDock::reset()
{
admsOutput->clear();
cppOutput->clear();
builderTabs->setTabIcon(0,QPixmap());
builderTabs->setTabIcon(1,QPixmap());
}
* \brief MessageDock::slotAdmsChanged monitors the adms log, update tab icon
*/
void MessageDock::slotAdmsChanged()
{
QString logContents = admsOutput->toPlainText();
QStringList lines = logContents.split("\n");
bool error = false;
QList<QTextEdit::ExtraSelection> extraSelections;
for (int i = 0; i < lines.size(); ++i) {
QString line = lines[i];
if (line.contains("[fatal..]",Qt::CaseSensitive)) {
int pos = admsOutput->document()->findBlockByLineNumber(i).position();
QTextCursor cursor = admsOutput->textCursor();
cursor.setPosition(pos);
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = cursor;
extraSelections.append(selection);
error = true;
}
else if (line.contains("[error..]",Qt::CaseSensitive)) {
error = true;
}
else if (line.contains("*** No rule to make target",Qt::CaseSensitive)) {
error = true;
}
}
admsOutput->setExtraSelections(extraSelections);
if (error)
builderTabs->setTabIcon(0,QPixmap(":/bitmaps/svg/error.svg"));
else
builderTabs->setTabIcon(0,QPixmap(":/bitmaps/svg/ok_apply.svg"));
}
* \brief MessageDock::slotCppChanged monitors the compiler log, update tab icon
*/
void MessageDock::slotCppChanged()
{
QString logContents = cppOutput->toPlainText();
bool error = false;
if (logContents.contains("*** No rule to make target")) {
error = true;
}
else if (logContents.contains("error",Qt::CaseInsensitive)) {
error = true;
}
if (error)
builderTabs->setTabIcon(1,QPixmap(":/bitmaps/svg/error.svg"));
else
builderTabs->setTabIcon(1,QPixmap(":/bitmaps/svg/ok_apply.svg"));
}
* \brief MessageDock::slotCursor
*/
void MessageDock::slotCursor()
{
qWarning() << admsOutput->textCursor().blockNumber();
int gotoLine = -1;
QString line = admsOutput->textCursor().block().text();
if (line.contains("[fatal..]",Qt::CaseSensitive)) {
if (line.contains(":",Qt::CaseSensitive)) {
int a,b;
a = line.indexOf(":")+1;
b = line.indexOf(":",a);
gotoLine = line.mid(a,b-a).trimmed().toInt();
qWarning() << "goto line " << gotoLine;
}
if (line.contains("syntax error ",Qt::CaseSensitive)) {
int a,b;
a = line.indexOf("at line");
b = line.indexOf("--",a);
gotoLine = line.mid(a+7,b-a-7).trimmed().toInt();
qWarning() << "goto line " << gotoLine;
}
}
* add slot to TextDoc
* it takes the gotoLine
* hightlings the line
* QucsApp::getDoc() //current should be a TextDoc
*/
if (gotoLine >= 0) {
TextDoc * d = (TextDoc*)QucsMain->getDoc();
QTextCursor cursor = d->textCursor();
int pos = d->document()->findBlockByLineNumber(gotoLine-1).position();
cursor.setPosition(pos);
QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = cursor;
extraSelections.append(d->extraSelections());
extraSelections.append(selection);
d->setExtraSelections(extraSelections);
d->setFocus();
d->setTextCursor(cursor);
}
}