Console/ILogger: Refactor and extension

=======================================

Refactor:
 - Substitute the use of variadic templates with parameter packs.
 - Use recently incorporated external library "fmt" to handle printf like formating.
 - Extensive cleaning of pragmas and unnecessary forward declarations.
 - Parameter packs and libfmt provide a much stronger type checking now, so
   conversions that are by standard implicit as bool to int need an explicit static_cast
   to avoid compilation warnings.

Extension:
 - Include a notifier field, so that the originator of the message can be provided. E.g. Document#DocumentObject
 - Include a new type of message called CriticalMessage, this message is intended to have
   special behaviour in the future. Namely, it will be used to notify forward compatilibity issues.
   It will be used to substitute the current signal/slot mechanism.
 - Include two new types of messages for user notifications (Notification and TranslatedNotification). This messages
   will be use to convey UI notifications intended for the user (such as non-intrusive message about the usage of a tool). There
   are two versions to mark whether the string provided as a message is already translated or not. When using the console system for
   notifications, these notifications may originate from the App or the Gui. In the former, it is generally the case that the strings
   of messages are not (yet) translated (but they can be marked with QT_TRANSLATE_NOOP). In the latter, often the messages to be provided
   are already translated.

Python support for CriticalMessage, Notification and TranslatedNofification, including shortcuts:

    Crt = FreeCAD.Console.PrintCritical
    Ntf = FreeCAD.Console.PrintNotification
    Tnf = FreeCAD.Console.PrintTranslatedNotification
This commit is contained in:
Abdullah Tahiri
2023-03-03 12:34:15 +01:00
committed by abdullahtahiriyo
parent 2dac347526
commit c604d1741d
28 changed files with 655 additions and 285 deletions

View File

@@ -70,10 +70,11 @@ class GuiExport ReportHighlighter : public QSyntaxHighlighter
{
public:
enum Paragraph {
Message = 0, /**< normal text */
Warning = 1, /**< Warning */
Error = 2, /**< Error text */
LogText = 3 /**< Log text */
Message = 0, /**< normal text */
Warning = 1, /**< Warning */
Error = 2, /**< Error text */
LogText = 3, /**< Log text */
Critical = 4, /**< critical text */
};
public:
@@ -87,6 +88,7 @@ public:
* @see ReportOutput::Message
* @see ReportOutput::Warning
* @see ReportOutput::Error
* @see ReportOutput::Critical
*/
void setParagraphType(Paragraph);
@@ -110,11 +112,16 @@ public:
*/
void setErrorColor( const QColor& col );
/**
* Sets the text color to \a col.
*/
void setCriticalColor( const QColor& col );
private:
/** @name for internal use only */
//@{
Paragraph type;
QColor txtCol, logCol, warnCol, errCol;
QColor txtCol, logCol, warnCol, errCol, criticalCol;
//@}
};
@@ -134,7 +141,7 @@ public:
/** Observes its parameter group. */
void OnChange(Base::Subject<const char*> &rCaller, const char * sReason) override;
void SendLog(const std::string& msg, Base::LogStyle level) override;
void SendLog(const std::string& notifiername, const std::string& msg, Base::LogStyle level) override;
/// returns the name for observer handling
const char* Name() override {return "ReportOutput";}
@@ -150,6 +157,8 @@ public:
bool isLogMessage() const;
/** Returns true whether normal messages are reported. */
bool isNormalMessage() const;
/** Returns true whether critical messages are reported. */
bool isCritical() const;
protected:
/** For internal use only */
@@ -172,12 +181,16 @@ public Q_SLOTS:
void onToggleLogMessage();
/** Toggles the report of normal messages. */
void onToggleNormalMessage();
/** Toggles the report of normal messages. */
void onToggleCritical();
/** Toggles whether to show report view on warnings*/
void onToggleShowReportViewOnWarning();
/** Toggles whether to show report view on errors*/
void onToggleShowReportViewOnError();
/** Toggles whether to show report view on normal messages*/
void onToggleShowReportViewOnNormalMessage();
/** Toggles whether to show report view on normal messages*/
void onToggleShowReportViewOnCritical();
/** Toggles whether to show report view on log messages*/
void onToggleShowReportViewOnLogMessage();
/** Toggles the redirection of Python stdout. */