FreeCAD

Форк
0
/
View.cpp 
99 строк · 3.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de>              *
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
#include "View.h"
27
#include "Application.h"
28
#include "Document.h"
29

30
using namespace Gui;
31

32
//**************************************************************************
33
// BaseView
34
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35

36
TYPESYSTEM_SOURCE_ABSTRACT(Gui::BaseView,Base::BaseClass)
37

38

39
BaseView::BaseView( Gui::Document* pcDocument)
40
  :_pcDocument(pcDocument)
41
{
42
    if (pcDocument){
43
        pcDocument->attachView(this);
44
        bIsPassive = false;
45
    }
46
    else{
47
        Application::Instance->attachView(this);
48
        bIsPassive = true;
49
    }
50
}
51

52
BaseView::~BaseView()
53
{
54
    onClose();
55
}
56

57
void BaseView::onClose()
58
{
59
    if (bIsDetached)
60
        return;
61

62
    if (bIsPassive) {
63
        Application::Instance->detachView(this);
64
        if (_pcDocument)
65
            _pcDocument->detachView(this, true);
66
    }
67
    else {
68
        if (_pcDocument)
69
            _pcDocument->detachView(this);
70
    }
71

72
    _pcDocument = nullptr;
73
    bIsDetached = true;
74
}
75

76
void BaseView::deleteSelf()
77
{
78
    delete this;
79
}
80

81
void BaseView::setDocument(Gui::Document* pcDocument)
82
{
83
    if (_pcDocument == pcDocument)
84
        return;
85
    // detaches and attaches the observer
86
    if (_pcDocument)
87
        _pcDocument->detachView(this, true);
88
    if (pcDocument)
89
        pcDocument->attachView(this,true);
90

91
    // set the new document as the active one
92
    _pcDocument = pcDocument;
93
}
94

95
/// returns the document the view is attached to
96
App::Document* BaseView::getAppDocument() const
97
{
98
    return _pcDocument ? _pcDocument->getDocument() : nullptr;
99
}
100

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

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

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

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