1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-19 20:22:56 +08:00

update PropertyHeader

This commit is contained in:
jared 2020-11-13 13:35:42 +08:00
parent bb09cc2a37
commit 09c784532a
10 changed files with 177 additions and 316 deletions

View File

@ -1,4 +1,4 @@
set(TaoCommonPath ${CMAKE_CURRENT_SOURCE_DIR}/TaoCommon PARENT_SCOPE)
set(TaoCommonPath ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
file(GLOB_RECURSE files *.h *.hpp *.cpp *.c)
set(TaoCommonFiles ${files} PARENT_SCOPE)
message("TaoCommonFiles ${TaoCommonFiles}")

View File

@ -0,0 +1,78 @@
#pragma once
#include "CIMCommDef.h"
//json <20><><EFBFBD>л<EFBFBD>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QVariant>
#include <QVariantList>
#include <QVariantMap>
///@brief <20><><EFBFBD>л<EFBFBD>
#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 <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
#define JsonDeserialize_Begin(class_name) \
public:\
class_name(const QJsonObject& other)\
{\
QVariantMap vmap = other.toVariantMap();
#define JsonDeserialize_End() \
}
///@brief <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>л<EFBFBD>
#define JsonPartialDeserialize_Begin(class_name)\
public:\
class_name& operator=(const QJsonObject& other)\
{\
QVariantMap vmap = other.toVariantMap();
#define JsonPartialDeserialize_End()\
return *this;\
}\
///@brief <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>
#define JsonPureProperty(val) \
vmap.unite((QVariantMap)val);
#define JsonProperty(name, val, atom_type) \
vmap[name] = QVariant::fromValue<atom_type>(val);\
if(vmap[name].isNull()) vmap.remove(name);
#define JsonContainerProperty(name, val, atom_type)\
{\
QVariantList lst;\
for(atom_type t : val)\
{\
lst << QVariant::fromValue<atom_type>(t);\
}\
vmap[name] = lst;\
}\
#define JsonDeserializeContainerProperty(name, val, atom_type)\
if(vmap[name].canConvert<QVariantList>())\
{\
QSequentialIterable iterable = vmap[name].value<QSequentialIterable>();\
Q_FOREACH(const QVariant &v, iterable) \
{\
val.push_back(v.value<atom_type>());\
}\
}
#define JsonDeserializeProperty(name, val, type)\
val = vmap[name].value<type>();

View File

@ -1,47 +1,68 @@
#pragma once
#include <QObject>
#include <QtGlobal>
#define READ_PROPERTY(TYPE, NAME) \
private: \
Q_PROPERTY(TYPE NAME READ NAME NOTIFY NAME##Changed) \
public: \
const TYPE &NAME() const \
{ \
return m_##NAME; \
} \
Q_SIGNAL void NAME##Changed(const TYPE &value); \
\
private: \
TYPE m_##NAME;
#define READONLY_PROPERTY(TYPE, NAME) \
private: \
Q_PROPERTY(TYPE NAME READ NAME CONSTANT) \
public: \
const TYPE &NAME() const \
{ \
return m_##NAME; \
} \
\
private: \
TYPE m_##NAME;
template <typename T>
struct Compare;
#define AUTO_PROPERTY(TYPE, NAME) \
private: \
Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME##Changed) \
public: \
const TYPE &NAME() const \
{ \
return m_##NAME; \
} \
void NAME(const TYPE &value) \
{ \
if (m_##NAME == value) \
return; \
m_##NAME = value; \
emit NAME##Changed(value); \
} \
Q_SIGNAL void NAME##Changed(const TYPE &value); \
\
private: \
TYPE m_##NAME;
template <typename T>
struct Compare
{
static bool isEqual(const T &t1, const T &t2)
{
return t1 == t2;
}
};
template<>
struct Compare<float>
{
static bool isEqual(float f1, float f2)
{
return qFuzzyCompare(f1, f2);
}
};
template<>
struct Compare<double>
{
static bool isEqual(double d1, double d2)
{
return qFuzzyCompare(d1, d2);
}
};
#define READ_PROPERTY(T, NAME, InitValue) \
private: \
Q_PROPERTY(T NAME READ NAME NOTIFY NAME##Changed) \
public: \
const T &NAME() const { return m_##NAME; } \
Q_SIGNAL void NAME##Changed(const T &value); \
\
private: \
T m_##NAME = InitValue;
#define READONLY_PROPERTY(T, NAME, InitValue) \
private: \
Q_PROPERTY(T NAME READ NAME CONSTANT) \
public: \
const T &NAME() const { return m_##NAME; } \
\
private: \
T m_##NAME = InitValue;
#define AUTO_PROPERTY(T, NAME, InitValue) \
private: \
Q_PROPERTY(T NAME READ NAME WRITE set_##NAME NOTIFY NAME##Changed) \
public: \
const T &NAME() const { return m_##NAME; } \
Q_SLOT void set_##NAME(const T &value) \
{ \
if (Compare<T>::isEqual(m_##NAME, value)) \
return; \
m_##NAME = value; \
emit NAME##Changed(value); \
} \
Q_SIGNAL void NAME##Changed(const T &value); \
\
private: \
T m_##NAME = InitValue;

View File

@ -4,31 +4,14 @@
INCLUDEPATH += $$PWD
hFile = $$files($$PWD/*.h, true)
hppFile = $$files($$PWD/*.hpp, true)
cppFile = $$files($$PWD/*.cpp, true)
HEADERS += \
$$PWD/Common/FileReadWrite.h \
$$PWD/Common/PropertyHelper.h \
$$PWD/Common/ObjectMap.h \
$$PWD/QuickTool/QuickTool.h \
$$PWD/Common/Subject.h \
$$PWD/Common/Package.h \
$$PWD/Frameless/TaoFrameLessView.h \
$$PWD/Logger/LoggerTemplate.h \
$$PWD/Logger/Logger.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 \
$$PWD/TaoCommonGlobal.h
$$hFile \
$$hppFile
SOURCES += \
$$PWD/Frameless/TaoFrameLessView.cpp \
$$PWD/Logger/Logger.cpp \
$$PWD/QuickTool/QuickTool.cpp \
$$PWD/TaoModel/TaoListItemBase.cpp \
$$PWD/TaoModel/TaoListModel.cpp \
$$PWD/Thread/ThreadPool.cpp \
$$PWD/Trans/Trans.cpp
$$cppFile

View File

@ -13,7 +13,7 @@ aux_source_directory(Src/DeviceAddTable SRC2)
include(taoVersion)
add_compile_definitions(TaoCommon_NO_LIB)
add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty ${CMAKE_SOURCE_DIR}/build/3rdparty)
add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/TaoCommon ${CMAKE_SOURCE_DIR}/build/3rdparty/TaoCommon)
#message("TaoCommonPath ${TaoCommonPath}")
#message("TaoCommonFiles ${TaoCommonFiles}")

View File

@ -21,83 +21,3 @@ void AppInfo::beforeUiReady(QQmlContext *ctx)
void AppInfo::afterUiReady() {}
void AppInfo::setAppName(const QString &appName)
{
if (m_appName == appName)
return;
m_appName = appName;
emit appNameChanged(m_appName);
}
void AppInfo::setAppVersion(const QString &appVersion)
{
if (m_appVersion == appVersion)
return;
m_appVersion = appVersion;
emit appVersionChanged(m_appVersion);
}
void AppInfo::setLatestVersion(const QString &latestVersion)
{
if (m_latestVersion == latestVersion)
return;
m_latestVersion = latestVersion;
emit latestVersionChanged(m_latestVersion);
}
void AppInfo::setBuildDateTime(const QString &buildDateTime)
{
if (m_buildDateTime == buildDateTime)
return;
m_buildDateTime = buildDateTime;
emit buildDateTimeChanged(m_buildDateTime);
}
void AppInfo::setBuildRevision(const QString &buildRevision)
{
if (m_buildRevision == buildRevision)
return;
m_buildRevision = buildRevision;
emit buildRevisionChanged(m_buildRevision);
}
void AppInfo::setCopyRight(const QString &copyRight)
{
if (m_copyRight == copyRight)
return;
m_copyRight = copyRight;
emit copyRightChanged(m_copyRight);
}
void AppInfo::setDescript(const QString &descript)
{
if (m_descript == descript)
return;
m_descript = descript;
emit descriptChanged(m_descript);
}
void AppInfo::setCompilerVendor(const QString &compilerVendor)
{
if (m_compilerVendor == compilerVendor)
return;
m_compilerVendor = compilerVendor;
emit compilerVendorChanged(m_compilerVendor);
}
void AppInfo::setSplashShow(bool splashShow)
{
if (m_splashShow == splashShow)
return;
m_splashShow = splashShow;
emit splashShowChanged(m_splashShow);
}

View File

@ -3,23 +3,21 @@
#include <QObject>
#include <QString>
#include <QQmlContext>
#include "Common/PropertyHelper.h"
class AppInfo : public QObject
{
Q_OBJECT
Q_PROPERTY(QString appName READ appName WRITE setAppName NOTIFY appNameChanged)
Q_PROPERTY(QString appVersion READ appVersion WRITE setAppVersion NOTIFY appVersionChanged)
Q_PROPERTY(QString latestVersion READ latestVersion WRITE setLatestVersion NOTIFY
latestVersionChanged)
Q_PROPERTY(QString buildDateTime READ buildDateTime WRITE setBuildDateTime NOTIFY
buildDateTimeChanged)
Q_PROPERTY(QString buildRevision READ buildRevision WRITE setBuildRevision NOTIFY
buildRevisionChanged)
Q_PROPERTY(QString copyRight READ copyRight WRITE setCopyRight NOTIFY copyRightChanged)
Q_PROPERTY(QString descript READ descript WRITE setDescript NOTIFY descriptChanged)
Q_PROPERTY(QString compilerVendor READ compilerVendor WRITE setCompilerVendor NOTIFY
compilerVendorChanged)
Q_PROPERTY(bool splashShow READ splashShow WRITE setSplashShow NOTIFY splashShowChanged)
AUTO_PROPERTY(QString, appName, "")
AUTO_PROPERTY(QString, appVersion, "")
AUTO_PROPERTY(QString, latestVersion, "")
AUTO_PROPERTY(QString, buildDateTime, "")
AUTO_PROPERTY(QString, buildRevision, "")
AUTO_PROPERTY(QString, copyRight, "")
AUTO_PROPERTY(QString, descript, "")
AUTO_PROPERTY(QString, compilerVendor, "")
AUTO_PROPERTY(bool, splashShow, false)
public:
explicit AppInfo(QObject *parent = nullptr);
@ -28,73 +26,4 @@ public:
void afterUiReady();
const QString &appName() const { return m_appName; }
const QString &appVersion() const { return m_appVersion; }
const QString &latestVersion() const { return m_latestVersion; }
const QString &buildDateTime() const { return m_buildDateTime; }
const QString &buildRevision() const { return m_buildRevision; }
const QString &copyRight() const { return m_copyRight; }
const QString &descript() const { return m_descript; }
const QString &compilerVendor() const { return m_compilerVendor; }
bool splashShow() const { return m_splashShow; }
public slots:
void setAppName(const QString &appName);
void setAppVersion(const QString &appVersion);
void setLatestVersion(const QString &latestVersion);
void setBuildDateTime(const QString &buildDateTime);
void setBuildRevision(const QString &buildRevision);
void setCopyRight(const QString &copyRight);
void setDescript(const QString &descript);
void setCompilerVendor(const QString &compilerVendor);
void setSplashShow(bool splashShow);
signals:
void appNameChanged(const QString &appName);
void appVersionChanged(const QString &appVersion);
void latestVersionChanged(const QString &latestVersion);
void buildDateTimeChanged(const QString &buildDateTime);
void buildRevisionChanged(const QString &buildRevision);
void copyRightChanged(const QString &copyRight);
void descriptChanged(const QString &descript);
void compilerVendorChanged(const QString &compilerVendor);
void splashShowChanged(bool splashShow);
protected:
private:
QString m_appName;
QString m_appVersion;
QString m_latestVersion;
QString m_buildDateTime;
QString m_buildRevision;
QString m_copyRight;
QString m_descript;
QString m_compilerVendor;
bool m_splashShow = false;
};

View File

@ -1,20 +1,18 @@
#include "DeviceAddItem.h"
DeviceAddItem::DeviceAddItem(QObject *parent)
: TaoListItemBase(parent)
{
}
DeviceAddItem::DeviceAddItem(QObject *parent) : TaoListItemBase(parent) { }
DeviceAddItem::~DeviceAddItem() { }
bool DeviceAddItem::match(const QString &key)
{
if (key.isEmpty())
{
if (key.isEmpty()) {
return true;
}
if (m_name.contains(key, Qt::CaseInsensitive)) {
return true;
} else if (m_address.contains(key, Qt::CaseInsensitive)) {
return true;
} else if (m_modelString.contains(key, Qt::CaseInsensitive)){
} else if (m_modelString.contains(key, Qt::CaseInsensitive)) {
return true;
}
return false;

View File

@ -1,89 +1,21 @@
#pragma once
#include "TaoModel/TaoListItemBase.h"
#include"Common/PropertyHelper.h"
#include <QObject>
class DeviceAddItem : public TaoListItemBase
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
Q_PROPERTY(QString modelString READ modelString WRITE setModelString NOTIFY modelStringChanged)
Q_PROPERTY(bool online READ online WRITE setOnline NOTIFY onlineChanged)
AUTO_PROPERTY(QString, name, "")
AUTO_PROPERTY(QString, address, "")
AUTO_PROPERTY(QString, modelString, "")
AUTO_PROPERTY(bool, online, false)
public:
explicit DeviceAddItem(QObject *parent = nullptr);
const QString &name() const
{
return m_name;
}
const QString &address() const
{
return m_address;
}
const QString &modelString() const
{
return m_modelString;
}
bool online() const
{
return m_online;
}
virtual ~DeviceAddItem() override;
bool match(const QString &key) override;
public slots:
void setName(const QString &name)
{
if (m_name == name)
return;
m_name = name;
emit nameChanged(m_name);
}
void setAddress(const QString &address)
{
if (m_address == address)
return;
m_address = address;
emit addressChanged(m_address);
}
void setModelString(const QString &modelString)
{
if (m_modelString == modelString)
return;
m_modelString = modelString;
emit modelStringChanged(m_modelString);
}
void setOnline(bool online)
{
if (m_online == online)
return;
m_online = online;
emit onlineChanged(m_online);
}
signals:
void nameChanged(const QString &name);
void addressChanged(const QString &address);
void modelStringChanged(const QString &modelString);
void onlineChanged(bool online);
private:
QString m_name;
QString m_address;
QString m_modelString;
bool m_online = false;
};

View File

@ -154,15 +154,15 @@ void DeviceAddModel::removeRow(int row)
DeviceAddItem *DeviceAddModel::genOne(uint32_t value)
{
auto item = new DeviceAddItem;
item->setOnline(value % 2 == 0);
item->setName(nameTemplate.arg(value));
item->set_online(value % 2 == 0);
item->set_name(nameTemplate.arg(value));
int ip4 = value % 256;
int ip3 = value / 256 % 256;
int ip2 = value / 256 / 256 % 256;
int ip1 = value / 256 / 256 / 256 % 256;
item->setAddress(ipTemplate.arg(ip1).arg(ip2).arg(ip3).arg(ip4));
item->setModelString(modelTemplate.arg(value % 2 == 0 ? value : 0xffffffff - value));
item->set_address(ipTemplate.arg(ip1).arg(ip2).arg(ip3).arg(ip4));
item->set_modelString(modelTemplate.arg(value % 2 == 0 ? value : 0xffffffff - value));
return item;
}
void DeviceAddModel::doUpdateName(int row, const QString &name)
@ -174,5 +174,5 @@ void DeviceAddModel::doUpdateName(int row, const QString &name)
if (n.isEmpty()) {
return;
}
static_cast<DeviceAddItem *>(mDatas.at(row))->setName(name);
static_cast<DeviceAddItem *>(mDatas.at(row))->set_name(name);
}