Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/messagedock.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                             messagedock.cpp
00003                             ---------------
00004     begin                : Tue Mar 11 2014
00005     copyright            : (C) 2014 by Guilherme Brondani Torri
00006     email                : guitorri AT gmail DOT com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "messagedock.h"
00019 
00020 #include "main.h"
00021 #include "qucsdoc.h"
00022 #include "textdoc.h"
00023 
00024 #include <QDockWidget>
00025 #include <QDebug>
00026 
00040 MessageDock::MessageDock(QucsApp *App_): QWidget()
00041 {
00042 
00043     builderTabs = new QTabWidget();
00044     builderTabs->setTabPosition(QTabWidget::South);
00045 
00046     // 1) add a dock for the adms messages
00047     admsOutput = new QPlainTextEdit();
00048     admsOutput->setReadOnly(true);
00049 
00050     builderTabs->insertTab(0,admsOutput,tr("admsXml"));
00051 
00052 
00053     // 2) add a dock for the cpp compiler messages
00054     cppOutput = new QPlainTextEdit();
00055     cppOutput->setReadOnly(true);
00056 
00057     builderTabs->insertTab(1,cppOutput,tr("Compiler"));
00058 
00059     msgDock = new QDockWidget(tr("admsXml Dock"));
00060     msgDock->setWidget(builderTabs);
00061     App_->addDockWidget(Qt::BottomDockWidgetArea, msgDock);
00062 
00063     // start hidden
00064     msgDock->hide();
00065 
00066     // monitor the amds output
00067     connect(admsOutput,SIGNAL(textChanged()), this, SLOT(slotAdmsChanged()));
00068     // monitor the compiler output
00069     connect(cppOutput,SIGNAL(textChanged()), this, SLOT(slotCppChanged()));
00070     // check out if cursor over 'fail' line
00071     connect(admsOutput, SIGNAL(cursorPositionChanged()), this, SLOT(slotCursor()));
00072 }
00073 
00077 void MessageDock::reset()
00078 {
00079     admsOutput->clear();
00080     cppOutput->clear();
00081 
00082     builderTabs->setTabIcon(0,QPixmap());
00083     builderTabs->setTabIcon(1,QPixmap());
00084 }
00085 
00089 void MessageDock::slotAdmsChanged()
00090 {
00091     // look for [fatal..] output of admsXml
00092     // get line from either
00093     //  * [fatal..] ./3ph_vs.va:34:42: analog function '$abstime' is undefined
00094     //  * [fatal..] ./mypotentiometer.va: during lexical analysis syntax error at line 33 --
00095     //  * [fatal..] [./mypotentiometer.va:63:1]: at 'Rad_Angle':
00096 
00097     // \todo can we change the mouse cursor over the highlighted lines?
00098     // A Qt::PointingHandCursor would be nice.
00099     QString logContents = admsOutput->toPlainText();
00100     QStringList lines = logContents.split("\n");
00101 
00102     bool error = false;
00103 
00104     QList<QTextEdit::ExtraSelection> extraSelections;
00105     for (int i = 0; i < lines.size(); ++i) {
00106         QString line = lines[i];
00107 
00108         if (line.contains("[fatal..]",Qt::CaseSensitive)) {
00109             // get cursor for the line
00110             int pos = admsOutput->document()->findBlockByLineNumber(i).position();
00111             QTextCursor cursor = admsOutput->textCursor();
00112             cursor.setPosition(pos);
00113 
00114             // highlight 'fatal' lines on the log
00115             QTextEdit::ExtraSelection selection;
00116             QColor lineColor = QColor(Qt::yellow).lighter(160);
00117             selection.format.setBackground(lineColor);
00118             selection.format.setProperty(QTextFormat::FullWidthSelection, true);
00119             selection.cursor = cursor;
00120             extraSelections.append(selection);
00121 
00122             error = true;
00123         }
00124         else if (line.contains("[error..]",Qt::CaseSensitive)) {
00125             // Do something with error?
00126              error = true;
00127         }
00128         else if (line.contains("*** No rule to make target",Qt::CaseSensitive)) {
00129             // Do something with error?
00130              error = true;
00131         }
00132     }
00133 
00134     // highlight all the fatal warnings
00135     admsOutput->setExtraSelections(extraSelections);
00136 
00137     // Change adms tab icon
00138     if (error)
00139          builderTabs->setTabIcon(0,QPixmap(":/bitmaps/error.png"));
00140     else
00141          builderTabs->setTabIcon(0,QPixmap(":/bitmaps/tick.png"));
00142 }
00143 
00147 void MessageDock::slotCppChanged()
00148 {
00149     QString logContents = cppOutput->toPlainText();
00150 
00151     bool error = false;
00152 
00153     if (logContents.contains("*** No rule to make target")) {
00154         error = true;
00155     }
00156     else if (logContents.contains("error",Qt::CaseInsensitive)) {
00157         error = true;
00158     }
00159 
00160     // Change compiler tab icon
00161     if (error)
00162          builderTabs->setTabIcon(1,QPixmap(":/bitmaps/error.png"));
00163     else
00164          builderTabs->setTabIcon(1,QPixmap(":/bitmaps/tick.png"));
00165 }
00166 
00170 void MessageDock::slotCursor()
00171 {
00172     qWarning()  << admsOutput->textCursor().blockNumber();
00173     int gotoLine = -1;
00174     QString line =  admsOutput->textCursor().block().text();
00175     if (line.contains("[fatal..]",Qt::CaseSensitive)) {
00176         // \todo improve the parsing of line
00177         // try to find line number: ":34:"
00178         if (line.contains(":",Qt::CaseSensitive)) {
00179             int a,b;
00180             a = line.indexOf(":")+1;
00181             b = line.indexOf(":",a);
00182             gotoLine = line.mid(a,b-a).trimmed().toInt();
00183             qWarning() << "goto line " << gotoLine;
00184         }
00185 
00186         // try to find line number: "syntax error at line 33 --"
00187         if (line.contains("syntax error ",Qt::CaseSensitive)) {
00188             int a,b;
00189             a = line.indexOf("at line");
00190             b = line.indexOf("--",a);
00191             gotoLine = line.mid(a+7,b-a-7).trimmed().toInt();
00192             qWarning() << "goto line " << gotoLine;
00193         }
00194     }
00195 
00196   // \todo set hightlight in QucsDoc Verilog-A file?
00197   // move cursor? addt line number? highliht line number? set in focus
00198 
00199     /*
00200      * add slot to TextDoc
00201      * it takes the gotoLine
00202      * hightlings the line
00203      * QucsApp::getDoc() //current should be a TextDoc
00204      */
00205 //    QucsDoc *foo =  QucsMain->getDoc();
00206 //    qWarning() << foo->DocName;
00207 
00208     if (gotoLine >= 0) {
00209 
00210         // \todo it will mark whatever document is open. parse the model file
00211         // name from the fatal message and ->findDoc instead of ->getDoc?
00212 
00213         // grab active text document
00214         TextDoc * d = (TextDoc*)QucsMain->getDoc();
00215 
00216         QTextCursor cursor = d->textCursor();
00217         int pos = d->document()->findBlockByLineNumber(gotoLine-1).position();
00218         cursor.setPosition(pos);
00219 
00220         // Highligt a give line
00221         QList<QTextEdit::ExtraSelection> extraSelections;
00222         QTextEdit::ExtraSelection selection;
00223         QColor lineColor = QColor(Qt::yellow).lighter(160);
00224         selection.format.setBackground(lineColor);
00225         selection.format.setProperty(QTextFormat::FullWidthSelection, true);
00226         selection.cursor = cursor;
00227 
00228         // get existing
00229         extraSelections.append(d->extraSelections());
00230 
00231         // append new
00232         extraSelections.append(selection);
00233 
00234         // color the selections on the active document
00235         d->setExtraSelections(extraSelections);
00236 
00237         //move focus to VA code
00238         d->setFocus();
00239         //move cursor to highlighted line
00240 //        d->setCursor(d->document()->);
00241         d->setTextCursor(cursor);
00242     }
00243 
00247 
00248 
00249 }
00250 
00251 
00252 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines