208 lines
4.4 KiB
C++
208 lines
4.4 KiB
C++
|
#pragma execution_character_set("utf-8")
|
|||
|
|
|||
|
#include "DataManager.h"
|
|||
|
#include "M_ProjectDAO.h"
|
|||
|
#include "ProjectData.h"
|
|||
|
#include "global.h"
|
|||
|
#include "DictItem.h"
|
|||
|
#include "DictData.h"
|
|||
|
|
|||
|
|
|||
|
DataManager& GetDataRoot()
|
|||
|
{
|
|||
|
static DataManager dataMgr;
|
|||
|
return dataMgr;
|
|||
|
}
|
|||
|
|
|||
|
DataManager::DataManager()
|
|||
|
{
|
|||
|
// pTheDBPlatform = new DBPlatformSpace::DBPlatformNew();
|
|||
|
|
|||
|
platformData.insert(DataType::project, mapProject);
|
|||
|
platformData.insert(DataType::dataModel, mapDataModel);
|
|||
|
platformData.insert(DataType::dataPack, mapDataPack);
|
|||
|
platformData.insert(DataType::dataClass, mapDataClass);
|
|||
|
platformData.insert(DataType::dataAttribute, mapDataAttribute);
|
|||
|
}
|
|||
|
|
|||
|
DataManager::~DataManager()
|
|||
|
{
|
|||
|
if (pTheDBPlatform)
|
|||
|
{
|
|||
|
delete pTheDBPlatform;
|
|||
|
pTheDBPlatform = nullptr;
|
|||
|
}
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
|
|||
|
// while (!lastProject.isEmpty())
|
|||
|
// {
|
|||
|
// DPData* pdata = lastProject.back();
|
|||
|
// delete pdata;
|
|||
|
// pdata = nullptr;
|
|||
|
// }
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
|
|||
|
bool DataManager::addChild(DPData* pNewData)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
if (pNewData->saveSelf())
|
|||
|
{
|
|||
|
pNewData->_id = pNewData->_pDBDAO->_ID;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
_childrenMap.insert(pNewData->_id, pNewData);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>map
|
|||
|
insertDataMap(DataType::project, pNewData->_id, pNewData);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else {
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*ɾ<><C9BE>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ŀ*/
|
|||
|
bool DataManager::deleteChild(unsigned int id)
|
|||
|
{
|
|||
|
if (_childrenMap.remove(id))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*<2A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>*/
|
|||
|
void DataManager::getAllChildren(DPData*, bool)
|
|||
|
{
|
|||
|
const int MINCOUNT = 2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD><D0B5><EFBFBD>Ŀ
|
|||
|
std::list<M_ProjectDAO*> projectList;
|
|||
|
ResultMsg rm = M_ProjectDAO::FindAll(projectList);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_ProjectDAO::FindAll failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_ProjectDAO::FindAll success");
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾһ<CABE><D2BB>
|
|||
|
int listSize = static_cast<int>(projectList.size());
|
|||
|
int lastCount = listSize> MINCOUNT ? MINCOUNT : listSize;
|
|||
|
int addLastlist = 0;
|
|||
|
lastProject.clear();
|
|||
|
for (list<M_ProjectDAO*>::iterator it = projectList.begin(); it != projectList.end(); ++it)
|
|||
|
{
|
|||
|
ProjectData* pNew;
|
|||
|
bool addto = false;
|
|||
|
if (_childrenMap.contains((*it)->_ID))
|
|||
|
{
|
|||
|
pNew = qobject_cast<ProjectData*>(_childrenMap.value((*it)->_ID));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pNew = new ProjectData();
|
|||
|
addto = true;
|
|||
|
}
|
|||
|
pNew->loadData(*it);
|
|||
|
pNew->_parent = this;
|
|||
|
if (addto)
|
|||
|
{
|
|||
|
_childrenMap.insert(pNew->_id, pNew);
|
|||
|
insertDataMap(DataType::project, pNew->_id, pNew);
|
|||
|
}
|
|||
|
if (addLastlist < lastCount)
|
|||
|
{
|
|||
|
lastProject.append(pNew);
|
|||
|
addLastlist++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void DataManager::insertDataMap(DataType type, unsigned int id, DPData* pData)
|
|||
|
{
|
|||
|
platformData[type].insert(id, pData);
|
|||
|
}
|
|||
|
|
|||
|
void DataManager::deleteInDataMap(DataType type, unsigned int id)
|
|||
|
{
|
|||
|
platformData[type].remove(id);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
DPData* DataManager::findObjectById(DataType type, int id)
|
|||
|
{
|
|||
|
QMap<unsigned int, DPData*> map = platformData.value(type);
|
|||
|
if (map.contains(id))
|
|||
|
{
|
|||
|
return platformData.value(type).value(id);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return nullptr;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataManager::DataType DataManager::transformType(int type)
|
|||
|
{
|
|||
|
if (type == g_TYPE_DATAPACK)
|
|||
|
{
|
|||
|
return DataManager::DataType::dataPack;
|
|||
|
}
|
|||
|
else if (type == g_TYPE_DATACLASS)
|
|||
|
{
|
|||
|
return DataManager::DataType::dataClass;
|
|||
|
}
|
|||
|
else if (type == g_TYPE_DATAATTRUBUTE)
|
|||
|
{
|
|||
|
return DataManager::DataType::dataAttribute;
|
|||
|
}
|
|||
|
else if (type == g_TYPE_SCENEINFO)
|
|||
|
{
|
|||
|
return DataManager::DataType::scene;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>type<70><65><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD>Ʊ<EFBFBD>ʶ<EFBFBD><CAB6>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DPData* DataManager::findobjectByNameInDatamodel(int type, QString propertyName, QString name, int dataModelId)
|
|||
|
{
|
|||
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>map
|
|||
|
QMap<unsigned int, DPData*> dstDataMap = platformData.value(transformType(type));
|
|||
|
QMap<unsigned int, DPData*>::iterator it = dstDataMap.begin();
|
|||
|
while (it != dstDataMap.end())
|
|||
|
{
|
|||
|
QString vName = (*it)->property(CommonHelper::qstringToString(propertyName)).toString();
|
|||
|
if (vName == name)
|
|||
|
{
|
|||
|
DPData* pData = *it;
|
|||
|
//<2F><><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
if (pData->getDataModelOwner()->_id == dataModelId )
|
|||
|
{
|
|||
|
return (*it);
|
|||
|
}
|
|||
|
}
|
|||
|
it++;
|
|||
|
}
|
|||
|
return nullptr;
|
|||
|
}
|
|||
|
|
|||
|
void DataManager::getDataMap(DataType type, QMap<unsigned int, DPData*>& map)
|
|||
|
{
|
|||
|
map = platformData.value(type);
|
|||
|
}
|
|||
|
|
|||
|
void DataManager::clearAllProject()
|
|||
|
{
|
|||
|
qDeleteAll(_childrenMap);
|
|||
|
_childrenMap.clear();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|