NCL Composer  0.1.5
 All Classes Functions Variables Pages
NCLProblemsView.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "NCLProblemsView.h"
19 
20 NCLProblemsView::NCLProblemsView(QWidget *parent):
21  QDockWidget("Problems", parent)
22 {
23  mainWindow = new QMainWindow(parent);
24 
25  createViewActions();
26  createToolBar();
27  createTreeWidget();
28 }
29 
30 void NCLProblemsView::createViewActions()
31 {
32  clearProblemsAct = new QAction( QIcon(":/images/clear-icon.png"),
33  tr("&Clear Problems"), this);
34 
35  clearProblemsAct->setStatusTip(tr("Clear All"));
36  connect(clearProblemsAct, SIGNAL(triggered()), this, SLOT(clearProblems()));
37 }
38 
39 void NCLProblemsView::createToolBar()
40 {
41  QToolBar *file = mainWindow->addToolBar(tr("File"));
42  file->addAction(clearProblemsAct);
43  file->setIconSize(QSize(16, 16));
44 }
45 
46 void NCLProblemsView::createTreeWidget()
47 {
48  QStringList labels;
49  labels << QObject::tr("Description") << QObject::tr("file")
50  << QObject::tr("line");
51 
52  problemsList = new QTreeWidget(this);
53  problemsList->setSortingEnabled(1);
54  problemsList->setStyleSheet(/*"background-color:*/ "font-size: 11px;");
55  problemsList->setHeaderLabels(labels);
56 
57  QTreeWidgetItem *lst1 = new QTreeWidgetItem(problemsList);
58  lst1->setIcon(0, QIcon(":/images/error-icon-16.png"));
59  lst1->setText(0, "Error!");
60  lst1->setText(1, "0");
61 
62  setFeatures(QDockWidget::DockWidgetMovable |
63  QDockWidget::DockWidgetFloatable);
64 
65  mainWindow->setCentralWidget(problemsList);
66 
67  setWidget(mainWindow);
68 }
69 
70 void NCLProblemsView::clearProblems()
71 {
72  problemsList->clear();
73 }
74 
75 //TODO: ERROR OR WARNING ??
76 void NCLProblemsView::addProblem( QString message,
77  QString file,
78  int line,
79  int column,
80  int severity /*ERROR OR WARNING?*/)
81 {
82  QTreeWidgetItem *error = new QTreeWidgetItem(problemsList);
83  if(severity == 0)
84  error->setIcon(0, QIcon(":/images/error-icon-16.png"));
85  else
86  error->setIcon(0, QIcon(":/images/warning-big.png"));
87  error->setText(0, message);
88  error->setText(1, file);
89  error->setText(2, QString::number(line));
90 }
91