Skip to content

Commit

Permalink
Added probe for getting a FMessageBox log.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjell Morgenstern authored and KjellMorgenstern committed Dec 12, 2023
1 parent f49a795 commit 33576a4
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pri/utils.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#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"
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions src/utils/FMessageLogProbe.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
********************************************************************/

#include "FMessageLogProbe.h"

#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>


FMessageLogProbe::FMessageLogProbe() : FProbe("FMessageLog") {}

QVariant FMessageLogProbe::read() {
QList<QPair<QString, QString>> messages = FMessageBox::getLoggedMessages();
QJsonArray jsonMessages;

for (const QPair<QString, QString> &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;
}
35 changes: 35 additions & 0 deletions src/utils/FMessageLogProbe.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
********************************************************************/

#ifndef FMESSAGELOGPROBE_H
#define FMESSAGELOGPROBE_H

#include "testing/FProbe.h"
#include "utils/fmessagebox.h"
#include <QVariant>

class FMessageLogProbe : public FProbe {
public:
FMessageLogProbe();
QVariant read() override;
void write(QVariant) override {}
};

#endif // FMESSAGELOGPROBE_H
15 changes: 15 additions & 0 deletions src/utils/fmessagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.

bool FMessageBox::BlockMessages = false;

QList<QPair<QString, QString>> FMessageBox::messageLog;

FMessageBox::FMessageBox(QWidget * parent) : QMessageBox(parent) {
}

Expand All @@ -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<QPair<QString, QString>> 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/fmessagebox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QPair<QString, QString>> getLoggedMessages();

public:
static bool BlockMessages;

protected:
static void logMessage(const QString &title, const QString &text);
static QList<QPair<QString, QString>> messageLog;
};


Expand Down

0 comments on commit 33576a4

Please sign in to comment.