FreeCAD
1/****************************************************************************2* Copyright (c) 2023 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
3* *
4* This file is part of the FreeCAD CAx development system. *
5* *
6* FreeCAD is free software: you can redistribute it and/or modify it *
7* under the terms of the GNU Lesser General Public License as *
8* published by the Free Software Foundation, either version 2.1 of the *
9* License, or (at your option) any later version. *
10* *
11* FreeCAD is distributed in the hope that it will be useful, but *
12* WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14* Lesser General Public License for more details. *
15* *
16* You should have received a copy of the GNU Lesser General Public *
17* License along with FreeCAD. If not, see *
18* <https://www.gnu.org/licenses/>. *
19* *
20***************************************************************************/
21
22#include "PreCompiled.h"23#ifndef _PreComp_24#endif25
26#include "ParamHandler.h"27
28using namespace Gui;29
30ParamHandlers::ParamHandlers()31{
32}
33
34ParamHandlers::~ParamHandlers()35{
36}
37
38void ParamHandlers::addHandler(const ParamKey &key, const std::shared_ptr<ParamHandler> &handler)39{
40if (handlers.empty()) {41conn = App::GetApplication().GetUserParameter().signalParamChanged.connect(42[this](ParameterGrp *Param, ParameterGrp::ParamType, const char *Name, const char *) {43if (!Param || !Name)44return;45auto it = handlers.find(ParamKey(Param, Name));46if (it != handlers.end() && it->second->onChange(&it->first)) {47pendings.insert(it->second);48timer.start(100);49}50});51
52timer.setSingleShot(true);53QObject::connect(&timer, &QTimer::timeout, [this]() {54for (const auto &v : pendings) {55v->onTimer();56}57pendings.clear();58});59}60handlers[key] = handler;61}
62