QT INI文件配置20191126

代码如下:

#ifndef BTZZ_INI3_H
#define BTZZ_INI3_H

#include <QtGui/QMainWindow>
#include "ui_btzz_ini3.h"
#include "ParamaManage.h"

class BTZZ_INI3 : public QMainWindow
{
	Q_OBJECT

public:
	BTZZ_INI3(QWidget *parent = 0, Qt::WFlags flags = 0);
	~BTZZ_INI3();
	ParamaManage* m_ParamaManage;

private:
	Ui::BTZZ_INI3Class ui;

	public slots:
		void onbtnSave();
		void onbtnLoad();
public:
	void LoadPaveParamUI();
	void SavePaveParamUI();
};

#endif // BTZZ_INI3_H
#include "btzz_ini3.h"

BTZZ_INI3::BTZZ_INI3(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
	ui.setupUi(this);
	//
	m_ParamaManage=new ParamaManage;
	m_ParamaManage->InitParam();
	//SAVE AND LOAD
	connect(ui.btnSave,SIGNAL(clicked()),this,SLOT(onbtnSave()));
	connect(ui.btnLoad,SIGNAL(clicked()),this,SLOT(onbtnLoad()));
	//
	connect(ui.spinBox_CurrentLayer,SIGNAL(valueChanged(int)),this,SLOT(onbtnLoad()));
	connect(ui.comboBox_WorkBarrel,SIGNAL(currentIndexChanged(int)),this,SLOT(onbtnLoad()));
	//
	LoadPaveParamUI();
	//
}

BTZZ_INI3::~BTZZ_INI3()
{
	delete m_ParamaManage;
}

void BTZZ_INI3::onbtnSave()
{
	SavePaveParamUI();
}

void BTZZ_INI3::onbtnLoad()
{
	LoadPaveParamUI();
}

void BTZZ_INI3::LoadPaveParamUI()
{
	m_ParamaManage->LoadPaveParam();
	//
	int nBarrelIndex = ui.comboBox_WorkBarrel->currentIndex();
	//
	ui.spinBox_PaveLayer->setValue(m_ParamaManage->m_stPaveParam.nPaveLayer);
	//
	ui.spinBox_CurrentLayer->setMinimum(0);
	ui.spinBox_CurrentLayer->setMaximum(m_ParamaManage->m_stPaveParam.nPaveLayer-1);
	int nCurrentLayer = ui.spinBox_CurrentLayer->value();
	//
	ui.spinBox_InnerValueJ1->setValue(m_ParamaManage->m_stPaveParam.PaveLayer[nCurrentLayer].innercycle.stStart[nBarrelIndex].IAxis[0]);
	ui.spinBox_InnerValueJ2->setValue(m_ParamaManage->m_stPaveParam.PaveLayer[nCurrentLayer].innercycle.stStart[nBarrelIndex].IAxis[1]);
	//
	ui.spinBox_OuterValueJ1->setValue(m_ParamaManage->m_stPaveParam.PaveLayer[nCurrentLayer].outercycle.stStart[nBarrelIndex].IAxis[0]);
	ui.spinBox_OuterValueJ2->setValue(m_ParamaManage->m_stPaveParam.PaveLayer[nCurrentLayer].outercycle.stStart[nBarrelIndex].IAxis[1]);
}

void BTZZ_INI3::SavePaveParamUI()
{
	//barrel index
	int nBarrelIndex = ui.comboBox_WorkBarrel->currentIndex();
	//PaveLayer Number
	int nPaveLayer = ui.spinBox_PaveLayer->value();
	m_ParamaManage->m_stPaveParam.nPaveLayer=nPaveLayer;
	//Current PaveLayer
	ui.spinBox_CurrentLayer->setMinimum(0);
	ui.spinBox_CurrentLayer->setMaximum(nPaveLayer-1);
	int nCurrentLayer = ui.spinBox_CurrentLayer->value();
	//inner
	AxisPos Checkpos;
	Checkpos.IAxis[0]=ui.spinBox_InnerValueJ1->value();
	Checkpos.IAxis[1]=ui.spinBox_InnerValueJ2->value();
	m_ParamaManage->m_stPaveParam.PaveLayer[nCurrentLayer].innercycle.stStart[nBarrelIndex] = Checkpos;
	//outer
	Checkpos.IAxis[0]=ui.spinBox_OuterValueJ1->value();
	Checkpos.IAxis[1]=ui.spinBox_OuterValueJ2->value();
	m_ParamaManage->m_stPaveParam.PaveLayer[nCurrentLayer].outercycle.stStart[nBarrelIndex] = Checkpos;
	//Save to File
	m_ParamaManage->SavePaveParam();
}
#pragma once

struct AxisPos
{
	int IAxis[2];
	AxisPos()
	{
		IAxis[0]=0;
		IAxis[1]=0;
	}
};

enum Work_barrel
{
	barrel_1=0,
	barrel_2,
	barrel_support
};

typedef struct
{
	AxisPos stStart[barrel_support];
}PaveInfo;

typedef struct
{
	PaveInfo innercycle;
	PaveInfo outercycle;
}PaveLayerParam;

#define MaxPaveLayer 20

typedef struct
{
	int nPaveLayer;
	PaveLayerParam PaveLayer[MaxPaveLayer];
}PaveAllParam;

class ParamaManage
{
public:
	ParamaManage(void);
	~ParamaManage(void);
public:
	char m_sKeyValue[256];
	char m_sRetValue[256];
	char m_sWriteValue[256];
	//
	char m_sFileName[256];
	//
	void ClearReturnValue();
	void ClearKeyValue();
	void ClearWriteValue();
public:
	void Release();
	void InitParam();
	void LoadPaveParam();
	void SavePaveParam();
public:
	PaveAllParam m_stPaveParam;

};
#include "ParamaManage.h"
#include <Windows.h>
#include <string.h>
#include <direct.h>
#include <stdio.h>
#include <QSettings>

#define SAFE_DELETE(a) {if(NULL!=a)delete a; a= NULL;}
#define MAX_KEYLENGTH 256
#define StringDefault "0"

ParamaManage::ParamaManage(void)
{

}

ParamaManage::~ParamaManage(void)
{

}

void ParamaManage::ClearReturnValue()
{
	memset(m_sRetValue,0,255);
}

void ParamaManage::ClearKeyValue()
{
	memset(m_sKeyValue,0,255);
}

void ParamaManage::ClearWriteValue()
{
	memset(m_sWriteValue,0,255);
}

void ParamaManage::Release()
{

}

void ParamaManage::InitParam()
{
	char cur_dir[_MAX_DIR];

	_getcwd(cur_dir,sizeof(cur_dir));

	memset(m_sFileName,0,255);

	sprintf_s(m_sFileName,"%s\\Setting\\%s",cur_dir,"Setting.ini");
}

void ParamaManage::LoadPaveParam()
{
	//
	ClearKeyValue();
	sprintf_s(m_sKeyValue,"%s","nPaveLayer");
	ClearReturnValue();
	GetPrivateProfileStringA("PaveAllParam",m_sKeyValue,StringDefault,m_sRetValue,MAX_KEYLENGTH,m_sFileName);
	m_stPaveParam.nPaveLayer=atoi(m_sRetValue);
	//
	//QSettings *configIni = new QSettings("Setting\\Setting.ini", QSettings::IniFormat);
	//int nPaveLayers = configIni->value("PaveAllParam/nPaveLayer").toInt();
	//
	for(int barrel=0;barrel<barrel_support;barrel++)
	{
		for(int i=0;i< m_stPaveParam.nPaveLayer;i++)
		{
			for(int j=0;j<2;j++)
			{
				//inner
				ClearKeyValue();
				sprintf_s(m_sKeyValue,"%s%d%s%d%s%d","barrel",barrel,"layer",i,"innercyclestStartdbAxis",j);
				ClearReturnValue();
				GetPrivateProfileStringA("PaveAllParam",m_sKeyValue,StringDefault,m_sRetValue,MAX_KEYLENGTH,m_sFileName);
				m_stPaveParam.PaveLayer[i].innercycle.stStart[barrel].IAxis[j]=atoi(m_sRetValue);
				//outer
				ClearKeyValue();
				sprintf_s(m_sKeyValue,"%s%d%s%d%s%d","barrel",barrel,"layer",i,"outercyclestStartdbAxis",j);
				ClearReturnValue();
				GetPrivateProfileStringA("PaveAllParam",m_sKeyValue,StringDefault,m_sRetValue,MAX_KEYLENGTH,m_sFileName);
				m_stPaveParam.PaveLayer[i].outercycle.stStart[barrel].IAxis[j]=atoi(m_sRetValue);
			}
		}
	}
}

void ParamaManage::SavePaveParam()
{
	//
	ClearKeyValue();
	sprintf_s(m_sKeyValue,"%s","nPaveLayer");
	ClearWriteValue();
	sprintf_s(m_sWriteValue,"%d", m_stPaveParam.nPaveLayer);
	WritePrivateProfileStringA("PaveAllParam",m_sKeyValue,m_sWriteValue,m_sFileName);
	//
	for(int barrel=0;barrel<barrel_support;barrel++)
	{
		for(int i=0;i< m_stPaveParam.nPaveLayer;i++)
		{
			for(int j=0;j<2;j++)
			{
				//inner
				ClearKeyValue();
				sprintf_s(m_sKeyValue,"%s%d%s%d%s%d","barrel",barrel,"layer",i,"innercyclestStartdbAxis",j);
				ClearWriteValue();
				sprintf_s(m_sWriteValue,"%d",m_stPaveParam.PaveLayer[i].innercycle.stStart[barrel].IAxis[j]);
				WritePrivateProfileStringA("PaveAllParam",m_sKeyValue,m_sWriteValue,m_sFileName);
				//outer
				ClearKeyValue();
				sprintf_s(m_sKeyValue,"%s%d%s%d%s%d","barrel",barrel,"layer",i,"outercyclestStartdbAxis",j);
				ClearWriteValue();
				sprintf_s(m_sWriteValue,"%d",m_stPaveParam.PaveLayer[i].outercycle.stStart[barrel].IAxis[j]);
				WritePrivateProfileStringA("PaveAllParam",m_sKeyValue,m_sWriteValue,m_sFileName);
			}
		}
	}
}
发布了140 篇原创文章 · 获赞 26 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_41211961/article/details/103257858