Commit 53765b39 authored by CAMP C++ Builder's avatar CAMP C++ Builder

core API: StatusProperty and StatusPropertyWidget and required changes to AbstractPropertyWidget

parent 37ac01ea
...@@ -62,6 +62,7 @@ SET(CampvisApplicationToBeMocced ...@@ -62,6 +62,7 @@ SET(CampvisApplicationToBeMocced
gui/properties/propertycollectionwidget.h gui/properties/propertycollectionwidget.h
gui/properties/simpletransferfunctioneditor.h gui/properties/simpletransferfunctioneditor.h
gui/properties/stringpropertywidget.h gui/properties/stringpropertywidget.h
gui/properties/statuspropertywidget.h
gui/properties/transferfunctionpropertywidget.h gui/properties/transferfunctionpropertywidget.h
tools/qtexteditlog.h tools/qtexteditlog.h
tools/bufferinglog.h tools/bufferinglog.h
......
...@@ -67,8 +67,8 @@ namespace campvis { ...@@ -67,8 +67,8 @@ namespace campvis {
_property->s_changed.disconnect(this); _property->s_changed.disconnect(this);
} }
void AbstractPropertyWidget::addWidget(QWidget* widget) { void AbstractPropertyWidget::addWidget(QWidget* widget, int stretch) {
_layout->addWidget(widget, 1); _layout->addWidget(widget, stretch);
} }
void AbstractPropertyWidget::onPropertyChanged(const AbstractProperty* property) { void AbstractPropertyWidget::onPropertyChanged(const AbstractProperty* property) {
......
...@@ -63,7 +63,7 @@ namespace campvis { ...@@ -63,7 +63,7 @@ namespace campvis {
/** /**
* Adds a widget to the local Qt layout. * Adds a widget to the local Qt layout.
*/ */
void addWidget(QWidget* widget); void addWidget(QWidget* widget, int stretch = 1);
AbstractProperty* _property; ///< The property this widget handles AbstractProperty* _property; ///< The property this widget handles
DataContainer* _dataContainer; ///< DataContainer to use (e.g. to populate GUI), may be 0! DataContainer* _dataContainer; ///< DataContainer to use (e.g. to populate GUI), may be 0!
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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
//
// 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.
//
// ================================================================================================
#include "statuspropertywidget.h"
#include <QLabel>
namespace campvis {
const char * StatusPropertyWidget::baseStyle = "text-align: center; padding: 1px; font-weight: bold;";
StatusPropertyWidget::StatusPropertyWidget(StatusProperty * property, DataContainer* dataContainer /*= nullptr*/, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, false, dataContainer, parent)
{
_statusLabel = new QLabel(this);
_statusLabel->setText(QString::fromStdString(property->getValue().string));
_statusLabel->setStyleSheet(getStyleFromStatusType(property->getValue().status));
_statusLabel->setMinimumWidth(100);
_statusLabel->setMaximumWidth(100);
_statusLabel->setAlignment(Qt::AlignCenter);
addWidget(new QWidget(this), 1); //spacer item to force right-alignment
addWidget(_statusLabel, 0);
//_statusLabel->setStyleSheet();
}
StatusPropertyWidget::~StatusPropertyWidget() {
}
void StatusPropertyWidget::updateWidgetFromProperty() {
StatusProperty * prop = static_cast<StatusProperty*>(_property);
QString qs = QString::fromStdString(prop->getValue().string);
_statusLabel->setText(qs);
_statusLabel->setStyleSheet(getStyleFromStatusType(prop->getValue().status));
}
QString StatusPropertyWidget::getStyleFromStatusType(Status::StatusType type) const {
switch (type) {
case Status::UNKNOWN:
return QString("color: black; background-color: grey; border: 1px solid black;") + baseStyle;
case Status::OK:
return QString("color: black; background-color: green; border: 1px solid darkgreen;") + baseStyle;
case Status::WARNING:
return QString("color: black; background-color: orange; border: 1px solid darkorange;") + baseStyle;
case Status::CRITICAL:
return QString("color: black; background-color: red; border: 1px solid darkred; text-align: center; padding: 2px;") + baseStyle;
default:
return QString("color: black; background-color: white; border: 1px solid grey;") + baseStyle;
}
};
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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
//
// 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.
//
// ================================================================================================
#ifndef STATUSPROPERTYWIDGET_H__
#define STATUSPROPERTYWIDGET_H__
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "core/properties/statusproperty.h"
namespace campvis {
/**
* Widget for a StringProperty
*/
class StatusPropertyWidget : public AbstractPropertyWidget {
Q_OBJECT;
public:
/**
* Creates a new PropertyWidget for the property \a property.
* \param property The property the widget shall handle
* \param dataContainer DataContainer to use (optional), defaults to nullptr.
* \param parent Parent Qt widget
*/
StatusPropertyWidget(StatusProperty * property, DataContainer* dataContainer = nullptr, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~StatusPropertyWidget();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private:
static const char* baseStyle;
QString getStyleFromStatusType(Status::StatusType type) const;
QLabel * _statusLabel;
};
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
template class PropertyWidgetRegistrar<StatusPropertyWidget, StatusProperty>;
}
#endif // STATUSPROPERTYWIDGET_H__
...@@ -34,5 +34,6 @@ ...@@ -34,5 +34,6 @@
#include "core/properties/optionproperty.h" #include "core/properties/optionproperty.h"
#include "core/properties/stringproperty.h" #include "core/properties/stringproperty.h"
#include "core/properties/transferfunctionproperty.h" #include "core/properties/transferfunctionproperty.h"
#include "core/properties/statusproperty.h"
#endif // ALLPROPERTIES_H__ #endif // ALLPROPERTIES_H__
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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
//
// 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.
//
// ================================================================================================
#include "statusproperty.h"
namespace campvis {
const std::string StatusProperty::loggerCat_ = "CAMPVis.core.datastructures.StatusProperty";
StatusProperty::StatusProperty(const std::string& name, const std::string& title, const Status & value)
: GenericProperty<Status>(name, title, value)
{
}
StatusProperty::~StatusProperty() {
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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
//
// 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.
//
// ================================================================================================
#ifndef STATUSPROPERTY_H__
#define STATUSPROPERTY_H__
#include "core/properties/genericproperty.h"
#include <string>
#include <tuple>
namespace campvis {
// simple class to store status as a combination of string and type
struct Status {
public:
/// Enumeration of the possible status types
enum StatusType {
UNKNOWN,
OK,
WARNING,
CRITICAL
};
Status(std::string string_arg, StatusType status_arg)
: string(string_arg)
, status(status_arg)
{};
bool operator==(const Status & rhs) {
return status == rhs.status && string == rhs.string;
};
bool operator!=(const Status &rhs) {
return status != rhs.status || string != rhs.string;
};
std::string string;
StatusType status;
};
class CAMPVIS_CORE_API StatusProperty : public GenericProperty<Status> {
public:
/**
* Creates a new StatusProperty
* \param name Property name (unchangable!)
* \param title Property title (e.g. used for GUI)
* \param value Initial value
*/
StatusProperty(const std::string& name, const std::string& title, const Status & value = Status(std::string(""), Status::UNKNOWN));
/**
* Virtual Destructor
**/
virtual ~StatusProperty();
// convenience setter
void setStatus(std::string str, Status::StatusType status)
{
setValue(Status(str, status));
};
protected:
static const std::string loggerCat_;
};
}
#endif // STATUSPROPERTY_H__
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