125 lines
3.6 KiB
C++
125 lines
3.6 KiB
C++
|
|
#include "WidgetSettingClass.h"
|
|||
|
|
#include <QFileInfo>
|
|||
|
|
#include <QDir>
|
|||
|
|
|
|||
|
|
|
|||
|
|
WidgetSettingClass::~WidgetSettingClass()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WidgetSettingClass& WidgetSettingClass::instance()
|
|||
|
|
{
|
|||
|
|
static WidgetSettingClass instance;
|
|||
|
|
return instance;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ʵ<>ֹ<EFBFBD><D6B9>캯<EFBFBD><ECBAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
|||
|
|
WidgetSettingClass::WidgetSettingClass(QObject* parent)
|
|||
|
|
: QObject(parent), m_settings(new QSettings(this))
|
|||
|
|
{
|
|||
|
|
lastFileDialogPath = QString();
|
|||
|
|
|
|||
|
|
iniPath = this->getExeDirectionApplicationPath()+u8"\\LAMPWINDData.ini";
|
|||
|
|
|
|||
|
|
if (!QFileInfo(iniPath).exists()) {
|
|||
|
|
QSettings writeSettings(iniPath, QSettings::IniFormat);
|
|||
|
|
writeSettings.setValue("Application/Name", u8"<EFBFBD>糡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
writeSettings.setValue("Application/Version", 1.0);
|
|||
|
|
writeSettings.setValue("Application/LastfilePath", this->getExeDirectionApplicationPath());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
QSettings readSettings(iniPath, QSettings::IniFormat);
|
|||
|
|
QString appName = readSettings.value("Application/Name").toString();
|
|||
|
|
double version = readSettings.value("Application/Version").toDouble();
|
|||
|
|
this->lastFileDialogPath= readSettings.value("Application/LastfilePath").toString();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getWindTool_nc2WindDataToolPath()
|
|||
|
|
{
|
|||
|
|
QString appDir = QCoreApplication::applicationDirPath();
|
|||
|
|
QDir baseDir(appDir);
|
|||
|
|
QString toolPyPath = baseDir.absoluteFilePath(u8"tools\\windTools\\ERA5ToWindDataConverter.py");
|
|||
|
|
toolPyPath = QDir::cleanPath(toolPyPath);
|
|||
|
|
return toolPyPath;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getWindTool_PythonEnvPath()
|
|||
|
|
{
|
|||
|
|
QString appDir = QCoreApplication::applicationDirPath();
|
|||
|
|
QDir baseDir(appDir);
|
|||
|
|
QString pythonExePath = baseDir.absoluteFilePath(u8"pyEnv\\lampprocess\\python.exe");
|
|||
|
|
pythonExePath = QDir::cleanPath(pythonExePath);
|
|||
|
|
|
|||
|
|
qDebug() << "Python executable path:" << pythonExePath;
|
|||
|
|
return pythonExePath;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getExeApplicationPath()
|
|||
|
|
{
|
|||
|
|
// <20>ȵõ<C8B5><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
QString appFilePath = QCoreApplication::applicationFilePath();
|
|||
|
|
// ʹ<><CAB9>QFileInfo<66><6F>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ڵľ<DAB5><C4BE><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
QFileInfo fileInfo(appFilePath);
|
|||
|
|
return fileInfo.absolutePath(); // <20><><EFBFBD><EFBFBD>Ŀ¼·<C2BC><C2B7>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getExeDirectionApplicationPath()
|
|||
|
|
{
|
|||
|
|
return QCoreApplication::applicationDirPath();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getWindReaddLLApplicationPath()
|
|||
|
|
{
|
|||
|
|
QString appDir = QCoreApplication::applicationDirPath();
|
|||
|
|
QDir baseDir(appDir);
|
|||
|
|
QString toolPath = baseDir.absoluteFilePath(u8"WindDataOperator.dll");
|
|||
|
|
toolPath = QDir::cleanPath(toolPath);
|
|||
|
|
return toolPath;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getLastFileDialogPath()
|
|||
|
|
{
|
|||
|
|
return this->lastFileDialogPath;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void WidgetSettingClass::setLastFileDialogPath(QString path)
|
|||
|
|
{
|
|||
|
|
lastFileDialogPath = path;
|
|||
|
|
iniPath = this->getExeDirectionApplicationPath() + u8"\\LAMPWINDData.ini";
|
|||
|
|
|
|||
|
|
if (!QFileInfo(iniPath).exists()) {
|
|||
|
|
QSettings writeSettings(iniPath, QSettings::IniFormat);
|
|||
|
|
writeSettings.setValue("Application/LastfilePath", lastFileDialogPath);
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
QSettings writeSettings(iniPath, QSettings::IniFormat);
|
|||
|
|
writeSettings.setValue("Application/LastfilePath", lastFileDialogPath);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString WidgetSettingClass::getTempFolder()
|
|||
|
|
{
|
|||
|
|
QString tempPath2 = QDir::tempPath();
|
|||
|
|
qDebug() << u8"ϵͳ<EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD> (QDir): " << tempPath2;
|
|||
|
|
QString tempfolderpath= tempPath2 + "\\lampwind";
|
|||
|
|
|
|||
|
|
QDir dir;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (dir.exists(tempfolderpath)) {
|
|||
|
|
qDebug() << "Ŀ¼<EFBFBD>Ѵ<EFBFBD><EFBFBD>ڣ<EFBFBD>" << tempfolderpath;
|
|||
|
|
}
|
|||
|
|
else if (dir.mkpath(tempfolderpath)) {
|
|||
|
|
qDebug() << "Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>" << tempfolderpath;
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
qDebug() << "Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>" << tempfolderpath;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return tempfolderpath;
|
|||
|
|
}
|