Skip to content

Commit 0a496b8

Browse files
committed
Fixed log crash issue #56
1 parent 1f69e26 commit 0a496b8

File tree

6 files changed

+66
-45
lines changed

6 files changed

+66
-45
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.13) # 2.2 - case insensitive syntax
22
# 3.13 included policy CMP0077
33

4-
project(ModbusTools VERSION 0.4.4 LANGUAGES CXX)
4+
project(ModbusTools VERSION 0.4.5 LANGUAGES CXX)
55

66
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
77
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

src/core/gui/logview/core_logview.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ mbCoreLogView::mbCoreLogView(QWidget *parent)
7777
//header->setSectionResizeMode(QHeaderView::ResizeToContents);
7878
//header->hide();
7979

80+
m_maxSize = 1<<20;
81+
m_offset = 0;
82+
8083
m_view = new QPlainTextEdit(this);
8184
m_view->setReadOnly(true);
8285
setFontString(Defaults::instance().font);
@@ -141,6 +144,7 @@ void mbCoreLogView::clear()
141144
{
142145
//m_model->clear();
143146
m_view->clear();
147+
m_offset = 0;
144148
}
145149

146150
void mbCoreLogView::exportLog()
@@ -173,5 +177,20 @@ void mbCoreLogView::logMessage(mb::LogFlag flag, const QString &source, const QS
173177
mb::toString(flag),
174178
text);
175179
}
180+
int sz = m_view->document()->characterCount();
181+
int linesz = s.size()+1;
182+
if ((sz + linesz) > m_maxSize)
183+
{
184+
QTextCursor cursor = m_view->textCursor();
185+
cursor.setPosition(0); // start of document
186+
cursor.setPosition(m_offset, QTextCursor::KeepAnchor); // select until offset
187+
cursor.removeSelectedText(); // remove the selection
188+
//m_view->clear();
189+
m_offset = sz-m_offset;
190+
}
191+
else if ((sz >= m_maxSize/2) && (m_offset == 0))
192+
{
193+
m_offset = sz;
194+
}
176195
m_view->appendPlainText(s);
177196
}

src/core/gui/logview/core_logview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public Q_SLOTS:
7575
mbCore *m_core;
7676
QToolBar *m_toolBar;
7777
QPlainTextEdit *m_view;
78+
int m_maxSize;
79+
int m_offset;
7880
//QTableView *m_view;
7981
//mbCoreLogViewModel *m_model;
8082
};

src/core/sdk/mbcore_config.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#ifndef MBCORE_CONFIG_H
2-
#define MBCORE_CONFIG_H
3-
4-
/*
5-
Major part of mbtools version
6-
*/
7-
#define MBTOOLS_VERSION_MAJOR 0
8-
9-
/*
10-
Minor part of mbtools version
11-
*/
12-
#define MBTOOLS_VERSION_MINOR 4
13-
14-
/*
15-
Patch part of mbtools version
16-
*/
17-
#define MBTOOLS_VERSION_PATCH 4
18-
19-
#endif // MBCORE_CONFIG_H
1+
#ifndef MBCORE_CONFIG_H
2+
#define MBCORE_CONFIG_H
3+
4+
/*
5+
Major part of mbtools version
6+
*/
7+
#define MBTOOLS_VERSION_MAJOR 0
8+
9+
/*
10+
Minor part of mbtools version
11+
*/
12+
#define MBTOOLS_VERSION_MINOR 4
13+
14+
/*
15+
Patch part of mbtools version
16+
*/
17+
#define MBTOOLS_VERSION_PATCH 5
18+
19+
#endif // MBCORE_CONFIG_H

src/server/python/mbconfig.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
# -----------------------------------------------------------------------------
2-
# mbconfig.py
3-
#
4-
# DO NOT EDIT THIS FILE! It is autogenerated.
5-
#
6-
# This is Python module for ModbusTools server configuration.
7-
# It is intended to be converted into a usable Python module
8-
# containing configuration parameters and logic for the Modbus server.
9-
# -----------------------------------------------------------------------------
10-
11-
# Major part of mbtools version
12-
MBTOOLS_VERSION_MAJOR = 0
13-
14-
# Minor part of mbtools version
15-
MBTOOLS_VERSION_MINOR = 4
16-
17-
# Patch part of mbtools version
18-
MBTOOLS_VERSION_PATCH = 4
19-
20-
# Integer representation of mbtools version
21-
MBTOOLS_VERSION_INT = (0 << 16) | (4 << 8) | 4
22-
23-
# String representation of mbtools version
24-
MBTOOLS_VERSION_STR = "0.4.4"
1+
# -----------------------------------------------------------------------------
2+
# mbconfig.py
3+
#
4+
# DO NOT EDIT THIS FILE! It is autogenerated.
5+
#
6+
# This is Python module for ModbusTools server configuration.
7+
# It is intended to be converted into a usable Python module
8+
# containing configuration parameters and logic for the Modbus server.
9+
# -----------------------------------------------------------------------------
10+
11+
# Major part of mbtools version
12+
MBTOOLS_VERSION_MAJOR = 0
13+
14+
# Minor part of mbtools version
15+
MBTOOLS_VERSION_MINOR = 4
16+
17+
# Patch part of mbtools version
18+
MBTOOLS_VERSION_PATCH = 5
19+
20+
# Integer representation of mbtools version
21+
MBTOOLS_VERSION_INT = (0 << 16) | (4 << 8) | 5
22+
23+
# String representation of mbtools version
24+
MBTOOLS_VERSION_STR = "0.4.5"

src/version.pri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CONFIG += skip_target_version_ext
22

3-
VERSION = "0.4.4.0"
3+
VERSION = "0.4.5.0"
44

55
#__MBTOOLS_VERSION_LIST__ = $$split(VERSION, .)
66
#

0 commit comments

Comments
 (0)