Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 0d12f058 authored by schultezub's avatar schultezub
Browse files

* introduced enabled state in AbstractProcessor and AbstractPipeline

 * added enabled state column to PipelineTreeWidget

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@261 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent c45e4354
......@@ -34,6 +34,12 @@
namespace TUMVis {
namespace {
const int COLUMN_NAME = 0;
const int COLUMN_ENABLED_STATE = 1;
const int COLUMN_DESCRIPTION = 2;
}
// = TreeModel items ==============================================================================
TreeItem::TreeItem(TreeItem* parent /*= 0*/)
......@@ -65,7 +71,12 @@ namespace TUMVis {
int TreeItem::getChildCount() {
return _children.count();
}
bool TreeItem::setData(int column, int role, const QVariant& value) const {
return false;
}
PipelineTreeItem::PipelineTreeItem(AbstractPipeline* pipeline, TreeItem* parent)
: TreeItem(parent)
, _pipeline(pipeline)
......@@ -76,8 +87,15 @@ namespace TUMVis {
QVariant PipelineTreeItem::getData(int column, int role) const {
switch (role) {
case Qt::DisplayRole:
if (column == 0)
if (column == COLUMN_NAME)
return QVariant(QString::fromStdString(_pipeline->getName()));
else
return QVariant();
case Qt::CheckStateRole:
if (column == COLUMN_ENABLED_STATE)
return _pipeline->getEnabled() ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
else
return QVariant();
case Qt::UserRole:
return qVariantFromValue(static_cast<void*>(_pipeline));
default:
......@@ -88,6 +106,16 @@ namespace TUMVis {
PipelineTreeItem::~PipelineTreeItem() {
}
bool PipelineTreeItem::setData(int column, int role, const QVariant& value) const {
if (column == COLUMN_ENABLED_STATE) {
if (role == Qt::CheckStateRole) {
_pipeline->setEnabled(value == Qt::Checked ? true : false);
return true;
}
}
return false;
}
ProcessorTreeItem::ProcessorTreeItem(AbstractProcessor* processor, TreeItem* parent)
: TreeItem(parent)
......@@ -99,10 +127,17 @@ namespace TUMVis {
QVariant ProcessorTreeItem::getData(int column, int role) const {
switch (role) {
case Qt::DisplayRole:
if (column == 0)
if (column == COLUMN_NAME)
return QVariant(QString::fromStdString(_processor->getName()));
if (column == 1)
else if (column == COLUMN_DESCRIPTION)
return QVariant(QString::fromStdString(_processor->getDescription()));
else
return QVariant();
case Qt::CheckStateRole:
if (column == COLUMN_ENABLED_STATE)
return _processor->getEnabled() ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
else
return QVariant();
case Qt::UserRole:
return qVariantFromValue(static_cast<void*>(_processor));
default:
......@@ -113,16 +148,28 @@ namespace TUMVis {
ProcessorTreeItem::~ProcessorTreeItem() {
}
bool ProcessorTreeItem::setData(int column, int role, const QVariant& value) const {
if (column == COLUMN_ENABLED_STATE) {
if (role == Qt::CheckStateRole) {
_processor->setEnabled(value == Qt::Checked ? true : false);
return true;
}
}
return false;
}
RootTreeItem::RootTreeItem(TreeItem* parent /*= 0*/)
: TreeItem(parent)
{}
QVariant RootTreeItem::getData(int column, int role) const {
if (role == Qt::DisplayRole) {
if (column == 0)
if (column == COLUMN_NAME)
return QVariant(QString("Pipeline/Processor"));
else if (column == 1)
else if (column == COLUMN_DESCRIPTION)
return QVariant(QString("Description"));
else if (column == COLUMN_ENABLED_STATE)
return QVariant(QString("Enabled"));
}
return QVariant();
......@@ -152,11 +199,28 @@ namespace TUMVis {
return item->getData(index.column(), role);
}
bool PipelineTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) {
if (!index.isValid())
return false;
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
return item->setData(index.column(), role, value);
}
Qt::ItemFlags PipelineTreeModel::flags(const QModelIndex &index) const {
if (!index.isValid())
return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
switch (index.column()) {
case COLUMN_DESCRIPTION:
return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
case COLUMN_NAME:
return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
case COLUMN_ENABLED_STATE:
return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
}
return 0;
}
QVariant PipelineTreeModel::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/) const {
......@@ -211,7 +275,7 @@ namespace TUMVis {
}
int PipelineTreeModel::columnCount(const QModelIndex &parent /*= QModelIndex()*/) const {
return 2;
return 3;
}
void PipelineTreeModel::setData(const std::vector<AbstractPipeline*>& pipelines) {
......@@ -227,7 +291,6 @@ namespace TUMVis {
}
}
// = PipelineTreeWidget ===========================================================================
PipelineTreeWidget::PipelineTreeWidget(QWidget* parent /*= 0*/)
......@@ -243,6 +306,8 @@ namespace TUMVis {
void PipelineTreeWidget::update(const std::vector<AbstractPipeline*>& pipelines) {
_treeModel->setData(pipelines);
expandAll();
resizeColumnToContents(0);
resizeColumnToContents(1);
}
void PipelineTreeWidget::setupWidget() {
......@@ -250,7 +315,6 @@ namespace TUMVis {
tgtAssert(_treeModel != 0, "Failed creating TreeViewWidget model.");
setModel(_treeModel);
resizeColumnToContents(0);
}
}
\ No newline at end of file
......@@ -67,6 +67,16 @@ namespace TUMVis {
*/
virtual QVariant getData(int column, int role) const = 0;
/**
* Sets the data at the given column to \a value using the given role.
* Overwrite if needed, default implementation will only return false.
* \param column Column
* \param role Access role
* \param value Value to set
* \return false
*/
virtual bool setData(int column, int role, const QVariant& value) const;
/**
* Returns the parent TreeItem
* \return _parent
......@@ -120,6 +130,9 @@ namespace TUMVis {
/// \see TreeItem::getData()
virtual QVariant getData(int column, int role) const;
/// \see TreeItem::setData()
virtual bool setData(int column, int role, const QVariant& value) const;
private:
AbstractPipeline* _pipeline; ///< Base pipeline
};
......@@ -135,6 +148,9 @@ namespace TUMVis {
/// \see TreeItem::getData()
virtual QVariant getData(int column, int role) const;
/// \see TreeItem::setData()
virtual bool setData(int column, int role, const QVariant& value) const;
private:
AbstractProcessor* _processor; ///< Base processor
};
......@@ -154,6 +170,15 @@ namespace TUMVis {
void setData(const std::vector<AbstractPipeline*>& pipelines);
QVariant data(const QModelIndex &index, int role) const;
/**
* Sets the data at index \a index to \a value.
* \param index position where to set data
* \param value new data
* \param role edit role
**/
bool setData(const QModelIndex& index, const QVariant& value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
......
......@@ -87,7 +87,7 @@ namespace TUMVis {
void AbstractPipeline::executeProcessor(AbstractProcessor* processor) {
tgtAssert(processor != 0, "Processor must not be 0.");
if (! processor->getInvalidationLevel().isValid()) {
if (processor->getEnabled() && !processor->getInvalidationLevel().isValid()) {
processor->lockProperties();
processor->process(_data);
processor->unlockProperties();
......@@ -102,4 +102,12 @@ namespace TUMVis {
return _processors;
}
bool AbstractPipeline::getEnabled() const {
return _enabled;
}
void AbstractPipeline::setEnabled(bool enabled) {
_enabled = enabled;
}
}
......@@ -33,7 +33,6 @@
#include "tgt/logmanager.h"
#include "tbb/include/tbb/spin_mutex.h"
#include "tbb/include/tbb/mutex.h"
#include "tbb/include/tbb/compat/condition_variable"
#include "core/tools/invalidationlevel.h"
#include "core/datastructures/datacontainer.h"
#include "core/properties/propertycollection.h"
......@@ -106,6 +105,18 @@ namespace TUMVis {
*/
InvalidationLevel& getInvalidationLevel();
/**
* Gets the flag whether this pipeline is currently enabled.
* \return _enabled
*/
bool getEnabled() const;
/**
* Sets the flag whether this pipeline is currently enabled.
* \param enabled New flag whether this pipeline is currently enabled.
*/
void setEnabled(bool enabled);
/// Signal being emitted when this pipeline has been invalidated.
sigslot::signal0<> s_PipelineInvalidated;
......@@ -133,6 +144,7 @@ namespace TUMVis {
std::vector<AbstractProcessor*> _processors; ///< List of all processors of this pipeline
InvalidationLevel _invalidationLevel; ///< current invalidation level
bool _enabled; ///< flag whether this pipeline is currently enabled
tbb::spin_mutex _localMutex; ///< mutex for altering local members
tbb::mutex _evaluationMutex; ///< mutex for the evaluation of this pipeline
......
......@@ -76,4 +76,12 @@ namespace TUMVis {
applyInvalidationLevel(prop->getInvalidationLevel());
}
bool AbstractProcessor::getEnabled() const {
return _enabled;
}
void AbstractProcessor::setEnabled(bool enabled) {
_enabled = enabled;
}
}
......@@ -123,6 +123,18 @@ namespace TUMVis {
* \param il Invalidation level to apply.
*/
void applyInvalidationLevel(InvalidationLevel il);
/**
* Gets the flag whether this processor is currently enabled.
* \return _enabled
*/
bool getEnabled() const;
/**
* Sets the flag whether this processor is currently enabled.
* \param enabled New flag whether this processor is currently enabled.
*/
void setEnabled(bool enabled);
/**
* Locks all properties in the processor's PropertyCollection and marks them as "in use".
......@@ -149,7 +161,7 @@ namespace TUMVis {
protected:
InvalidationLevel _invalidationLevel; ///< current invalidation level of this processor
bool _enabled; ///< flag whether this processor is currently enabled
static const std::string loggerCat_;
......
......@@ -47,7 +47,8 @@ namespace TUMVis {
std::unique_lock<tbb::mutex> lock(_pipeline->_evaluationMutex);
while (! _stopExecution) {
_pipeline->execute();
if (_pipeline->getEnabled())
_pipeline->execute();
while (!_stopExecution && _pipeline->getInvalidationLevel().isValid())
_evaluationCondition.wait(lock);
......
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