From bc9c1741dd95544f9cf42ed44db99ec0d2b05944 Mon Sep 17 00:00:00 2001 From: jared Date: Mon, 25 Jan 2021 14:03:56 +0800 Subject: [PATCH] remove TaoCommon files --- 3rdparty/TaoCommon/CMakeLists.txt | 9 - 3rdparty/TaoCommon/Common/FileReadWrite.h | 108 ------ 3rdparty/TaoCommon/Common/JsonSerialize.h | 157 --------- 3rdparty/TaoCommon/Common/ObjectMap.h | 149 -------- 3rdparty/TaoCommon/Common/Package.h | 34 -- 3rdparty/TaoCommon/Common/PropertyHelper.h | 90 ----- 3rdparty/TaoCommon/Common/Subject.h | 98 ------ .../TaoCommon/Frameless/TaoFrameLessView.h | 36 -- .../Frameless/TaoFrameLessView_unix.cpp | 80 ----- .../Frameless/TaoFrameLessView_win.cpp | 261 -------------- 3rdparty/TaoCommon/Logger/Logger.cpp | 144 -------- 3rdparty/TaoCommon/Logger/Logger.h | 23 -- 3rdparty/TaoCommon/Logger/LoggerTemplate.h | 125 ------- 3rdparty/TaoCommon/QuickTool/QuickTool.cpp | 91 ----- 3rdparty/TaoCommon/QuickTool/QuickTool.h | 38 -- 3rdparty/TaoCommon/TaoCommon.pri | 41 --- 3rdparty/TaoCommon/TaoCommon.pro | 14 - 3rdparty/TaoCommon/TaoCommonGlobal.h | 12 - .../TaoCommon/TaoModel/TaoListItemBase.cpp | 8 - 3rdparty/TaoCommon/TaoModel/TaoListItemBase.h | 93 ----- 3rdparty/TaoCommon/TaoModel/TaoListModel.cpp | 329 ------------------ 3rdparty/TaoCommon/TaoModel/TaoListModel.h | 144 -------- .../TaoCommon/TaoModel/TaoListModelBase.hpp | 221 ------------ 3rdparty/TaoCommon/Thread/ThreadCommon.h | 9 - 3rdparty/TaoCommon/Thread/ThreadPool.cpp | 19 - 3rdparty/TaoCommon/Thread/ThreadPool.h | 39 --- .../TaoCommon/Thread/ThreadWorkerController.h | 122 ------- 3rdparty/TaoCommon/Trans/Trans.cpp | 138 -------- 3rdparty/TaoCommon/Trans/Trans.h | 64 ---- 29 files changed, 2696 deletions(-) delete mode 100644 3rdparty/TaoCommon/CMakeLists.txt delete mode 100644 3rdparty/TaoCommon/Common/FileReadWrite.h delete mode 100644 3rdparty/TaoCommon/Common/JsonSerialize.h delete mode 100644 3rdparty/TaoCommon/Common/ObjectMap.h delete mode 100644 3rdparty/TaoCommon/Common/Package.h delete mode 100644 3rdparty/TaoCommon/Common/PropertyHelper.h delete mode 100644 3rdparty/TaoCommon/Common/Subject.h delete mode 100644 3rdparty/TaoCommon/Frameless/TaoFrameLessView.h delete mode 100644 3rdparty/TaoCommon/Frameless/TaoFrameLessView_unix.cpp delete mode 100644 3rdparty/TaoCommon/Frameless/TaoFrameLessView_win.cpp delete mode 100644 3rdparty/TaoCommon/Logger/Logger.cpp delete mode 100644 3rdparty/TaoCommon/Logger/Logger.h delete mode 100644 3rdparty/TaoCommon/Logger/LoggerTemplate.h delete mode 100644 3rdparty/TaoCommon/QuickTool/QuickTool.cpp delete mode 100644 3rdparty/TaoCommon/QuickTool/QuickTool.h delete mode 100644 3rdparty/TaoCommon/TaoCommon.pri delete mode 100644 3rdparty/TaoCommon/TaoCommon.pro delete mode 100644 3rdparty/TaoCommon/TaoCommonGlobal.h delete mode 100644 3rdparty/TaoCommon/TaoModel/TaoListItemBase.cpp delete mode 100644 3rdparty/TaoCommon/TaoModel/TaoListItemBase.h delete mode 100644 3rdparty/TaoCommon/TaoModel/TaoListModel.cpp delete mode 100644 3rdparty/TaoCommon/TaoModel/TaoListModel.h delete mode 100644 3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp delete mode 100644 3rdparty/TaoCommon/Thread/ThreadCommon.h delete mode 100644 3rdparty/TaoCommon/Thread/ThreadPool.cpp delete mode 100644 3rdparty/TaoCommon/Thread/ThreadPool.h delete mode 100644 3rdparty/TaoCommon/Thread/ThreadWorkerController.h delete mode 100644 3rdparty/TaoCommon/Trans/Trans.cpp delete mode 100644 3rdparty/TaoCommon/Trans/Trans.h diff --git a/3rdparty/TaoCommon/CMakeLists.txt b/3rdparty/TaoCommon/CMakeLists.txt deleted file mode 100644 index 0ae2fe1c..00000000 --- a/3rdparty/TaoCommon/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(TaoCommonPath ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) -file(GLOB_RECURSE files *.h *.hpp *.cpp *.c) -if(WIN32) - list(FILTER files EXCLUDE REGEX ".*_unix.cpp$") -else() - list(FILTER files EXCLUDE REGEX ".*_win.cpp$") -endif() -set(TaoCommonFiles ${files} PARENT_SCOPE) -message("TaoCommonFiles ${files}") diff --git a/3rdparty/TaoCommon/Common/FileReadWrite.h b/3rdparty/TaoCommon/Common/FileReadWrite.h deleted file mode 100644 index de042520..00000000 --- a/3rdparty/TaoCommon/Common/FileReadWrite.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include "Logger/Logger.h" -namespace TaoCommon { -[[maybe_unused]] -static bool readFile(const QString &filePath, QByteArray &content) -{ - QFile file(filePath); - if (!file.open(QFile::ReadOnly)) { - LOG_WARN << "open file " << filePath << "failed:" << file.errorString(); - return false; - } - content = file.readAll(); - file.close(); - return true; -} -[[maybe_unused]] -static bool readJson(const QByteArray &data, QJsonDocument &doc) -{ - QJsonParseError err; - doc = QJsonDocument::fromJson(data, &err); - if (doc.isNull()) { - LOG_WARN << "parse json failed:" << err.errorString(); - return false; - } - return true; -} -[[maybe_unused]] -static bool readJson(const QByteArray &data, QJsonArray &array) -{ - QJsonDocument doc; - bool ok = readJson(data, doc); - if (ok) { - array = doc.array(); - } - return ok; -} -[[maybe_unused]] -static bool readJson(const QByteArray &data, QJsonObject &object) -{ - QJsonDocument doc; - bool ok = readJson(data, doc); - if (ok) { - object = doc.object(); - } - return ok; -} -[[maybe_unused]] -static bool readJsonFile(const QString &filePath, QJsonDocument &jsonDoc) -{ - QByteArray data; - if (!readFile(filePath, data)) { - return false; - } - return readJson(data, jsonDoc); -} -[[maybe_unused]] -static bool readJsonFile(const QString &filePath, QJsonObject &jsonObj) -{ - QByteArray data; - if (!readFile(filePath, data)) { - return false; - } - return readJson(data, jsonObj); -} -[[maybe_unused]] -static bool readJsonFile(const QString &filePath, QJsonArray &jsonArray) -{ - QByteArray data; - if (!readFile(filePath, data)) { - return false; - } - return readJson(data, jsonArray); -} -[[maybe_unused]] -static bool writeFile(const QString &filePath, const QByteArray &content) -{ - QFile file(filePath); - if (!file.open(QFile::WriteOnly)) { - LOG_WARN << "open file " << filePath << "failed:" << file.errorString(); - return false; - } - file.write(content); - file.close(); - return true; -} -[[maybe_unused]] -static bool writeJsonFile(const QString &filePath, const QJsonDocument &doc) -{ - return writeFile(filePath, doc.toJson()); -} -[[maybe_unused]] -static bool writeJsonFile(const QString &filePath, const QJsonArray &jsonArray) -{ - return writeJsonFile(filePath, QJsonDocument(jsonArray)); -} -[[maybe_unused]] -static bool writeJsonFile(const QString &filePath, const QJsonObject &jsonObj) -{ - return writeJsonFile(filePath, QJsonDocument(jsonObj)); -} - -} // namespace TaoCommon diff --git a/3rdparty/TaoCommon/Common/JsonSerialize.h b/3rdparty/TaoCommon/Common/JsonSerialize.h deleted file mode 100644 index c8a53720..00000000 --- a/3rdparty/TaoCommon/Common/JsonSerialize.h +++ /dev/null @@ -1,157 +0,0 @@ -#pragma once - -// json 序列化 -#include -#include -#include - -#include -#include -#include - -///@brief 序列化. object to Json, object to Variant or VariantMap -#define JsonSerialize_Begin() \ -public: \ - operator QVariant() const { return QVariant::fromValue(this->operator QVariantMap()); } \ - operator QJsonObject() const \ - { \ - return QJsonObject::fromVariantMap(this->operator QVariantMap()); \ - } \ - operator QVariantMap() const \ - { \ - QVariantMap vmap; - -#define JsonSerialize_End() \ - return vmap; \ - } - -///@brief 序列化属性映射 -#define JsonPureProperty(NAME) vmap.unite((QVariantMap)m_##NAME); - -#define JsonProperty(NAME) \ - vmap[#NAME] = QVariant::fromValue(m_##NAME); \ - if (vmap.value(#NAME).isNull()) \ - vmap.remove(#NAME); - -#define JsonContainerProperty(NAME) \ - { \ - QVariantList lst; \ - lst.reserve(m_##NAME.size()); \ - for (const auto &t : m_##NAME) { \ - lst << QVariant::fromValue(t); \ - } \ - vmap[#NAME] = lst; \ - } - -///@brief 反序列化 object from json -#define JsonDeserialize_Begin(class_name) \ -public: \ - class_name(const QJsonObject &other) \ - { \ - QVariantMap vmap = other.toVariantMap(); - -#define JsonDeserialize_End() } - -///@brief 部分反序列化 -#define JsonPartialDeserialize_Begin(class_name) \ -public: \ - class_name &operator=(const QJsonObject &other) \ - { \ - QVariantMap vmap = other.toVariantMap(); - -#define JsonPartialDeserialize_End() \ - return *this; \ - } - -#define JsonDeserializeContainerProperty(NAME) \ - if (vmap.value(#NAME).canConvert()) { \ - const auto &list = vmap.value(#NAME).value(); \ - m_##NAME.clear(); \ - m_##NAME.reserve(list.size()); \ - for (const auto &v : list) { \ - m_##NAME.push_back(v.value()); \ - } \ - } - -#define JsonDeserializeProperty(NAME) m_##NAME = vmap.value(#NAME).value(); - - -/** -* Example: -* -class AppInfo : public QObject -{ - Q_OBJECT - - AUTO_PROPERTY(QString, appName, "") - AUTO_PROPERTY(bool, splashShow, false) - AUTO_PROPERTY(float, scale, 1.0f) - AUTO_PROPERTY(double, ratio, 14.0 / 9.0) - AUTO_PROPERTY(QStringList, customs, {}) - - JsonSerialize_Begin() - JsonProperty(appName) - JsonProperty(splashShow) - JsonProperty(scale) - JsonProperty(ratio) - JsonContainerProperty(customs) - JsonSerialize_End() - - JsonDeserialize_Begin(AppInfo) - JsonDeserializeProperty(appName) - JsonDeserializeProperty(splashShow) - JsonDeserializeProperty(scale) - JsonDeserializeProperty(ratio) - JsonDeserializeContainerProperty(customs) - JsonDeserialize_End() - - - JsonPartialDeserialize_Begin(AppInfo) - JsonDeserializeProperty(appName) - JsonDeserializeProperty(splashShow) - JsonDeserializeProperty(scale) - JsonDeserializeProperty(ratio) - JsonDeserializeContainerProperty(customs) - JsonPartialDeserialize_End() - -public: - explicit AppInfo(QObject *parent = nullptr); - virtual ~AppInfo() override; -}; - -these MACOR will generate these function: - -AppInfo(const QJsonobject &obj) -AppInfo &operator=(const QJsonobject &obj) - -operator QJsonobject() -operator QVariantMap() -operator QVariant() - -*/ - -/** -* then you can use it. -* -* 1. init AppInfo from Json by construct or operator= -* - -* -* QJsonObject obj; -* AppInfo info = obj; -* -* 2. convert object to Json or VariantMap by operator -* -* -* AppInfo info; -* ... -* QJsonObject obj = info; -* QVariant var = info; -* QVariantMap map = info; -* -**/ - - - - - diff --git a/3rdparty/TaoCommon/Common/ObjectMap.h b/3rdparty/TaoCommon/Common/ObjectMap.h deleted file mode 100644 index d9f9bef7..00000000 --- a/3rdparty/TaoCommon/Common/ObjectMap.h +++ /dev/null @@ -1,149 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -namespace TaoCommon { - -//对象存储器 -template -class ObjectMap -{ -public: - virtual ~ObjectMap() { clear(); } - void addObj(const Key &key, const Value &obj) { m_objMap[key] = obj; } - bool removeObj(const Key &key) { return (0 != m_objMap.erase(key)); } - Value getObj(const Key &key) const - { - auto itor = m_objMap.find(key); - if (itor == m_objMap.end()) { - return nullptr; - } else { - return itor->second; - } - } - template - void forEach(const CallbackType &callback) const - { - for (const auto &pair : m_objMap) { - callback(pair.second.get()); - } - } - void clear() { m_objMap.clear(); } - -protected: - std::unordered_map m_objMap; -}; -//智能对象存储器。自动生成key,自动管理对象。 -template -class CObjectMap -{ -public: - virtual ~CObjectMap() { clear(); } - template - DeriveObjectType *getObject() const - { - static_assert(std::is_base_of::value, - "DeriveObjectType must be derive from ObjectType"); - - auto objPtr = m_objMap.getObj(std::type_index(typeid(std::shared_ptr))); - return std::static_pointer_cast(objPtr).get(); - } - template - void createObject(Args &... args) - { - static_assert(std::is_base_of::value, - "DeriveObjectType must be derive from ObjectType"); - - auto obj = std::make_shared(args...); - m_objMap.addObj(std::type_index(typeid(obj)), std::static_pointer_cast(obj)); - } - template - bool destroyObject() - { - static_assert(std::is_base_of::value, - "DeriveObjectType must be derive from ObjectType"); - - return m_objMap.removeObj(std::type_index(typeid(std::shared_ptr))); - } - void forEach(const std::function &callback) const - { - m_objMap.forEach(callback); - } - void clear() { m_objMap.clear(); } - -protected: - ObjectMap> m_objMap; -}; -//优先级对象存储器。自动生成key,自动管理对象。支持按优先级处理 -template -class CLevelObjectMap -{ -public: - virtual ~CLevelObjectMap() { clear(); } - template - DeriveObjectType *getObject() const - { - static_assert(std::is_base_of::value, - "DeriveObjectType must be derive from ObjectType"); - - auto index = std::type_index(typeid(std::shared_ptr)); - - for (const auto &mainPair : m_map) { - const std::unordered_map> &subMap = - mainPair.second; - - auto itor = subMap.find(index); - if (itor != subMap.end()) { - return std::static_pointer_cast(itor->second).get(); - } - } - return nullptr; - } - template - void createObject(uint32_t level, Args &&... args) - { - static_assert(std::is_base_of::value, - "DeriveObjectType must be derive from ObjectType"); - - auto obj = std::make_shared(args...); - m_map[level][std::type_index(typeid(obj))] = std::static_pointer_cast(obj); - } - template - bool destroyObject() - { - static_assert(std::is_base_of::value, - "DeriveObjectType must be derive from ObjectType"); - - auto index = std::type_index(typeid(std::shared_ptr)); - for (auto &mainPair : m_map) { - std::unordered_map> &subMap = - mainPair.second; - - auto itor = subMap.find(index); - if (itor != subMap.end()) { - auto retItor = subMap.erase(itor); - return retItor != subMap.end(); - } - } - return false; - } - void forEach(const std::function &callback) const - { - for (const auto &mainPair : m_map) { - const std::unordered_map> &subMap = - mainPair.second; - for (const auto &subPair : subMap) { - callback(subPair.second.get()); - } - } - } - void clear() { m_map.clear(); } - -private: - std::map>> m_map; -}; -} // namespace TaoCommon diff --git a/3rdparty/TaoCommon/Common/Package.h b/3rdparty/TaoCommon/Common/Package.h deleted file mode 100644 index 7c34df7f..00000000 --- a/3rdparty/TaoCommon/Common/Package.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include -#include -#include -#include -const int static headerLength = sizeof(quint32); - -static QByteArray pack(const QByteArray &data) -{ - QByteArray header(headerLength, 0); - QDataStream os(&header, QIODevice::WriteOnly); - os << static_cast(data.length()); - return header + data; -} -static QByteArrayList unpack(const QByteArray &data) -{ - QByteArrayList list; - QDataStream inStream(data); - quint32 sum = data.size(); - quint32 pos = 0; - while (pos + headerLength < sum) { - quint32 packageLen = 0; - packageLen = 0; - inStream >> packageLen; - if (packageLen + headerLength > sum - pos) { - break; - } - QByteArray subPackage = data.mid(pos + headerLength, packageLen); - inStream.skipRawData(packageLen); - list.append(subPackage); - pos += headerLength + packageLen; - } - return list; -} diff --git a/3rdparty/TaoCommon/Common/PropertyHelper.h b/3rdparty/TaoCommon/Common/PropertyHelper.h deleted file mode 100644 index 75fb8ca8..00000000 --- a/3rdparty/TaoCommon/Common/PropertyHelper.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once -#include -#include - -template -struct Compare; - -template -struct Compare -{ - static bool isEqual(const T &t1, const T &t2) { return t1 == t2; } -}; -template<> -struct Compare -{ - static bool isEqual(float f1, float f2) { return qFuzzyCompare(f1, f2); } -}; -template<> -struct Compare -{ - static bool isEqual(double d1, double d2) { return qFuzzyCompare(d1, d2); } -}; -//member variant -#define PROP_MEM(T, NAME, InitValue) T m_##NAME = InitValue; - -//get method -#define PROP_GET(T, NAME) \ - const T &NAME() const { return m_##NAME; } -//change signal -#define PROP_CHANGE(T, NAME) Q_SIGNAL void NAME##Changed(const T &value); - -//set method -#define PROP_SET(T, NAME) \ - void set_##NAME(const T &value) \ - { \ - if (Compare::isEqual(m_##NAME, value)) \ - return; \ - m_##NAME = value; \ - emit NAME##Changed(value); \ - } -//ReadOnly property -#define READONLY_PROPERTY(T, NAME, InitValue) \ -private: \ - Q_PROPERTY(T NAME READ NAME CONSTANT) \ -public: \ - PROP_GET(T, NAME) \ -private: \ - PROP_MEM(T, NAME, InitValue) - -//Readable property -#define READ_PROPERTY(T, NAME, InitValue) \ -private: \ - Q_PROPERTY(T NAME READ NAME NOTIFY NAME##Changed) \ -public: \ - PROP_GET(T, NAME) \ - PROP_SET(T, NAME) \ - PROP_CHANGE(T, NAME) \ -private: \ - PROP_MEM(T, NAME, InitValue) -//Read Write property -#define AUTO_PROPERTY(T, NAME, InitValue) \ -private: \ - Q_PROPERTY(T NAME READ NAME WRITE set_##NAME NOTIFY NAME##Changed) \ -public: \ - PROP_GET(T, NAME) \ - Q_SLOT PROP_SET(T, NAME) PROP_CHANGE(T, NAME) private : PROP_MEM(T, NAME, InitValue) - -/** -* Example: -* -class AppInfo : public QObject -{ - Q_OBJECT - - AUTO_PROPERTY(QString, appName, "") - AUTO_PROPERTY(QString, descript, "") - AUTO_PROPERTY(QString, compilerVendor, "") - AUTO_PROPERTY(bool, splashShow, false) - AUTO_PROPERTY(float, scale, 1.0f) - AUTO_PROPERTY(double, ratio, 14.0 / 9.0) - AUTO_PROPERTY(QStringList, customs, {}) -public: - explicit AppInfo(QObject *parent = nullptr); - virtual ~AppInfo() override; -public: - -}; - - -*/ diff --git a/3rdparty/TaoCommon/Common/Subject.h b/3rdparty/TaoCommon/Common/Subject.h deleted file mode 100644 index 0dae8035..00000000 --- a/3rdparty/TaoCommon/Common/Subject.h +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once -#include -#include -#include -namespace TaoCommon { -//观察者模式,Subject-Observer。 -// Subject 事件或消息的主体。模板参数为观察者类型 -template -class Subject -{ -public: - virtual ~Subject() { m_obsList.clear(); } - //订阅 - void subscibe(ObserverType *obs) - { - auto itor = std::find(m_obsList.begin(), m_obsList.end(), obs); - if (m_obsList.end() == itor) { - m_obsList.push_back(obs); - } - } - //取消订阅 - void unSubscibe(ObserverType *obs) - { - m_obsList.erase(std::remove(m_obsList.begin(), m_obsList.end(), obs)); - } - //发布。这里的模板参数为函数类型。 - template - void publish(FuncType func) - { - for (auto obs : m_obsList) { - //调用回调函数,将obs作为第一个参数传递 - func(obs); - } - } - //发布。支持过滤观察者。通常用在 观察者触发消息发布时,过滤观察者自己。 - template - void publish(FuncType func, ObserverType *exceptObs) - { - for (auto obs : m_obsList) { - //调用回调函数,将obs作为第一个参数传递 - if (obs != exceptObs) { - func(obs); - } - } - } - -private: - std::vector m_obsList; -}; - -//优先级观察者模式,Subject-Observer。 -template -class LevelSubject -{ -public: - virtual ~LevelSubject() { m_obsMap.clear(); } - //订阅 - void subscibe(ObserverType *obs, uint32_t level) - { - auto &vec = m_obsMap[level]; - auto itor = std::find(vec.begin(), vec.end(), obs); - if (vec.end() == itor) { - vec.push_back(obs); - } - } - //取消订阅 - void unSubscibe(ObserverType *obs) - { - for (auto &obsPair : m_obsMap) { - obsPair.second.erase(std::remove(obsPair.second.begin(), obsPair.second.end(), obs)); - } - } - //发布。这里的模板参数为函数类型。 - template - void publish(FuncType func) - { - for (const auto &obsPair : m_obsMap) { - for (const auto &obs : obsPair.second) { - func(obs); - } - } - } - template - void publish(FuncType func, ObserverType *exceptObs) - { - for (const auto &obsPair : m_obsMap) { - for (const auto &obs : obsPair.second) { - if (obs != exceptObs) { - func(obs); - } - } - } - } - -private: - std::map> m_obsMap; -}; -} // namespace TaoCommon diff --git a/3rdparty/TaoCommon/Frameless/TaoFrameLessView.h b/3rdparty/TaoCommon/Frameless/TaoFrameLessView.h deleted file mode 100644 index e09f9e48..00000000 --- a/3rdparty/TaoCommon/Frameless/TaoFrameLessView.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "TaoCommonGlobal.h" -#include -//无边框窗口,主要用来实现自定义标题栏。 -//Windows平台支持拖动和改变大小,支持Aero效果 -//非Windows平台,去掉边框,不做其它处理。由Qml模拟resize和拖动。 -class TaoFrameLessViewPrivate; -class TAO_API TaoFrameLessView : public QQuickView -{ - Q_OBJECT - using Super = QQuickView; - Q_PROPERTY(bool isMax READ isMax NOTIFY isMaxChanged) -public: - explicit TaoFrameLessView(QWindow *parent = nullptr); - ~TaoFrameLessView(); - void moveToScreenCenter(); - bool isMax() const; - QQuickItem *titleItem() const; - - static QRect calcCenterGeo(const QRect &screenGeo, const QSize &normalSize); -public slots: - void setIsMax(bool isMax); - void setTitleItem(QQuickItem *item); -signals: - void isMaxChanged(bool isMax); - -protected: -# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; -# else - bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; -# endif - -private: - TaoFrameLessViewPrivate *d; -}; diff --git a/3rdparty/TaoCommon/Frameless/TaoFrameLessView_unix.cpp b/3rdparty/TaoCommon/Frameless/TaoFrameLessView_unix.cpp deleted file mode 100644 index 7db7c9e8..00000000 --- a/3rdparty/TaoCommon/Frameless/TaoFrameLessView_unix.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "Frameless/TaoFrameLessView.h" -#include -#include -#include -#include - -class TaoFrameLessViewPrivate -{ -public: - bool m_isMax = false; - QQuickItem *m_titleItem = nullptr; -}; -TaoFrameLessView::TaoFrameLessView(QWindow *parent) : Super(parent), d(new TaoFrameLessViewPrivate) -{ - setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); - setResizeMode(SizeRootObjectToView); - - setIsMax(windowState() == Qt::WindowMaximized); - connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { setIsMax(state == Qt::WindowMaximized); }); -} -TaoFrameLessView::~TaoFrameLessView() -{ - delete d; -} -QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &normalSize) -{ - int w = normalSize.width(); - int h = normalSize.height(); - int x = screenGeo.x() + (screenGeo.width() - w) / 2; - int y = screenGeo.y() + (screenGeo.height() - h) / 2; - if (screenGeo.width() < w) { - x = screenGeo.x(); - w = screenGeo.width(); - } - if (screenGeo.height() < h) { - y = screenGeo.y(); - h = screenGeo.height(); - } - - return { x, y, w, h }; -} -void TaoFrameLessView::moveToScreenCenter() -{ - auto geo = calcCenterGeo(screen()->availableGeometry(), size()); - if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) { - setMinimumSize(geo.size()); - } - setGeometry(geo); - update(); -} -bool TaoFrameLessView::isMax() const -{ - return d->m_isMax; -} -QQuickItem *TaoFrameLessView::titleItem() const -{ - return d->m_titleItem; -} -void TaoFrameLessView::setIsMax(bool isMax) -{ - if (d->m_isMax == isMax) - return; - - d->m_isMax = isMax; - emit isMaxChanged(d->m_isMax); -} -void TaoFrameLessView::setTitleItem(QQuickItem *item) -{ - d->m_titleItem = item; -} -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) -#else -bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, long *result) -#endif - -{ - return Super::nativeEvent(eventType, message, result); -} - diff --git a/3rdparty/TaoCommon/Frameless/TaoFrameLessView_win.cpp b/3rdparty/TaoCommon/Frameless/TaoFrameLessView_win.cpp deleted file mode 100644 index 7339167a..00000000 --- a/3rdparty/TaoCommon/Frameless/TaoFrameLessView_win.cpp +++ /dev/null @@ -1,261 +0,0 @@ -#include "Frameless/TaoFrameLessView.h" - -#include -#include -#include -#include - -#include -#include -#include // Fixes error C2504: 'IUnknown' : base class undefined -#include -#include -#pragma comment(lib, "Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved -#pragma comment(lib, "User32.lib") -// we cannot just use WS_POPUP style -// WS_THICKFRAME: without this the window cannot be resized and so aero snap, de-maximizing and minimizing won't work -// WS_SYSMENU: enables the context menu with the move, close, maximize, minize... commands (shift + right-click on the task bar item) -// WS_CAPTION: enables aero minimize animation/transition -// WS_MAXIMIZEBOX, WS_MINIMIZEBOX: enable minimize/maximize -enum class Style : DWORD { - windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, - aero_borderless = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, - basic_borderless = WS_POPUP | WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX -}; -static bool isCompositionEnabled() -{ - BOOL composition_enabled = FALSE; - bool success = ::DwmIsCompositionEnabled(&composition_enabled) == S_OK; - return composition_enabled && success; -} -static Style selectBorderLessStyle() -{ - return isCompositionEnabled() ? Style::aero_borderless : Style::basic_borderless; -} -static void setShadow(HWND handle, bool enabled) -{ - if (isCompositionEnabled()) { - static const MARGINS shadow_state[2] { { 0, 0, 0, 0 }, { 1, 1, 1, 1 } }; - ::DwmExtendFrameIntoClientArea(handle, &shadow_state[enabled]); - } -} -static long hitTest(RECT winrect, long x, long y, int borderWidth) -{ - // 鼠标区域位于窗体边框,进行缩放 - if ((x >= winrect.left) && (x < winrect.left + borderWidth) && (y >= winrect.top) && (y < winrect.top + borderWidth)) { - return HTTOPLEFT; - } else if (x < winrect.right && x >= winrect.right - borderWidth && y >= winrect.top && y < winrect.top + borderWidth) { - return HTTOPRIGHT; - } else if (x >= winrect.left && x < winrect.left + borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth) { - return HTBOTTOMLEFT; - } else if (x < winrect.right && x >= winrect.right - borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth) { - return HTBOTTOMRIGHT; - } else if (x >= winrect.left && x < winrect.left + borderWidth) { - return HTLEFT; - } else if (x < winrect.right && x >= winrect.right - borderWidth) { - return HTRIGHT; - } else if (y >= winrect.top && y < winrect.top + borderWidth) { - return HTTOP; - } else if (y < winrect.bottom && y >= winrect.bottom - borderWidth) { - return HTBOTTOM; - } else { - return 0; - } -} - -static bool isMaxWin(QWindow *win) -{ - return win->windowState() == Qt::WindowMaximized; -} -static bool isFullWin(QQuickView *win) -{ - return win->windowState() == Qt::WindowFullScreen; -} - - -class TaoFrameLessViewPrivate -{ -public: - bool m_isMax; - QQuickItem *m_titleItem = nullptr; - bool borderless = true; // is the window currently borderless - bool borderless_resize = true; // should the window allow resizing by dragging the borders while borderless - bool borderless_drag = true; // should the window allow moving my dragging the client area - bool borderless_shadow = true; // should the window display a native aero shadow while borderless - void setBorderLess(HWND handle, bool enabled) - { - auto newStyle = enabled ? selectBorderLessStyle() : Style::windowed; - auto oldStyle = static_cast - - - -

TaoLogger 日志文件

- - -)logTemplate"); -} diff --git a/3rdparty/TaoCommon/QuickTool/QuickTool.cpp b/3rdparty/TaoCommon/QuickTool/QuickTool.cpp deleted file mode 100644 index 6bdbbd4a..00000000 --- a/3rdparty/TaoCommon/QuickTool/QuickTool.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "QuickTool.h" -#include -#include - -QuickTool::QuickTool(QObject *parent) : QObject(parent) { } - -QuickTool::QuickTool(QObject *rootObject, QObject *parent) - : QObject(parent), pRootObject(rootObject) -{ -} - -QuickTool::~QuickTool() { } -void QuickTool::findRootByNode(QObject *nodeObject) -{ - pRootObject = nodeObject; - if (pRootObject) { - QObject *pParent = nullptr; - while ((pParent = pRootObject->parent())) { - pRootObject = pParent; - } - } -} -QRect QuickTool::getItemGeometryToScene(const QString &targetObjName) const -{ - if (!pRootObject) { - return {}; - } - auto pItem = pRootObject->findChild(targetObjName); - if (pItem) { - if (pItem->parentItem()) { - auto pos = pItem->parentItem()->mapToScene(pItem->position()); - return QRectF { pos.x(), pos.y(), pItem->width(), pItem->height() }.toRect(); - } else { - return pItem->boundingRect().toRect(); - } - } - return {}; -} - -void QuickTool::setAppOverrideCursor(QCursor cursor) -{ - qApp->setOverrideCursor(cursor); -} - -void QuickTool::restoreAppOverrideCursor() -{ - qApp->restoreOverrideCursor(); -} - -QPoint QuickTool::cursorGlobalPos() const -{ - return QCursor::pos(); -} - -QObject *QuickTool::getObject(const QString &targetObjName) const -{ - if (!pRootObject) { - return nullptr; - } - return pRootObject->findChild(targetObjName); -} - -QVariant QuickTool::getObjectProperty(QObject *targetObj, const QString &propertyName) const -{ - return targetObj->property(propertyName.toUtf8().constData()); -} - -void QuickTool::setObjectProperty(QObject *targetObj, const QString &propertyName, - const QVariant &value) const -{ - targetObj->setProperty(propertyName.toUtf8().constData(), value); -} - -QVariant QuickTool::getObjectProperty(const QString &targetObjName, - const QString &propertyName) const -{ - auto pObj = getObject(targetObjName); - if (pObj) { - return getObjectProperty(pObj, propertyName); - } - return {}; -} - -void QuickTool::setObjectProperty(const QString &targetObjName, const QString &propertyName, - const QVariant &value) const -{ - auto pObj = getObject(targetObjName); - if (pObj) { - setObjectProperty(pObj, propertyName, value); - } -} diff --git a/3rdparty/TaoCommon/QuickTool/QuickTool.h b/3rdparty/TaoCommon/QuickTool/QuickTool.h deleted file mode 100644 index 49f79e44..00000000 --- a/3rdparty/TaoCommon/QuickTool/QuickTool.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include "TaoCommonGlobal.h" -class TAO_API QuickTool : public QObject -{ - Q_OBJECT -public: - explicit QuickTool(QObject *parent = nullptr); - explicit QuickTool(QObject *rootObject, QObject *parent = nullptr); - virtual ~QuickTool() override; - void setRootObjet(QObject *rootObj) { pRootObject = rootObj; } - QObject *rootObject() const { return pRootObject; } - void findRootByNode(QObject *nodeObject); - -public slots: - QObject *getObject(const QString &targetObjName) const; - - QVariant getObjectProperty(QObject *targetObj, const QString &propertyName) const; - void setObjectProperty(QObject *targetObj, const QString &propertyName, - const QVariant &value) const; - - QVariant getObjectProperty(const QString &targetObjName, const QString &propertyName) const; - void setObjectProperty(const QString &targetObjName, const QString &propertyName, - const QVariant &value) const; - - QRect getItemGeometryToScene(const QString &targetObjName) const; - - void setAppOverrideCursor(QCursor cursor); - void restoreAppOverrideCursor(); - - QPoint cursorGlobalPos() const; - -private: - QObject *pRootObject = nullptr; -}; diff --git a/3rdparty/TaoCommon/TaoCommon.pri b/3rdparty/TaoCommon/TaoCommon.pri deleted file mode 100644 index 8e419ea8..00000000 --- a/3rdparty/TaoCommon/TaoCommon.pri +++ /dev/null @@ -1,41 +0,0 @@ -!build_TaoCommon_lib:{ - DEFINES +=TaoCommon_NO_LIB -} - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/Common/FileReadWrite.h \ - $$PWD/Common/JsonSerialize.h \ - $$PWD/Common/ObjectMap.h \ - $$PWD/Common/Package.h \ - $$PWD/Common/PropertyHelper.h \ - $$PWD/Common/Subject.h \ - $$PWD/Frameless/TaoFrameLessView.h \ - $$PWD/Logger/Logger.h \ - $$PWD/Logger/LoggerTemplate.h \ - $$PWD/QuickTool/QuickTool.h \ - $$PWD/TaoCommonGlobal.h \ - $$PWD/TaoModel/TaoListItemBase.h \ - $$PWD/TaoModel/TaoListModel.h \ - $$PWD/TaoModel/TaoListModelBase.hpp \ - $$PWD/Thread/ThreadCommon.h \ - $$PWD/Thread/ThreadPool.h \ - $$PWD/Thread/ThreadWorkerController.h \ - $$PWD/Trans/Trans.h - -SOURCES += \ - $$PWD/Logger/Logger.cpp \ - $$PWD/QuickTool/QuickTool.cpp \ - $$PWD/TaoModel/TaoListItemBase.cpp \ - $$PWD/TaoModel/TaoListModel.cpp \ - $$PWD/Thread/ThreadPool.cpp \ - $$PWD/Trans/Trans.cpp - -win32 { - SOURCES += \ - $$PWD/Frameless/TaoFrameLessView_win.cpp -} else { - SOURCES += \ - $$PWD/Frameless/TaoFrameLessView_unix.cpp -} diff --git a/3rdparty/TaoCommon/TaoCommon.pro b/3rdparty/TaoCommon/TaoCommon.pro deleted file mode 100644 index 4ca225a1..00000000 --- a/3rdparty/TaoCommon/TaoCommon.pro +++ /dev/null @@ -1,14 +0,0 @@ -TARGET = TaoCommon - -load(qt_module) - -QT += core gui quick -QMAKE_TARGET_COMPANY = "jaredtao.github.io" -QMAKE_TARGET_COPYRIGHT = "Copyright (C) 2019-2022 JaredTao " -QMAKE_TARGET_PRODUCT = "TaoCommon" -QMAKE_TARGET_DESCRIPTION = "common use code for Qt." - -CONFIG += build_TaoCommon_lib -DEFINES += TaoCommon_Library - -include(TaoCommon.pri) diff --git a/3rdparty/TaoCommon/TaoCommonGlobal.h b/3rdparty/TaoCommon/TaoCommonGlobal.h deleted file mode 100644 index 0da70374..00000000 --- a/3rdparty/TaoCommon/TaoCommonGlobal.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include - -#if !defined(BUILD_STATIC) && !defined(TaoCommon_NO_LIB) -# if defined(TaoCommon_Library) -# define TAO_API Q_DECL_EXPORT -# else -# define TAO_API Q_DECL_IMPORT -# endif -#else -# define TAO_API -#endif diff --git a/3rdparty/TaoCommon/TaoModel/TaoListItemBase.cpp b/3rdparty/TaoCommon/TaoModel/TaoListItemBase.cpp deleted file mode 100644 index 3525c8bc..00000000 --- a/3rdparty/TaoCommon/TaoModel/TaoListItemBase.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "TaoListItemBase.h" - -TaoListItemBase::TaoListItemBase(QObject *parent) - : QObject(parent) -{ -} - -TaoListItemBase::~TaoListItemBase() {} diff --git a/3rdparty/TaoCommon/TaoModel/TaoListItemBase.h b/3rdparty/TaoCommon/TaoModel/TaoListItemBase.h deleted file mode 100644 index b84c9c75..00000000 --- a/3rdparty/TaoCommon/TaoModel/TaoListItemBase.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include -#include "TaoCommonGlobal.h" -class TAO_API TaoListItemBase : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool isChecked READ isChecked WRITE setIsChecked NOTIFY isCheckedChanged) - Q_PROPERTY(bool isSelected READ isSelected WRITE setIsSelected NOTIFY isSelectedChanged) - Q_PROPERTY(bool isVisible READ isVisible WRITE setIsVisible NOTIFY isVisibleChanged) - Q_PROPERTY(bool isAlternate READ isAlternate WRITE setIsAlternate NOTIFY isAlternateChanged) -public: - explicit TaoListItemBase(QObject *parent = nullptr); - ~TaoListItemBase() override; - TaoListItemBase(const TaoListItemBase &other) - { - setIsChecked(other.isChecked()); - setIsSelected(other.isSelected()); - setIsVisible(other.isVisible()); - setIsAlternate(other.isAlternate()); - } - - TaoListItemBase &operator=(const TaoListItemBase &other) - { - setIsChecked(other.isChecked()); - setIsSelected(other.isSelected()); - setIsVisible(other.isVisible()); - setIsAlternate(other.isAlternate()); - return *this; - } - bool isChecked() const { return mIsChecked; } - - bool isSelected() const { return mIsSelected; } - - bool isVisible() const { return mIsVisible; } - bool isAlternate() const { return mIsAlternate; } - // Model call this for search. return true if contents match key, others return false. - virtual bool match(const QString &key) - { - Q_UNUSED(key) - return true; - } -public slots: - void setIsChecked(bool isChecked) - { - if (mIsChecked == isChecked) - return; - - mIsChecked = isChecked; - emit isCheckedChanged(mIsChecked); - } - - void setIsSelected(bool isSelected) - { - if (mIsSelected == isSelected) - return; - - mIsSelected = isSelected; - emit isSelectedChanged(mIsSelected); - } - - void setIsVisible(bool isVisible) - { - if (mIsVisible == isVisible) - return; - - mIsVisible = isVisible; - emit isVisibleChanged(mIsVisible); - } - void setIsAlternate(bool isAlternate) - { - if (mIsAlternate == isAlternate) { - return; - } - mIsAlternate = isAlternate; - emit isAlternateChanged(mIsAlternate); - } - -signals: - void isCheckedChanged(bool isChecked); - - void isSelectedChanged(bool isSelected); - - void isVisibleChanged(bool isVisible); - - void isAlternateChanged(bool isAlternate); - -private: - bool mIsChecked = false; - bool mIsSelected = false; - bool mIsVisible = true; - bool mIsAlternate = false; -}; diff --git a/3rdparty/TaoCommon/TaoModel/TaoListModel.cpp b/3rdparty/TaoCommon/TaoModel/TaoListModel.cpp deleted file mode 100644 index f4c1c64f..00000000 --- a/3rdparty/TaoCommon/TaoModel/TaoListModel.cpp +++ /dev/null @@ -1,329 +0,0 @@ -#include "TaoListModel.h" - -#include -#include -#include -TaoListModel::TaoListModel(QObject *parent) : TaoListModelBase(parent) -{ - connect(&mSearchTimer, &QTimer::timeout, this, &TaoListModel::onSearch); - mSearchTimer.setInterval(300); - mSearchTimer.setSingleShot(true); -} - -TaoListModel::~TaoListModel() { } - -void TaoListModel::check(int row, bool checked) -{ - if (row < 0 || row >= mDatas.size()) { - return; - } - - mDatas.at(row)->setIsChecked(checked); - if (mDatas.at(row)->isSelected()) { - for (const auto &obj : mDatas) { - if (obj->isVisible() && obj->isSelected()) { - obj->setIsChecked(checked); - } - } - } - - bool allCheck = true; - if (checked == false || mDatas.count() <= 0) { - allCheck = false; - } else { - for (const auto &obj : mDatas) { - if (obj->isVisible() && false == obj->isChecked()) { - allCheck = false; - break; - } - } - } - if (mAllChecked != allCheck) { - mAllChecked = allCheck; - emit allCheckedChanged(mAllChecked); - } - updateCheckedCount(); -} -void TaoListModel::setAllChecked(bool allChecked) -{ - for (const auto &obj : mDatas) { - if (obj->isVisible()) { - obj->setIsChecked(allChecked); - } - } - updateCheckedCount(); - if (mAllChecked == allChecked) - return; - - mAllChecked = allChecked; - emit allCheckedChanged(mAllChecked); -} -void TaoListModel::search(const QString &searchKey) -{ - mSearchkey = searchKey.simplified(); - mSearchTimer.start(300); -} -void TaoListModel::searchImmediate(const QString &searchKey) -{ - mSearchkey = searchKey.simplified(); - onSearch(); -} -void TaoListModel::onSearch() -{ - - for (const auto &obj : mDatas) - { - obj->setIsVisible(obj->match(mSearchkey)); - } - - updateCalcInfo(); -} -void TaoListModel::deselectAll() -{ - for (const auto &obj : mDatas) { - if (obj->isVisible()) { - obj->setIsSelected(false); - } - } - updateSelectedCount(); -} - -void TaoListModel::selectAll() -{ - for (const auto &obj : mDatas) { - if (obj->isVisible()) { - obj->setIsSelected(true); - } - } - updateSelectedCount(); -} - -bool TaoListModel::isSelected(int row) const -{ - if (row < 0 || row >= mDatas.size()) { - return false; - } - return mDatas.at(row)->isSelected(); -} - -void TaoListModel::select(int row) -{ - if (row < 0 || row >= mDatas.size()) { - return; - } - mDatas.at(row)->setIsSelected(true); - updateSelectedCount(); -} - -void TaoListModel::deselect(int row) -{ - if (row < 0 || row >= mDatas.size()) { - return; - } - mDatas.at(row)->setIsSelected(false); - updateSelectedCount(); -} - -void TaoListModel::selectRange(int from, int to) -{ - int minRow = qMin(from, to); - int maxRow = qMax(from, to); - for (int i = 0; i < mDatas.size(); ++i) { - mDatas.at(i)->setIsSelected(mDatas.at(i)->isVisible() && minRow <= i && i <= maxRow); - } - updateSelectedCount(); -} - -void TaoListModel::selectSingle(int row) -{ - for (int i = 0; i < mDatas.size(); ++i) { - mDatas.at(i)->setIsSelected(i == row); - } - updateSelectedCount(); -} -void TaoListModel::doPress(int row, bool shift, bool ctrl, bool outRange) -{ - if (outRange) { - row = mDatas.size(); - } else { - if (row < 0 || row >= mDatas.size()) { - return; - } - } - - mIsPressed = true; - if (ctrl) { - mLastPressedRow = row; - if (isSelected(mLastPressedRow)) { - deselect(mLastPressedRow); - } else { - select(mLastPressedRow); - } - } else if (shift) { - selectRange(mLastPressedRow, row); - } else { - mLastPressedRow = row; - selectSingle(mLastPressedRow); - } -} -void TaoListModel::doMove(int row, bool outRange) -{ - if (outRange) { - row = mDatas.size(); - } else { - - if (row < 0 || row >= mDatas.size()) { - return; - } - } - if (mIsPressed) { - selectRange(mLastPressedRow, row); - } -} -void TaoListModel::doRelease() -{ - mIsPressed = false; -} - -void TaoListModel::sortByRole() -{ - if (mDatas.size() <= 1) - { - return; - } - if (mSortOrder == Qt::SortOrder::AscendingOrder) - { - if (const auto &sortCall = mSortCallbacksAscend.value(mSortRole)) - { - QList copyObjs; - copyObjs = mDatas; - std::sort(copyObjs.begin(), copyObjs.end(), sortCall); - mDatas = copyObjs; - emit dataChanged(index(0, 0), index(mDatas.count() - 1, 0)); - updateAlternate(); - } - } - else - { - if (const auto &sortCall = mSortCallbacksDescend.value(mSortRole)) - { - QList copyObjs; - copyObjs = mDatas; - std::sort(copyObjs.begin(), copyObjs.end(), sortCall); - mDatas = copyObjs; - emit dataChanged(index(0, 0), index(mDatas.count() - 1, 0)); - updateAlternate(); - } - } -} - -void TaoListModel::setHeaderRoles(const QStringList &headerRoles) -{ - if (mHeaderRoles == headerRoles) - return; - - mHeaderRoles = headerRoles; - emit headerRolesChanged(mHeaderRoles); -} - -void TaoListModel::setSortOrder(Qt::SortOrder sortOrder) -{ - if (mSortOrder == sortOrder) - return; - - mSortOrder = sortOrder; - emit sortOrderChanged(mSortOrder); -} - -void TaoListModel::setSortRole(const QString &sortRole) -{ - if (mSortRole == sortRole) - return; - - mSortRole = sortRole; - emit sortRoleChanged(mSortRole); -} - -void TaoListModel::updateAllCheck() -{ - bool allCheck = false; - if (!mDatas.empty()) { - allCheck = std::all_of(mDatas.begin(), mDatas.end(), [](TaoListItemBase *obj) { - return obj->isVisible() && obj->isChecked(); - }); - } - if (mAllChecked == allCheck) - return; - - mAllChecked = allCheck; - emit allCheckedChanged(mAllChecked); -} - -void TaoListModel::updateVisibleCount() -{ - int count = std::count_if(mDatas.begin(), mDatas.end(), - [](TaoListItemBase *obj) { return obj->isVisible(); }); - setVisibledCount(count); -} - -void TaoListModel::updateSelectedCount() -{ - int count = std::count_if(mDatas.begin(), mDatas.end(), [](TaoListItemBase *obj) { - return obj->isVisible() && obj->isSelected(); - }); - setSelectedCount(count); -} - -void TaoListModel::updateCheckedCount() -{ - int count = std::count_if(mDatas.begin(), mDatas.end(), [](TaoListItemBase *obj) { - return obj->isVisible() && obj->isChecked(); - }); - setCheckedCount(count); -} -void TaoListModel::updateAlternate() -{ - bool alter = false; - for (const auto &obj : mDatas) { - if (obj->isVisible()) { - obj->setIsAlternate(alter); - alter = !alter; - } - } -} -void TaoListModel::setVisibledCount(int visibledCount) -{ - if (mVisibledCount == visibledCount) - return; - - mVisibledCount = visibledCount; - emit visibledCountChanged(mVisibledCount); -} - -void TaoListModel::setSelectedCount(int selectedCount) -{ - if (mSelectedCount == selectedCount) - return; - - mSelectedCount = selectedCount; - emit selectedCountChanged(mSelectedCount); -} - -void TaoListModel::setCheckedCount(int checkedCount) -{ - if (mCheckedCount == checkedCount) - return; - - mCheckedCount = checkedCount; - emit checkedCountChanged(mCheckedCount); -} - -void TaoListModel::updateCalcInfo() -{ - updateAllCheck(); - updateCheckedCount(); - updateVisibleCount(); - updateSelectedCount(); - updateAlternate(); - emit signalUpdateCalcCount(); -} diff --git a/3rdparty/TaoCommon/TaoModel/TaoListModel.h b/3rdparty/TaoCommon/TaoModel/TaoListModel.h deleted file mode 100644 index 1a8c0d9c..00000000 --- a/3rdparty/TaoCommon/TaoModel/TaoListModel.h +++ /dev/null @@ -1,144 +0,0 @@ -#pragma once - -#include "TaoListModelBase.hpp" -#include "TaoListItemBase.h" -#include "TaoCommonGlobal.h" -#include -class TAO_API TaoListModel : public TaoListModelBase -{ - Q_OBJECT - Q_PROPERTY(bool allChecked READ allChecked WRITE setAllChecked NOTIFY allCheckedChanged) - Q_PROPERTY(int visibledCount READ visibledCount NOTIFY visibledCountChanged) - Q_PROPERTY(int selectedCount READ selectedCount NOTIFY selectedCountChanged) - Q_PROPERTY(int checkedCount READ checkedCount NOTIFY checkedCountChanged) - - Q_PROPERTY( - QStringList headerRoles READ headerRoles WRITE setHeaderRoles NOTIFY headerRolesChanged) - Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) - Q_PROPERTY(QString sortRole READ sortRole WRITE setSortRole NOTIFY sortRoleChanged) - -public: - using Super = TaoListModelBase; - explicit TaoListModel(QObject *parent = nullptr); - ~TaoListModel() override; - Q_INVOKABLE QVariant data(int row) const { return Super::data(row); } - //[begin] check - bool allChecked() const { return mAllChecked; } - Q_INVOKABLE void check(int row, bool checked); - //[end] check - - //[begin] search. control visible - Q_INVOKABLE void search(const QString &searchKey); - const QString & searchKey() const - { - return mSearchkey; - } - Q_INVOKABLE void searchImmediate(const QString &searchKey); - void clearSearchKey() - { - mSearchkey.clear(); - } - //[end] search - - //[begin] select - Q_INVOKABLE void deselectAll(); - Q_INVOKABLE void selectAll(); - Q_INVOKABLE bool isSelected(int row) const; - Q_INVOKABLE void select(int row); - Q_INVOKABLE void deselect(int row); - Q_INVOKABLE void selectRange(int from, int to); - Q_INVOKABLE void selectSingle(int row); - //[end] select - - Q_INVOKABLE void doPress(int row, bool shift, bool ctrl, bool outRange); - Q_INVOKABLE void doMove(int row, bool outRange); - Q_INVOKABLE void doRelease(); - - //[begin] sort - const QStringList &headerRoles() const { return mHeaderRoles; } - - Qt::SortOrder sortOrder() const { return mSortOrder; } - - const QString &sortRole() const { return mSortRole; } - using SortCallback = std::function; - // Map ,key should match to headerRoles - void setSortCallbacksAscend(const QMap &callbacksMap) - { - mSortCallbacksAscend = callbacksMap; - } - void setSortCallbacksDescend(const QMap &callbacksMap) - { - mSortCallbacksDescend = callbacksMap; - } - - Q_INVOKABLE virtual void sortByRole(); - //[end] sort - - //[begin] count - int visibledCount() const { return mVisibledCount; } - - int selectedCount() const { return mSelectedCount; } - - int checkedCount() const { return mCheckedCount; } - - //[end] count - - void updateCalcInfo() override; - - Q_INVOKABLE void notifyScrollTo(int index) - { - emit scrollTo(index); - } -public slots: - void setAllChecked(bool allChecked); - - void setHeaderRoles(const QStringList &headerRoles); - - void setSortOrder(Qt::SortOrder sortOrder); - - void setSortRole(const QString &sortRole); - - void setVisibledCount(int visibledCount); - void setSelectedCount(int selectedCount); - void setCheckedCount(int checkedCount); - -signals: - void scrollTo(int index); - void allCheckedChanged(bool allChecked); - void visibledCountChanged(int visibledCount); - - void selectedCountChanged(int selectedCount); - - void checkedCountChanged(int checkedCount); - - void headerRolesChanged(const QStringList &headerRoles); - - void sortOrderChanged(Qt::SortOrder sortOrder); - - void sortRoleChanged(const QString &sortRole); - - void signalUpdateCalcCount(); -protected slots: - void onSearch(); -protected: - void updateAllCheck(); - void updateVisibleCount(); - void updateSelectedCount(); - void updateCheckedCount(); - void updateAlternate(); - -protected: - bool mAllChecked = false; - bool mIsPressed = false; - Qt::SortOrder mSortOrder = Qt::AscendingOrder; - int mVisibledCount = 0; - int mSelectedCount = 0; - int mCheckedCount = 0; - int mLastPressedRow = -1; - QStringList mHeaderRoles; - QString mSortRole; - QMap mSortCallbacksAscend; - QMap mSortCallbacksDescend; - QString mSearchkey; - QTimer mSearchTimer; -}; diff --git a/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp b/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp deleted file mode 100644 index fa5f76b2..00000000 --- a/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp +++ /dev/null @@ -1,221 +0,0 @@ -#pragma once -#include -#include -template -class TaoListModelBase : public QAbstractListModel -{ -public: - using Super = QAbstractListModel; - explicit TaoListModelBase(QObject *parent = nullptr); - explicit TaoListModelBase(const QList &datas, QObject *parent = nullptr); - virtual ~TaoListModelBase() override; - -public: - //[begin] query data - int rowCount(const QModelIndex &parent) const override; - QVariant data(int row) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - - //[end] query data - - //[begin] reset data - void resetData(const QList &datas); - const QList &datas() const { return mDatas; } - // quick reset - void quickResetData(const QList &datas); - //[end] reset data - - //[begin] add data - void append(const QList &datas); - void prepend(T data); - void insert(int row, const QList &datas); - //[end] add data - - //[begin] remove data - void clear(); - void removeAt(int row); - //[end] remove data - - //[begin] update data - void updateData(int row, T data); - //[end] update data - -public: - virtual void updateCalcInfo() { } - -protected: - QList mDatas; -}; - -template -TaoListModelBase::TaoListModelBase(QObject *parent) : Super(parent) -{ -} -template -TaoListModelBase::TaoListModelBase(const QList &datas, QObject *parent) - : Super(parent), mDatas(datas) -{ -} -template -TaoListModelBase::~TaoListModelBase() -{ - mDatas.clear(); -} - -template -int TaoListModelBase::rowCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent) - return mDatas.count(); -} -template -QVariant TaoListModelBase::data(const QModelIndex &index, int role) const -{ - if (index.row() < 0 || index.row() >= mDatas.size()) { - return {}; - } - - if (role == Qt::DisplayRole || role == Qt::EditRole) { - auto data = mDatas.at(index.row()); - return QVariant::fromValue(data); - } - - return {}; -} -template -QVariant TaoListModelBase::data(int row) const -{ - return data(index(row), Qt::DisplayRole); -} -template -void TaoListModelBase::resetData(const QList &datas) -{ - auto oldObjs = mDatas; - beginResetModel(); - mDatas = datas; - endResetModel(); - qDeleteAll(oldObjs); - updateCalcInfo(); -} - -template -void TaoListModelBase::quickResetData(const QList &datas) -{ - if (datas.isEmpty()) { - clear(); - return; - } - if (mDatas.isEmpty()) { - append(datas); - } else { - auto delta = mDatas.count() - datas.count(); - if (delta > 0) { - //删掉多余的 - beginRemoveRows({}, datas.count(), mDatas.count() - 1); - for (int i = 0; i < delta; ++i) { - auto pObj = mDatas.last(); - mDatas.removeLast(); - pObj->deleteLater(); - } - endRemoveRows(); - //标记旧的 - auto copy = mDatas; - //存储新的 - mDatas = datas; - //刷新数据 - emit dataChanged(index(0, 0), index(datas.count() - 1, 0)); - qDeleteAll(copy); - } else if (delta < 0) { - //标记旧的 - auto copy = mDatas; - beginInsertRows({}, mDatas.count(), mDatas.count() - delta); - //存储新的 - mDatas = datas; - endInsertRows(); - //刷新数据 - emit dataChanged(index(0, 0), index(datas.count() - 1, 0)); - qDeleteAll(copy); - } else { - //标记旧的 - auto copy = mDatas; - //存储新的 - mDatas = datas; - //刷新数据 - emit dataChanged(index(0, 0), index(datas.count() - 1, 0)); - qDeleteAll(copy); - } - updateCalcInfo(); - } -} - -template -void TaoListModelBase::append(const QList &datas) -{ - if (datas.count() <= 0) { - return; - } - beginInsertRows({}, mDatas.count(), mDatas.count() + datas.count() - 1); - mDatas.append(datas); - endInsertRows(); - updateCalcInfo(); -} -template -void TaoListModelBase::prepend(T data) -{ - beginInsertRows({}, 0, 1); - mDatas.prepend(data); - endInsertRows(); - updateCalcInfo(); -} -template -void TaoListModelBase::insert(int row, const QList &datas) -{ - if (row < 0 || row > mDatas.size()) { - return; - } - beginInsertRows({}, row, row + datas.count() - 1); - int srow = row; - for (const auto &obj : datas) { - mDatas.insert(srow, obj); - srow++; - } - endInsertRows(); - updateCalcInfo(); -} -template -void TaoListModelBase::clear() -{ - if (mDatas.count() <= 0) { - return; - } - beginRemoveRows({}, 0, mDatas.count() - 1); - qDeleteAll(mDatas); - mDatas.clear(); - endRemoveRows(); - updateCalcInfo(); -} -template -void TaoListModelBase::removeAt(int row) -{ - if (row < 0 || row >= mDatas.size()) { - return; - } - beginRemoveRows({}, row, row); - auto obj = mDatas.at(row); - mDatas.removeAt(row); - endRemoveRows(); - obj->deleteLater(); - updateCalcInfo(); -} -template -void TaoListModelBase::updateData(int row, T data) -{ - if (row < 0 || row >= mDatas.size()) { - return; - } - auto oldObj = mDatas.at(row); - mDatas[row] = data; - emit dataChanged(index(row, 0), index(row, 0)); - oldObj->deleteLater(); - updateCalcInfo(); -} diff --git a/3rdparty/TaoCommon/Thread/ThreadCommon.h b/3rdparty/TaoCommon/Thread/ThreadCommon.h deleted file mode 100644 index 890fcf5f..00000000 --- a/3rdparty/TaoCommon/Thread/ThreadCommon.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include -#include -namespace TaoCommon { -using WorkCallback = std::function; -using WorkResultCallback = std::function; -} -Q_DECLARE_METATYPE(TaoCommon::WorkCallback); -Q_DECLARE_METATYPE(TaoCommon::WorkResultCallback); diff --git a/3rdparty/TaoCommon/Thread/ThreadPool.cpp b/3rdparty/TaoCommon/Thread/ThreadPool.cpp deleted file mode 100644 index 3e124445..00000000 --- a/3rdparty/TaoCommon/Thread/ThreadPool.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "ThreadPool.h" - -#include -namespace TaoCommon { -ThreadObject::ThreadObject(const WorkCallback &work) : m_workCall(work) {} -void ThreadObject::run() -{ - bool ok = m_workCall(); - emit readyResult(ok); -} -// workCall in sub thread, resultCall in main thread -void ThreadPool::work(const WorkCallback &workCall, const WorkResultCallback &resultCall) -{ - ThreadObject *obj = new ThreadObject(workCall); - obj->setAutoDelete(true); - connect(obj, &ThreadObject::readyResult, this, resultCall); - QThreadPool::globalInstance()->start(obj); -} -} diff --git a/3rdparty/TaoCommon/Thread/ThreadPool.h b/3rdparty/TaoCommon/Thread/ThreadPool.h deleted file mode 100644 index 5ad7da34..00000000 --- a/3rdparty/TaoCommon/Thread/ThreadPool.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include "TaoCommonGlobal.h" -#include "ThreadCommon.h" -#include -#include -namespace TaoCommon { -// 对Qt线程池的简单封装,适合一次性执行的任务。 -// 用法: ThreadPool::getInstance()->work(workCall, resultCall) -// workCall是在新线程中执行的任务,resultCall是任务执行完成后,回到调用线程中用来处理执行结果。 -// 不支持任务取消、暂停。 - -class ThreadObject : public QObject, public QRunnable -{ - Q_OBJECT -public: - explicit ThreadObject(const WorkCallback &work); - void run() override; -signals: - void readyResult(bool); - -private: - WorkCallback m_workCall; -}; -class TAO_API ThreadPool : public QObject -{ - Q_OBJECT -public: - static ThreadPool *getInstance() - { - static ThreadPool poll; - return &poll; - } - // workCall in sub thread, resultCall in main thread - void work(const WorkCallback &workCall, const WorkResultCallback &resultCall); - -private: - ThreadPool() {} -}; -} // namespace TaoCommon diff --git a/3rdparty/TaoCommon/Thread/ThreadWorkerController.h b/3rdparty/TaoCommon/Thread/ThreadWorkerController.h deleted file mode 100644 index e686a66b..00000000 --- a/3rdparty/TaoCommon/Thread/ThreadWorkerController.h +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once -#include "TaoCommonGlobal.h" -#include "ThreadCommon.h" -#include -#include -namespace TaoCommon { -// 对Qt Worker-Controller 线程模型的简单封装,适合精确控制的任务。 -// 用法: ThreadController::getInstance()->work(workCall, resultCall) -// workCall是在新线程中执行的任务,resultCall是任务执行完成后,回到调用线程中用来处理执行结果。 -// work函数返回值为任务id。 -// 取消任务用ThreadController::getInstance()->cancle(id)函数。 -class ThreadWorker : public QObject -{ - Q_OBJECT -public: - ThreadWorker(uint64_t id, const WorkCallback &workCall, QObject *parent = nullptr) - : QObject(parent), m_id(id), m_workCall(workCall) - { - } - -signals: - void workFinished(bool, uint64_t); -public slots: - void doWork() - { - bool ret = m_workCall(); - emit workFinished(ret, m_id); - } - -private: - const uint64_t m_id; - WorkCallback m_workCall; -}; -class TAO_API ThreadController : public QObject -{ - Q_OBJECT -public: - static ThreadController *getInstance() - { - static ThreadController controller; - return &controller; - } - - ~ThreadController() - { - for (const auto &k : m_threadMap.keys()) { - if (m_threadMap.value(k)->isRunning()) { - m_threadMap.value(k)->quit(); - m_threadMap.value(k)->wait(); - } - } - qDeleteAll(m_threadMap); - m_threadMap.clear(); - m_resultCallback.clear(); - } - uint64_t work(const WorkCallback &workCall, const WorkResultCallback &resultCall) - { - QThread *thread = new QThread; - m_rollId++; - ThreadWorker *obj = new ThreadWorker(m_rollId, workCall); - m_threadMap[m_rollId] = thread; - m_resultCallback[m_rollId] = resultCall; - obj->moveToThread(thread); - - connect(thread, &QThread::finished, obj, &QObject::deleteLater); - connect(thread, &QThread::started, obj, &ThreadWorker::doWork); - connect(obj, &ThreadWorker::workFinished, this, &ThreadController::onWorkFinished, - Qt::QueuedConnection); - thread->start(); - return m_rollId; - } - void cancle(uint64_t id) - { - auto it = m_threadMap.find(id); - if (it != m_threadMap.end()) { - if ((*it)->isRunning()) { - (*it)->terminate(); - } - } - m_resultCallback.remove(id); - } - void quit(uint64_t id) - { - auto it = m_threadMap.find(id); - if (it != m_threadMap.end()) { - if ((*it)->isRunning()) { - (*it)->quit(); - (*it)->wait(); - (*it)->deleteLater(); - } - } - m_resultCallback.remove(id); - } - QList getAllWorkId() const { return m_threadMap.keys(); } -protected slots: - void onWorkFinished(bool ok, uint64_t id) - { - auto it = m_threadMap.find(id); - if (it != m_threadMap.end()) { - if ((*it)->isRunning()) { - (*it)->quit(); - (*it)->wait(); - (*it)->deleteLater(); - } - m_threadMap.remove(id); - } - auto caller = m_resultCallback.find(id); - if (caller != m_resultCallback.end()) { - (*caller)(ok); - m_resultCallback.remove(id); - } - } - -protected: - ThreadController(QObject *parent = nullptr) : QObject(parent) {} - -private: - uint64_t m_rollId = 0; - QMap m_threadMap; - QMap m_resultCallback; -}; -} // namespace LCIM diff --git a/3rdparty/TaoCommon/Trans/Trans.cpp b/3rdparty/TaoCommon/Trans/Trans.cpp deleted file mode 100644 index f031b903..00000000 --- a/3rdparty/TaoCommon/Trans/Trans.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "Trans.h" -#include "Common/FileReadWrite.h" -#include -#include -#include -#include -#include -#include -const static auto cEnglisthStr = u8"English"; -const static auto cChineseStr = u8"简体中文"; -Trans::Trans(QObject *parent) : QTranslator(parent) {} - -void Trans::beforeUiReady(QQmlContext *ctx, const QString &folder) -{ - m_ctx = ctx; - ctx->setContextProperty("trans", this); - if (folder.isEmpty()) { - loadFolder(qApp->applicationDirPath() + "/Trans"); - } else { - loadFolder(folder); - } - qApp->installTranslator(this); -} - -void Trans::afterUiReady() {} - -QString Trans::translate(const char *context, const char *sourceText, const char *disambiguation, - int n) const -{ - Q_UNUSED(context) - Q_UNUSED(disambiguation) - Q_UNUSED(n) - - return trans(sourceText); -} - -void Trans::loadFolder(const QString &folder) -{ - qWarning() << "Trans loadFolder" << folder; - QDir dir(folder); - auto infos = dir.entryInfoList({ "language_*.json" }, QDir::Files); - QString lang; - for (const auto &info : infos) { - load(lang, info.absoluteFilePath()); - } - - initEnglish(); - auto langs = m_map.keys(); - if (langs.contains(cChineseStr)) { - langs.removeAll(cChineseStr); - langs.push_front(cChineseStr); - } - setLanguages(langs); - if (m_map.contains(cChineseStr)) { - setCurrentLang(cChineseStr); - } else { - setCurrentLang(cEnglisthStr); - } - emit folderLoaded(folder); -} - -bool Trans::load(QString &lang, const QString &filePath) -{ - lang.clear(); - QJsonObject rootObj; - if (!TaoCommon::readJsonFile(filePath, rootObj)) { - return false; - } - lang = rootObj.value("lang").toString(); - const auto &trans = rootObj.value("trans").toArray(); - for (const auto &i : trans) { - auto transObj = i.toObject(); - QString key = transObj.value("key").toString(); - QString value = transObj.value("value").toString(); - m_map[lang][key] = value; - } - emit langLoaded(lang); - return true; -} - -const QString &Trans::currentLang() const -{ - return m_currentLang; -} - -const QStringList &Trans::languages() const -{ - return m_languages; -} - -const QString &Trans::transString() const -{ - return m_transString; -} - -void Trans::initEnglish() -{ - if (!m_map.contains(cEnglisthStr)) { - QHash map; - if (m_map.contains(cChineseStr)) { - map = m_map.value(cChineseStr); - } else { - map = m_map.value(m_map.keys().first()); - } - for (const auto &key : map.keys()) { - m_map[cEnglisthStr][key] = key; - } - } -} - -QString Trans::trans(const QString &source) const -{ - return m_map.value(m_currentLang).value(source, source); -} - -void Trans::setCurrentLang(const QString ¤tLang) -{ - if (m_currentLang == currentLang) - return; - - m_currentLang = currentLang; - emit currentLangChanged(m_currentLang); - -#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) - m_ctx->engine()->retranslate(); -#else - emit transStringChanged(); -#endif -} - -void Trans::setLanguages(const QStringList &languages) -{ - if (m_languages == languages) - return; - - m_languages = languages; - emit languagesChanged(m_languages); -} diff --git a/3rdparty/TaoCommon/Trans/Trans.h b/3rdparty/TaoCommon/Trans/Trans.h deleted file mode 100644 index 08647bb0..00000000 --- a/3rdparty/TaoCommon/Trans/Trans.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include "TaoCommonGlobal.h" -class QQmlContext; -class TAO_API Trans : public QTranslator -{ - Q_OBJECT - Q_PROPERTY(QString currentLang READ currentLang WRITE setCurrentLang NOTIFY currentLangChanged) - Q_PROPERTY(QStringList languages READ languages NOTIFY languagesChanged) - Q_PROPERTY(QString transString READ transString NOTIFY transStringChanged) -public: - Trans(QObject *parent = nullptr); - - Q_INVOKABLE void loadFolder(const QString &folder); - - Q_INVOKABLE bool load(QString &lang, const QString &filePath); - -public: - void beforeUiReady(QQmlContext *ctx, const QString &folder = {}); - - void afterUiReady(); - - QString translate(const char *context, const char *sourceText, - const char *disambiguation = nullptr, int n = -1) const override; - -public: - const QString ¤tLang() const; - - const QStringList &languages() const; - - const QString &transString() const; - -public slots: - QString trans(const QString &source) const; - void setCurrentLang(const QString ¤tLang); -signals: - void currentLangChanged(const QString ¤tLang); - - void languagesChanged(const QStringList &languages); - - void langLoaded(const QString &lang); - - void folderLoaded(const QString &folder); - - void transStringChanged(); - -protected: - void setLanguages(const QStringList &languages); - - void initEnglish(); - -private: - QString m_currentLang; - // <"English", <"key", "value">> - QHash> m_map; - QStringList m_languages; - QString m_transString; - QQmlContext *m_ctx = nullptr; -};