1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-17 20:12:54 +08:00

foramt all

This commit is contained in:
jared 2023-04-25 09:59:36 +08:00
parent 021f3385e1
commit 70e4213128
42 changed files with 1091 additions and 960 deletions

View File

@ -17,23 +17,31 @@ ColumnLimit: 160
TabWidth: 4
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
UseTab: Never
UseTab: Always
# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
AlignAfterOpenBracket: AlwaysBreak
#对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right
# 连续赋值时,对齐所有等号
AlignConsecutiveAssignments: true
# 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: true
# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right
# 对齐连续的宏定义
AlignConsecutiveMacros: true
# 对齐尾注释
AlignTrailingComments: true
# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义与Attach类似),
# Mozilla(除枚举、函数、记录定义与Attach类似), Stroustrup(除函数定义、catch、else与Attach类似),
# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
# 注:这里认为语句块也属于函数
BreakBeforeBraces: Custom
BreakBeforeBraces: Allman
# 大括号换行只有当BreakBeforeBraces设置为Custom时才有效
BraceWrapping:
# class定义后面
@ -61,6 +69,9 @@ BraceWrapping:
# 缩进大括号
IndentBraces: false
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
BreakBeforeBinaryOperators: None
# 继承列表的逗号前换行
BreakBeforeInheritanceComma: true
@ -77,12 +88,6 @@ BreakConstructorInitializers: BeforeComma
# 总是在template声明后换行
AlwaysBreakTemplateDeclarations: true
# false表示函数实参要么都在同一行要么都各自一行
BinPackArguments: false
# false表示所有形参要么都在同一行要么都各自一行
BinPackParameters: false
# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
CommentPragmas: '^ IWYU pragma:'
@ -95,11 +100,11 @@ AlignTrailingComments: true
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
AllowShortFunctionsOnASingleLine: Empty
# 构造函数的初始化列表要么都在同一行,要么都各自一行
ConstructorInitializerAllOnOneLineOrOnePerLine: false
# false表示函数实参要么都在同一行,要么都各自一行
BinPackArguments: false
# 指针和引用的对齐: Left, Right, Middle
PointerAlignment: Left
# false表示所有形参要么都在同一行要么都各自一行
BinPackParameters: false
# 需要被解读为foreach循环而不是函数调用的宏
ForEachMacros:
@ -107,6 +112,7 @@ ForEachMacros:
- Q_FOREACH
- BOOST_FOREACH
IndentCaseLabels: true
IncludeBlocks: Preserve
# 对#include进行排序匹配了某正则表达式的#include拥有对应的优先级匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前)
@ -120,5 +126,4 @@ IncludeCategories:
Priority: 1
- Regex: '.*'
Priority: 1
...

View File

@ -1,6 +1,6 @@
#include "Logger/Logger.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "Logger/Logger.h"
int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);

View File

@ -1,6 +1,6 @@
#include "Logger/Logger.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "Logger/Logger.h"
int main(int argc, char* argv[])
{

View File

@ -27,7 +27,8 @@ static void showSomeLogger()
// u8是c++11标准支持的字符串字面量写法可以参考https://zh.cppreference.com/w/cpp/language/string_literal
// QStringLiteral是Qt特有的宏用来在编译期生成字符串字面量
// QString::fromLocal8Bit可以在运行过程中动态处理中文字符串。
for (int i = 0; i < 1000; ++i) {
for (int i = 0; i < 1000; ++i)
{
gCount++;
int count = gCount;
LOG_DEBUG << currentThreadId() << u8"山有木兮木有枝,心悦君兮君不知。";
@ -44,12 +45,14 @@ static void logThread()
vector<std::thread> threads;
//创建N个线程
for (unsigned long long i = 0; i < N; ++i) {
for (unsigned long long i = 0; i < N; ++i)
{
threads.emplace_back(thread(showSomeLogger));
}
// join,等线程结束。
for (unsigned long long i = 0; i < N; ++i) {
for (unsigned long long i = 0; i < N; ++i)
{
threads[i].join();
}
LOG_INFO << currentThreadId() << u8"故事到这就结束了总共输出log" << gCount;

View File

@ -1,12 +1,13 @@
#pragma once
#include "Logger/Logger.h"
#include <QDebug>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include "Logger/Logger.h"
namespace TaoCommon {
namespace TaoCommon
{
static bool readFile(const QString& filePath, QByteArray& content, QString* errStr = nullptr)
{
@ -112,5 +113,4 @@ static bool writeJsonFile(const QString& filePath, const QJsonObject& jsonObj, Q
return writeJsonFile(filePath, QJsonDocument(jsonObj), errStr);
}
} // namespace TaoCommon

View File

@ -1,9 +1,9 @@
#pragma once
// json 序列化
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariant>
#include <QVariantList>
@ -12,7 +12,10 @@
///@brief 序列化. object to Json, object to Variant or VariantMap
#define JsonSerialize_Begin() \
public: \
operator QVariant() const { return QVariant::fromValue(this->operator QVariantMap()); } \
operator QVariant() const \
{ \
return QVariant::fromValue(this->operator QVariantMap()); \
} \
operator QJsonObject() const \
{ \
return QJsonObject::fromVariantMap(this->operator QVariantMap()); \
@ -37,7 +40,8 @@ public:
{ \
QVariantList lst; \
lst.reserve(m_##NAME.size()); \
for (const auto &t : m_##NAME) { \
for (const auto& t : m_##NAME) \
{ \
lst << QVariant::fromValue(t); \
} \
vmap[#NAME] = lst; \
@ -64,11 +68,13 @@ public:
}
#define JsonDeserializeContainerProperty(NAME) \
if (vmap.value(#NAME).canConvert<QVariantList>()) { \
if (vmap.value(#NAME).canConvert<QVariantList>()) \
{ \
const auto& list = vmap.value(#NAME).value<QVariantList>(); \
m_##NAME.clear(); \
m_##NAME.reserve(list.size()); \
for (const auto &v : list) { \
for (const auto& v : list) \
{ \
m_##NAME.push_back(v.value<decltype(m_##NAME)::value_type>()); \
} \
}
@ -149,8 +155,3 @@ operator QVariant()
* QVariantMap map = info;
*
**/

View File

@ -1,14 +1,15 @@
#pragma once
#include <cmath>
#include <QtGlobal>
#include <algorithm>
#include <cmath>
// inRange 检查 value 小于等于 max 大于等于min
// inRange<T>通用模版函数
template <typename T>
static bool inRange(const T& value, const T& min, const T& max)
{
if (min <= value && value <= max) {
if (min <= value && value <= max)
{
return true;
}
return false;
@ -17,7 +18,8 @@ static bool inRange(const T &value, const T &min, const T &max)
template <>
static bool inRange<double>(const double& value, const double& min, const double& max)
{
if (std::isgreaterequal(value, min) && std::islessequal(value, max)) {
if (std::isgreaterequal(value, min) && std::islessequal(value, max))
{
return true;
}
return false;
@ -26,7 +28,8 @@ static bool inRange<double>(const double &value, const double &min, const double
template <>
static bool inRange<float>(const float& value, const float& min, const float& max)
{
if (std::isgreaterequal(value, min) && std::islessequal(value, max)) {
if (std::isgreaterequal(value, min) && std::islessequal(value, max))
{
return true;
}
return false;

View File

@ -6,33 +6,50 @@
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
namespace TaoCommon {
namespace TaoCommon
{
//对象存储器
template <typename Key, typename Value>
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)); }
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()) {
if (itor == m_objMap.end())
{
return nullptr;
} else {
}
else
{
return itor->second;
}
}
template <class CallbackType>
void forEach(const CallbackType& callback) const
{
for (const auto &pair : m_objMap) {
for (const auto& pair : m_objMap)
{
callback(pair.second.get());
}
}
void clear() { m_objMap.clear(); }
void clear()
{
m_objMap.clear();
}
protected:
std::unordered_map<Key, Value> m_objMap;
@ -42,12 +59,14 @@ template<typename ObjectType>
class CObjectMap
{
public:
virtual ~CObjectMap() { clear(); }
virtual ~CObjectMap()
{
clear();
}
template <typename DeriveObjectType>
DeriveObjectType* getObject() const
{
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value,
"DeriveObjectType must be derive from ObjectType");
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value, "DeriveObjectType must be derive from ObjectType");
auto objPtr = m_objMap.getObj(std::type_index(typeid(std::shared_ptr<DeriveObjectType>)));
return std::static_pointer_cast<DeriveObjectType>(objPtr).get();
@ -55,8 +74,7 @@ public:
template <typename DeriveObjectType, typename... Args>
void createObject(Args&... args)
{
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value,
"DeriveObjectType must be derive from ObjectType");
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value, "DeriveObjectType must be derive from ObjectType");
auto obj = std::make_shared<DeriveObjectType>(args...);
m_objMap.addObj(std::type_index(typeid(obj)), std::static_pointer_cast<ObjectType>(obj));
@ -64,8 +82,7 @@ public:
template <typename DeriveObjectType>
bool destroyObject()
{
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value,
"DeriveObjectType must be derive from ObjectType");
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value, "DeriveObjectType must be derive from ObjectType");
return m_objMap.removeObj(std::type_index(typeid(std::shared_ptr<DeriveObjectType>)));
}
@ -73,7 +90,10 @@ public:
{
m_objMap.forEach(callback);
}
void clear() { m_objMap.clear(); }
void clear()
{
m_objMap.clear();
}
protected:
ObjectMap<std::type_index, std::shared_ptr<ObjectType>> m_objMap;
@ -83,21 +103,24 @@ template<typename ObjectType>
class CLevelObjectMap
{
public:
virtual ~CLevelObjectMap() { clear(); }
virtual ~CLevelObjectMap()
{
clear();
}
template <typename DeriveObjectType>
DeriveObjectType* getObject() const
{
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value,
"DeriveObjectType must be derive from ObjectType");
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value, "DeriveObjectType must be derive from ObjectType");
auto index = std::type_index(typeid(std::shared_ptr<DeriveObjectType>));
for (const auto &mainPair : m_map) {
const std::unordered_map<std::type_index, std::shared_ptr<ObjectType>> &subMap =
mainPair.second;
for (const auto& mainPair : m_map)
{
const std::unordered_map<std::type_index, std::shared_ptr<ObjectType>>& subMap = mainPair.second;
auto itor = subMap.find(index);
if (itor != subMap.end()) {
if (itor != subMap.end())
{
return std::static_pointer_cast<DeriveObjectType>(itor->second).get();
}
}
@ -106,8 +129,7 @@ public:
template <typename DeriveObjectType, typename... Args>
void createObject(uint32_t level, Args&&... args)
{
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value,
"DeriveObjectType must be derive from ObjectType");
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value, "DeriveObjectType must be derive from ObjectType");
auto obj = std::make_shared<DeriveObjectType>(args...);
m_map[level][std::type_index(typeid(obj))] = std::static_pointer_cast<ObjectType>(obj);
@ -115,16 +137,16 @@ public:
template <typename DeriveObjectType>
bool destroyObject()
{
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value,
"DeriveObjectType must be derive from ObjectType");
static_assert(std::is_base_of<ObjectType, DeriveObjectType>::value, "DeriveObjectType must be derive from ObjectType");
auto index = std::type_index(typeid(std::shared_ptr<DeriveObjectType>));
for (auto &mainPair : m_map) {
std::unordered_map<std::type_index, std::shared_ptr<ObjectType>> &subMap =
mainPair.second;
for (auto& mainPair : m_map)
{
std::unordered_map<std::type_index, std::shared_ptr<ObjectType>>& subMap = mainPair.second;
auto itor = subMap.find(index);
if (itor != subMap.end()) {
if (itor != subMap.end())
{
auto retItor = subMap.erase(itor);
return retItor != subMap.end();
}
@ -133,15 +155,19 @@ public:
}
void forEach(const std::function<void(ObjectType*)>& callback) const
{
for (const auto &mainPair : m_map) {
const std::unordered_map<std::type_index, std::shared_ptr<ObjectType>> &subMap =
mainPair.second;
for (const auto &subPair : subMap) {
for (const auto& mainPair : m_map)
{
const std::unordered_map<std::type_index, std::shared_ptr<ObjectType>>& subMap = mainPair.second;
for (const auto& subPair : subMap)
{
callback(subPair.second.get());
}
}
}
void clear() { m_map.clear(); }
void clear()
{
m_map.clear();
}
private:
std::map<uint32_t, std::unordered_map<std::type_index, std::shared_ptr<ObjectType>>> m_map;

View File

@ -25,11 +25,13 @@ static QByteArrayList unpack(const QByteArray &data)
QDataStream inStream(data);
quint32 sum = data.size();
quint32 pos = 0;
while (pos + headerLength < sum) {
while (pos + headerLength < sum)
{
quint32 packageLen = 0;
packageLen = 0;
inStream >> packageLen;
if (packageLen + headerLength > sum - pos) {
if (packageLen + headerLength > sum - pos)
{
break;
}
QByteArray subPackage = data.mid(pos + headerLength, packageLen);

View File

@ -2,19 +2,24 @@
#include <algorithm>
#include <map>
#include <vector>
namespace TaoCommon {
namespace TaoCommon
{
//观察者模式Subject-Observer。
// Subject 事件或消息的主体。模板参数为观察者类型
template <typename ObserverType>
class Subject
{
public:
virtual ~Subject() { m_obsList.clear(); }
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) {
if (m_obsList.end() == itor)
{
m_obsList.push_back(obs);
}
}
@ -27,7 +32,8 @@ public:
template <typename FuncType>
void publish(FuncType func)
{
for (auto obs : m_obsList) {
for (auto obs : m_obsList)
{
//调用回调函数将obs作为第一个参数传递
func(obs);
}
@ -36,9 +42,11 @@ public:
template <typename FuncType>
void publish(FuncType func, ObserverType* exceptObs)
{
for (auto obs : m_obsList) {
for (auto obs : m_obsList)
{
//调用回调函数将obs作为第一个参数传递
if (obs != exceptObs) {
if (obs != exceptObs)
{
func(obs);
}
}
@ -53,20 +61,25 @@ template<typename ObserverType>
class LevelSubject
{
public:
virtual ~LevelSubject() { m_obsMap.clear(); }
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) {
if (vec.end() == itor)
{
vec.push_back(obs);
}
}
//取消订阅
void unSubscibe(ObserverType* obs)
{
for (auto &obsPair : m_obsMap) {
for (auto& obsPair : m_obsMap)
{
obsPair.second.erase(std::remove(obsPair.second.begin(), obsPair.second.end(), obs));
}
}
@ -74,8 +87,10 @@ public:
template <typename FuncType>
void publish(FuncType func)
{
for (const auto &obsPair : m_obsMap) {
for (const auto &obs : obsPair.second) {
for (const auto& obsPair : m_obsMap)
{
for (const auto& obs : obsPair.second)
{
func(obs);
}
}
@ -83,9 +98,12 @@ public:
template <typename FuncType>
void publish(FuncType func, ObserverType* exceptObs)
{
for (const auto &obsPair : m_obsMap) {
for (const auto &obs : obsPair.second) {
if (obs != exceptObs) {
for (const auto& obsPair : m_obsMap)
{
for (const auto& obs : obsPair.second)
{
if (obs != exceptObs)
{
func(obs);
}
}

View File

@ -11,7 +11,9 @@ public:
bool m_isFull = false;
QQuickItem* m_titleItem = nullptr;
};
TaoFrameLessView::TaoFrameLessView(QWindow *parent) : Super(parent), d(new TaoFrameLessViewPrivate)
TaoFrameLessView::TaoFrameLessView(QWindow* parent)
: Super(parent)
, d(new TaoFrameLessViewPrivate)
{
setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
setResizeMode(SizeRootObjectToView);
@ -38,11 +40,13 @@ QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &norma
int h = normalSize.height();
int x = screenGeo.x() + (screenGeo.width() - w) / 2;
int y = screenGeo.y() + (screenGeo.height() - h) / 2;
if (screenGeo.width() < w) {
if (screenGeo.width() < w)
{
x = screenGeo.x();
w = screenGeo.width();
}
if (screenGeo.height() < h) {
if (screenGeo.height() < h)
{
y = screenGeo.y();
h = screenGeo.height();
}
@ -52,7 +56,8 @@ QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &norma
void TaoFrameLessView::moveToScreenCenter()
{
auto geo = calcCenterGeo(screen()->availableGeometry(), size());
if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) {
if (minimumWidth() > geo.width() || minimumHeight() > geo.height())
{
setMinimumSize(geo.size());
}
setGeometry(geo);

View File

@ -3,9 +3,9 @@
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QMutex>
#include <QDebug>
#include <QTextStream>
#include <string>
@ -15,36 +15,40 @@
#include <cstdio>
#endif
namespace Logger {
namespace Logger
{
static QString gLogDir;
static int gLogMaxCount;
static void outputMessage(QtMsgType type, const QMessageLogContext& context, const QString& msg);
static void outputMessageAsync(QtMsgType type, const QMessageLogContext &context,
const QString &msg);
static void outputMessageAsync(QtMsgType type, const QMessageLogContext& context, const QString& msg);
void initLog(const QString& logPath, int logMaxCount, bool async)
{
if (async) {
if (async)
{
qInstallMessageHandler(outputMessageAsync);
} else {
}
else
{
qInstallMessageHandler(outputMessage);
}
gLogDir = QCoreApplication::applicationDirPath() + QStringLiteral("/") + logPath;
gLogMaxCount = logMaxCount;
QDir dir(gLogDir);
if (!dir.exists()) {
if (!dir.exists())
{
dir.mkpath(dir.absolutePath());
}
QStringList infoList = dir.entryList(QDir::Files, QDir::Name);
while (infoList.size() > gLogMaxCount) {
while (infoList.size() > gLogMaxCount)
{
dir.remove(infoList.first());
infoList.removeFirst();
}
}
static void outputMessageAsync(QtMsgType type, const QMessageLogContext &context,
const QString &msg)
static void outputMessageAsync(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
static const QString messageTemp = QStringLiteral("<div class=\"%1\">%2</div>\r\n");
static const char typeList[] = { 'd', 'w', 'c', 'f', 'i' };
@ -67,8 +71,10 @@ static void outputMessageAsync(QtMsgType type, const QMessageLogContext &context
QString htmlMessage = messageTemp.arg(typeList[static_cast<int>(type)]).arg(message);
QString newfileName = QStringLiteral("%1/%2_log.html").arg(gLogDir).arg(fileNameDt);
mutex.lock();
if (file.fileName() != newfileName) {
if (file.isOpen()) {
if (file.fileName() != newfileName)
{
if (file.isOpen())
{
file.close();
}
file.setFileName(newfileName);
@ -80,14 +86,16 @@ static void outputMessageAsync(QtMsgType type, const QMessageLogContext &context
#else
textStream.setCodec("UTF-8");
#endif
if (!exist) {
if (!exist)
{
textStream << logTemplate << "\r\n";
}
}
textStream << htmlMessage;
textStream.flush();
count += htmlMessage.length();
if (count >= maxCount) {
if (count >= maxCount)
{
file.close();
file.open(QIODevice::WriteOnly | QIODevice::Append);
}
@ -128,7 +136,8 @@ static void outputMessage(QtMsgType type, const QMessageLogContext &context, con
#else
textStream.setCodec("UTF-8");
#endif
if (!exist) {
if (!exist)
{
textStream << logTemplate << "\r\n";
}
textStream << htmlMessage;

View File

@ -1,8 +1,9 @@
#pragma once
#include "TaoCommonGlobal.h"
#include <QString>
#include <QDebug>
namespace Logger {
#include <QString>
namespace Logger
{
#ifdef _DEBUG
#define LOG_DEBUG qDebug() << __FILE__ << __LINE__
#define LOG_INFO qInfo() << __FILE__ << __LINE__
@ -18,6 +19,5 @@ namespace Logger {
// logPath 存储路径
// logMaxCount 最大数
// async 是否异步存储 默认异步存储。异步存储会缓存log达到一定数量、或者软件退出时才写入文件。
void TAO_API initLog(const QString &logPath = QStringLiteral("Log"), int logMaxCount = 1024,
bool async = true);
void TAO_API initLog(const QString& logPath = QStringLiteral("Log"), int logMaxCount = 1024, bool async = true);
} // namespace Logger

View File

@ -1,7 +1,8 @@
#pragma once
#include <QString>
#include <string>
namespace Logger {
namespace Logger
{
const static auto logTemplate = QString::fromUtf8(u8R"logTemplate(
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

View File

@ -5,6 +5,4 @@ QuickListItemBase::QuickListItemBase(QObject *parent)
{
}
QuickListItemBase::~QuickListItemBase()
{
}
QuickListItemBase::~QuickListItemBase() { }

View File

@ -1,7 +1,7 @@
#pragma once
#include <QObject>
#include "TaoCommonGlobal.h"
#include <QObject>
class TAO_API QuickListItemBase : public QObject
{
Q_OBJECT

View File

@ -10,9 +10,7 @@ QuickListModel::QuickListModel(QObject *parent)
mSearchTimer.setSingleShot(true);
}
QuickListModel::~QuickListModel()
{
}
QuickListModel::~QuickListModel() { }
void QuickListModel::check(int row, bool checked)
{

View File

@ -1,8 +1,8 @@
#pragma once
#include "TaoCommonGlobal.h"
#include <QAbstractListModel>
#include <QList>
#include <QSet>
#include "TaoCommonGlobal.h"
template <class T>
class QuickModelBase : public QAbstractListModel
{
@ -48,15 +48,14 @@ public:
//[end] update data
public:
virtual void updateCalcInfo()
{
}
virtual void updateCalcInfo() { }
bool compareDataChanged(const QList<T>& data1, const QList<T>& data2)
{
bool changed = false;
QSet<T> set1;
for (auto it = data1.begin(); it != data1.end(); it++) set1.insert(*it);
for (auto it = data1.begin(); it != data1.end(); it++)
set1.insert(*it);
QSet<T> set2;
for (auto it = data2.begin(); it != data2.end() && !changed; it++)
@ -80,12 +79,12 @@ public:
return changed;
}
protected:
QList<T> mDatas;
QSet<T> mAllDatas;
};
template <class T>
QuickModelBase<T>::QuickModelBase(QObject* parent)
: Super(parent)
@ -96,7 +95,8 @@ QuickModelBase<T>::QuickModelBase(const QList<T> &datas, QObject *parent)
: Super(parent)
, mDatas(datas)
{
for (auto it = datas.begin(); it != datas.end(); it++) mAllDatas.insert(*it);
for (auto it = datas.begin(); it != datas.end(); it++)
mAllDatas.insert(*it);
}
template <class T>
QuickModelBase<T>::~QuickModelBase()
@ -139,7 +139,8 @@ void QuickModelBase<T>::resetData(const QList<T> &datas)
mAllDatas.clear();
beginResetModel();
mDatas = datas;
for (auto it = datas.begin(); it != datas.end(); it++) mAllDatas.insert(*it);
for (auto it = datas.begin(); it != datas.end(); it++)
mAllDatas.insert(*it);
endResetModel();
qDeleteAll(oldObjs);
updateCalcInfo();
@ -154,7 +155,8 @@ void QuickModelBase<T>::append(const QList<T> &datas)
}
beginInsertRows({}, mDatas.count(), mDatas.count() + datas.count() - 1);
mDatas.append(datas);
for (auto it = datas.begin(); it != datas.end(); it++) mAllDatas.insert(*it);
for (auto it = datas.begin(); it != datas.end(); it++)
mAllDatas.insert(*it);
endInsertRows();
updateCalcInfo();
}

View File

@ -1,9 +1,9 @@
#pragma once
#include "TaoCommonGlobal.h"
#include <QObject>
#include <QVariant>
#include <QVector>
#include "TaoCommonGlobal.h"
class TAO_API QuickTreeItem : public QObject
{
Q_OBJECT

View File

@ -1,5 +1,6 @@
#include "QuickTreeModel.h"
QuickTreeModel::QuickTreeModel(QObject *parent) :QAbstractItemModel(parent)
QuickTreeModel::QuickTreeModel(QObject* parent)
: QAbstractItemModel(parent)
{
m_rootItem = new QuickTreeItem(nullptr);
QVector<QVariant> datas;

View File

@ -1,9 +1,9 @@
#pragma once
#include "QuickTreeItem.h"
#include "TaoCommonGlobal.h"
#include <QAbstractItemModel>
#include <QSet>
#include <QVector>
#include "TaoCommonGlobal.h"
#include "QuickTreeItem.h"
class TAO_API QuickTreeModel : public QAbstractItemModel
{
Q_OBJECT

View File

@ -1,9 +1,10 @@
#pragma once
#include <QMetaType>
#include <functional>
namespace TaoCommon {
namespace TaoCommon
{
using WorkCallback = std::function<bool()>;
using WorkResultCallback = std::function<void(bool)>;
}
} // namespace TaoCommon
Q_DECLARE_METATYPE(TaoCommon::WorkCallback);
Q_DECLARE_METATYPE(TaoCommon::WorkResultCallback);

View File

@ -1,8 +1,12 @@
#include "ThreadPool.h"
#include <QThreadPool>
namespace TaoCommon {
ThreadObject::ThreadObject(const WorkCallback &work) : m_workCall(work) {}
namespace TaoCommon
{
ThreadObject::ThreadObject(const WorkCallback& work)
: m_workCall(work)
{
}
void ThreadObject::run()
{
bool ok = m_workCall();
@ -16,4 +20,4 @@ void ThreadPool::work(const WorkCallback &workCall, const WorkResultCallback &re
connect(obj, &ThreadObject::readyResult, this, resultCall);
QThreadPool::globalInstance()->start(obj);
}
}
} // namespace TaoCommon

View File

@ -3,13 +3,16 @@
#include "ThreadCommon.h"
#include <QObject>
#include <QRunnable>
namespace TaoCommon {
namespace TaoCommon
{
// 对Qt线程池的简单封装适合一次性执行的任务。
// 用法: ThreadPool::getInstance()->work(workCall, resultCall)
// workCall是在新线程中执行的任务resultCall是任务执行完成后回到调用线程中用来处理执行结果。
// 不支持任务取消、暂停。
class ThreadObject : public QObject, public QRunnable
class ThreadObject
: public QObject
, public QRunnable
{
Q_OBJECT
public:

View File

@ -3,7 +3,8 @@
#include "ThreadCommon.h"
#include <QMap>
#include <QThread>
namespace TaoCommon {
namespace TaoCommon
{
// 对Qt Worker-Controller 线程模型的简单封装,适合精确控制的任务。
// 用法: ThreadController::getInstance()->work(workCall, resultCall)
// workCall是在新线程中执行的任务resultCall是任务执行完成后回到调用线程中用来处理执行结果。
@ -14,7 +15,9 @@ 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)
: QObject(parent)
, m_id(id)
, m_workCall(workCall)
{
}
@ -43,8 +46,10 @@ public:
~ThreadController()
{
for (const auto &k : m_threadMap.keys()) {
if (m_threadMap.value(k)->isRunning()) {
for (const auto& k : m_threadMap.keys())
{
if (m_threadMap.value(k)->isRunning())
{
m_threadMap.value(k)->quit();
m_threadMap.value(k)->wait();
}
@ -64,16 +69,17 @@ public:
connect(thread, &QThread::finished, obj, &QObject::deleteLater);
connect(thread, &QThread::started, obj, &ThreadWorker::doWork);
connect(obj, &ThreadWorker::workFinished, this, &ThreadController::onWorkFinished,
Qt::QueuedConnection);
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()) {
if (it != m_threadMap.end())
{
if ((*it)->isRunning())
{
(*it)->terminate();
}
}
@ -82,8 +88,10 @@ public:
void quit(uint64_t id)
{
auto it = m_threadMap.find(id);
if (it != m_threadMap.end()) {
if ((*it)->isRunning()) {
if (it != m_threadMap.end())
{
if ((*it)->isRunning())
{
(*it)->quit();
(*it)->wait();
(*it)->deleteLater();
@ -91,13 +99,18 @@ public:
}
m_resultCallback.remove(id);
}
QList<uint64_t> getAllWorkId() const { return m_threadMap.keys(); }
QList<uint64_t> 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()) {
if (it != m_threadMap.end())
{
if ((*it)->isRunning())
{
(*it)->quit();
(*it)->wait();
(*it)->deleteLater();
@ -105,18 +118,22 @@ protected slots:
m_threadMap.remove(id);
}
auto caller = m_resultCallback.find(id);
if (caller != m_resultCallback.end()) {
if (caller != m_resultCallback.end())
{
(*caller)(ok);
m_resultCallback.remove(id);
}
}
protected:
ThreadController(QObject *parent = nullptr) : QObject(parent) {}
ThreadController(QObject* parent = nullptr)
: QObject(parent)
{
}
private:
uint64_t m_rollId = 0;
QMap<uint64_t, QThread*> m_threadMap;
QMap<uint64_t, WorkResultCallback> m_resultCallback;
};
} // namespace LCIM
} // namespace TaoCommon

View File

@ -1,22 +1,28 @@
#include "Trans.h"
#include "Common/FileReadWrite.h"
#include <QDir>
#include <QQmlContext>
#include <QCoreApplication>
#include <QDir>
#include <QLocale>
#include <QQuickView>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickView>
const static auto cEnglisthStr = u8"English";
const static auto cChineseStr = u8"简体中文";
Trans::Trans(QObject *parent) : QTranslator(parent) {}
Trans::Trans(QObject* parent)
: QTranslator(parent)
{
}
void Trans::beforeUiReady(QQmlContext* ctx, const QString& folder)
{
m_ctx = ctx;
ctx->setContextProperty("trans", this);
if (folder.isEmpty()) {
if (folder.isEmpty())
{
loadFolder(qApp->applicationDirPath() + "/Trans");
} else {
}
else
{
loadFolder(folder);
}
qApp->installTranslator(this);
@ -24,8 +30,7 @@ void Trans::beforeUiReady(QQmlContext *ctx, const QString &folder)
void Trans::afterUiReady() { }
QString Trans::translate(const char *context, const char *sourceText, const char *disambiguation,
int n) const
QString Trans::translate(const char* context, const char* sourceText, const char* disambiguation, int n) const
{
Q_UNUSED(context)
Q_UNUSED(disambiguation)
@ -40,20 +45,25 @@ void Trans::loadFolder(const QString &folder)
QDir dir(folder);
auto infos = dir.entryInfoList({ "language_*.json" }, QDir::Files);
QString lang;
for (const auto &info : infos) {
for (const auto& info : infos)
{
load(lang, info.absoluteFilePath());
}
initEnglish();
auto langs = m_map.keys();
if (langs.contains(cChineseStr)) {
if (langs.contains(cChineseStr))
{
langs.removeAll(cChineseStr);
langs.push_front(cChineseStr);
}
setLanguages(langs);
if (m_map.contains(cChineseStr)) {
if (m_map.contains(cChineseStr))
{
setCurrentLang(cChineseStr);
} else {
}
else
{
setCurrentLang(cEnglisthStr);
}
emit folderLoaded(folder);
@ -63,12 +73,14 @@ bool Trans::load(QString &lang, const QString &filePath)
{
lang.clear();
QJsonObject rootObj;
if (!TaoCommon::readJsonFile(filePath, 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) {
for (const auto& i : trans)
{
auto transObj = i.toObject();
QString key = transObj.value("key").toString();
QString value = transObj.value("value").toString();
@ -95,14 +107,19 @@ const QString &Trans::transString() const
void Trans::initEnglish()
{
if (!m_map.contains(cEnglisthStr)) {
if (!m_map.contains(cEnglisthStr))
{
QHash<QString, QString> map;
if (m_map.contains(cChineseStr)) {
if (m_map.contains(cChineseStr))
{
map = m_map.value(cChineseStr);
} else {
}
else
{
map = m_map.value(m_map.keys().first());
}
for (const auto &key : map.keys()) {
for (const auto& key : map.keys())
{
m_map[cEnglisthStr][key] = key;
}
}

View File

@ -1,11 +1,11 @@
#pragma once
#include <QObject>
#include "TaoCommonGlobal.h"
#include <QHash>
#include <QList>
#include <QObject>
#include <QString>
#include <QTranslator>
#include "TaoCommonGlobal.h"
class QQmlContext;
class TAO_API Trans : public QTranslator
{
@ -25,8 +25,7 @@ public:
void afterUiReady();
QString translate(const char *context, const char *sourceText,
const char *disambiguation = nullptr, int n = -1) const override;
QString translate(const char* context, const char* sourceText, const char* disambiguation = nullptr, int n = -1) const override;
public:
const QString& currentLang() const;

8
clang-foramt-All.ps1 Normal file
View File

@ -0,0 +1,8 @@
$scriptDir=$PSScriptRoot
$currentDir=Get-Location
Write-Host "currentDir" $currentDir
Write-Host "scriptDir" $scriptDir
$names="*.h","*.cpp","*.c","*.hpp"
Get-ChildItem -Include $names -Recurse $currentDir | ForEach-Object {
clang-format -i $_.FullName
}

View File

@ -1,7 +1,7 @@
#include <QQuickView>
#include <QQmlEngine>
#include <QQmlContext>
#include <QGuiApplication>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickView>
int main(int argc, char** argv)
{
QGuiApplication app(argc, argv);

View File

@ -11,11 +11,15 @@ int main(int argc, char *argv[])
engine.addImportPath(TaoQuickImportPath);
engine.rootContext()->setContextProperty("taoQuickImagePath", TaoQuickImagePath);
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
},
Qt::QueuedConnection);
engine.load(url);
return app.exec();

View File

@ -1,8 +1,9 @@
#include "AppInfo.h"
#include "Ver-u8.h"
#include <QQmlContext>
#include <QSysInfo>
#include "Ver-u8.h"
AppInfo::AppInfo(QObject *parent) : QObject(parent)
AppInfo::AppInfo(QObject* parent)
: QObject(parent)
{
m_appName = VER_PRODUCTNAME_STR;
m_appVersion = TaoVer;
@ -25,11 +26,6 @@ void AppInfo::afterUiReady()
// auto json = QJsonDocument(*this).toJson(QJsonDocument::Indented);
// json.replace("\\n\\r","\\\n");
// qWarning() << json;
}
AppInfo::~AppInfo()
{
}
AppInfo::~AppInfo() { }

View File

@ -1,10 +1,10 @@
#pragma once
#include <QObject>
#include <QString>
#include <QQmlContext>
#include "Common/PropertyHelper.h"
#include "Common/JsonSerialize.h"
#include "Common/PropertyHelper.h"
#include <QObject>
#include <QQmlContext>
#include <QString>
class AppInfo : public QObject
{
Q_OBJECT
@ -22,55 +22,24 @@ class AppInfo : public QObject
AUTO_PROPERTY(double, ratio, 14.0 / 9.0)
AUTO_PROPERTY(QStringList, customs, {})
JsonSerialize_Begin()
JsonProperty(appName)
JsonProperty(appVersion)
JsonProperty(latestVersion)
JsonProperty(buildDateTime)
JsonProperty(buildRevision)
JsonProperty(copyRight)
JsonProperty(descript)
JsonProperty(compilerVendor)
JsonProperty(splashShow)
JsonProperty(scale)
JsonProperty(ratio)
JsonContainerProperty(customs)
JsonSerialize_End()
JsonSerialize_Begin() JsonProperty(appName) JsonProperty(appVersion) JsonProperty(latestVersion) JsonProperty(buildDateTime) JsonProperty(buildRevision)
JsonProperty(copyRight) JsonProperty(descript) JsonProperty(compilerVendor) JsonProperty(splashShow) JsonProperty(scale) JsonProperty(ratio)
JsonContainerProperty(customs) JsonSerialize_End()
JsonDeserialize_Begin(AppInfo)
JsonDeserializeProperty(appName)
JsonDeserializeProperty(appVersion)
JsonDeserializeProperty(latestVersion)
JsonDeserializeProperty(buildDateTime)
JsonDeserializeProperty(buildRevision)
JsonDeserializeProperty(copyRight)
JsonDeserializeProperty(descript)
JsonDeserializeProperty(compilerVendor)
JsonDeserializeProperty(splashShow)
JsonDeserializeProperty(scale)
JsonDeserializeProperty(ratio)
JsonDeserializeContainerProperty(customs)
JsonDeserialize_End()
JsonDeserialize_Begin(AppInfo) JsonDeserializeProperty(appName) JsonDeserializeProperty(appVersion) JsonDeserializeProperty(latestVersion)
JsonDeserializeProperty(buildDateTime) JsonDeserializeProperty(buildRevision) JsonDeserializeProperty(copyRight)
JsonDeserializeProperty(descript) JsonDeserializeProperty(compilerVendor) JsonDeserializeProperty(splashShow)
JsonDeserializeProperty(scale) JsonDeserializeProperty(ratio) JsonDeserializeContainerProperty(customs) JsonDeserialize_End()
JsonPartialDeserialize_Begin(AppInfo) JsonDeserializeProperty(appName) JsonDeserializeProperty(appVersion)
JsonDeserializeProperty(latestVersion) JsonDeserializeProperty(buildDateTime) JsonDeserializeProperty(buildRevision)
JsonDeserializeProperty(copyRight) JsonDeserializeProperty(descript) JsonDeserializeProperty(compilerVendor)
JsonDeserializeProperty(splashShow) JsonDeserializeProperty(scale) JsonDeserializeProperty(ratio)
JsonDeserializeContainerProperty(customs) JsonPartialDeserialize_End()
JsonPartialDeserialize_Begin(AppInfo)
JsonDeserializeProperty(appName)
JsonDeserializeProperty(appVersion)
JsonDeserializeProperty(latestVersion)
JsonDeserializeProperty(buildDateTime)
JsonDeserializeProperty(buildRevision)
JsonDeserializeProperty(copyRight)
JsonDeserializeProperty(descript)
JsonDeserializeProperty(compilerVendor)
JsonDeserializeProperty(splashShow)
JsonDeserializeProperty(scale)
JsonDeserializeProperty(ratio)
JsonDeserializeContainerProperty(customs)
JsonPartialDeserialize_End()
public:
explicit AppInfo(QObject *parent = nullptr);
public : explicit AppInfo(QObject* parent = nullptr);
virtual ~AppInfo() override;
public:
void beforeUiReady(QQmlContext* ctx);

View File

@ -1,6 +1,7 @@
#include "DeviceAddItem.h"
#include <QHostAddress>
DeviceAddItem::DeviceAddItem(QObject *parent) : QuickListItemBase(parent)
DeviceAddItem::DeviceAddItem(QObject* parent)
: QuickListItemBase(parent)
{
connect(this, &DeviceAddItem::addressChanged, this, [this]() { m_ipv4Address = QHostAddress(address()).toIPv4Address(); });
}
@ -8,16 +9,20 @@ DeviceAddItem::DeviceAddItem(QObject *parent) : QuickListItemBase(parent)
DeviceAddItem::~DeviceAddItem() { }
bool DeviceAddItem::match(const QString& key)
{
if (key.isEmpty()) {
if (key.isEmpty())
{
return true;
}
if (m_name.contains(key, Qt::CaseInsensitive)) {
if (m_name.contains(key, Qt::CaseInsensitive))
{
return true;
}
if (m_address.contains(key, Qt::CaseInsensitive)) {
if (m_address.contains(key, Qt::CaseInsensitive))
{
return true;
}
if (m_modelString.contains(key, Qt::CaseInsensitive)) {
if (m_modelString.contains(key, Qt::CaseInsensitive))
{
return true;
}
return false;

View File

@ -17,7 +17,10 @@ public:
virtual ~DeviceAddItem() override;
bool match(const QString& key) override;
quint32 toIPv4Address() const { return m_ipv4Address; }
quint32 toIPv4Address() const
{
return m_ipv4Address;
}
private:
quint32 m_ipv4Address = 0;

View File

@ -2,8 +2,8 @@
#include "DeviceAddItem.h"
#include <QCoreApplication>
#include <QEventLoop>
#include <QHostAddress>
#include <QFile>
#include <QHostAddress>
#include <QString>
#include <chrono>
#include <random>
@ -17,7 +17,9 @@ public:
std::default_random_engine randomEngine;
std::uniform_int_distribution<uint32_t> u65535 { 0, 0xffffffff };
};
DeviceAddModel::DeviceAddModel(QObject *parent) : QuickListModel(parent), d(new DeviceAddModelPrivate)
DeviceAddModel::DeviceAddModel(QObject* parent)
: QuickListModel(parent)
, d(new DeviceAddModelPrivate)
{
setHeaderRoles(sHeaderRoles);
}
@ -29,20 +31,25 @@ DeviceAddModel::~DeviceAddModel()
void DeviceAddModel::sortByRole()
{
if (mDatas.count() <= 1) {
if (mDatas.count() <= 1)
{
return;
}
int index = sHeaderRoles.indexOf(mSortRole);
switch (index) {
case 0: {
switch (index)
{
case 0:
{
sortByName(mSortOrder);
break;
}
case 1: {
case 1:
{
sortByAddress(mSortOrder);
break;
}
case 2: {
case 2:
{
sortByModel(mSortOrder);
break;
}
@ -59,7 +66,8 @@ void DeviceAddModel::initData()
objs.reserve(N);
auto c1 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < N; ++i) {
for (int i = 0; i < N; ++i)
{
auto item = genOne(i);
objs.append(item);
// if (i % 5 == 0)
@ -85,7 +93,8 @@ void DeviceAddModel::addMulti(int count)
QList<QuickListItemBase*> objs;
objs.reserve(count);
for (int i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i)
{
auto item = genOne(d->u65535(d->randomEngine));
objs.push_back(item);
// if (i % 5 == 0)
@ -98,19 +107,25 @@ void DeviceAddModel::addMulti(int count)
void DeviceAddModel::insertBeforeSelected()
{
if (mDatas.count() <= 0) {
if (mDatas.count() <= 0)
{
auto item = genOne(d->u65535(d->randomEngine));
insert(0, { item });
} else {
}
else
{
int pos = -1;
for (int i = 0; i < mDatas.count(); ++i) {
for (int i = 0; i < mDatas.count(); ++i)
{
const auto& obj = mDatas.at(i);
if (obj->isVisible() && obj->isSelected()) {
if (obj->isVisible() && obj->isSelected())
{
pos = i;
break;
}
}
if (pos >= 0) {
if (pos >= 0)
{
auto item = genOne(d->u65535(d->randomEngine));
insert(pos, { item });
}
@ -130,11 +145,15 @@ void DeviceAddModel::clearAll()
void DeviceAddModel::removeSelected()
{
for (int i = 0; i < mDatas.count();) {
for (int i = 0; i < mDatas.count();)
{
const auto& obj = mDatas.at(i);
if (obj->isVisible() && obj->isSelected()) {
if (obj->isVisible() && obj->isSelected())
{
removeAt(i);
} else {
}
else
{
++i;
}
}
@ -142,11 +161,15 @@ void DeviceAddModel::removeSelected()
void DeviceAddModel::removeChecked()
{
for (int i = 0; i < mDatas.count();) {
for (int i = 0; i < mDatas.count();)
{
const auto& obj = mDatas.at(i);
if (obj->isVisible() && obj->isChecked()) {
if (obj->isVisible() && obj->isChecked())
{
removeAt(i);
} else {
}
else
{
++i;
}
}
@ -160,11 +183,14 @@ void DeviceAddModel::removeRow(int row)
void DeviceAddModel::sortByName(Qt::SortOrder order)
{
QList<QuickListItemBase*> copyObjs = mDatas;
if (order == Qt::SortOrder::AscendingOrder) {
if (order == Qt::SortOrder::AscendingOrder)
{
std::sort(copyObjs.begin(), copyObjs.end(), [](QuickListItemBase* obj1, QuickListItemBase* obj2) -> bool {
return (static_cast<DeviceAddItem*>(obj1))->name() < (static_cast<DeviceAddItem*>(obj2))->name();
});
} else {
}
else
{
std::sort(copyObjs.begin(), copyObjs.end(), [](QuickListItemBase* obj1, QuickListItemBase* obj2) -> bool {
return (static_cast<DeviceAddItem*>(obj1))->name() > (static_cast<DeviceAddItem*>(obj2))->name();
});
@ -176,11 +202,14 @@ void DeviceAddModel::sortByName(Qt::SortOrder order)
void DeviceAddModel::sortByAddress(Qt::SortOrder order)
{
QList<QuickListItemBase*> copyObjs = mDatas;
if (order == Qt::SortOrder::AscendingOrder) {
if (order == Qt::SortOrder::AscendingOrder)
{
std::sort(copyObjs.begin(), copyObjs.end(), [=](QuickListItemBase* obj1, QuickListItemBase* obj2) -> bool {
return static_cast<DeviceAddItem*>(obj1)->toIPv4Address() < static_cast<DeviceAddItem*>(obj2)->toIPv4Address();
});
} else {
}
else
{
std::sort(copyObjs.begin(), copyObjs.end(), [=](QuickListItemBase* obj1, QuickListItemBase* obj2) -> bool {
return static_cast<DeviceAddItem*>(obj1)->toIPv4Address() > static_cast<DeviceAddItem*>(obj2)->toIPv4Address();
});
@ -192,11 +221,14 @@ void DeviceAddModel::sortByAddress(Qt::SortOrder order)
void DeviceAddModel::sortByModel(Qt::SortOrder order)
{
QList<QuickListItemBase*> copyObjs = mDatas;
if (order == Qt::SortOrder::AscendingOrder) {
if (order == Qt::SortOrder::AscendingOrder)
{
std::sort(copyObjs.begin(), copyObjs.end(), [](QuickListItemBase* obj1, QuickListItemBase* obj2) -> bool {
return (static_cast<DeviceAddItem*>(obj1))->modelString().toULongLong() < (static_cast<DeviceAddItem*>(obj2))->modelString().toULongLong();
});
} else {
}
else
{
std::sort(copyObjs.begin(), copyObjs.end(), [](QuickListItemBase* obj1, QuickListItemBase* obj2) -> bool {
return (static_cast<DeviceAddItem*>(obj1))->modelString().toULongLong() > (static_cast<DeviceAddItem*>(obj2))->modelString().toULongLong();
});
@ -221,14 +253,14 @@ DeviceAddItem *DeviceAddModel::genOne(uint32_t value)
}
void DeviceAddModel::doUpdateName(int row, const QString& name)
{
if (row < 0 || row >= rowCount({})) {
if (row < 0 || row >= rowCount({}))
{
return;
}
const auto& n = name.simplified();
if (n.isEmpty()) {
if (n.isEmpty())
{
return;
}
static_cast<DeviceAddItem*>(mDatas.at(row))->set_name(name);
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <QObject>
#include "QuickModel/QuickListModel.h"
#include <QObject>
class DeviceAddModelPrivate;
class DeviceAddItem;
class DeviceAddModel : public QuickListModel
@ -27,12 +27,14 @@ public slots:
void removeSelected();
void removeChecked();
void removeRow(int row);
private:
void sortByName(Qt::SortOrder order);
void sortByAddress(Qt::SortOrder order);
void sortByModel(Qt::SortOrder order);
DeviceAddItem* genOne(uint32_t value);
private:
DeviceAddModelPrivate* d;
};

View File

@ -68,7 +68,6 @@ int main(int argc, char **argv)
view.rootContext()->setContextProperty("isDebug", QVariant(false));
#endif
#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
view.rootContext()->setContextProperty("hasShape", true);
#else
@ -87,7 +86,8 @@ int main(int argc, char **argv)
view.rootContext()->setContextProperty("deviceAddModel", &model);
const QUrl url(qmlPath + QStringLiteral("main.qml"));
QObject::connect(&view, &QQuickView::statusChanged, &view, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) {
if (status == QQuickView::Status::Ready)
{
trans.afterUiReady();
appInfo.afterUiReady();
quickTool.setRootObjet(view.rootObject());

View File

@ -3,28 +3,28 @@
/* Add C++ includes here */
#if defined __cplusplus
# include <QtGui>
# include <QtCore>
# include <QString>
# include <QObject>
#include <QBuffer>
#include <QByteArray>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QHash>
#include <QMap>
# include <QFile>
# include <QDir>
# include <QBuffer>
#include <QMutex>
#include <QObject>
#include <QString>
#include <QTextStream>
#include <QThread>
#include <QTime>
#include <QTimer>
# include <QMutex>
# include <QByteArray>
# include <QThread>
# include <QDateTime>
# include <QTextStream>
# include <QDebug>
#include <QtCore>
#include <QtGui>
# include <QtMath>
# include <QPixmap>
#include <QImage>
#include <QPainter>
#include <QPixmap>
#include <QSettings>
#include <QtMath>
#endif

View File

@ -25,4 +25,3 @@
#define TOSTRING(arg) TOSTRING2(arg)
#define RELEASE_VER_STR TOSTRING(RELEASE_VER_MAIN) "." TOSTRING(RELEASE_VER_MAIN2) "." TOSTRING(RELEASE_VER_SUB)