添加配置,未完成
This commit is contained in:
+1
-1
@@ -48,7 +48,7 @@ include (./MissionUI/MissionUI.pri)
|
|||||||
include (./MenuBarUI/MenuBarUI.pri)
|
include (./MenuBarUI/MenuBarUI.pri)
|
||||||
include (./CommandUI/CommandUI.pri)
|
include (./CommandUI/CommandUI.pri)
|
||||||
include (./CheckUI/CheckUI.pri)
|
include (./CheckUI/CheckUI.pri)
|
||||||
|
include (./Config/Config.pri)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ CommandUI::CommandUI(QWidget *parent) :
|
|||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
|
||||||
|
//查找默认的值
|
||||||
|
|
||||||
|
|
||||||
//载入json
|
//载入json
|
||||||
loadCommandJson(CommandFile);
|
loadCommandJson(CommandFile);
|
||||||
@@ -71,8 +73,6 @@ CommandUI::CommandUI(QWidget *parent) :
|
|||||||
|
|
||||||
btn->setText(info.toObject().find(_TextJsonKey).value().toString());
|
btn->setText(info.toObject().find(_TextJsonKey).value().toString());
|
||||||
|
|
||||||
//btn->setMinimumSize(CMDwidth,CMDheight);
|
|
||||||
//btn->resize(CMDwidth,CMDheight);
|
|
||||||
btn->setFixedSize(CMDwidth,CMDheight);
|
btn->setFixedSize(CMDwidth,CMDheight);
|
||||||
|
|
||||||
ui->gridLayout_Command->addWidget(btn,
|
ui->gridLayout_Command->addWidget(btn,
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
|
||||||
|
Config::Config()
|
||||||
|
{
|
||||||
|
qDebug() << "Config Operation";
|
||||||
|
|
||||||
|
QDir *Dir = new QDir;
|
||||||
|
if(!Dir->exists("./Config"))
|
||||||
|
if(Dir->mkdir("./Config"))//如果文件夹不存在就新建
|
||||||
|
{
|
||||||
|
qInfo() << "create config dir";
|
||||||
|
}
|
||||||
|
delete Dir;
|
||||||
|
Dir = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Config::~Config()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Config::getDefaultCommandFile()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::setDefaultCommandFile(QString file)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Config::loadJson(const QString& jsonFilename)
|
||||||
|
{
|
||||||
|
if (jsonFilename.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Loading " << jsonFilename;
|
||||||
|
|
||||||
|
QFile jsonFile(jsonFilename);
|
||||||
|
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
qWarning() << "Unable to open file" << jsonFilename << jsonFile.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray bytes = jsonFile.readAll();
|
||||||
|
|
||||||
|
jsonFile.close();
|
||||||
|
QJsonParseError jsonParseError;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError);
|
||||||
|
if (jsonParseError.error != QJsonParseError::NoError) {
|
||||||
|
qWarning() << jsonFilename << "Unable to open json document" << jsonParseError.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject json = doc.object();
|
||||||
|
CMD_version = json.value(_versionJsonKey).toInt();
|
||||||
|
qDebug() << "command version :" << CMD_version;
|
||||||
|
|
||||||
|
CMDwidth = json.value(_WidthJsonKey).toInt();
|
||||||
|
CMDheight = json.value(_HeightJsonKey).toInt();
|
||||||
|
|
||||||
|
|
||||||
|
QJsonValue jsonValue = json.value(_CommandButtonJsonKey);
|
||||||
|
|
||||||
|
if (!jsonValue.isArray()) {
|
||||||
|
qWarning() << jsonFilename << "_CommandButtonJsonKey not array";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CMD_infoArray = jsonValue.toArray();
|
||||||
|
|
||||||
|
for(QJsonValue info: CMD_infoArray) {
|
||||||
|
if (!info.isObject()) {
|
||||||
|
qWarning() << jsonFilename << "mavCmdArray should contain objects";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "QDir"
|
||||||
|
#include "QJsonArray"
|
||||||
|
#include "QJsonDocument"
|
||||||
|
#include "QJsonObject"
|
||||||
|
#include "QJsonParseError"
|
||||||
|
|
||||||
|
|
||||||
|
class Config
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Config(QObject *parent = nullptr);
|
||||||
|
~Config();
|
||||||
|
|
||||||
|
|
||||||
|
QString getDefaultCommandFile();
|
||||||
|
void setDefaultCommandFile(QString file);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIG_H
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
|
||||||
|
QT += opengl
|
||||||
|
QT += network
|
||||||
|
QT += sql
|
||||||
|
QT += svg
|
||||||
|
QT += quickwidgets
|
||||||
|
QT += quick
|
||||||
|
QT += qml
|
||||||
|
QT += texttospeech
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/Config.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/Config.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user