PSQt/src/GUILogger.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------
00002 // File and Version Information:
00003 //   $Id: GUILogger.cpp 9841 2015-03-26 18:35:44Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Author: Mikhail S. Dubrovin
00006 //---------------------------------------------------------------------
00007 
00008 //--------------------------
00009 
00010 #include "PSQt/GUILogger.h"
00011 #include "PSQt/Logger.h"
00012 
00013 #include <iostream>  // std::cout
00014 #include <sstream>   // std::stringstream
00015 
00016 #include <QIntValidator>
00017 
00018 //using namespace std; // for cout without std::
00019 
00020 namespace PSQt {
00021 
00022 //--------------------------
00023 
00024 GUILogger::GUILogger( QWidget *parent, const bool& showbuts, const bool& showframe)
00025   : Frame(parent) //  , Logger()
00026   , m_showbuts(showbuts)
00027   , m_showframe(showframe)
00028 {
00029   m_txt_edi  = new QTextEdit();
00030   m_but_save = new QPushButton("Save");
00031   m_combo    = new QComboBox(this);
00032 
00033   m_list << strLevel(DEBUG).c_str()
00034          << strLevel(INFO).c_str()
00035          << strLevel(WARNING).c_str()
00036          << strLevel(ERROR).c_str()
00037          << strLevel(CRITICAL).c_str();
00038 
00039   m_combo -> addItems(m_list);
00040   m_combo -> setCurrentIndex(1); 
00041 
00042   m_cbox = new QHBoxLayout;
00043   m_cbox -> addStretch(1);
00044   m_cbox -> addWidget(m_combo);
00045   m_cbox -> addWidget(m_but_save);
00046 
00047   m_vbox = new QVBoxLayout;
00048   m_vbox -> addWidget(m_txt_edi);
00049   m_vbox -> addLayout(m_cbox);
00050 
00051   this -> setLayout(m_vbox);
00052 
00053   this -> showTips();
00054   this -> setStyle();
00055   this -> addStartRecords();
00056 
00057   connect(Logger::getLogger(), SIGNAL(signal_new_record(Record&)), this, SLOT(addNewRecord(Record&)));
00058   connect(m_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCombo(int)) );
00059   connect(m_but_save, SIGNAL(clicked()), this, SLOT(onSave()) );
00060 }
00061 
00062 //--------------------------
00063 void
00064 GUILogger::showTips() 
00065 {
00066   m_combo->setToolTip("Select the level of messages to show");
00067   m_txt_edi->setToolTip("Log messages");
00068   m_but_save->setToolTip("Save log in file");
00069 }
00070 
00071 //--------------------------
00072 void
00073 GUILogger::setStyle() 
00074 {
00075   setGeometry(100, 100, 500, 300);
00076 
00077   m_but_save->setVisible(m_showbuts);
00078   m_combo   ->setVisible(m_showbuts);
00079 
00080   Frame::setBoarderVisible(m_showframe);
00081   if (! m_showframe) this -> setContentsMargins(-9,-9,-9,-9);
00082 
00083   //this -> setWindowTitle(tr("GUILogger"));
00084   //this -> setMinimumWidth(700);
00085   //this -> setFixedWidth(220);
00086   //this -> setFixedHeight(50);
00087   //this -> setFixedHeight( (m_show_frame)? 50 : 34);
00088 
00089   //this -> move(300,50);
00090 }
00091 
00092 //--------------------------
00093 void 
00094 GUILogger::resizeEvent(QResizeEvent *event)
00095 {
00096   stringstream ss; ss << "w:" << event->size().width() << " h:" <<  event->size().height();
00097   setWindowTitle(ss.str().c_str());
00098 }
00099 
00100 //--------------------------
00101 void
00102 GUILogger::moveEvent(QMoveEvent *event)
00103 {
00104   stringstream ss; ss << "x:" << event->pos().x() << " y:" << event->pos().y();
00105   setWindowTitle(ss.str().c_str());
00106 }
00107 
00108 //--------------------------
00109 void 
00110 GUILogger::closeEvent(QCloseEvent *event)
00111 {
00112   QWidget::closeEvent(event);
00113   stringstream ss; ss << "closeEvent(...): type = " << event -> type();
00114   MsgInLog(_name_(), INFO, ss.str());
00115 }
00116 
00117 //--------------------------
00118 void  
00119 GUILogger::onCombo(int i)
00120 {
00121   std::string str_level = m_list.at(i).toStdString();
00122   MsgInLog(_name_(), INFO, "Selected level: " + str_level);
00123 
00124   LEVEL level = levelFromString(str_level);
00125   std::string recs = Logger::getLogger()->strRecordsForLevel(level);
00126   m_txt_edi->clear();
00127   m_txt_edi->append(recs.c_str());
00128 
00129   SetMsgLevel(level);
00130 
00131   scrollDown();
00132 }
00133 
00134 //--------------------------
00135 void  
00136 GUILogger::onSave()
00137 {
00138   MsgInLog(_name_(), INFO, "\"Save\" button is clicked");
00139   SaveLog();
00140 }
00141 
00142 //--------------------------
00143 void 
00144 GUILogger::scrollDown()
00145 {
00146   m_txt_edi->moveCursor(QTextCursor::End);
00147   m_txt_edi->repaint();
00148 }
00149 
00150 //--------------------------
00151 void 
00152 GUILogger::addNewRecord(Record& rec)
00153 {
00154   //std::cout << rec.strRecordTotal() << '\n';  
00155   //m_txt_edi->append(rec.strRecordTotal().c_str());
00156   m_txt_edi->append(rec.strRecord().c_str());
00157 
00158   scrollDown();
00159 }
00160 
00161 
00162 //--------------------------
00163 void 
00164 GUILogger::addStartRecords()
00165 {
00166   std::string start_recs = Logger::getLogger()->strRecordsForLevel(Logger::getLogger()->getLevel());
00167   m_txt_edi->append(start_recs.c_str());
00168 
00169   //cout << _name_() << "addStartRecords():\n" << start_recs << '\n';
00170 
00171   scrollDown();
00172 }
00173 
00174 //--------------------------
00175 //--------------------------
00176 //--------------------------
00177 //--------------------------
00178 
00179 } // namespace PSQt
00180 
00181 //--------------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7