FreeCAD

Форк
0
/
PropertyEnumAttacherItem.cpp 
100 строк · 3.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2017 Peter Lama <peterldev94@gmail.com>                 *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include "PreCompiled.h"
25

26
#ifndef _PreComp_
27
# ifdef _MSC_VER
28
#  define _USE_MATH_DEFINES
29
#  include <cmath>
30
# endif //_MSC_VER
31
#endif // _PreComp_
32

33
#include <Gui/Application.h>
34
#include <Gui/Control.h>
35
#include <Gui/ViewProviderDocumentObject.h>
36

37
#include "PropertyEnumAttacherItem.h"
38

39
using namespace PartGui;
40

41
PROPERTYITEM_SOURCE(PartGui::PropertyEnumAttacherItem)
42

43
PropertyEnumAttacherItem::PropertyEnumAttacherItem() = default;
44

45
QWidget* PropertyEnumAttacherItem::createEditor(QWidget* parent,
46
                                                const std::function<void()>& method) const
47
{
48
    Gui::LabelButton* modeEditor = new Gui::LabelButton(parent);
49
    QObject::connect(modeEditor, &Gui::LabelButton::valueChanged, method);
50
    QObject::connect(modeEditor, &Gui::LabelButton::buttonClicked, this, &PropertyEnumAttacherItem::openTask);
51
    modeEditor->setDisabled(isReadOnly());
52
    return modeEditor;
53
}
54

55
void PropertyEnumAttacherItem::setEditorData(QWidget *editor, const QVariant& data) const
56
{
57
    Gui::LabelButton* modeEditor = qobject_cast<Gui::LabelButton*>(editor);
58
    modeEditor->setValue(data);
59
}
60

61
QVariant PropertyEnumAttacherItem::editorData(QWidget *editor) const
62
{
63
    Gui::LabelButton* modeEditor = qobject_cast<Gui::LabelButton*>(editor);
64
    return modeEditor->value();
65
}
66

67
void PropertyEnumAttacherItem::openTask()
68
{
69
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
70
    TaskDlgAttacher* task;
71
    task = qobject_cast<TaskDlgAttacher*>(dlg);
72

73
    if (dlg && !task) {
74
        // there is already another task dialog which must be closed first
75
        Gui::Control().showDialog(dlg);
76
        return;
77
    }
78
    if (!task) {
79
        const App::Property* prop = getFirstProperty();
80
        if (prop) {
81
            App::PropertyContainer* parent = prop->getContainer();
82

83
            if (parent->isDerivedFrom<App::DocumentObject>()) {
84
                App::DocumentObject* obj = static_cast<App::DocumentObject*>(parent);
85
                Gui::ViewProvider* view = Gui::Application::Instance->getViewProvider(obj);
86

87
                if (view->isDerivedFrom<Gui::ViewProviderDocumentObject>()) {
88
                    task = new TaskDlgAttacher(static_cast<Gui::ViewProviderDocumentObject*>(view));
89
                }
90
            }
91
        }
92
        if (!task) {
93
            return;
94
        }
95
    }
96

97
    Gui::Control().showDialog(task);
98
}
99

100
#include "moc_PropertyEnumAttacherItem.cpp"
101

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

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

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

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