Commit a89b5e15 authored by schultezub's avatar schultezub
Browse files

Finally, OptionPropertyWidget is there! :)

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@424 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 5c930d64
......@@ -36,6 +36,7 @@ SET(CampvisApplicationToBeMocced
gui/properties/floatpropertywidget.h
gui/properties/geometry1dtransferfunctioneditor.h
gui/properties/geometry2dtransferfunctioneditor.h
gui/properties/optionpropertywidget.h
gui/properties/propertycollectionwidget.h
gui/properties/simpletransferfunctioneditor.h
gui/properties/stringpropertywidget.h
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "optionpropertywidget.h"
#include <QComboBox>
#include "core/properties/optionproperty.h"
namespace campvis {
OptionPropertyWidget::OptionPropertyWidget(AbstractOptionProperty* property, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, parent)
, _comboBox(0)
{
_comboBox = new QComboBox(this);
updateWidgetFromProperty();
addWidget(_comboBox);
connect(_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxIndexChanged(int)));
}
OptionPropertyWidget::~OptionPropertyWidget() {
static_cast<IntProperty*>(_property)->s_minMaxChanged.disconnect(this);
}
void OptionPropertyWidget::updateWidgetFromProperty() {
AbstractOptionProperty* prop = static_cast<AbstractOptionProperty*>(_property);
_comboBox->blockSignals(true);
_comboBox->clear();
// build combo box from descriptions
std::vector< std::pair<std::string, std::string> > options = prop->getOptionsAsPairOfStrings();
for (std::vector< std::pair<std::string, std::string> >::iterator it = options.begin(); it != options.end(); ++it) {
_comboBox->addItem(QString::fromStdString(it->second), QString::fromStdString(it->first));
}
// set selected options
_comboBox->setCurrentIndex(prop->getValue());
_comboBox->blockSignals(false);
_comboBox->blockSignals(false);
}
void OptionPropertyWidget::onComboBoxIndexChanged(int value) {
_ignorePropertyUpdates = true;
AbstractOptionProperty* prop = static_cast<AbstractOptionProperty*>(_property);
prop->setValue(value);
_ignorePropertyUpdates = false;
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef OPTIONPROPERTYWIDGET_H__
#define OPTIONPROPERTYWIDGET_H__
#include "application/gui/properties/abstractpropertywidget.h"
#include "core/properties/optionproperty.h"
class QComboBox;
namespace campvis {
class AbstractOptionProperty;
/**
* Widget for a IntProperty
*/
class OptionPropertyWidget : public AbstractPropertyWidget {
Q_OBJECT;
public:
/**
* Creates a new OptionPropertyWidget for the property \a property.
* \param property The property the widget shall handle
* \param parent Parent Qt widget
*/
OptionPropertyWidget(AbstractOptionProperty* property, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~OptionPropertyWidget();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private slots:
void onComboBoxIndexChanged(int value);
private:
QComboBox* _comboBox;
};
}
#endif // OPTIONPROPERTYWIDGET_H__
......@@ -34,12 +34,14 @@
#include "application/gui/properties/camerapropertywidget.h"
#include "application/gui/properties/intpropertywidget.h"
#include "application/gui/properties/floatpropertywidget.h"
#include "application/gui/properties/optionpropertywidget.h"
#include "application/gui/properties/stringpropertywidget.h"
#include "application/gui/properties/transferfunctionpropertywidget.h"
#include "core/properties/abstractproperty.h"
#include "core/properties/cameraproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
#include "core/properties/transferfunctionproperty.h"
......@@ -52,6 +54,11 @@ namespace campvis {
return new BoolPropertyWidget(tester);
}
// OptionProperty must test before IntProperty
if (AbstractOptionProperty* tester = dynamic_cast<AbstractOptionProperty*>(property)) {
return new OptionPropertyWidget(tester);
}
if (IntProperty* tester = dynamic_cast<IntProperty*>(property)) {
return new IntPropertyWidget(tester);
}
......
......@@ -58,6 +58,12 @@ namespace campvis {
* Pure virtual destructor.
*/
virtual ~AbstractOptionProperty() = 0 {};
/**
* Returns all Options als pair of std::strings.
* \return A vector of the options encoded as pair (id, title).
*/
virtual std::vector< std::pair<std::string, std::string> > getOptionsAsPairOfStrings() const = 0;
};
template<typename T>
......@@ -122,6 +128,9 @@ namespace campvis {
*/
const std::vector< GenericOption<T> >& getOptions() const;
/// \see AbstractOptionProperty::getOptionsAsPairOfStrings()
virtual std::vector< std::pair<std::string, std::string> > getOptionsAsPairOfStrings() const;
/**
* Returns the currently selected option.
* \return _options[_value]
......@@ -177,6 +186,15 @@ namespace campvis {
return _options;
}
template<typename T>
std::vector< std::pair<std::string, std::string> > campvis::GenericOptionProperty<T>::getOptionsAsPairOfStrings() const {
std::vector< std::pair<std::string, std::string> > toReturn;
for (std::vector< GenericOption<T> >::const_iterator it = _options.begin(); it != _options.end(); ++it) {
toReturn.push_back(std::make_pair(it->_id, it->_title));
}
return toReturn;
}
template<typename T>
const GenericOption<T>& campvis::GenericOptionProperty<T>::getOption() const {
return _options[getValue()];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment