performance improvements

This commit is contained in:
Akash Mozumdar 2019-09-11 14:27:57 -04:00
parent 770f219078
commit 90bed9c2db
2 changed files with 18 additions and 13 deletions

View File

@ -4,6 +4,7 @@
#include "host/util.h" #include "host/util.h"
#include <shellapi.h> #include <shellapi.h>
#include <QStringListModel> #include <QStringListModel>
#include <QScrollBar>
#include <QMenu> #include <QMenu>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFileDialog> #include <QFileDialog>
@ -89,7 +90,7 @@ MainWindow::MainWindow(QWidget *parent) :
QSettings settings(CONFIG_FILE, QSettings::IniFormat); QSettings settings(CONFIG_FILE, QSettings::IniFormat);
if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect()); if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect());
if (settings.contains(FONT)) SetOutputFont(settings.value(FONT).toString()); SetOutputFont(settings.value(FONT, ui->textOutput->font().toString()).toString());
TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool(); TextThread::filterRepetition = settings.value(FILTER_REPETITION, TextThread::filterRepetition).toBool();
autoAttach = settings.value(AUTO_ATTACH, autoAttach).toBool(); autoAttach = settings.value(AUTO_ATTACH, autoAttach).toBool();
autoAttachSavedOnly = settings.value(ATTACH_SAVED_ONLY, autoAttachSavedOnly).toBool(); autoAttachSavedOnly = settings.value(ATTACH_SAVED_ONLY, autoAttachSavedOnly).toBool();
@ -186,10 +187,9 @@ void MainWindow::ProcessDisconnected(DWORD processId)
void MainWindow::ThreadAdded(TextThread& thread) void MainWindow::ThreadAdded(TextThread& thread)
{ {
std::wstring threadCode = Util::GenerateCode(thread.hp, thread.tp.processId); std::wstring threadCode = Util::GenerateCode(thread.hp, thread.tp.processId);
QString ttString = TextThreadString(thread) + S(FormatString(L" (%s)", threadCode));
bool savedMatch = savedThreadCtx == thread.tp.ctx && savedThreadCtx2 == thread.tp.ctx2 && savedThreadCode == threadCode; bool savedMatch = savedThreadCtx == thread.tp.ctx && savedThreadCtx2 == thread.tp.ctx2 && savedThreadCode == threadCode;
if (savedMatch) savedThreadCtx = savedThreadCtx2 = savedThreadCode[0] = 0; if (savedMatch) savedThreadCtx = savedThreadCtx2 = savedThreadCode[0] = 0;
QMetaObject::invokeMethod(this, [this, ttString, savedMatch] QMetaObject::invokeMethod(this, [this, savedMatch, ttString = TextThreadString(thread) + S(FormatString(L" (%s)", threadCode))]
{ {
ui->ttCombo->addItem(ttString); ui->ttCombo->addItem(ttString);
if (savedMatch) ViewThread(ui->ttCombo->count() - 1); if (savedMatch) ViewThread(ui->ttCombo->count() - 1);
@ -198,8 +198,7 @@ void MainWindow::ThreadAdded(TextThread& thread)
void MainWindow::ThreadRemoved(TextThread& thread) void MainWindow::ThreadRemoved(TextThread& thread)
{ {
QString ttString = TextThreadString(thread); QMetaObject::invokeMethod(this, [this, ttString = TextThreadString(thread)]
QMetaObject::invokeMethod(this, [this, ttString]
{ {
int threadIndex = ui->ttCombo->findText(ttString, Qt::MatchStartsWith); int threadIndex = ui->ttCombo->findText(ttString, Qt::MatchStartsWith);
if (threadIndex == ui->ttCombo->currentIndex()) ViewThread(0); if (threadIndex == ui->ttCombo->currentIndex()) ViewThread(0);
@ -211,11 +210,14 @@ bool MainWindow::SentenceReceived(TextThread& thread, std::wstring& sentence)
{ {
if (!DispatchSentenceToExtensions(sentence, GetSentenceInfo(thread).data())) return false; if (!DispatchSentenceToExtensions(sentence, GetSentenceInfo(thread).data())) return false;
sentence += L'\n'; sentence += L'\n';
if (current == &thread) QMetaObject::invokeMethod(this, [this, sentence] if (current == &thread) QMetaObject::invokeMethod(this, [this, sentence = S(sentence)]
{ {
ui->textOutput->moveCursor(QTextCursor::End); auto scrollbar = ui->textOutput->verticalScrollBar();
ui->textOutput->insertPlainText(S(sentence)); bool atBottom = scrollbar->value() == scrollbar->maximum();
ui->textOutput->moveCursor(QTextCursor::End); QTextCursor cursor(ui->textOutput->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(sentence);
if (atBottom) scrollbar->setValue(scrollbar->maximum());
}); });
return true; return true;
} }

View File

@ -75,15 +75,18 @@
</item> </item>
<item> <item>
<widget class="QPlainTextEdit" name="textOutput"> <widget class="QPlainTextEdit" name="textOutput">
<property name="contextMenuPolicy"> <property name="font">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="font">
<font> <font>
<family>Meiryo</family> <family>Meiryo</family>
<pointsize>12</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>