From 4192bfc412645f4aedab4170b3253d7d7971a76f Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 29 Jun 2019 08:46:31 +0530 Subject: [PATCH] organize qt includes --- GUI/extenwindow.cpp | 2 -- GUI/extenwindow.h | 2 ++ GUI/mainwindow.cpp | 12 ++---------- GUI/mainwindow.h | 1 - extensions/extrawindow.cpp | 10 ++-------- extensions/lua.cpp | 6 ++---- extensions/network.cpp | 1 + extensions/regexfilter.cpp | 7 ++++--- extensions/threadlinker.cpp | 6 +----- {GUI => include}/qtcommon.h | 14 ++++++++++++-- 10 files changed, 26 insertions(+), 35 deletions(-) rename {GUI => include}/qtcommon.h (65%) diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 7d25cf1..b143edb 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -6,8 +6,6 @@ #include #include #include -#include -#include extern const char* EXTENSIONS; extern const char* INVALID_EXTENSION; diff --git a/GUI/extenwindow.h b/GUI/extenwindow.h index 4f54450..685796a 100644 --- a/GUI/extenwindow.h +++ b/GUI/extenwindow.h @@ -33,3 +33,5 @@ private: Ui::ExtenWindow* ui; }; + +inline HMODULE LoadLibraryOnce(std::wstring fileName) { if (HMODULE module = GetModuleHandleW(fileName.c_str())) return module; return LoadLibraryW(fileName.c_str()); } diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 2cbd529..a60cc24 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -3,15 +3,7 @@ #include "defs.h" #include "host/util.h" #include -#include -#include -#include -#include -#include -#include #include -#include -#include #include extern const char* ATTACH; @@ -454,12 +446,12 @@ void MainWindow::FindHooks() if (!dialog.exec()) return; QByteArray pattern = QByteArray::fromHex(patternInput.text().replace("??", QString::number(XX, 16)).toUtf8()); memcpy(sp.pattern, pattern.data(), sp.length = min(pattern.size(), 25)); - try { filter = std::wregex(S(filterInput.text())); } catch (std::regex_error) {} + try { filter = S(filterInput.text()); } catch (std::regex_error) {} } else { // sp.length is 0 in this branch, so default will be used - filter = cjkCheckbox.isChecked() ? std::wregex(L"[\\u3000-\\ua000]{4,}") : std::wregex(L"[\\u0020-\\u1000]{4,}"); + filter = std::wregex(cjkCheckbox.isChecked() ? L"[\\u3000-\\ua000]{4,}" : L"[\\u0020-\\u1000]{4,}"); } auto hooks = std::make_shared(); diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 4baaaac..58664f5 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -3,7 +3,6 @@ #include "qtcommon.h" #include "extenwindow.h" #include "host/host.h" -#include namespace Ui { diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index 47a21b8..36d36eb 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -1,17 +1,11 @@ +#include "qtcommon.h" #include "extension.h" #include "ui_extrawindow.h" #include "defs.h" -#include #include -#include #include -#include -#include -#include -#include #include #include -#include extern const char* EXTRA_WINDOW_INFO; extern const char* TOPMOST; @@ -164,7 +158,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) { if (!sentenceInfo["current select"]) return false; - QString qSentence = QString::fromStdWString(sentence); + QString qSentence = S(sentence); if (!window.settings.value(SHOW_ORIGINAL).toBool()) qSentence = qSentence.section('\n', qSentence.count('\n') / 2 + 1); QMetaObject::invokeMethod(&window, [=] { window.ui.display->setText(qSentence); }); diff --git a/extensions/lua.cpp b/extensions/lua.cpp index 4d1d4c7..c9925d1 100644 --- a/extensions/lua.cpp +++ b/extensions/lua.cpp @@ -1,10 +1,8 @@ -#include "extension.h" +#include "qtcommon.h" +#include "extension.h" #include "util.h" #include -#include -#include #include -#include extern const char* LUA_INTRO; extern const char* LOAD_LUA_SCRIPT; diff --git a/extensions/network.cpp b/extensions/network.cpp index 66e68e0..5899b18 100644 --- a/extensions/network.cpp +++ b/extensions/network.cpp @@ -61,6 +61,7 @@ void Unescape(std::wstring& text) if (text[i + 1] == L'r') text[i + 1] = 0x200b; // for some reason \r gets displayed as a newline if (text[i + 1] == L'n') text[i + 1] = L'\n'; if (text[i + 1] == L't') text[i + 1] = L'\t'; + if (text[i + 1] == L'\\') ++i; } } } diff --git a/extensions/regexfilter.cpp b/extensions/regexfilter.cpp index a9a4f86..b9cff0d 100644 --- a/extensions/regexfilter.cpp +++ b/extensions/regexfilter.cpp @@ -1,3 +1,4 @@ +#include "qtcommon.h" #include "extension.h" #include "ui_regexfilter.h" @@ -22,12 +23,12 @@ public: } private: - void setRegex(QString newRegex) + void setRegex(QString regex) { std::lock_guard l(m); - try { regex = newRegex.toStdWString(); } + try { ::regex = S(regex); } catch (std::regex_error) { return ui.output->setText(INVALID_REGEX); } - ui.output->setText(QString(CURRENT_FILTER).arg(newRegex)); + ui.output->setText(QString(CURRENT_FILTER).arg(regex)); } Ui::FilterWindow ui; diff --git a/extensions/threadlinker.cpp b/extensions/threadlinker.cpp index 365bc36..c284bdf 100644 --- a/extensions/threadlinker.cpp +++ b/extensions/threadlinker.cpp @@ -1,9 +1,5 @@ +#include "qtcommon.h" #include "extension.h" -#include -#include -#include -#include -#include #include extern const char* THREAD_LINKER; diff --git a/GUI/qtcommon.h b/include/qtcommon.h similarity index 65% rename from GUI/qtcommon.h rename to include/qtcommon.h index 5d6f42c..ad3fe7e 100644 --- a/GUI/qtcommon.h +++ b/include/qtcommon.h @@ -4,12 +4,22 @@ #include #include #include -#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } }; inline std::wstring S(const QString& S) { return { S.toStdWString() }; } inline QString S(const std::wstring& S) { return QString::fromStdWString(S); } -inline HMODULE LoadLibraryOnce(std::wstring fileName) { if (HMODULE module = GetModuleHandleW(fileName.c_str())) return module; return LoadLibraryW(fileName.c_str()); }