Debian Codegraph @

src/plugins/schedulers/tj/taskjuggler/TjMessageHandler.h

raw
1 /*
2 * TjMessageHandler.h - TaskJuggler
3 *
4 * Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 * by Chris Schlaeger <[email protected]>
6 * SPDX-FileCopyrightText: 2011 Dag Andersen <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * $Id$
13 */
14 #ifndef _TjMessageHandler_h_
15 #define _TjMessageHandler_h_
16
17 #include <QObject>
18 #include <QString>
19
20 namespace TJ
21 {
22
23 /**
24 * This class handles all error or warning messages that the library functions
25 * can send out. Depending on the mode it either send the messages to STDERR
26 * or raises a Qt signal.
27 *
28 * @short Handles all error or warning messages.
29 * @author Chris Schlaeger <[email protected]>
30 */
31
32 class CoreAttributes;
33
34 class TjMessageHandler : public QObject
35 {
36 Q_OBJECT
37 public:
38 explicit TjMessageHandler(bool cm = true) :
39 QObject(),
40 consoleMode(cm),
41 warnings(0),
42 errors(0)
43 { }
44 ~TjMessageHandler() override { }
45
46 void warningMessage(const QString& msg, const CoreAttributes *object = nullptr);
47 void warningMessage(const QString& msg, const QString& file,
48 int line = -1);
49
50 void errorMessage(const QString& msg, const CoreAttributes *object = nullptr);
51 void errorMessage(const QString& msg, const QString& file,
52 int line = -1);
53
54 void fatalMessage(const QString& msg, const QString& file = QString(),
55 int line = -1);
56
57 void setConsoleMode(bool cm) { consoleMode = cm; }
58
59 void resetCounters() { warnings = errors = infos = debugs = 0; }
60 void reset() { resetCounters(); messages.clear(); }
61
62 bool isWarning(int messagePos) const { return warningPositions.contains(messagePos); }
63 int getWarnings() const { return warnings; }
64 QString getWarningMessage(int pos) const { return getMessage(warningPositions.value(pos) ); }
65
66 bool isError(int messagePos) const { return errorPositions.contains(messagePos); }
67 int getErrors() const { return errors; }
68 QString getErrorMessage(int pos) const { return getMessage(errorPositions.value(pos) ); }
69
70 bool isInfo(int messagePos) const { return infoPositions.contains(messagePos); }
71 void infoMessage(const QString &msg, const CoreAttributes *object = nullptr);
72 int getInfos() const { return infos; }
73 QString getInfoMessage(int pos) const { return getMessage(infoPositions.value(pos) ); }
74
75 bool isDebug(int messagePos) const { return debugPositions.contains(messagePos); }
76 void debugMessage(const QString &msg, const CoreAttributes *object = nullptr);
77 int getDebugs() const { return debugs; }
78 QString getDebugMessage(int pos) const { return getMessage(debugPositions.value(pos) ); }
79
80 int getMessageCount() const { return messages.count(); }
81 QString getMessage(int pos) const { return messages.value(pos); }
82
83 Q_SIGNALS:
84 void printWarning(const QString& msg, const QString& file, int line);
85 void printError(const QString& msg, const QString& file, int line);
86 void printFatal(const QString& msg, const QString& file, int line);
87
88 void message(int type, const QString &msg, TJ::CoreAttributes *object);
89
90 private:
91 bool consoleMode;
92 QList<QString> messages;
93 int warnings;
94 QList<int> warningPositions;
95 int errors;
96 QList<int> errorPositions;
97 int infos;
98 QList<int> infoPositions;
99 int debugs;
100 QList<int> debugPositions;
101 };
102
103 extern TjMessageHandler TJMH;
104
105 } // namespace TJ
106
107 #endif