Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
messagedock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  messagedock.cpp
3  ---------------
4  begin : Tue Mar 11 2014
5  copyright : (C) 2014 by Guilherme Brondani Torri
6  email : guitorri AT gmail DOT com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "messagedock.h"
19 
20 #include "main.h"
21 #include "qucsdoc.h"
22 #include "textdoc.h"
23 
24 #include <QVBoxLayout>
25 
40 {
41 
42  builderTabs = new QTabWidget();
43  builderTabs->setTabPosition(QTabWidget::South);
44 
45  // 1) add a dock for the adms messages
46  admsOutput = new QPlainTextEdit();
47  admsOutput->setReadOnly(true);
48 
49  builderTabs->insertTab(0,admsOutput,tr("admsXml"));
50 
51 
52  // 2) add a dock for the cpp compiler messages
53  cppOutput = new QPlainTextEdit();
54  cppOutput->setReadOnly(true);
55 
56  builderTabs->insertTab(1,cppOutput,tr("Compiler"));
57 
58  msgDock = new QDockWidget();
59  msgDock->setWidget(builderTabs);
60  App_->addDockWidget(Qt::BottomDockWidgetArea, msgDock);
61 
62  // start hidden
63  msgDock->hide();
64 
65  // monitor the amds output
66  connect(admsOutput,SIGNAL(textChanged()), this, SLOT(slotAdmsChanged()));
67  // monitor the compiler output
68  connect(cppOutput,SIGNAL(textChanged()), this, SLOT(slotCppChanged()));
69  // check out if cursor over 'fail' line
70  connect(admsOutput, SIGNAL(cursorPositionChanged()), this, SLOT(slotCursor()));
71 }
72 
77 {
78  admsOutput->clear();
79  cppOutput->clear();
80 
81  builderTabs->setTabIcon(0,QPixmap());
82  builderTabs->setTabIcon(1,QPixmap());
83 }
84 
89 {
90  // look for [fatal..] output of admsXml
91  // get line from either
92  // * [fatal..] ./3ph_vs.va:34:42: analog function '$abstime' is undefined
93  // * [fatal..] ./mypotentiometer.va: during lexical analysis syntax error at line 33 --
94  // * [fatal..] [./mypotentiometer.va:63:1]: at 'Rad_Angle':
95 
96  // \todo can we change the mouse cursor over the highlighted lines?
97  // A Qt::PointingHandCursor would be nice.
98  QString logContents = admsOutput->toPlainText();
99  QStringList lines = logContents.split("\n");
100 
101  bool error = false;
102 
103  QList<QTextEdit::ExtraSelection> extraSelections;
104  for (int i = 0; i < lines.size(); ++i) {
105  QString line = lines[i];
106 
107  if (line.contains("[fatal..]",Qt::CaseSensitive)) {
108  // get cursor for the line
109  int pos = admsOutput->document()->findBlockByLineNumber(i).position();
110  QTextCursor cursor = admsOutput->textCursor();
111  cursor.setPosition(pos);
112 
113  // highlight 'fatal' lines on the log
114  QTextEdit::ExtraSelection selection;
115  QColor lineColor = QColor(Qt::yellow).lighter(160);
116  selection.format.setBackground(lineColor);
117  selection.format.setProperty(QTextFormat::FullWidthSelection, true);
118  selection.cursor = cursor;
119  extraSelections.append(selection);
120 
121  error = true;
122  }
123  else if (line.contains("[error..]",Qt::CaseSensitive)) {
124  // Do something with error?
125  error = true;
126  }
127  else if (line.contains("*** No rule to make target",Qt::CaseSensitive)) {
128  // Do something with error?
129  error = true;
130  }
131  }
132 
133  // highlight all the fatal warnings
134  admsOutput->setExtraSelections(extraSelections);
135 
136  // Change adms tab icon
137  if (error)
138  builderTabs->setTabIcon(0,QPixmap(":/bitmaps/error.png"));
139  else
140  builderTabs->setTabIcon(0,QPixmap(":/bitmaps/tick.png"));
141 }
142 
147 {
148  QString logContents = cppOutput->toPlainText();
149 
150  bool error = false;
151 
152  if (logContents.contains("*** No rule to make target")) {
153  error = true;
154  }
155  else if (logContents.contains("error",Qt::CaseInsensitive)) {
156  error = true;
157  }
158 
159  // Change compiler tab icon
160  if (error)
161  builderTabs->setTabIcon(1,QPixmap(":/bitmaps/error.png"));
162  else
163  builderTabs->setTabIcon(1,QPixmap(":/bitmaps/tick.png"));
164 }
165 
170 {
171  qWarning() << admsOutput->textCursor().blockNumber();
172  int gotoLine = -1;
173  QString line = admsOutput->textCursor().block().text();
174  if (line.contains("[fatal..]",Qt::CaseSensitive)) {
175  // \todo improve the parsing of line
176  // try to find line number: ":34:"
177  if (line.contains(":",Qt::CaseSensitive)) {
178  int a,b;
179  a = line.indexOf(":")+1;
180  b = line.indexOf(":",a);
181  gotoLine = line.mid(a,b-a).stripWhiteSpace().toInt();
182  qWarning() << "goto line " << gotoLine;
183  }
184 
185  // try to find line number: "syntax error at line 33 --"
186  if (line.contains("syntax error ",Qt::CaseSensitive)) {
187  int a,b;
188  a = line.indexOf("at line");
189  b = line.indexOf("--",a);
190  gotoLine = line.mid(a+7,b-a-7).stripWhiteSpace().toInt();
191  qWarning() << "goto line " << gotoLine;
192  }
193  }
194 
195  // \todo set hightlight in QucsDoc Verilog-A file?
196  // move cursor? addt line number? highliht line number? set in focus
197 
198  /*
199  * add slot to TextDoc
200  * it takes the gotoLine
201  * hightlings the line
202  * QucsApp::getDoc() //current should be a TextDoc
203  */
204 // QucsDoc *foo = QucsMain->getDoc();
205 // qWarning() << foo->DocName;
206 
207  if (gotoLine >= 0) {
208 
209  // \todo it will mark whatever document is open. parse the model file
210  // name from the fatal message and ->findDoc instead of ->getDoc?
211 
212  // grab active text document
213  TextDoc * d = (TextDoc*)QucsMain->getDoc();
214 
215  QTextCursor cursor = d->textCursor();
216  int pos = d->document()->findBlockByLineNumber(gotoLine-1).position();
217  cursor.setPosition(pos);
218 
219  // Highligt a give line
220  QList<QTextEdit::ExtraSelection> extraSelections;
221  QTextEdit::ExtraSelection selection;
222  QColor lineColor = QColor(Qt::yellow).lighter(160);
223  selection.format.setBackground(lineColor);
224  selection.format.setProperty(QTextFormat::FullWidthSelection, true);
225  selection.cursor = cursor;
226 
227  // get existing
228  extraSelections.append(d->extraSelections());
229 
230  // append new
231  extraSelections.append(selection);
232 
233  // color the selections on the active document
234  d->setExtraSelections(extraSelections);
235 
236  //move focus to VA code
237  d->setFocus();
238  //move cursor to highlighted line
239 // d->setCursor(d->document()->);
240  d->setTextCursor(cursor);
241  }
242 
246 
247 
248 }
249 
250 
251 
Definition of the TextDoc class.
void slotAdmsChanged()
MessageDock::slotAdmsChanged monitors the adms log, update tab icon.
Definition: messagedock.cpp:88
void slotCursor()
MessageDock::slotCursor.
MessageDock(QucsApp *)
MessageDock::MessageDock constructor.
Definition: messagedock.cpp:39
The MessageDock class definiion.
QucsDoc * getDoc(int No=-1)
Definition: qucs.cpp:562
QPlainTextEdit * admsOutput
admsOutput holds the make output of running admsXml
Definition: messagedock.h:47
Definitions and declarations for the main application.
QucsApp * QucsMain
Definition: main.cpp:54
void reset()
MessageDock::reset clear the text and tab icons.
Definition: messagedock.cpp:76
QDockWidget * msgDock
Definition: messagedock.h:36
QPlainTextEdit * cppOutput
cppOutput holds the make output of running a C++ compiler
Definition: messagedock.h:51
QTabWidget * builderTabs
Definition: messagedock.h:42
The TextDoc class definition.
Definition: textdoc.h:49
void slotCppChanged()
MessageDock::slotCppChanged monitors the compiler log, update tab icon.
Definition: qucs.h:61