From 33576a4d67f40f95ad007d42f669c4122756a2e4 Mon Sep 17 00:00:00 2001 From: Kjell Morgenstern Date: Fri, 10 Nov 2023 18:17:52 +0100 Subject: [PATCH] Added probe for getting a FMessageBox log. --- pri/utils.pri | 6 +++-- src/fapplication.cpp | 3 +++ src/utils/FMessageLogProbe.cpp | 44 ++++++++++++++++++++++++++++++++++ src/utils/FMessageLogProbe.h | 35 +++++++++++++++++++++++++++ src/utils/fmessagebox.cpp | 15 ++++++++++++ src/utils/fmessagebox.h | 5 ++++ 6 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/utils/FMessageLogProbe.cpp create mode 100644 src/utils/FMessageLogProbe.h diff --git a/pri/utils.pri b/pri/utils.pri index 3b827522e..faeb4abf4 100644 --- a/pri/utils.pri +++ b/pri/utils.pri @@ -41,7 +41,8 @@ src/utils/ratsnestcolors.h \ src/utils/schematicrectconstants.h \ src/utils/s2s.h \ src/utils/textutils.h \ -src/utils/zoomslider.h +src/utils/zoomslider.h \ +src/utils/FMessageLogProbe.h SOURCES += \ $$PWD/../src/utils/ftooltip.cpp \ @@ -67,4 +68,5 @@ src/utils/ratsnestcolors.cpp \ src/utils/schematicrectconstants.cpp \ src/utils/s2s.cpp \ src/utils/textutils.cpp \ -src/utils/zoomslider.cpp +src/utils/zoomslider.cpp \ +src/utils/FMessageLogProbe.cpp diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 655fa0a53..97d6c0714 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -35,6 +35,7 @@ along with Fritzing. If not, see . #include "utils/folderutils.h" #include "utils/lockmanager.h" #include "utils/fmessagebox.h" +#include "utils/FMessageLogProbe.h" #include "dialogs/translatorlistmodel.h" #include "partsbinpalette/partsbinview.h" #include "partsbinpalette/svgiconwidget.h" @@ -554,6 +555,8 @@ int FApplication::init() { m_started = false; m_lastTopmostWindow = nullptr; + new FMessageLogProbe(); + connect(&m_activationTimer, SIGNAL(timeout()), this, SLOT(updateActivation())); m_activationTimer.setInterval(10); m_activationTimer.setSingleShot(true); diff --git a/src/utils/FMessageLogProbe.cpp b/src/utils/FMessageLogProbe.cpp new file mode 100644 index 000000000..82d7d22c7 --- /dev/null +++ b/src/utils/FMessageLogProbe.cpp @@ -0,0 +1,44 @@ +/******************************************************************* + +Part of the Fritzing project - http://fritzing.org +Copyright (c) 2023 Fritzing GmbH + +Fritzing is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Fritzing is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Fritzing. If not, see . + +********************************************************************/ + +#include "FMessageLogProbe.h" + +#include +#include +#include + + +FMessageLogProbe::FMessageLogProbe() : FProbe("FMessageLog") {} + +QVariant FMessageLogProbe::read() { + QList> messages = FMessageBox::getLoggedMessages(); + QJsonArray jsonMessages; + + for (const QPair &message : messages) { + QJsonObject messageObj; + messageObj["title"] = message.first; + messageObj["text"] = message.second; + jsonMessages.append(messageObj); + } + + QJsonDocument doc(jsonMessages); + QString jsonString = doc.toJson(QJsonDocument::Indented); + return jsonString; +} diff --git a/src/utils/FMessageLogProbe.h b/src/utils/FMessageLogProbe.h new file mode 100644 index 000000000..1dfb433a6 --- /dev/null +++ b/src/utils/FMessageLogProbe.h @@ -0,0 +1,35 @@ +/******************************************************************* + +Part of the Fritzing project - http://fritzing.org +Copyright (c) 2023 Fritzing GmbH + +Fritzing is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Fritzing is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Fritzing. If not, see . + +********************************************************************/ + +#ifndef FMESSAGELOGPROBE_H +#define FMESSAGELOGPROBE_H + +#include "testing/FProbe.h" +#include "utils/fmessagebox.h" +#include + +class FMessageLogProbe : public FProbe { +public: + FMessageLogProbe(); + QVariant read() override; + void write(QVariant) override {} +}; + +#endif // FMESSAGELOGPROBE_H diff --git a/src/utils/fmessagebox.cpp b/src/utils/fmessagebox.cpp index a3968d6bd..b053a2898 100644 --- a/src/utils/fmessagebox.cpp +++ b/src/utils/fmessagebox.cpp @@ -23,6 +23,8 @@ along with Fritzing. If not, see . bool FMessageBox::BlockMessages = false; +QList> FMessageBox::messageLog; + FMessageBox::FMessageBox(QWidget * parent) : QMessageBox(parent) { } @@ -32,7 +34,17 @@ int FMessageBox::exec() { return QMessageBox::exec(); } + +void FMessageBox::logMessage(const QString &title, const QString &text) { + messageLog.append(qMakePair(title, text)); +} + +QList> FMessageBox::getLoggedMessages() { + return messageLog; +} + QMessageBox::StandardButton FMessageBox::critical( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons, StandardButton defaultButton) { + logMessage("critical: " + title, text); if (BlockMessages) { DebugDialog::debug("critcal " + title); DebugDialog::debug(text); @@ -43,6 +55,7 @@ QMessageBox::StandardButton FMessageBox::critical( QWidget * parent, const QStri } QMessageBox::StandardButton FMessageBox::information( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons, StandardButton defaultButton) { + logMessage("information: " + title, text); if (BlockMessages) { DebugDialog::debug("information " + title); DebugDialog::debug(text); @@ -53,6 +66,7 @@ QMessageBox::StandardButton FMessageBox::information( QWidget * parent, const QS } QMessageBox::StandardButton FMessageBox::question( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons, StandardButton defaultButton) { + logMessage("question: " + title, text); if (BlockMessages) { DebugDialog::debug("question " + title); DebugDialog::debug(text); @@ -63,6 +77,7 @@ QMessageBox::StandardButton FMessageBox::question( QWidget * parent, const QStri } QMessageBox::StandardButton FMessageBox::warning( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons, StandardButton defaultButton) { + logMessage("warning: " + title, text); if (BlockMessages) { DebugDialog::debug("warning " + title); DebugDialog::debug(text); diff --git a/src/utils/fmessagebox.h b/src/utils/fmessagebox.h index 338442893..53fdf9689 100644 --- a/src/utils/fmessagebox.h +++ b/src/utils/fmessagebox.h @@ -37,9 +37,14 @@ class FMessageBox : public QMessageBox { static QMessageBox::StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); static QMessageBox::StandardButton question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); static QMessageBox::StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); + static QList> getLoggedMessages(); public: static bool BlockMessages; + +protected: + static void logMessage(const QString &title, const QString &text); + static QList> messageLog; };