You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/FITK_Kernel/FITKAppFramework/FITKGlobalData.cpp

91 lines
2.3 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "FITKGlobalData.h"
#include "FITKRunTimeSetting.h"
#include "FITKKeyMouseStates.h"
#include "FITKCore/FITKAbstractDataObject.h"
#include <QWidget>
namespace AppFrame
{
QMutex FITKGlobalData::_mutex;
FITKGlobalData::FITKGlobalData()
{
_runtimeSetting = new FITKRunTimeSetting;
_keyMouseStates = new FITKKeyMouseStates;
}
FITKGlobalData::~FITKGlobalData()
{
//释放全部内存
auto gloData = _gData.values();
for (auto d : gloData)
delete d;
_gData.clear();
if (_runtimeSetting) delete _runtimeSetting;
if (_keyMouseStates) delete _keyMouseStates;
}
void FITKGlobalData::setMainWindow(QWidget* mw)
{
// 将mw赋值给私有成员变量_mainwindow保存主窗口的指针。
_mainwindow = mw;
if (_mainwindow)
connect(_mainwindow, &QWidget::destroyed, this, [&] {_mainwindow = nullptr; });
}
QWidget* FITKGlobalData::getMainWindow()
{
// 直接返回私有成员变量_mainwindow的值即当前主窗口的指针。
return _mainwindow;
}
AppFrame::FITKRunTimeSetting* FITKGlobalData::getRunTimeSetting()
{
// 直接返回私有成员变量_runtimeSetting的值即指向运行时设置对象的指针。
return _runtimeSetting;
}
FITKKeyMouseStates* FITKGlobalData::getKeyMouseStates()
{
return _keyMouseStates;
}
QList<int> FITKGlobalData::getGlobalDataIDs()
{
const QList<Core::FITKAbstractDataObject*> objs = _gData.values();
QList<int> ids;
for (Core::FITKAbstractDataObject* obj : objs)
{
if(obj == nullptr) continue;
ids.append(obj->getDataObjectID());
}
return ids;
}
void FITKGlobalData::insertData(int dt, Core::FITKAbstractDataObject* d)
{
//空指针,不操作
if (d == nullptr) return;
//数据存在,先删除原来数据
if (_gData.contains(dt))
{
auto d = _gData.value(dt);
_gData.remove(dt);
if (d) delete d;
}
//插入数据管理
_gData.insert(dt, d);
}
// void FITKGlobalData::mainWindowDestorySlot(QObject* obj)
// {
// if(_mainwindow == obj)
// _mainwindow = nullptr;
// }
}