1 /* Copyright (c) 2015  Gerald Knizia
2  *
3  * This file is part of the IboView program (see: http://www.iboview.org)
4  *
5  * IboView is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * IboView is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/
16  *
17  * Please see IboView documentation in README.txt for:
18  * -- A list of included external software and their licenses. The included
19  *    external software's copyright is not touched by this agreement.
20  * -- Notes on re-distribution and contributions to/further development of
21  *    the IboView software
22  */
23 
24 #ifndef IV_LOG_H
25 #define IV_LOG_H
26 
27 #include <QString>
28 #include <QTextStream>
29 #include "CtIo.h"
30 
31 class FLogQt : public QObject, public ct::FLog
32 {
33    Q_OBJECT
34 public:
35    void Flush(); // override
36 
37    explicit FLogQt(QObject *parent=0);
38    ~FLogQt();
39 
40    FRunStatus GetStatus(); // override
41 signals:
42    void textEmitted(QString s);
43    void sectionEnded();
44    // ^- that is really just a work-around for QTextBrowser getting really slow when
45    //    appending stuff to long texts...
46    void reportEnded(QString Log);
47 public slots:
48    // tell the running process to emit an abort signal the next time
49    // CheckStatus() is called. Works like this:
50    //
51    // Gui Thread: send (queued) abort signal to FLogQt. This flags
52    //     the AbortSignalled flag in the FLogQt object.
53    // Worker thread: call CheckStatus() at convenient point during
54    //     calculations. If CheckStatus sees that an abort was
55    //     signalled, it raises the corresponding FLogError
56    //     exception.
57    void emitAbortSignal();
58    void endSection();
59    virtual void endReport();
60 protected:
61    bool m_AbortSignalled;
62 };
63 
64 
65 class FMemoryLogQt : public FLogQt
66 {
67    Q_OBJECT
68 public:
69    explicit FMemoryLogQt(QObject *parent=0);
70    ~FMemoryLogQt();
71 
72    QString const &GetText();
73    void Clear();
74    void Flush(); // override
75 public slots:
76    void appendText(QString s);
77    void endReport(); // overwrite
78 protected:
79    QString
80       m_LogText;
81    QTextStream
82       m_LogStream;
83 };
84 
85 
86 #endif // IV_LOG_H
87