Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

propertycollectionwidget.cpp 5.88 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
// 
// ================================================================================================

25
26
#include "propertycollectionwidget.h"

schultezub's avatar
schultezub committed
27
28
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
29
#include "core/datastructures/datacontainer.h"
30
31
32
#include "core/properties/abstractproperty.h"
#include "core/properties/propertycollection.h"

33
#include <QMetaType>
34
35
#include <QPushButton>

schultezub's avatar
schultezub committed
36
namespace campvis {
37
38
39
    PropertyCollectionWidget::PropertyCollectionWidget(QWidget* parent /*= 0*/)
        : QWidget(parent)
        , _propCollection(0)
40
        , _dataContainer(0)
41
42
43
44
45
46
        , _layout(0)
    {
        setupWidget();
    }

    PropertyCollectionWidget::~PropertyCollectionWidget() {
47
        clearWidgetMap();
48
49
    }

50
    void PropertyCollectionWidget::updatePropCollection(HasPropertyCollection* propertyCollection, DataContainer* dc) {
51
        // remove and delete all widgets of the previous PropertyCollection
52
        clearWidgetMap();
53
        
54
55
56
        _propCollection = propertyCollection;
        _dataContainer = dc;

57
        // create widgets for the new PropertyCollection
schultezub's avatar
schultezub committed
58
59
        if (propertyCollection != 0) {
            for (std::vector<AbstractProperty*>::const_iterator it = propertyCollection->getProperties().begin(); it != propertyCollection->getProperties().end(); ++it) {
60
61
62
63
64
                addProperty(*it);
            } 

            propertyCollection->s_propertyAdded.connect(this, &PropertyCollectionWidget::onPropCollectionPropAdded);
            propertyCollection->s_propertyRemoved.connect(this, &PropertyCollectionWidget::onPropCollectionPropRemoved);
65
        }
66
        _layout->addStretch(1);
67
68
69
70
    }

    void PropertyCollectionWidget::setupWidget() {
        _layout = new QVBoxLayout();
71
        _layout->setSpacing(8);
72
        _layout->setMargin(0);
73
        setLayout(_layout);
74
        connect(this, SIGNAL(s_propertyVisibilityChanged(const AbstractProperty*)), this, SLOT(onWidgetVisibilityChanged(const AbstractProperty*)), Qt::QueuedConnection);
75
        connect(this, SIGNAL(propertyAdded(AbstractProperty*)), this, SLOT(addProperty(AbstractProperty*)));
76
        connect(this, SIGNAL(propertyRemoved(AbstractProperty*, QWidget*)), this, SLOT(removeProperty(AbstractProperty*, QWidget*)));
77
78
    }

79
80
    void PropertyCollectionWidget::clearWidgetMap() {
        for (std::map<AbstractProperty*, QWidget*>::iterator it = _widgetMap.begin(); it != _widgetMap.end(); ++it) {
81
82
            it->first->s_visibilityChanged.disconnect(this);
            removeProperty(it->first, it->second);
83
84
85
        }

        _widgetMap.clear();
86
87
88
89
90

        if (_propCollection != 0) {
            _propCollection->s_propertyAdded.disconnect(this);
            _propCollection->s_propertyRemoved.disconnect(this);
        }
91
92
93
    }

    void PropertyCollectionWidget::onPropertyVisibilityChanged(const AbstractProperty* prop) {
94
95
96
97
98
99
100
101
        // This method is not always called on the main thread, so it is not safe to check anything here.
        // The event is instead forwarded using the QT sigslot mechanism through a queued connection to the
        // main thread.

        emit s_propertyVisibilityChanged(prop);
    }

    void PropertyCollectionWidget::onWidgetVisibilityChanged(const AbstractProperty* prop) {
102
103
104
        // const_cast does not harm anything.
        std::map<AbstractProperty*, QWidget*>::iterator item = _widgetMap.find(const_cast<AbstractProperty*>(prop));
        if (item != _widgetMap.end())
105
            item->second->setVisible(item->first->isVisible());
106
107
    }

108
109
110
111
112
113
    void PropertyCollectionWidget::onPropCollectionPropAdded(AbstractProperty* prop) {
        emit propertyAdded(prop);
    }

    void PropertyCollectionWidget::onPropCollectionPropRemoved(AbstractProperty* prop) {
        std::map<AbstractProperty*, QWidget*>::iterator it = _widgetMap.find(prop);
114
115
116
117
        if (it != _widgetMap.end()) {
            emit propertyRemoved(it->first, it->second);
            _widgetMap.erase(it);
        }
118
119
120
    }

    void PropertyCollectionWidget::addProperty(AbstractProperty* prop) {
121
        QWidget* propWidget = PropertyWidgetFactory::getRef().createWidget(prop, _dataContainer);
122
123
124
125
126
        if (propWidget == 0)
            propWidget = new QPushButton(QString::fromStdString(prop->getTitle()));

        _widgetMap.insert(std::make_pair(prop, propWidget));
        _layout->addWidget(propWidget);
127

128
        prop->s_visibilityChanged.connect(this, &PropertyCollectionWidget::onPropertyVisibilityChanged);
129
        prop->s_visibilityChanged.emitSignal(prop);
130
131
    }

132
133
134
135
    void PropertyCollectionWidget::removeProperty(AbstractProperty* prop, QWidget* widget) {
        prop->s_visibilityChanged.disconnect(this);
        _layout->removeWidget(widget);
        delete widget;
136
137
    }

138
}