Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
viewlogswidget.cpp
Go to the documentation of this file.
1 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
2 // FGx FlightGear Launcher // viewlogwidget.cpp
3 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-
4 // (c) 2010-2012
5 // Yves Sablonier, Pete Morgan
6 // Geoff McLane
7 // GNU GPLv2, see main.cpp and shipped licence.txt for further information
8 
9 #include <QHBoxLayout>
10 
11 #include <QGroupBox>
12 #include <QFile>
13 
14 
15 #include "logs/viewlogswidget.h"
16 #include "utilities/utilities.h"
17 
19  QWidget(parent)
20 {
21 
22  mainObject = mOb;
23 
24  setProperty("settings_namespace", QVariant("log_window"));
26 
27  setWindowIcon(QIcon(":/icon/log"));
28  setWindowTitle(tr("Log"));
29 
30  QHBoxLayout *mainLayout = new QHBoxLayout();
31 
32  setLayout(mainLayout);
33 
34  tabWidget = new QTabWidget();
35  mainLayout->addWidget(tabWidget);
36 
37  //================================================
38  //== FgFs Log
39  txtFgFsLog = new QPlainTextEdit();
40  tabWidget->addTab(txtFgFsLog, QIcon(":/icon/log"), "FlightGear log");
41 
42 
43  //================================================
44  //== Terrasync Log
45  txtTerraSyncLog = new QPlainTextEdit();
46  tabWidget->addTab(txtTerraSyncLog, QIcon(":/icon/log"), "TerraSync log");
47 
48  //================================================
49  //== FgCom Log
50  txtFgComLog = new QPlainTextEdit();
51  tabWidget->addTab(txtFgComLog, QIcon(":/icon/log"), "Fgcom log");
52 
53 
54  //==============================================
55  //== Fgx Log
56  QGroupBox *groupBox = new QGroupBox(tr("Log Output"));
57  tabWidget->addTab(groupBox, QIcon(":/icon/log"), "FGx log");
58 
59 
60  QHBoxLayout *layoutBox = new QHBoxLayout();
61  groupBox->setLayout(layoutBox);
62 
63  txtFgxLog= new QPlainTextEdit();
64  layoutBox->addWidget(txtFgxLog);
65 
66 
67  QVBoxLayout *layoutButtons = new QVBoxLayout();
68  layoutBox->addLayout(layoutButtons);
69 
70  buttonFgxRefresh = new QPushButton();
71  buttonFgxRefresh->setText(tr("Refresh"));
72  buttonFgxRefresh->setIcon(QIcon(":/icon/refresh"));
73  connect(buttonFgxRefresh, SIGNAL(clicked()), this, SLOT(on_load_fgx_log_file()));
74 
75  layoutButtons->addWidget(buttonFgxRefresh);
76 
77 
78  layoutButtons->addStretch(20);
79 
80 
82 }
83 
84 
85 //=========================================================
86 //== FGx log
88 
89  QString file_name = mainObject->log_file_path();
90  QFile file(file_name);
91  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
92  return;
93  }
94  txtFgxLog->setPlainText( file.readAll());
95 }
96 
97 
98 
99 
100 
101 
102 //=========================================================
103 //== clear log
104 void ViewLogsWidget::clear_log(QString log_name)
105 {
106  if(log_name == "fgfs"){
107  txtFgFsLog->clear();
108  if (stgFgFsLog.length()) {
109  outLog("clear_log:"+log_name+":"+stgFgFsLog);
110  stgFgFsLog.clear();
111  }
112  }else if(log_name == "fgx"){
113  txtFgxLog->clear();
114  if (stgFgxLog.length()) {
115  outLog("clean_log:"+log_name+":"+stgFgxLog);
116  stgFgxLog.clear();
117  }
118  }else if(log_name == "fgcom"){
119  txtFgComLog->clear();
120  if (stgFgComLog.length()) {
121  outLog("clear_log:"+log_name+":"+stgFgComLog);
122  stgFgComLog.clear();
123  }
124 
125  }else if(log_name == "terrasync"){
126  txtTerraSyncLog->clear();
127  if (stgTerraSyncLog.length()) {
128  outLog("clear_log:"+log_name+":"+stgTerraSyncLog);
129  stgTerraSyncLog.clear();
130  }
131  }
132 }
133 
134 //=========================================================
135 //== add log
136 void ViewLogsWidget::add_log(QString log_name, QString line)
137 {
138  bool hasle = line.contains(QChar('\n'));
139  QString trim = line.trimmed();
140  int len = trim.length();
141  if(log_name == "fgfs"){
142  txtFgFsLog->insertPlainText(line);
143  txtFgFsLog->moveCursor(QTextCursor::End);
144  if (len) {
145  if (hasle)
146  stgFgFsLog.append(trim);
147  else
148  stgFgFsLog.append(line);
149  }
150  if (hasle && stgFgFsLog.length()) {
151  outLog("add_log:"+log_name+":"+stgFgFsLog);
152  stgFgFsLog.clear();
153  }
154 
155  }else if(log_name == "fgx"){
156  txtFgxLog->insertPlainText(line);
157  txtFgxLog->moveCursor(QTextCursor::End);
158  if (len) {
159  if (hasle)
160  stgFgxLog.append(trim);
161  else
162  stgFgxLog.append(line);
163  }
164  if (hasle && stgFgxLog.length()) {
165  outLog("add_log:"+log_name+":"+stgFgxLog);
166  stgFgxLog.clear();
167  }
168 
169  }else if(log_name == "fgcom"){
170  txtFgComLog->insertPlainText(line);
171  txtFgComLog->moveCursor(QTextCursor::End);
172  if (len) {
173  if (hasle)
174  stgFgComLog.append(trim);
175  else
176  stgFgComLog.append(line);
177  }
178  if (hasle && stgFgComLog.length()) {
179  outLog("add_log:"+log_name+":"+stgFgComLog);
180  stgFgComLog.clear();
181  }
182 
183  }else if(log_name == "terrasync"){
184  txtTerraSyncLog->insertPlainText(line);
185  txtTerraSyncLog->moveCursor(QTextCursor::End);
186  if (len) {
187  if (hasle)
188  stgTerraSyncLog.append(trim);
189  else
190  stgTerraSyncLog.append(line);
191  }
192  if (hasle && stgTerraSyncLog.length()) {
193  outLog("add_log:"+log_name+":"+stgTerraSyncLog);
194  stgTerraSyncLog.clear();
195  }
196  } else {
197  if (len)
198  outLog("add_log:"+log_name+"????:"+trim);
199  }
200 }
201 
202 //=========================================================
203 //== CloseEvent
204 void ViewLogsWidget::closeEvent(QCloseEvent *event){
205  clear_log("fgfs");
206  clear_log("fgx");
207  clear_log("fgcom");
208  clear_log("terrasync");
210  mainObject->settings->sync();
211  event->accept();
212 }
213 
215 {
216  clear_log("fgfs");
217  clear_log("fgx");
218  clear_log("fgcom");
219  clear_log("terrasync");
220 }
221 
QTabWidget * tabWidget
static QString log_file_path()
Log File.
Definition: mainobject.cpp:388
The MainObject is an extended QObject, and the main "controller" for FGx.
Definition: mainobject.h:66
QPlainTextEdit * txtFgComLog
void clear_log(QString log_name)
void closeEvent(QCloseEvent *event)
void saveWindow(QWidget *widget)
Saves a window's size and position.
Definition: xsettings.cpp:90
QPushButton * buttonFgxRefresh
void restoreWindow(QWidget *widget)
Restores a size window position.
Definition: xsettings.cpp:101
ViewLogsWidget(MainObject *mob, QWidget *parent=0)
QString stgTerraSyncLog
void add_log(QString log_name, QString log)
void on_load_fgx_log_file()
QPlainTextEdit * txtFgxLog
QPlainTextEdit * txtFgFsLog
QString stgFgComLog
QString stgFgFsLog
MainObject * mainObject
QPlainTextEdit * txtTerraSyncLog
XSettings * settings
Definition: mainobject.h:85