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