Last active
July 3, 2016 14:34
-
-
Save alopatindev/17a39fce20049989a0e4b63f002ac2c2 to your computer and use it in GitHub Desktop.
QDeviceMonitor: possible solution for memory leak and performance issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/qdevicemonitor/devices/AndroidDevice.cpp b/qdevicemonitor/devices/AndroidDevice.cpp | |
index e3cc6aa..349ae2b 100644 | |
--- a/qdevicemonitor/devices/AndroidDevice.cpp | |
+++ b/qdevicemonitor/devices/AndroidDevice.cpp | |
@@ -250,7 +250,7 @@ void AndroidDevice::filterAndAddToTextEdit(const QString& line) | |
if (filtersMatch) | |
{ | |
- const auto verbosityColorType = static_cast<ColorTheme::ColorType>(verbosityLevel); | |
+ /*const auto verbosityColorType = static_cast<ColorTheme::ColorType>(verbosityLevel); | |
m_deviceWidget->addText(verbosityColorType, verbosity); | |
m_deviceWidget->addText(ColorTheme::DateTime, date); | |
m_deviceWidget->addText(ColorTheme::DateTime, time); | |
@@ -258,7 +258,8 @@ void AndroidDevice::filterAndAddToTextEdit(const QString& line) | |
m_deviceWidget->addText(ColorTheme::Tid, tid); | |
m_deviceWidget->addText(ColorTheme::Tag, tag); | |
m_deviceWidget->addText(verbosityColorType, text); | |
- m_deviceWidget->flushText(); | |
+ m_deviceWidget->flushText();*/ | |
+ m_deviceWidget->addText(text, verbosity, date, time, pid, tid, tag); | |
} | |
} | |
else | |
diff --git a/qdevicemonitor/qdevicemonitor.pro b/qdevicemonitor/qdevicemonitor.pro | |
index 914857f..00be905 100644 | |
--- a/qdevicemonitor/qdevicemonitor.pro | |
+++ b/qdevicemonitor/qdevicemonitor.pro | |
@@ -4,7 +4,7 @@ | |
# | |
#------------------------------------------------- | |
-QT += core gui | |
+QT += core gui webenginewidgets | |
QT_VERSION = 5 | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
diff --git a/qdevicemonitor/ui/DeviceWidget.cpp b/qdevicemonitor/ui/DeviceWidget.cpp | |
index afda727..e1eb5dd 100644 | |
--- a/qdevicemonitor/ui/DeviceWidget.cpp | |
+++ b/qdevicemonitor/ui/DeviceWidget.cpp | |
@@ -34,7 +34,7 @@ DeviceWidget::DeviceWidget(QPointer<QWidget> parent, QPointer<DeviceFacade> devi | |
m_ui = QSharedPointer<Ui::DeviceWidget>::create(); | |
m_ui->setupUi(this); | |
- m_defaultTextEditPalette = m_ui->textEdit->palette(); | |
+// m_defaultTextEditPalette = m_ui->textEdit->palette(); | |
m_redPalette = QPalette(Qt::red); | |
m_redPalette.setColor(QPalette::Highlight, Qt::red); | |
@@ -43,14 +43,17 @@ DeviceWidget::DeviceWidget(QPointer<QWidget> parent, QPointer<DeviceFacade> devi | |
//ui->textEdit->setFontFamily(m_deviceFacade->getFont()); | |
//ui->textEdit->setFontPointSize(m_deviceFacade->getFontSize()); | |
- m_ui->textEdit->setAttribute(Qt::WA_OpaquePaintEvent); | |
+/* m_ui->textEdit->setAttribute(Qt::WA_OpaquePaintEvent); | |
m_ui->textEdit->setUndoRedoEnabled(false); | |
- m_ui->textEdit->document()->setMaximumBlockCount(m_deviceFacade->getVisibleLines()); | |
+ m_ui->textEdit->document()->setMaximumBlockCount(m_deviceFacade->getVisibleLines());*/ | |
clearTextEdit(); | |
m_ui->verbositySlider->valueChanged(m_ui->verbositySlider->value()); | |
m_ui->wrapCheckBox->setCheckState(m_ui->wrapCheckBox->isChecked() ? Qt::Checked : Qt::Unchecked); | |
+ | |
+ m_ui->webEngineView->page()->load(QString("file:///home/sbar/git/qdevicemonitor/qdevicemonitor/ui/TextView.html")); | |
+ //m_ui->webEngineView->page()->load(QString("https://www.google.com")); | |
} | |
DeviceWidget::~DeviceWidget() | |
@@ -74,7 +77,8 @@ void DeviceWidget::on_verbositySlider_valueChanged(const int value) | |
void DeviceWidget::on_wrapCheckBox_toggled(const bool checked) | |
{ | |
- m_ui->textEdit->setLineWrapMode(checked ? QTextEdit::WidgetWidth : QTextEdit::NoWrap); | |
+ (void)checked; | |
+// m_ui->textEdit->setLineWrapMode(checked ? QTextEdit::WidgetWidth : QTextEdit::NoWrap); | |
maybeScrollTextEditToEnd(); | |
} | |
@@ -85,7 +89,8 @@ void DeviceWidget::on_scrollLockCheckBox_toggled(const bool) | |
void DeviceWidget::highlightFilterLineEdit(const bool red) | |
{ | |
- m_ui->filterLineEdit->setPalette(red ? m_redPalette : m_defaultTextEditPalette); | |
+ (void) red; | |
+// m_ui->filterLineEdit->setPalette(red ? m_redPalette : m_defaultTextEditPalette); | |
} | |
void DeviceWidget::maybeScrollTextEditToEnd() | |
@@ -101,9 +106,37 @@ void DeviceWidget::addText(const ColorTheme::ColorType color, const QStringRef& | |
addText(m_deviceFacade->getThemeColor(color), text); | |
} | |
+void DeviceWidget::addText(const QStringRef& text, const QStringRef& verbosity, const QStringRef& date, const QStringRef& time, const QStringRef& pid, const QStringRef& tid, const QStringRef& tag) | |
+{ | |
+ m_textStream | |
+ << "append([{" | |
+ << "'date':'" << date | |
+ << "','time':'" << time | |
+ << "','pid':'" << pid | |
+ << "','tid':'" << tid | |
+ << "','verbosity':'" << verbosity | |
+ << "','tag':'" << tag | |
+ << "','text':'" << text.toString().replace("'", "\\'") | |
+ << "'}]," | |
+ << m_deviceFacade->getVisibleLines() | |
+ << ");"; | |
+ flushText(); | |
+} | |
+ | |
void DeviceWidget::addText(const QColor& color, const QStringRef& text) | |
{ | |
+ (void) color; | |
+ (void) text; | |
+ /*if (m_textStream.atEnd()) { | |
+ m_textStream << "var lines = [];"; | |
+ } | |
m_textStream | |
+ << "lines.append({" | |
+ << "\"date\": \"11-12\", \"time\": \"11:11:11\", \"pid\": \"1234\", \"tid\": \"5678\", \"verbosity\": \"I\", \"tag\": \"hello\", \"text\": \"" | |
+ << text | |
+ << "\"" | |
+ << "});";*/ | |
+ /*m_textStream | |
<< "<font style=\"font-family: " << m_deviceFacade->getFont() | |
<< "; font-size: " << m_deviceFacade->getFontSize() | |
<< "pt; font-weight: " << (m_deviceFacade->isFontBold() ? "bold" : "none") | |
@@ -114,15 +147,23 @@ void DeviceWidget::addText(const QColor& color, const QStringRef& text) | |
#else | |
<< "\">" << text | |
#endif | |
- << " </font>"; | |
+ << " </font>";*/ | |
} | |
void DeviceWidget::flushText() | |
{ | |
m_textStream.flush(); | |
+ const QString text = m_textStream.readAll(); | |
+ if (!text.isEmpty()) | |
+ { | |
+ qDebug() << "text: `" << text << "`"; | |
+ m_ui->webEngineView->page()->runJavaScript(text); | |
+ } | |
+ | |
+ /*m_textStream.flush(); | |
m_ui->textEdit->setUpdatesEnabled(false); | |
m_ui->textEdit->append(m_textStream.readAll()); | |
- m_ui->textEdit->setUpdatesEnabled(true); | |
+ m_ui->textEdit->setUpdatesEnabled(true);*/ | |
} | |
void DeviceWidget::updateTextEditPalette() | |
@@ -137,22 +178,22 @@ void DeviceWidget::updateTextEditPalette() | |
{ | |
pal = m_defaultTextEditPalette; | |
} | |
- m_ui->textEdit->setPalette(pal); | |
+ //m_ui->textEdit->setPalette(pal); | |
} | |
void DeviceWidget::clearTextEdit() | |
{ | |
updateTextEditPalette(); | |
- getTextEdit().clear(); | |
+ //getTextEdit().clear(); | |
} | |
void DeviceWidget::scrollTextEditToEnd() | |
{ | |
- QScrollBar& sb = *(getTextEdit().verticalScrollBar()); | |
+ /*QScrollBar& sb = *(getTextEdit().verticalScrollBar()); | |
if (sb.maximum() > 0) | |
{ | |
sb.setValue(sb.maximum()); | |
- } | |
+ }*/ | |
} | |
void DeviceWidget::on_openLogFileButton_clicked() | |
diff --git a/qdevicemonitor/ui/DeviceWidget.h b/qdevicemonitor/ui/DeviceWidget.h | |
index 053fd8a..4066021 100644 | |
--- a/qdevicemonitor/ui/DeviceWidget.h | |
+++ b/qdevicemonitor/ui/DeviceWidget.h | |
@@ -50,10 +50,10 @@ public: | |
void hideVerbosity(); | |
inline QLineEdit& getFilterLineEdit() const { return *(m_ui->filterLineEdit); } | |
- inline QTextEdit& getTextEdit() const { return *(m_ui->textEdit); } | |
inline int getVerbosityLevel() const { return m_ui->verbositySlider->value(); } | |
void highlightFilterLineEdit(bool red); | |
void maybeScrollTextEditToEnd(); | |
+ void addText(const QStringRef& text, const QStringRef& verbosity, const QStringRef& date, const QStringRef& time, const QStringRef& pid, const QStringRef& tid, const QStringRef& tag); | |
void addText(const ColorTheme::ColorType color, const QStringRef& text); | |
void addText(const QColor& color, const QStringRef& text); | |
void flushText(); | |
diff --git a/qdevicemonitor/ui/DeviceWidget.ui b/qdevicemonitor/ui/DeviceWidget.ui | |
index 8270ffd..d41728f 100644 | |
--- a/qdevicemonitor/ui/DeviceWidget.ui | |
+++ b/qdevicemonitor/ui/DeviceWidget.ui | |
@@ -15,16 +15,12 @@ | |
</property> | |
<layout class="QVBoxLayout" name="verticalLayout"> | |
<item> | |
- <widget class="QTextEdit" name="textEdit"> | |
- <property name="html"> | |
- <string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> | |
-<html><head><meta name="qrichtext" content="1" /><style type="text/css"> | |
-p, li { white-space: pre-wrap; } | |
-</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> | |
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:18pt;"><br /></p></body></html></string> | |
- </property> | |
- <property name="textInteractionFlags"> | |
- <set>Qt::TextBrowserInteraction</set> | |
+ <widget class="QWebEngineView" name="webEngineView" native="true"> | |
+ <property name="sizePolicy"> | |
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | |
+ <horstretch>0</horstretch> | |
+ <verstretch>0</verstretch> | |
+ </sizepolicy> | |
</property> | |
</widget> | |
</item> | |
@@ -137,6 +133,14 @@ p, li { white-space: pre-wrap; } | |
</item> | |
</layout> | |
</widget> | |
+ <customwidgets> | |
+ <customwidget> | |
+ <class>QWebEngineView</class> | |
+ <extends>QWidget</extends> | |
+ <header location="global">QWebEngineView</header> | |
+ <container>1</container> | |
+ </customwidget> | |
+ </customwidgets> | |
<tabstops> | |
<tabstop>filterLineEdit</tabstop> | |
<tabstop>clearLogButton</tabstop> | |
@@ -144,25 +148,7 @@ p, li { white-space: pre-wrap; } | |
<tabstop>wrapCheckBox</tabstop> | |
<tabstop>scrollLockCheckBox</tabstop> | |
<tabstop>verbositySlider</tabstop> | |
- <tabstop>textEdit</tabstop> | |
</tabstops> | |
<resources/> | |
- <connections> | |
- <connection> | |
- <sender>clearLogButton</sender> | |
- <signal>clicked()</signal> | |
- <receiver>textEdit</receiver> | |
- <slot>clear()</slot> | |
- <hints> | |
- <hint type="sourcelabel"> | |
- <x>89</x> | |
- <y>739</y> | |
- </hint> | |
- <hint type="destinationlabel"> | |
- <x>121</x> | |
- <y>288</y> | |
- </hint> | |
- </hints> | |
- </connection> | |
- </connections> | |
+ <connections/> | |
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
var colors = {}; | |
var elementsPerLine = 8; | |
function createSpanElement (color, text) { | |
var element = document.createElement('span'); | |
element.setAttribute('style', 'color:' + color); | |
if (text.length != 0) { | |
text += ' '; | |
} | |
element.appendChild(document.createTextNode(text)); | |
return element; | |
} | |
function removeFirstLines (limitLines, textView) { | |
var maxChildren = limitLines * elementsPerLine + 1; | |
while (textView.children.length >= maxChildren) { | |
textView.removeChild(textView.firstChild); | |
} | |
} | |
function textColor (verbosity) { | |
switch (verbosity) { | |
case 'A': return 'red'; | |
case 'E': return 'red'; | |
case 'W': return 'yellow'; | |
case 'I': return 'green'; | |
case 'D': return 'blue'; | |
case 'V': return 'black'; | |
} | |
return 'black'; | |
} | |
function append (lines, limitLines) { | |
var textView = document.getElementById('TextView'); | |
for (i = 0; i < lines.length; i++) { | |
var line = lines[i]; | |
textView.appendChild(createSpanElement(colors.verbosity, line.verbosity)); | |
textView.appendChild(createSpanElement(colors.date, line.date)); | |
textView.appendChild(createSpanElement(colors.time, line.time)); | |
textView.appendChild(createSpanElement(colors.pid, line.pid)); | |
textView.appendChild(createSpanElement(colors.tid, line.tid)); | |
textView.appendChild(createSpanElement(colors.tag, line.tag)); | |
textView.appendChild(createSpanElement(textColor(line.verbosity), line.text)); | |
textView.appendChild(document.createElement('br')); | |
} | |
removeFirstLines(limitLines, textView); | |
textView.scrollTop = textView.scrollHeight; | |
} | |
</script> | |
</head> | |
<body> | |
<div class="span12" id="TextView" style="border: 1px solid grey; height: 400px; overflow:auto; font-family: Monospace;"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment