FreeCAD

Форк
0
/
ParamHandler.cpp 
61 строка · 2.6 Кб
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
#endif
25

26
#include "ParamHandler.h"
27

28
using namespace Gui;
29

30
ParamHandlers::ParamHandlers()
31
{
32
}
33

34
ParamHandlers::~ParamHandlers()
35
{
36
}
37

38
void ParamHandlers::addHandler(const ParamKey &key, const std::shared_ptr<ParamHandler> &handler)
39
{
40
    if (handlers.empty()) {
41
        conn = App::GetApplication().GetUserParameter().signalParamChanged.connect(
42
            [this](ParameterGrp *Param, ParameterGrp::ParamType, const char *Name, const char *) {
43
                if (!Param || !Name)
44
                    return;
45
                auto it =  handlers.find(ParamKey(Param, Name));
46
                if (it != handlers.end() && it->second->onChange(&it->first)) {
47
                    pendings.insert(it->second);
48
                    timer.start(100);
49
                }
50
            });
51

52
        timer.setSingleShot(true);
53
        QObject::connect(&timer, &QTimer::timeout, [this]() {
54
            for (const auto &v : pendings) {
55
                v->onTimer();
56
            }
57
            pendings.clear();
58
        });
59
    }
60
    handlers[key] = handler;
61
}
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.