2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

datanamepropertywidget.cpp 4.61 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
11
12
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
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
27
28
29
30
31
32
33
// 
// ================================================================================================

#include "datanamepropertywidget.h"
#include "core/datastructures/datacontainer.h"
#include "core/properties/datanameproperty.h"

#include <QComboBox>
#include <QLineEdit>

namespace campvis {
    DataNamePropertyWidget::DataNamePropertyWidget(DataNameProperty* property, DataContainer* dc, QWidget* parent /*= 0*/)
34
        : AbstractPropertyWidget(property, false, dc, parent)
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        , _lineEdit(0)
        , _combobox(0)
    {
        if (property->getAccessInfo() == DataNameProperty::READ) {
            _combobox = new QComboBox(this);
            _combobox->setEditable(true);

            if (dc != 0) {
                std::vector< std::pair<std::string, DataHandle> > tmp = dc->getDataHandlesCopy();
                QStringList sl;
                for (size_t i = 0; i < tmp.size(); ++i)
                    sl.append(QString::fromStdString(tmp[i].first));
                _combobox->addItems(sl);
                dc->s_dataAdded.connect(this, &DataNamePropertyWidget::onDataAdded);
49
                connect(this, SIGNAL(s_dataAddedQt(const QString&, QtDataHandle)), this, SLOT(onDataAddedQt(const QString&, QtDataHandle)));
50

51
                setCurrentComboBoxText(QString::fromStdString(property->getValue()));
52
53
54
55
56
57
58
59
60
61
62
63
64
65
            }

            addWidget(_combobox);
            connect(_combobox, SIGNAL(editTextChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
        }
        else {
            _lineEdit = new QLineEdit(this);
            _lineEdit->setText(QString::fromStdString(property->getValue()));
            addWidget(_lineEdit);
            connect(_lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
        }
    }

    DataNamePropertyWidget::~DataNamePropertyWidget() {
66
67
        if (_dataContainer != 0 && static_cast<DataNameProperty*>(_property)->getAccessInfo() == DataNameProperty::READ)
            _dataContainer->s_dataAdded.disconnect(this);
68
69
70
71
72
    }

    void DataNamePropertyWidget::updateWidgetFromProperty() {
        DataNameProperty* prop = static_cast<DataNameProperty*>(_property);
        QString qs = QString::fromStdString(prop->getValue());
73
74
75
76
77
78
79

        if (prop->getAccessInfo() == DataNameProperty::READ) {
            _combobox->blockSignals(true);
            setCurrentComboBoxText(qs);
            _combobox->blockSignals(false);
        }
        else if (_lineEdit->text() != qs) {
80
81
82
83
84
85
            _lineEdit->blockSignals(true);
            _lineEdit->setText(qs);
            _lineEdit->blockSignals(false);
        }
    }

86
87
88
89
90
91
92
93
94
    void DataNamePropertyWidget::setCurrentComboBoxText(const QString& text) {
        int idx = _combobox->findText(text);

        if (idx != -1)
            _combobox->setCurrentIndex(idx);
        else
            _combobox->setEditText(text);
    }

95
96
97
98
99
100
101
    void DataNamePropertyWidget::onTextChanged(const QString& text) {
        DataNameProperty* prop = static_cast<DataNameProperty*>(_property);
        ++_ignorePropertyUpdates;
        prop->setValue(text.toStdString());
        --_ignorePropertyUpdates;
    }

102
103
104
105
106
107
108
    void DataNamePropertyWidget::onDataAdded(const std::string& key, DataHandle dh) {
        emit s_dataAddedQt(QString::fromStdString(key), dh);
    }

    void DataNamePropertyWidget::onDataAddedQt(const QString& key, QtDataHandle dh) {
        if (_combobox->findText(key) == -1) {
            _combobox->addItem(key);
109
110
111
112
        }
    }


113
}