mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-09-03 13:47:51 -04:00
Optimize decoded text display to limit heap usage
Decoded text line now use considerably less heap memory as they accumulate. This change also limits the maximum number of decode lines saved per session to 5000. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7998 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
fdc3d2d4d8
commit
17bd43017e
@ -3,8 +3,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
#include <QFont>
|
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
#include <QTextBlock>
|
||||||
|
|
||||||
#include "qt_helpers.hpp"
|
#include "qt_helpers.hpp"
|
||||||
|
|
||||||
@ -16,22 +16,25 @@ DisplayText::DisplayText(QWidget *parent) :
|
|||||||
setReadOnly (true);
|
setReadOnly (true);
|
||||||
viewport ()->setCursor (Qt::ArrowCursor);
|
viewport ()->setCursor (Qt::ArrowCursor);
|
||||||
setWordWrapMode (QTextOption::NoWrap);
|
setWordWrapMode (QTextOption::NoWrap);
|
||||||
setStyleSheet ("");
|
document ()->setMaximumBlockCount (5000); // max lines to limit heap usage
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayText::setContentFont(QFont const& font)
|
void DisplayText::setContentFont(QFont const& font)
|
||||||
{
|
{
|
||||||
setFont (font);
|
char_font_ = font;
|
||||||
m_charFormat.setFont (font);
|
|
||||||
selectAll ();
|
selectAll ();
|
||||||
auto cursor = textCursor ();
|
auto cursor = textCursor ();
|
||||||
cursor.mergeCharFormat (m_charFormat);
|
cursor.beginEditBlock ();
|
||||||
|
auto char_format = cursor.charFormat ();
|
||||||
|
char_format.setFont (char_font_);
|
||||||
|
cursor.mergeCharFormat (char_format);
|
||||||
cursor.clearSelection ();
|
cursor.clearSelection ();
|
||||||
cursor.movePosition (QTextCursor::End);
|
cursor.movePosition (QTextCursor::End);
|
||||||
|
|
||||||
// position so viewport scrolled to left
|
// position so viewport scrolled to left
|
||||||
cursor.movePosition (QTextCursor::Up);
|
cursor.movePosition (QTextCursor::Up);
|
||||||
cursor.movePosition (QTextCursor::StartOfLine);
|
cursor.movePosition (QTextCursor::StartOfLine);
|
||||||
|
cursor.endEditBlock ();
|
||||||
|
|
||||||
setTextCursor (cursor);
|
setTextCursor (cursor);
|
||||||
ensureCursorVisible ();
|
ensureCursorVisible ();
|
||||||
@ -50,29 +53,35 @@ void DisplayText::insertLineSpacer(QString const& line)
|
|||||||
appendText (line, "#d3d3d3");
|
appendText (line, "#d3d3d3");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayText::appendText(QString const& text, QString const& bg)
|
void DisplayText::appendText(QString const& text, QColor bg)
|
||||||
{
|
{
|
||||||
QString escaped {text.trimmed().replace('<',"<").replace('>',">").replace(' ', " ")};
|
|
||||||
QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
|
|
||||||
bg + "\">" + escaped + "</td></tr></table>";
|
|
||||||
auto cursor = textCursor ();
|
auto cursor = textCursor ();
|
||||||
cursor.movePosition (QTextCursor::End);
|
cursor.movePosition (QTextCursor::End);
|
||||||
auto pos = cursor.position ();
|
auto block_format = cursor.blockFormat ();
|
||||||
cursor.insertHtml (s);
|
block_format.setBackground (bg);
|
||||||
cursor.setPosition (pos, QTextCursor::MoveAnchor);
|
if (0 == cursor.position ())
|
||||||
cursor.movePosition (QTextCursor::End, QTextCursor::KeepAnchor);
|
{
|
||||||
cursor.mergeCharFormat (m_charFormat);
|
cursor.setBlockFormat (block_format);
|
||||||
cursor.clearSelection ();
|
auto char_format = cursor.charFormat ();
|
||||||
|
char_format.setFont (char_font_);
|
||||||
|
cursor.setCharFormat (char_format);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cursor.insertBlock (block_format);
|
||||||
|
}
|
||||||
|
cursor.insertText (text);
|
||||||
|
|
||||||
// position so viewport scrolled to left
|
// position so viewport scrolled to left
|
||||||
cursor.movePosition (QTextCursor::Up);
|
cursor.movePosition (QTextCursor::Up);
|
||||||
cursor.movePosition (QTextCursor::StartOfLine);
|
cursor.movePosition (QTextCursor::StartOfLine);
|
||||||
setTextCursor (cursor);
|
setTextCursor (cursor);
|
||||||
ensureCursorVisible ();
|
ensureCursorVisible ();
|
||||||
|
document ()->setMaximumBlockCount (document ()->maximumBlockCount ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString DisplayText::_appendDXCCWorkedB4(QString message, QString const& callsign, QString * bg,
|
QString DisplayText::appendDXCCWorkedB4(QString message, QString const& callsign, QColor * bg,
|
||||||
LogBook logBook, QColor color_CQ,
|
LogBook logBook, QColor color_CQ,
|
||||||
QColor color_DXCC,
|
QColor color_DXCC,
|
||||||
QColor color_NewCall)
|
QColor color_NewCall)
|
||||||
@ -110,18 +119,18 @@ QString DisplayText::_appendDXCCWorkedB4(QString message, QString const& callsig
|
|||||||
if (!countryWorkedBefore) // therefore not worked call either
|
if (!countryWorkedBefore) // therefore not worked call either
|
||||||
{
|
{
|
||||||
message += "!";
|
message += "!";
|
||||||
*bg = color_DXCC.name();
|
*bg = color_DXCC;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (!callWorkedBefore) // but have worked the country
|
if (!callWorkedBefore) // but have worked the country
|
||||||
{
|
{
|
||||||
message += "~";
|
message += "~";
|
||||||
*bg = color_NewCall.name();
|
*bg = color_NewCall;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
message += " "; // have worked this call before
|
message += " "; // have worked this call before
|
||||||
*bg = color_CQ.name();
|
*bg = color_CQ;
|
||||||
}
|
}
|
||||||
charsAvail -= 1;
|
charsAvail -= 1;
|
||||||
|
|
||||||
@ -165,14 +174,14 @@ void DisplayText::displayDecodedText(DecodedText decodedText, QString myCall,
|
|||||||
QColor color_CQ, QColor color_MyCall,
|
QColor color_CQ, QColor color_MyCall,
|
||||||
QColor color_DXCC, QColor color_NewCall)
|
QColor color_DXCC, QColor color_NewCall)
|
||||||
{
|
{
|
||||||
QString bg="white";
|
QColor bg {Qt::white};
|
||||||
bool CQcall = false;
|
bool CQcall = false;
|
||||||
if (decodedText.string ().contains (" CQ ")
|
if (decodedText.string ().contains (" CQ ")
|
||||||
|| decodedText.string ().contains (" CQDX ")
|
|| decodedText.string ().contains (" CQDX ")
|
||||||
|| decodedText.string ().contains (" QRZ "))
|
|| decodedText.string ().contains (" QRZ "))
|
||||||
{
|
{
|
||||||
CQcall = true;
|
CQcall = true;
|
||||||
bg=color_CQ.name();
|
bg = color_CQ;
|
||||||
}
|
}
|
||||||
if (myCall != "" and (
|
if (myCall != "" and (
|
||||||
decodedText.indexOf (" " + myCall + " ") >= 0
|
decodedText.indexOf (" " + myCall + " ") >= 0
|
||||||
@ -180,13 +189,13 @@ void DisplayText::displayDecodedText(DecodedText decodedText, QString myCall,
|
|||||||
or decodedText.indexOf ("/" + myCall + " ") >= 0
|
or decodedText.indexOf ("/" + myCall + " ") >= 0
|
||||||
or decodedText.indexOf ("<" + myCall + " ") >= 0
|
or decodedText.indexOf ("<" + myCall + " ") >= 0
|
||||||
or decodedText.indexOf (" " + myCall + ">") >= 0)) {
|
or decodedText.indexOf (" " + myCall + ">") >= 0)) {
|
||||||
bg=color_MyCall.name();
|
bg = color_MyCall;
|
||||||
}
|
}
|
||||||
// if enabled add the DXCC entity and B4 status to the end of the
|
// if enabled add the DXCC entity and B4 status to the end of the
|
||||||
// preformated text line t1
|
// preformated text line t1
|
||||||
auto message = decodedText.string ();
|
auto message = decodedText.string ();
|
||||||
if (displayDXCCEntity && CQcall)
|
if (displayDXCCEntity && CQcall)
|
||||||
message = _appendDXCCWorkedB4 (message, decodedText.CQersCall (), &bg, logBook, color_CQ,
|
message = appendDXCCWorkedB4 (message, decodedText.CQersCall (), &bg, logBook, color_CQ,
|
||||||
color_DXCC, color_NewCall);
|
color_DXCC, color_NewCall);
|
||||||
appendText (message, bg);
|
appendText (message, bg);
|
||||||
}
|
}
|
||||||
@ -195,7 +204,6 @@ void DisplayText::displayDecodedText(DecodedText decodedText, QString myCall,
|
|||||||
void DisplayText::displayTransmittedText(QString text, QString modeTx, qint32 txFreq,
|
void DisplayText::displayTransmittedText(QString text, QString modeTx, qint32 txFreq,
|
||||||
QColor color_TxMsg, bool bFastMode)
|
QColor color_TxMsg, bool bFastMode)
|
||||||
{
|
{
|
||||||
QString bg=color_TxMsg.name();
|
|
||||||
QString t1=" @ ";
|
QString t1=" @ ";
|
||||||
if(modeTx=="FT8") t1=" ~ ";
|
if(modeTx=="FT8") t1=" ~ ";
|
||||||
if(modeTx=="JT4") t1=" $ ";
|
if(modeTx=="JT4") t1=" $ ";
|
||||||
@ -211,12 +219,11 @@ void DisplayText::displayTransmittedText(QString text, QString modeTx, qint32 tx
|
|||||||
t = QDateTime::currentDateTimeUtc().toString("hhmm") + \
|
t = QDateTime::currentDateTimeUtc().toString("hhmm") + \
|
||||||
" Tx " + t2 + t1 + text;
|
" Tx " + t2 + t1 + text;
|
||||||
}
|
}
|
||||||
appendText(t,bg);
|
appendText (t, color_TxMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayText::displayQSY(QString text)
|
void DisplayText::displayQSY(QString text)
|
||||||
{
|
{
|
||||||
QString t = QDateTime::currentDateTimeUtc().toString("hhmmss") + " " + text;
|
QString t = QDateTime::currentDateTimeUtc().toString("hhmmss") + " " + text;
|
||||||
QString bg="hot pink";
|
appendText (t, "hotpink");
|
||||||
appendText(t,bg);
|
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,13 @@
|
|||||||
#define DISPLAYTEXT_H
|
#define DISPLAYTEXT_H
|
||||||
|
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
#include "logbook/logbook.h"
|
#include "logbook/logbook.h"
|
||||||
#include "decodedtext.h"
|
#include "decodedtext.h"
|
||||||
|
|
||||||
|
class DisplayText
|
||||||
class DisplayText : public QTextEdit
|
: public QTextEdit
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -22,20 +24,18 @@ public:
|
|||||||
QColor color_TxMsg, bool bFastMode);
|
QColor color_TxMsg, bool bFastMode);
|
||||||
void displayQSY(QString text);
|
void displayQSY(QString text);
|
||||||
|
|
||||||
signals:
|
Q_SIGNAL void selectCallsign (bool alt, bool ctrl);
|
||||||
void selectCallsign(bool alt, bool ctrl);
|
|
||||||
|
|
||||||
public slots:
|
Q_SLOT void appendText (QString const& text, QColor bg = Qt::white);
|
||||||
void appendText(QString const& text, QString const& bg = "white");
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseDoubleClickEvent(QMouseEvent *e);
|
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _appendDXCCWorkedB4(QString message, QString const& callsign, QString * bg, LogBook logBook,
|
QString appendDXCCWorkedB4(QString message, QString const& callsign, QColor * bg, LogBook logBook,
|
||||||
QColor color_CQ, QColor color_DXCC, QColor color_NewCall);
|
QColor color_CQ, QColor color_DXCC, QColor color_NewCall);
|
||||||
|
|
||||||
QTextCharFormat m_charFormat;
|
QFont char_font_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DISPLAYTEXT_H
|
#endif // DISPLAYTEXT_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user