Skip to content

Commit 2e4e4a5

Browse files
authored
Merge pull request #1 from Bollos00/dev
Upgrade to version 1.1
2 parents c267a87 + dd7c862 commit 2e4e4a5

6 files changed

Lines changed: 48 additions & 27 deletions

File tree

QtMessageFilter/QtMessageFilter.pri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# MIT License
33
#
4-
# Copyright (c) 2020 Bollos00
4+
# Copyright (c) 2020-2021 Bruno Bollos Correa
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal

QtMessageFilter/src/QtMessageFilter/qtmessagefilter.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MIT License
33
//
4-
// Copyright (c) 2020 Bollos00
4+
// Copyright (c) 2020-2021 Bruno Bollos Correa
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal
@@ -31,16 +31,17 @@
3131
#include <QTimer>
3232
#include <QApplication>
3333
#include <QMutex>
34+
#include <QScrollBar>
3435

3536
QtMessageFilter* QtMessageFilter::m_singleton_instance = nullptr;
3637

3738
// For multi-thread safe
38-
QMutex mutex;
39+
QMutex qtMessageFilterMutex;
3940

40-
void QtMessageFilter::resetInstance(QWidget* parent, bool hide)
41+
void QtMessageFilter::resetInstance(QWidget* parent, bool hide, const ulong maximumItensSize, const ulong maximumMessageDetailsSize)
4142
{
4243
delete QtMessageFilter::m_singleton_instance;
43-
QtMessageFilter::m_singleton_instance = new QtMessageFilter(parent);
44+
QtMessageFilter::m_singleton_instance = new QtMessageFilter(parent, maximumItensSize, maximumMessageDetailsSize);
4445

4546
if(!hide)
4647
QtMessageFilter::showDialog();
@@ -130,7 +131,7 @@ void QtMessageFilter::reject()
130131
this->hide();
131132
}
132133

133-
QtMessageFilter::QtMessageFilter(QWidget *parent)
134+
QtMessageFilter::QtMessageFilter(QWidget *parent, const ulong maximumItensSize, const ulong maximumMessageDetailsSize)
134135
: QDialog(parent),
135136
m_debug(),
136137
m_info(),
@@ -152,8 +153,8 @@ QtMessageFilter::QtMessageFilter(QWidget *parent)
152153
m_current_dialog_vertical_layout(new QVBoxLayout(m_current_dialog)),
153154
m_current_dialog_text(new QPlainTextEdit(m_current_dialog)),
154155
m_log_file(new QFile()),
155-
m_maximum_itens_size(100),
156-
m_maximum_message_details_size(100)
156+
m_maximum_itens_size(maximumItensSize),
157+
m_maximum_message_details_size(maximumMessageDetailsSize)
157158
{
158159
f_configure_ui();
159160

@@ -257,7 +258,7 @@ void QtMessageFilter::f_configure_ui()
257258
this->setLayout(m_vertical_layout_global);
258259

259260
// Maximum and minimum sizes of the dialog
260-
this->setMaximumSize(800, 1200);
261+
this->setMaximumSize(800, 1600);
261262
this->setMinimumSize(400, 500);
262263

263264
// This looks unecessary, I shall investigate another option
@@ -302,12 +303,12 @@ void QtMessageFilter::f_configure_ui()
302303

303304
void QtMessageFilter::f_message_filter(const QtMsgType type, const QMessageLogContext& context, const QString& msg)
304305
{
305-
mutex.lock();
306+
qtMessageFilterMutex.lock();
306307

307308
if(QtMessageFilter::good())
308309
QtMessageFilter::f_instance()->f_message_output(type, context, msg);
309310

310-
mutex.unlock();
311+
qtMessageFilterMutex.unlock();
311312
}
312313

313314
void QtMessageFilter::f_message_output(const QtMsgType type,
@@ -553,7 +554,6 @@ void QtMessageFilter::f_remove_item_from_list(QSharedPointer<MessageDetails> mes
553554

554555
void QtMessageFilter::slot_create_message_item(QSharedPointer<MessageDetails> messageDetails)
555556
{
556-
MessageItem* item = new MessageItem(m_widget_scroll_area);
557557
QString styleSheet;
558558

559559
switch(messageDetails->type)
@@ -578,13 +578,26 @@ void QtMessageFilter::slot_create_message_item(QSharedPointer<MessageDetails> me
578578
return;
579579
}
580580

581+
MessageItem* item = new MessageItem(m_widget_scroll_area);
582+
581583
item->setText(messageDetails->message);
582584
item->setStyleSheet(styleSheet);
583585
m_list.append(QPair< QSharedPointer<MessageDetails>, MessageItem* >(messageDetails, item));
584586
item->adjustSize();
585587
m_vertical_layout_scroll_area->addWidget(item);
586588
item->show();
587589

590+
// Force update of the list of messages
591+
qApp->processEvents();
592+
593+
// If the item further below is visible, make sure the new item continues visible as well
594+
const bool lockDownertical = m_scroll_area->verticalScrollBar()->maximum() - m_scroll_area->verticalScrollBar()->value() < 50;
595+
596+
if(lockDownertical)
597+
{
598+
m_scroll_area->verticalScrollBar()->setValue(m_scroll_area->verticalScrollBar()->maximum());
599+
}
600+
588601
// Is this the best way of doing it?
589602
connect(item, &MessageItem::SIGNAL_leftButtonReleased,
590603
[this, messageDetails]{f_create_dialog_with_message_details(*messageDetails);});

QtMessageFilter/src/QtMessageFilter/qtmessagefilter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MIT License
33
//
4-
// Copyright (c) 2020 Bollos00
4+
// Copyright (c) 2020-2021 Bruno Bollos Correa
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
77
// of this software and associated documentation files (the "Software"), to deal
@@ -144,7 +144,7 @@ class QtMessageFilter : public QDialog
144144

145145
public:
146146

147-
static void resetInstance(QWidget* parent = nullptr, bool hideDialog = false);
147+
static void resetInstance(QWidget* parent = nullptr, bool hideDialog = false, const ulong maximumItensSize = 100, const ulong maximumMessageDetailsSize = 10);
148148
static void releaseInstance();
149149
static bool good();
150150

@@ -163,7 +163,7 @@ class QtMessageFilter : public QDialog
163163

164164
private:
165165

166-
QtMessageFilter(QWidget *parent = nullptr);
166+
QtMessageFilter(QWidget *parent = nullptr, const ulong maximumItensSize = 100, const ulong maximumMessageDetailsSize = 10);
167167
QtMessageFilter(const QtMessageFilter& that) = delete;
168168
QtMessageFilter(QtMessageFilter&& that) = delete;
169169
~QtMessageFilter();

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ This repository implements a [Message Handler for Qt Applications](https://doc.q
55

66
![Qt Message Filter example](./share/Screenshot0.png)
77

8-
If you want to include this feature on your project, just get the content of `./QtMessageFilter` and include the `QtMessageFilter.pri` file on your project, something like:
8+
If you are using QMake and want to include this feature on your project, just get the content of `./QtMessageFilter` and include the `QtMessageFilter.pri` file on your project, something like:
99
```qmake
1010
include(QtMessageFilter/QtMessageFilter.pri)
1111
```
1212

13-
It can receive messages coming from multiple threads and can be initialized with `QtMessageFilter::resetInstance()`, calling this will install the message handler and make all messages to be treated on the `QtMessageFilter` class. Even tho it is expected to use it during all run time, you can reinstall the default message handler calling `QtMessageFilter::releaseInstance()`, this will also delete the instance of the class. You can omit and show the QtMessageFilter GUI calling `QtMessageFilter::hideDialog()` and `QtMessageFilter::showDialog()`. I have ~~lazily~~ documented the behaviour of this class with a little more details [here](https://github.com/Bollos00/QtMessageFilter/blob/master/QtMessageFilter/src/QtMessageFilter/qtmessagefilter.h), you may also want to see a silly implementation of on the `tests` directory.
13+
It can receive messages coming from multiple threads and can be initialized with `QtMessageFilter::resetInstance()`, calling this will install the message handler and make all messages to be treated on the `QtMessageFilter` class. Even tho it is expected to use it during all run time, you can reinstall the default message handler calling `QtMessageFilter::releaseInstance()`, this will also delete the instance of the class. You can omit and show the QtMessageFilter GUI calling `QtMessageFilter::hideDialog()` and `QtMessageFilter::showDialog()`. I have ~~lazily~~ documented the behaviour of this class with a little more details [here](https://github.com/Bollos00/QtMessageFilter/blob/master/QtMessageFilter/src/QtMessageFilter/qtmessagefilter.h).
14+
15+
You may also want to see a silly implementation of on the `tests` directory, the example shows a simple gui that create messages of the four different types each 0,5 seconds. There, it is also possible to hide and show the QtMessageFilter dialog and reinstall the message handler.

tests/main.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIT License
22

3-
// Copyright (c) 2020 Bollos00
3+
// Copyright (c) 2020-2021 Bruno Bollos Correa
44

55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -29,6 +29,10 @@
2929
#include <QLabel>
3030
#include <QPushButton>
3131

32+
33+
// Set there the maximum number of items
34+
const int MAXIMUM_ITEMS_SIZE = 10;
35+
3236
class TestWidget : public QMainWindow
3337
{
3438
public:
@@ -72,7 +76,7 @@ class TestWidget : public QMainWindow
7276
if(QtMessageFilter::good())
7377
QtMessageFilter::releaseInstance();
7478
else
75-
QtMessageFilter::resetInstance(this);
79+
QtMessageFilter::resetInstance(this, false, MAXIMUM_ITEMS_SIZE);
7680
});
7781

7882
}
@@ -94,7 +98,7 @@ int main(int argc, char *argv[])
9498
QApplication a(argc, argv);
9599

96100
TestWidget* w = new TestWidget();
97-
QtMessageFilter::resetInstance(w, true);
101+
QtMessageFilter::resetInstance(w, true, MAXIMUM_ITEMS_SIZE);
98102

99103
QTimer* tmr = new QTimer();
100104
QObject::connect(tmr, &QTimer::timeout,
@@ -103,19 +107,21 @@ int main(int argc, char *argv[])
103107
static int k=0;
104108

105109
if(k%4 == 0)
110+
{
106111
qDebug()<<"Teste "<< k;
112+
}
107113
else if(k%4 == 1)
114+
{
108115
qInfo()<<"Teste "<< k<<'\n'<<"A great line of text, but a big, very and very big line of text, lot of characteres in one single line";
116+
}
109117
else if(k%4 == 2)
118+
{
110119
qWarning()<<"Teste "<< k<<'\n'<<"Another line here";
120+
}
111121
else
122+
{
112123
qCritical()<<"Teste "<< k;
113-
114-
// if(k%20 == 9)
115-
// QtMessageFilter::hideDialog();
116-
117-
// if(k%20 == 19)
118-
// QtMessageFilter::showDialog();
124+
}
119125

120126
k++;
121127
});

tests/test0.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
# Copyright (c) 2020 Bollos00
3+
# Copyright (c) 2020-2021 Bruno Bollos Correa
44

55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)