abstractpropertywidget.cpp 3.07 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-2013, 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 Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, 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
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
27
#include "abstractpropertywidget.h"
#include "core/properties/abstractproperty.h"

28
29
#include <QGroupBox>

schultezub's avatar
schultezub committed
30
namespace campvis {
schultezub's avatar
schultezub committed
31

32
33
    AbstractPropertyWidget::AbstractPropertyWidget(AbstractProperty* property, bool displayBoxed /*= false*/,
                                                   QWidget* parent /*= 0*/)
schultezub's avatar
schultezub committed
34
35
36
37
        : QWidget(parent)
        , _property(property)
        , _layout(0)
    {
schultezub's avatar
schultezub committed
38
39
        _ignorePropertyUpdates = 0;

40
41
42
43
        if (displayBoxed) {
            QBoxLayout* outerLayout = new QBoxLayout(QBoxLayout::LeftToRight, this);
            QGroupBox* groupBox = new QGroupBox(QString::fromStdString(_property->getTitle()));

44
            outerLayout->setMargin(4);
45
            outerLayout->addWidget(groupBox);
46

47
            _layout = new QBoxLayout(QBoxLayout::TopToBottom, groupBox);
48
49
            _layout->setSpacing(1);
            _layout->setMargin(3);
50
51
52
        }
        else {
            _titleLabel = new QLabel(QString::fromStdString(_property->getTitle() + ":"), this);
53

54
55
            _layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
            _layout->setSpacing(8);
56
            _layout->setMargin(4);
57
58
            _layout->addWidget(_titleLabel, 0);
        }
schultezub's avatar
schultezub committed
59
60

        _property->s_changed.connect(this, &AbstractPropertyWidget::onPropertyChanged);
61
        // cppcheck-suppress pureVirtualCall
62
        connect(this, SIGNAL(s_propertyChanged(const AbstractProperty*)), this, SLOT(updateWidgetFromProperty()));
schultezub's avatar
schultezub committed
63
64
65
66
67
68
69
70
71
72
73
    }

    AbstractPropertyWidget::~AbstractPropertyWidget() {
        _property->s_changed.disconnect(this);
    }

    void AbstractPropertyWidget::addWidget(QWidget* widget) {
        _layout->addWidget(widget, 1);
    }

    void AbstractPropertyWidget::onPropertyChanged(const AbstractProperty* property) {
schultezub's avatar
schultezub committed
74
        if (_ignorePropertyUpdates == 0)
75
            emit s_propertyChanged(property);
schultezub's avatar
schultezub committed
76
    }
77
}