gui: add basic gui code.
This commit is contained in:
27
Struct/CMakeLists.txt
Normal file
27
Struct/CMakeLists.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(Struct LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
|
||||
|
||||
set(SOURCES
|
||||
InfoClient.h
|
||||
InfoClient.cpp
|
||||
InfoPack.hpp
|
||||
InfoDirFile.h
|
||||
InfoDirFile.cpp
|
||||
InfoMsg.h
|
||||
InfoMsg.cpp
|
||||
)
|
||||
|
||||
add_library(Struct STATIC ${SOURCES})
|
||||
target_link_libraries(Struct Qt${QT_VERSION_MAJOR}::Core)
|
||||
target_include_directories(Struct PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
13
Struct/InfoClient.cpp
Normal file
13
Struct/InfoClient.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "InfoClient.h"
|
||||
|
||||
QDataStream& operator<<(QDataStream& data, const InfoClient& info)
|
||||
{
|
||||
info.serialize(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& data, InfoClient& info)
|
||||
{
|
||||
info.deserialize(data);
|
||||
return data;
|
||||
}
|
||||
49
Struct/InfoClient.h
Normal file
49
Struct/InfoClient.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef INFO_CLIENT_H
|
||||
#define INFO_CLIENT_H
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDataStream>
|
||||
#include <QIODevice>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
struct InfoClient {
|
||||
QString id;
|
||||
QString name;
|
||||
|
||||
void serialize(QDataStream& data) const
|
||||
{
|
||||
data << id << name;
|
||||
}
|
||||
|
||||
void deserialize(QDataStream& data)
|
||||
{
|
||||
data >> id >> name;
|
||||
}
|
||||
};
|
||||
|
||||
QDataStream& operator<<(QDataStream& data, const InfoClient& info);
|
||||
QDataStream& operator>>(QDataStream& data, InfoClient& info);
|
||||
|
||||
struct InfoClientVec {
|
||||
QVector<InfoClient> vec;
|
||||
|
||||
void serialize(QDataStream& data) const
|
||||
{
|
||||
data << vec.size();
|
||||
for (const auto& info : vec) {
|
||||
data << info;
|
||||
}
|
||||
}
|
||||
void deserialize(QDataStream& data)
|
||||
{
|
||||
qsizetype size;
|
||||
data >> size;
|
||||
vec.resize(size);
|
||||
for (quint32 i = 0; i < size; ++i) {
|
||||
data >> vec[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INFO_CLIENT_H
|
||||
13
Struct/InfoDirFile.cpp
Normal file
13
Struct/InfoDirFile.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "InfoDirFile.h"
|
||||
|
||||
QDataStream& operator<<(QDataStream& data, const DirFileInfo& info)
|
||||
{
|
||||
info.serialize(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& data, DirFileInfo& info)
|
||||
{
|
||||
info.deserialize(data);
|
||||
return data;
|
||||
}
|
||||
55
Struct/InfoDirFile.h
Normal file
55
Struct/InfoDirFile.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef INFO_DIR_FILE_H
|
||||
#define INFO_DIR_FILE_H
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDataStream>
|
||||
#include <QIODevice>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
enum FileType : uint32_t { None = 0, File, Dir, Link, Other };
|
||||
|
||||
struct DirFileInfo {
|
||||
QString name;
|
||||
quint64 size{};
|
||||
FileType type = None;
|
||||
QString fullPath;
|
||||
quint16 permission{};
|
||||
quint64 lastModified{};
|
||||
|
||||
void serialize(QDataStream& data) const
|
||||
{
|
||||
data << name << size << type << fullPath << permission << lastModified;
|
||||
}
|
||||
|
||||
void deserialize(QDataStream& data)
|
||||
{
|
||||
data >> name >> size >> type >> fullPath >> permission >> lastModified;
|
||||
}
|
||||
};
|
||||
|
||||
QDataStream& operator<<(QDataStream& data, const DirFileInfo& info);
|
||||
QDataStream& operator>>(QDataStream& data, DirFileInfo& info);
|
||||
|
||||
struct DirFileInfoVec {
|
||||
QVector<DirFileInfo> vec;
|
||||
|
||||
void serialize(QDataStream& data) const
|
||||
{
|
||||
data << vec.size();
|
||||
for (const auto& info : vec) {
|
||||
data << info;
|
||||
}
|
||||
}
|
||||
void deserialize(QDataStream& data)
|
||||
{
|
||||
qsizetype size;
|
||||
data >> size;
|
||||
vec.resize(size);
|
||||
for (quint32 i = 0; i < size; ++i) {
|
||||
data >> vec[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INFO_DIR_FILE_H
|
||||
28
Struct/InfoMsg.h
Normal file
28
Struct/InfoMsg.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef INFO_MSG_H
|
||||
#define INFO_MSG_H
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDataStream>
|
||||
#include <QIODevice>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
struct InfoMsg {
|
||||
qint32 mark{};
|
||||
QString msg;
|
||||
|
||||
void serialize(QDataStream& data) const
|
||||
{
|
||||
data << mark << msg;
|
||||
}
|
||||
|
||||
void deserialize(QDataStream& data)
|
||||
{
|
||||
data >> mark >> msg;
|
||||
}
|
||||
};
|
||||
|
||||
QDataStream& operator<<(QDataStream& data, const InfoMsg& info);
|
||||
QDataStream& operator>>(QDataStream& data, InfoMsg& info);
|
||||
|
||||
#endif // INFO_MSG_H
|
||||
25
Struct/InfoPack.hpp
Normal file
25
Struct/InfoPack.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef INFO_PACK_HPP
|
||||
#define INFO_PACK_HPP
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
|
||||
template <typename T> QByteArray infoPack(const T& obj)
|
||||
{
|
||||
QByteArray byteArray;
|
||||
QDataStream stream(&byteArray, QIODevice::ReadWrite);
|
||||
obj.serialize(stream);
|
||||
stream.device()->seek(0);
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
template <typename T> T infoUnpack(const QByteArray& byteArray)
|
||||
{
|
||||
T obj;
|
||||
QDataStream stream(byteArray);
|
||||
obj.deserialize(stream);
|
||||
return obj;
|
||||
}
|
||||
|
||||
#endif // INFO_PACK_HPP
|
||||
13
Struct/infoMsg.cpp
Normal file
13
Struct/infoMsg.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "InfoMsg.h"
|
||||
|
||||
QDataStream& operator<<(QDataStream& data, const InfoMsg& info)
|
||||
{
|
||||
info.serialize(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& data, InfoMsg& info)
|
||||
{
|
||||
info.deserialize(data);
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user