Skip to content

Commit

Permalink
首次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyangqingyun committed Oct 4, 2019
0 parents commit 315f102
Show file tree
Hide file tree
Showing 208 changed files with 26,451 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#### 项目介绍
Qt编写的一些开源的demo,包括串口调试助手、网络调试助手、自定义控件、其他小demo等,会一直持续更新完善,代码随意传播使用,拒绝打赏和捐赠,欢迎各位留言评论!

#### 目录说明
| 编号 | 文件夹 | 描述 |
| ------ | ------ | ------ |
| 1 | lightbutton | 高亮按钮控件 |
| 2 | movewidget | 通用控件移动类 |
| 3 | flatui | 模仿flatui类 |
| 4 | countcode | 代码统计组件 |
| 5 | gifwidget | 屏幕录制控件 |
| 6 | comtool | 串口调试助手 |
| 7 | nettool | 网络调试助手 |
| 8 | devicesizetable | 硬盘容量控件 |
| 9 | styledemo | 高仿PS黑色+扁平白色+淡蓝色风格主题 |
| 10 | navbutton | 导航按钮控件 |
| 11 | video_splite | 视频监控画面分割demo |
7 changes: 7 additions & 0 deletions comtool/api/api.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HEADERS += \
$$PWD/app.h \
$$PWD/quiwidget.h

SOURCES += \
$$PWD/app.cpp \
$$PWD/quiwidget.cpp
201 changes: 201 additions & 0 deletions comtool/api/app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#include "app.h"
#include "quiwidget.h"

QString App::ConfigFile = "config.ini";
QString App::SendFileName = "send.txt";
QString App::DeviceFileName = "device.txt";

QString App::PortName = "COM1";
int App::BaudRate = 9600;
int App::DataBit = 8;
QString App::Parity = "";
double App::StopBit = 1;

bool App::HexSend = false;
bool App::HexReceive = false;
bool App::Debug = false;
bool App::AutoClear = false;

bool App::AutoSend = false;
int App::SendInterval = 1000;
bool App::AutoSave = false;
int App::SaveInterval = 5000;

QString App::Mode = "Tcp_Client";
QString App::ServerIP = "127.0.0.1";
int App::ServerPort = 6000;
int App::ListenPort = 6000;
int App::SleepTime = 100;
bool App::AutoConnect = false;

void App::readConfig()
{
if (!checkConfig()) {
return;
}

QSettings set(App::ConfigFile, QSettings::IniFormat);

set.beginGroup("ComConfig");
App::PortName = set.value("PortName").toString();
App::BaudRate = set.value("BaudRate").toInt();
App::DataBit = set.value("DataBit").toInt();
App::Parity = set.value("Parity").toString();
App::StopBit = set.value("StopBit").toInt();

App::HexSend = set.value("HexSend").toBool();
App::HexReceive = set.value("HexReceive").toBool();
App::Debug = set.value("Debug").toBool();
App::AutoClear = set.value("AutoClear").toBool();

App::AutoSend = set.value("AutoSend").toBool();
App::SendInterval = set.value("SendInterval").toInt();
App::AutoSave = set.value("AutoSave").toBool();
App::SaveInterval = set.value("SaveInterval").toInt();
set.endGroup();

set.beginGroup("NetConfig");
App::Mode = set.value("Mode").toString();
App::ServerIP = set.value("ServerIP").toString();
App::ServerPort = set.value("ServerPort").toInt();
App::ListenPort = set.value("ListenPort").toInt();
App::SleepTime = set.value("SleepTime").toInt();
App::AutoConnect = set.value("AutoConnect").toBool();
set.endGroup();
}

void App::writeConfig()
{
QSettings set(App::ConfigFile, QSettings::IniFormat);

set.beginGroup("ComConfig");
set.setValue("PortName", App::PortName);
set.setValue("BaudRate", App::BaudRate);
set.setValue("DataBit", App::DataBit);
set.setValue("Parity", App::Parity);
set.setValue("StopBit", App::StopBit);

set.setValue("HexSend", App::HexSend);
set.setValue("HexReceive", App::HexReceive);
set.setValue("Debug", App::Debug);
set.setValue("AutoClear", App::AutoClear);

set.setValue("AutoSend", App::AutoSend);
set.setValue("SendInterval", App::SendInterval);
set.setValue("AutoSave", App::AutoSave);
set.setValue("SaveInterval", App::SaveInterval);
set.endGroup();

set.beginGroup("NetConfig");
set.setValue("Mode", App::Mode);
set.setValue("ServerIP", App::ServerIP);
set.setValue("ServerPort", App::ServerPort);
set.setValue("ListenPort", App::ListenPort);
set.setValue("SleepTime", App::SleepTime);
set.setValue("AutoConnect", App::AutoConnect);
set.endGroup();
}

void App::newConfig()
{
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
App::Parity = App::Parity.toLatin1();
#endif
writeConfig();
}

bool App::checkConfig()
{
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
QFile file(App::ConfigFile);
if (file.size() == 0) {
newConfig();
return false;
}

//如果配置文件不完整,则以初始值继续运行,并生成配置文件
if (file.open(QFile::ReadOnly)) {
bool ok = true;
while (!file.atEnd()) {
QString line = file.readLine();
line = line.replace("\r", "");
line = line.replace("\n", "");
QStringList list = line.split("=");

if (list.count() == 2) {
if (list.at(1) == "") {
ok = false;
break;
}
}
}

if (!ok) {
newConfig();
return false;
}
} else {
newConfig();
return false;
}

return true;
}

QStringList App::Intervals = QStringList();
QStringList App::Datas = QStringList();
QStringList App::Keys = QStringList();
QStringList App::Values = QStringList();

void App::readSendData()
{
//读取发送数据列表
App::Datas.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::SendFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
App::Datas.append(line);
}
}

file.close();
}
}

void App::readDeviceData()
{
//读取转发数据列表
App::Keys.clear();
App::Values.clear();
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::DeviceFileName);
QFile file(fileName);
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
line = line.trimmed();
line = line.replace("\r", "");
line = line.replace("\n", "");
if (!line.isEmpty()) {
QStringList list = line.split(";");
QString key = list.at(0);
QString value;
for (int i = 1; i < list.count(); i++) {
value += QString("%1;").arg(list.at(i));
}

//去掉末尾分号
value = value.mid(0, value.length() - 1);
App::Keys.append(key);
App::Values.append(value);
}
}

file.close();
}
}
51 changes: 51 additions & 0 deletions comtool/api/app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef APP_H
#define APP_H

#include "head.h"

class App
{
public:
static QString ConfigFile; //配置文件路径
static QString SendFileName; //发送配置文件名
static QString DeviceFileName; //模拟设备数据文件名

static QString PortName; //串口号
static int BaudRate; //波特率
static int DataBit; //数据位
static QString Parity; //校验位
static double StopBit; //停止位

static bool HexSend; //16进制发送
static bool HexReceive; //16进制接收
static bool Debug; //模拟设备
static bool AutoClear; //自动清空

static bool AutoSend; //自动发送
static int SendInterval; //自动发送间隔
static bool AutoSave; //自动保存
static int SaveInterval; //自动保存间隔

static QString Mode; //转换模式
static QString ServerIP; //服务器IP
static int ServerPort; //服务器端口
static int ListenPort; //监听端口
static int SleepTime; //延时时间
static bool AutoConnect; //自动重连

//读写配置参数及其他操作
static void readConfig(); //读取配置参数
static void writeConfig(); //写入配置参数
static void newConfig(); //以初始值新建配置文件
static bool checkConfig(); //校验配置文件

static QStringList Intervals;
static QStringList Datas;
static QStringList Keys;
static QStringList Values;
static void readSendData();
static void readDeviceData();

};

#endif // APP_H
Loading

0 comments on commit 315f102

Please sign in to comment.