205 lines
3.8 KiB
C++
205 lines
3.8 KiB
C++
|
#pragma execution_character_set("utf-8")
|
|||
|
|
|||
|
#include "common.h"
|
|||
|
//#include <QCoreApplication>
|
|||
|
#include <QFileDialog>
|
|||
|
#include <QDebug>
|
|||
|
#include "easylogging++.h"
|
|||
|
#include "Session.h"
|
|||
|
#include "mainwindow.h"
|
|||
|
|
|||
|
CommonHelper::CommonHelper()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
CommonHelper::~CommonHelper()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
bool CommonHelper::intTobool(int b)
|
|||
|
{
|
|||
|
return b == 1 ? true : false;
|
|||
|
}
|
|||
|
|
|||
|
bool CommonHelper::compareQStringlist(QStringList& a, QStringList& b)
|
|||
|
{
|
|||
|
if (a.size() != b.size())
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
for (int i = 0; i < a.size(); i++)
|
|||
|
{
|
|||
|
//ȥ<><C8A5>ǰ<EFBFBD><C7B0><EFBFBD>ո<EFBFBD>
|
|||
|
if ((a[i].simplified()).compare((b[i].simplified())) != 0)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool CommonHelper::convertExcelboolValue(const QString& src, int& dst)
|
|||
|
{
|
|||
|
if (src.compare("<EFBFBD><EFBFBD>") == 0)
|
|||
|
{
|
|||
|
dst = 1;
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (src.compare("<EFBFBD><EFBFBD>") == 0)
|
|||
|
{
|
|||
|
dst = 0;
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
QString CommonHelper::convertPropertyValue(const int src)
|
|||
|
{
|
|||
|
//ֻ<><D6BB><EFBFBD><EFBFBD>0.1ֵ
|
|||
|
if (src == 1)
|
|||
|
{
|
|||
|
return "<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return "<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//stringתUTF8
|
|||
|
std::string CommonHelper::stringToUtf8(const std::string& str) {
|
|||
|
return QString::fromLocal8Bit(str.c_str()).toUtf8().toStdString();
|
|||
|
}
|
|||
|
std::string CommonHelper::utf8ToStdString(const char* str) {
|
|||
|
return QString::fromUtf8(str).toLocal8Bit().toStdString();
|
|||
|
}
|
|||
|
std::string CommonHelper::utf8ToStdString(const std::string& str) {
|
|||
|
return QString::fromUtf8(str.c_str()).toLocal8Bit().toStdString();
|
|||
|
}
|
|||
|
const char* CommonHelper::utf8ToString(const char* str) {
|
|||
|
return QString::fromUtf8(str).toLocal8Bit().constData();
|
|||
|
}
|
|||
|
QString CommonHelper::utf8ToQString(const char* str) {
|
|||
|
return QString::fromUtf8(str);
|
|||
|
}
|
|||
|
QString CommonHelper::utf8ToQString(std::string&& str) {
|
|||
|
return QString::fromUtf8(str.c_str());
|
|||
|
}
|
|||
|
QString CommonHelper::jsonToQString(nlohmann::json& j) {
|
|||
|
return QString::fromUtf8(j.dump().c_str());
|
|||
|
}
|
|||
|
const char* CommonHelper::jsonToString(nlohmann::json& j) {
|
|||
|
return QString::fromUtf8(j.dump().c_str()).toLocal8Bit().constData();
|
|||
|
}
|
|||
|
std::string CommonHelper::qstringToUtf8(const QString& str) {
|
|||
|
return str.toUtf8().toStdString();
|
|||
|
}
|
|||
|
QString CommonHelper::stringToQstring(const std::string& str) {
|
|||
|
return QString::fromLocal8Bit(str.c_str(), static_cast<int>(str.size()));
|
|||
|
}
|
|||
|
std::string CommonHelper::qstringToStdString(const QString& str) {
|
|||
|
return str.toLocal8Bit().toStdString();
|
|||
|
}
|
|||
|
const char* CommonHelper::qstringToString(const QString& str) {
|
|||
|
return str.toLocal8Bit();
|
|||
|
}
|
|||
|
void CommonHelper::convertExcelInt(const QString& src, int& dst)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD>excel<65><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD>ת-1
|
|||
|
if (src.isEmpty())
|
|||
|
{
|
|||
|
dst = -1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
int v = src.toInt();
|
|||
|
dst = v < 0 ? -1 : v;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
QString CommonHelper::convertFolderTypeToString(const int type)
|
|||
|
{
|
|||
|
if (type == 0)
|
|||
|
{
|
|||
|
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else if (type == 1)
|
|||
|
{
|
|||
|
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else if (type == 2)
|
|||
|
{
|
|||
|
return "<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
return "<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
|
|||
|
QString CommonHelper::convertAttributeTypeTpString(const int type)
|
|||
|
{
|
|||
|
if (type == 1)
|
|||
|
{
|
|||
|
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else if (type == 2)
|
|||
|
{
|
|||
|
return "<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else if (type == 3)
|
|||
|
{
|
|||
|
return "ʵ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
return "<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
|
|||
|
QString CommonHelper::convertInterfaceTypeToStr(const int type)
|
|||
|
{
|
|||
|
if (type == 0)
|
|||
|
{
|
|||
|
return "void";
|
|||
|
}
|
|||
|
else if (type == 1)
|
|||
|
{
|
|||
|
return "static";
|
|||
|
}
|
|||
|
else if (type == 2)
|
|||
|
{
|
|||
|
return "virtual";
|
|||
|
}
|
|||
|
return "<EFBFBD><EFBFBD>Ч";
|
|||
|
}
|
|||
|
void CommonHelper::handleError(json& parameter, const char* error) {
|
|||
|
LOG(INFO) << error;
|
|||
|
parameter["error"] = "<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD>";
|
|||
|
}
|
|||
|
void CommonHelper::message(const QString& message, int type) {
|
|||
|
Session::getSession()->parent()->message(message, type);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
bool CommonHelper::checkDir(QString fullPath)
|
|||
|
{
|
|||
|
QDir dir(fullPath);
|
|||
|
if (dir.exists())
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return dir.mkdir(fullPath);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CommonHelper::deleteFilesInFolder(const QString& folderPath)
|
|||
|
{
|
|||
|
QDir folder(folderPath);
|
|||
|
QStringList files = folder.entryList(QDir::Files);
|
|||
|
|
|||
|
foreach(const QString & file, files) {
|
|||
|
folder.remove(file);
|
|||
|
}
|
|||
|
}
|