Skip to content

Commit

Permalink
pluginbase/ScopyJS: Added a suppress messages function for ScopyJS mode.
Browse files Browse the repository at this point in the history
Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 authored and adisuciu committed Sep 25, 2023
1 parent cae039e commit bcbbacd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pluginbase/include/pluginbase/scopyjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QFutureWatcher>
#include <QJSEngine>
#include "apiobject.h"
#include "qloggingcategory.h"
#include "scopy-pluginbase_export.h"
#include "scopy-pluginbase_config.h"
#include <QSocketNotifier>
Expand Down Expand Up @@ -55,6 +56,7 @@ class SCOPY_PLUGINBASE_EXPORT ScopyJS : public QObject
Q_INVOKABLE void printToConsole(const QString& text);
Q_INVOKABLE QString readFromConsole(const QString& text);
Q_INVOKABLE void returnToApplication();
Q_INVOKABLE void suppressScopyMessages(bool b);

QJSEngine *engine();

Expand All @@ -78,6 +80,8 @@ public Q_SLOTS:
QSocketNotifier *notifier;
bool done;
static ScopyJS * pinstance_;
static QLoggingCategory::CategoryFilter oldCategoryFilter;
static void jsCategoryFilter(QLoggingCategory *category);
};

}
Expand Down
36 changes: 35 additions & 1 deletion pluginbase/src/scopyjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
#include <iostream>
#include <common/common.h>


Q_LOGGING_CATEGORY(CAT_JS, "Scopy_JS")

using std::cout;
using namespace scopy;

QLoggingCategory::CategoryFilter ScopyJS::oldCategoryFilter{nullptr};

ScopyJS* ScopyJS::pinstance_{nullptr};
ScopyJS::ScopyJS(QObject *parent) : QObject(parent) {
}
Expand Down Expand Up @@ -101,6 +103,15 @@ void ScopyJS::returnToApplication()
}
}

void ScopyJS::suppressScopyMessages(bool b)
{
if (b) {
QLoggingCategory::installFilter(jsCategoryFilter);
} else {
QLoggingCategory::installFilter(oldCategoryFilter);
}
}

QJSEngine *ScopyJS::engine()
{
return &m_engine;
Expand Down Expand Up @@ -226,5 +237,28 @@ void ScopyJS::hasText()
out.flush();
}

void ScopyJS::jsCategoryFilter(QLoggingCategory *category)
{
if (oldCategoryFilter) {
oldCategoryFilter(category);
}
category->setEnabled(QtDebugMsg, false);
category->setEnabled(QtInfoMsg, false);
category->setEnabled(QtWarningMsg, false);
category->setEnabled(QtCriticalMsg, false);
category->setEnabled(QtFatalMsg, false);

if (qstrcmp(category->categoryName(), "Scopy_JS") == 0) {
category->setEnabled(QtDebugMsg, true);
category->setEnabled(QtInfoMsg, true);
category->setEnabled(QtWarningMsg, true);
category->setEnabled(QtCriticalMsg, true);
category->setEnabled(QtFatalMsg, true);
}

if (qstrcmp(category->categoryName(), "Scopy_API") == 0) {
category->setEnabled(QtWarningMsg, true);
}
}

#include "moc_scopyjs.cpp"

0 comments on commit bcbbacd

Please sign in to comment.