GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4LogInfo.cpp
Go to the documentation of this file.
1 // $Id: TGo4LogInfo.cpp 1512 2015-06-10 14:15:56Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4LogInfo.h"
15 
16 #include "TObject.h"
17 #include "TList.h"
18 
19 #include <QFileDialog>
20 #include <QTextStream>
21 #include <QHeaderView>
22 
23 TGo4LogInfo::TGo4LogInfo(QWidget *parent, const char* name) :
24  QGo4Widget(parent, name)
25 {
26  setupUi(this);
27 
28  setAcceptDrops(false);
29 
30  LogText->sortByColumn(1, Qt::DescendingOrder);
31 
32 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
33  LogText->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
34  LogText->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
35  LogText->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
36 #else
37  LogText->header()->setResizeMode(0, QHeaderView::ResizeToContents);
38  LogText->header()->setResizeMode(1, QHeaderView::ResizeToContents);
39  LogText->header()->setResizeMode(2, QHeaderView::ResizeToContents);
40 #endif
41  LogText->header()->setStretchLastSection(true);
42 }
43 
45 {
46  ResetWidget();
47  AddLink(slot, "Loginfo");
48 }
49 
50 void TGo4LogInfo::AddMessage(const QDateTime& dt, int level, QString msg)
51 {
52  QString Date = dt.toString("dd.MM.yy ");
53  QString Time = dt.toString("hh.mm.ss ");
54 
55  QTreeWidgetItem* Item = new QTreeWidgetItem();
56  Item->setText(0, Date);
57  Item->setText(1, Time);
58 
59  if (level==0) {
60  if(msg.contains("GO4-*")) level=1; else
61  if(msg.contains("GO4-#")) level=2; else
62  if(msg.contains("GO4-!")) level=3;
63  msg.remove(0, 6);
64  }
65 
66  switch(level) {
67  case 2:
68  Item->setText(2, "Warning");
69  Item->setIcon(0, QIcon(":/icons/warn.png"));
70  break;
71  case 3:
72  Item->setText(2, "Error");
73  Item->setIcon(0, QIcon(":/icons/error.png"));
74  break;
75  default:
76  Item->setText(2, "Info");
77  Item->setIcon(0, QIcon(":/icons/info.png"));
78  break;
79  }
80 
81  Item->setText(3, msg);
82 
83  LogText->addTopLevelItem(Item);
84  Item->setSelected(true);
85  LogText->setCurrentItem(Item);
86  LogText->scrollToItem(Item);
87 }
88 
89 void TGo4LogInfo::linkedObjectUpdated(const char * linkname, TObject * obj)
90 {
91  TList* lst = dynamic_cast<TList*>(obj);
92  if (lst != 0) {
93  TListIter iter(lst, kFALSE);
94  TObject* obj = 0;
95  while ((obj = iter()) != 0) {
96  // first item is id of current status message, used to submit next request
97  if (obj==lst->First()) continue;
98 
99  const char* msg = obj->GetName();
100 
101  const char* separ = strchr(msg,':');
102  if ((separ==0) || (strlen(separ)<3)) continue;
103 
104  Long64_t tm = TString(msg, separ-msg).Atoll();
105 
106  QDateTime dt;
107  dt.setTime_t((time_t) tm);
108 
109  separ++;
110  int level = 1;
111  if (*separ=='2') level=2; else
112  if (*separ=='3') level=3;
113 
114  AddMessage(dt, level, separ+2);
115  }
116  } else
117  if (obj!=0) {
118  AddMessage(QDateTime::currentDateTime(), 0, obj->GetName());
119  }
120 }
121 
122 
124 {
125  LogText->clear();
126 }
127 
129 {
130  QString TextToSave;
131  QFileDialog fd( this, "Save analysis log window", QString(),
132  "Plain text (*.txt)");
133  fd.setFileMode( QFileDialog::AnyFile );
134  fd.setAcceptMode(QFileDialog::AcceptSave);
135 
136  if ( fd.exec() != QDialog::Accepted ) return;
137 
138  QStringList flst = fd.selectedFiles();
139  if (flst.isEmpty()) return;
140 
141  QString fileName = flst[0];
142  if(!fileName.endsWith(".txt")) fileName.append(".txt");
143  QFile NewFile(fileName);
144  NewFile.open( QIODevice::ReadWrite | QIODevice::Append );
145  QTextStream t( &NewFile );
146 
147  QTreeWidgetItemIterator it(LogText);
148  while (*it) {
149  QTreeWidgetItem* itm = *it++;
150  t << itm->text(0) << " " << itm->text(1) << " " << itm->text(3) << "\n";
151  }
152  NewFile.close();
153 }
virtual void ResetWidget()
Definition: QGo4Widget.cpp:51
virtual void ClearLogInfo()
void linkedObjectUpdated(const char *linkname, TObject *obj)
Definition: TGo4LogInfo.cpp:89
void AddMessage(const QDateTime &dt, int level, QString msg)
Definition: TGo4LogInfo.cpp:50
virtual void SaveLogInfo()
void WorkWithInfo(TGo4Slot *slot)
Definition: TGo4LogInfo.cpp:44
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:121
TGo4LogInfo(QWidget *parent=0, const char *name=0)
Definition: TGo4LogInfo.cpp:23
string msg
Definition: go4init.py:11