Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4LogInfo.h"
00015
00016 #include "TObject.h"
00017 #include <QFileDialog>
00018 #include <QDateTime>
00019 #include <QTextStream>
00020 #include <QHeaderView>
00021
00022 TGo4LogInfo::TGo4LogInfo(QWidget *parent, const char* name) :
00023 QGo4Widget(parent, name)
00024 {
00025 setupUi(this);
00026
00027 setAcceptDrops(false);
00028
00029 LogText->sortByColumn(1, Qt::DescendingOrder);
00030
00031 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
00032 LogText->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
00033 LogText->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
00034 LogText->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
00035 #else
00036 LogText->header()->setResizeMode(0, QHeaderView::ResizeToContents);
00037 LogText->header()->setResizeMode(1, QHeaderView::ResizeToContents);
00038 LogText->header()->setResizeMode(2, QHeaderView::ResizeToContents);
00039 #endif
00040 LogText->header()->setStretchLastSection(true);
00041 }
00042
00043 void TGo4LogInfo::WorkWithInfo(TGo4Slot* slot)
00044 {
00045 ResetWidget();
00046 AddLink(slot, "Loginfo");
00047 }
00048
00049 void TGo4LogInfo::linkedObjectUpdated( const char * linkname, TObject * obj )
00050 {
00051 if (obj==0) return;
00052
00053 QDateTime dt = QDateTime::currentDateTime();
00054 QString Name = obj->GetName();
00055 QString Date = dt.toString("dd.MM.yy ");
00056 QString Time = dt.toString("hh.mm.ss ");
00057
00058 QTreeWidgetItem* Item = new QTreeWidgetItem();
00059 Item->setText(0, Date);
00060 Item->setText(1, Time);
00061
00062 if(Name.contains("GO4-*")) {
00063 Item->setText(2, "Info");
00064 Item->setIcon(0, QIcon(":/icons/info.png"));
00065 } else
00066 if (Name.contains("GO4-!")) {
00067 Item->setText(2, "Error");
00068 Item->setIcon(0, QIcon(":/icons/error.png"));
00069 } else
00070 if(Name.contains("GO4-#")) {
00071 Item->setText(2, "Warning");
00072 Item->setIcon(0, QIcon(":/icons/warn.png"));
00073 }
00074
00075 Name.remove(0, 6);
00076 Item->setText(3, Name);
00077
00078 LogText->addTopLevelItem(Item);
00079 Item->setSelected(true);
00080 LogText->setCurrentItem(Item);
00081 LogText->scrollToItem(Item);
00082 }
00083
00084
00085 void TGo4LogInfo::ClearLogInfo()
00086 {
00087 LogText->clear();
00088 }
00089
00090 void TGo4LogInfo::SaveLogInfo()
00091 {
00092 QString TextToSave;
00093 QFileDialog fd( this, "Save analysis log window", QString(),
00094 "Plain text (*.txt)");
00095 fd.setFileMode( QFileDialog::AnyFile );
00096 fd.setAcceptMode(QFileDialog::AcceptSave);
00097
00098 if ( fd.exec() != QDialog::Accepted ) return;
00099
00100 QStringList flst = fd.selectedFiles();
00101 if (flst.isEmpty()) return;
00102
00103 QString fileName = flst[0];
00104 if(!fileName.endsWith(".txt")) fileName.append(".txt");
00105 QFile NewFile(fileName);
00106 NewFile.open( QIODevice::ReadWrite | QIODevice::Append );
00107 QTextStream t( &NewFile );
00108
00109 QTreeWidgetItemIterator it(LogText);
00110 while (*it) {
00111 QTreeWidgetItem* itm = *it++;
00112 t << itm->text(0) << " " << itm->text(1) << " " << itm->text(3) << "\n";
00113 }
00114 NewFile.close();
00115 }