38 return serviceRef ? context->GetService<T>(serviceRef) : NULL;
43 return QColor(color.GetRed() * 255, color.GetGreen() * 255, color.GetBlue() * 255);
48 return data.isValid() ?
reinterpret_cast<mitk::BaseProperty *
>(data.value<
void *>()) : NULL;
55 mitkColor.SetRed(color.red() / 255.0f);
56 mitkColor.SetGreen(color.green() / 255.0f);
57 mitkColor.SetBlue(color.blue() / 255.0f);
68 return pair.second.GetPointer() == m_Property;
76 : QAbstractItemModel(parent),
78 m_FilterProperties(false),
79 m_PropertyAliases(NULL),
80 m_PropertyFilters(NULL)
82 this->CreateRootItem();
87 this->SetNewPropertyList(NULL);
93 return static_cast<QmitkPropertyItem *>(parent.internalPointer())->GetColumnCount();
95 return m_RootItem->GetColumnCount();
98 void QmitkPropertyItemModel::CreateRootItem()
100 QList<QVariant> rootData;
101 rootData <<
"Property"
106 this->beginResetModel();
107 this->endResetModel();
112 if (!index.isValid())
116 index.column() == 1 ?
GetBaseProperty(static_cast<QmitkPropertyItem *>(index.internalPointer())->
GetData(1)) : NULL;
118 if (role == Qt::DisplayRole)
120 if (index.column() == 0)
124 else if (index.column() == 1 &&
property != NULL)
127 return MitkToQt(colorProperty->GetValue());
128 else if (dynamic_cast<mitk::BoolProperty *>(property) == NULL)
129 return QString::fromStdString(property->GetValueAsString());
132 else if (index.column() == 1 &&
property != NULL)
134 if (role == Qt::CheckStateRole)
137 return boolProperty->GetValue() ? Qt::Checked : Qt::Unchecked;
139 else if (role == Qt::EditRole)
141 if (dynamic_cast<mitk::StringProperty *>(property) != NULL)
143 return QString::fromStdString(property->GetValueAsString());
145 else if (
mitk::IntProperty *intProperty = dynamic_cast<mitk::IntProperty *>(property))
147 return intProperty->GetValue();
149 else if (
mitk::FloatProperty *floatProperty = dynamic_cast<mitk::FloatProperty *>(property))
151 return floatProperty->GetValue();
155 return doubleProperty->GetValue();
162 values << QString::fromStdString(it->second);
166 else if (
mitk::ColorProperty *colorProperty = dynamic_cast<mitk::ColorProperty *>(property))
168 return MitkToQt(colorProperty->GetValue());
173 return QVariant::fromValue<void *>(property);
182 if (property == NULL)
183 return QModelIndex();
186 const PropertyMap *propertyMap = m_PropertyList->
GetMap();
188 PropertyMap::const_iterator it = std::find_if(propertyMap->begin(), propertyMap->end(), PropertyEqualTo(property));
190 if (it == propertyMap->end())
191 return QModelIndex();
193 QString name = QString::fromStdString(it->first);
195 if (!name.contains(
'.'))
197 QModelIndexList item = this->match(
index(0, 0), Qt::DisplayRole, name, 1, Qt::MatchExactly);
204 QStringList names = name.split(
'.');
205 QModelIndexList items =
206 this->match(
index(0, 0), Qt::DisplayRole, names.last(), -1, Qt::MatchRecursive | Qt::MatchExactly);
208 foreach (QModelIndex item, items)
210 QModelIndex candidate = item;
212 for (
int i = names.length() - 1; i != 0; --i)
214 QModelIndex
parent = item.parent();
216 if (parent.parent() == QModelIndex())
218 if (parent.data() != names.first())
224 if (parent.data() != names[i - 1])
232 return QModelIndex();
237 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
239 if (index.column() == 1)
241 if (index.data(Qt::EditRole).isValid())
242 flags |= Qt::ItemIsEditable;
244 if (index.data(Qt::CheckStateRole).isValid())
245 flags |= Qt::ItemIsUserCheckable;
258 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
259 return m_RootItem->GetData(section);
266 if (!this->hasIndex(row, column, parent))
267 return QModelIndex();
270 parent.isValid() ?
static_cast<QmitkPropertyItem *
>(parent.internalPointer()) : m_RootItem.get();
274 return childItem != NULL ? this->createIndex(row, column, childItem) : QModelIndex();
279 bool updateAliases = m_ShowAliases != (m_PropertyAliases != NULL);
280 bool updateFilters = m_FilterProperties != (m_PropertyFilters != NULL);
282 bool resetPropertyList =
false;
286 m_PropertyAliases = m_ShowAliases ? GetPropertyService<mitk::IPropertyAliases>() : NULL;
288 resetPropertyList = m_PropertyList.
IsNotNull();
293 m_PropertyFilters = m_FilterProperties ? GetPropertyService<mitk::IPropertyFilters>() : NULL;
295 if (!resetPropertyList)
296 resetPropertyList = m_PropertyList.
IsNotNull();
299 if (resetPropertyList)
300 this->SetNewPropertyList(m_PropertyList.
GetPointer());
303 void QmitkPropertyItemModel::OnPropertyDeleted(
const itk::Object * ,
const itk::EventObject &)
311 void QmitkPropertyItemModel::OnPropertyListDeleted(
const itk::Object *)
313 this->CreateRootItem();
316 void QmitkPropertyItemModel::OnPropertyModified(
const itk::Object *property,
const itk::EventObject &)
318 QModelIndex
index = this->FindProperty(static_cast<const mitk::BaseProperty *>(property));
320 if (index != QModelIndex())
321 emit dataChanged(index, index);
326 if (!child.isValid())
327 return QModelIndex();
331 if (parentItem == m_RootItem.get())
332 return QModelIndex();
334 return this->createIndex(parentItem->
GetRow(), 0, parentItem);
339 if (parent.column() > 0)
343 parent.isValid() ?
static_cast<QmitkPropertyItem *
>(parent.internalPointer()) : m_RootItem.get();
350 if (!index.isValid() || index.column() != 1 || (role != Qt::EditRole && role != Qt::CheckStateRole))
355 if (property == NULL)
360 boolProperty->SetValue(value.toInt() == Qt::Checked ?
true :
false);
364 stringProperty->SetValue(value.toString().toStdString());
366 else if (
mitk::IntProperty *intProperty = dynamic_cast<mitk::IntProperty *>(property))
368 intProperty->SetValue(value.toInt());
370 else if (
mitk::FloatProperty *floatProperty = dynamic_cast<mitk::FloatProperty *>(property))
372 floatProperty->SetValue(value.toFloat());
376 doubleProperty->SetValue(value.toDouble());
380 std::string selection = value.toString().toStdString();
382 if (selection != enumProperty->GetValueAsString() && enumProperty->IsValidEnumerationValue(selection))
383 enumProperty->SetValue(selection);
385 else if (
mitk::ColorProperty *colorProperty = dynamic_cast<mitk::ColorProperty *>(property))
387 colorProperty->SetValue(
QtToMitk(value.value<QColor>()));
390 m_PropertyList->InvokeEvent(itk::ModifiedEvent());
391 m_PropertyList->Modified();
402 this->beginResetModel();
407 this, &QmitkPropertyItemModel::OnPropertyListDeleted);
410 const PropertyMap *propertyMap = m_PropertyList->
GetMap();
412 for (PropertyMap::const_iterator propertyIt = propertyMap->begin(); propertyIt != propertyMap->end(); ++propertyIt)
414 std::map<std::string, unsigned long>::const_iterator tagIt = m_PropertyModifiedTags.find(propertyIt->first);
416 if (tagIt != m_PropertyModifiedTags.end())
417 propertyIt->second->RemoveObserver(tagIt->second);
419 tagIt = m_PropertyDeletedTags.find(propertyIt->first);
421 if (tagIt != m_PropertyDeletedTags.end())
422 propertyIt->second->RemoveObserver(tagIt->second);
425 m_PropertyModifiedTags.clear();
426 m_PropertyDeletedTags.clear();
429 m_PropertyList = propertyList;
434 this, &QmitkPropertyItemModel::OnPropertyListDeleted);
438 this, &QmitkPropertyItemModel::OnPropertyModified);
442 modifiedCommand->SetCallbackFunction(
this, &QmitkPropertyItemModel::OnPropertyModified);
444 const PropertyMap *propertyMap = m_PropertyList->
GetMap();
446 for (PropertyMap::const_iterator it = propertyMap->begin(); it != propertyMap->end(); ++it)
447 m_PropertyModifiedTags.insert(
448 std::make_pair(it->first, it->second->AddObserver(itk::ModifiedEvent(), modifiedCommand)));
452 deletedCommand->SetCallbackFunction(
this, &QmitkPropertyItemModel::OnPropertyDeleted);
454 for (PropertyMap::const_iterator it = propertyMap->begin(); it != propertyMap->end(); ++it)
455 m_PropertyDeletedTags.insert(
456 std::make_pair(it->first, it->second->AddObserver(itk::DeleteEvent(), deletedCommand)));
459 this->CreateRootItem();
461 if (m_PropertyList != NULL && !m_PropertyList->
IsEmpty())
464 bool filterProperties =
false;
466 if (m_PropertyFilters != NULL &&
467 (m_PropertyFilters->
HasFilter() || m_PropertyFilters->
HasFilter(m_ClassName.toStdString())))
469 filteredProperties = m_PropertyFilters->
ApplyFilter(*m_PropertyList->
GetMap(), m_ClassName.toStdString());
470 filterProperties =
true;
474 !filterProperties ? m_PropertyList->
GetMap() : &filteredProperties;
476 mitk::PropertyList::PropertyMap::const_iterator end = propertyMap->end();
478 for (mitk::PropertyList::PropertyMap::const_iterator iter = propertyMap->begin(); iter != end; ++iter)
480 std::vector<std::string> aliases;
482 if (m_PropertyAliases != NULL)
484 aliases = m_PropertyAliases->
GetAliases(iter->first, m_ClassName.toStdString());
486 if (aliases.empty() && !m_ClassName.isEmpty())
487 aliases = m_PropertyAliases->
GetAliases(iter->first);
492 QList<QVariant>
data;
493 data << QString::fromStdString(iter->first)
494 << QVariant::fromValue((reinterpret_cast<void *>(iter->second.GetPointer())));
500 std::vector<std::string>::const_iterator end = aliases.end();
501 for (std::vector<std::string>::const_iterator aliasIter = aliases.begin(); aliasIter != end; ++aliasIter)
503 QList<QVariant>
data;
504 data << QString::fromStdString(*aliasIter)
505 << QVariant::fromValue((reinterpret_cast<void *>(iter->second.GetPointer())));
513 this->endResetModel();
518 if (m_PropertyList.
GetPointer() != propertyList)
520 m_ClassName = className;
521 this->SetNewPropertyList(propertyList);
527 this->SetNewPropertyList(m_PropertyList);
void RemoveListener(const AbstractDelegate &delegate) const
void AddListener(const AbstractDelegate &delegate) const
itk::SmartPointer< Self > Pointer
~QmitkPropertyItemModel()
int rowCount(const QModelIndex &parent=QModelIndex()) const override
std::pair< std::string, BaseProperty::Pointer > PropertyMapElementType
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
itkObjectEvent ObjectDelete
AddEvent is emitted when the object pointed to gets deleted.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual bool HasFilter(const std::string &className="") const =0
Check if a specific data node class name has a property filter.
virtual std::map< std::string, BaseProperty::Pointer > ApplyFilter(const std::map< std::string, BaseProperty::Pointer > &propertyMap, const std::string &className="") const =0
Apply property filter to property list.
Key-value list holding instances of BaseProperty.
QModelIndex parent(const QModelIndex &child) const override
int GetChildCount() const
mitk::PropertyList * GetPropertyList() const
static mitk::BaseProperty * GetBaseProperty(const QVariant &data)
ObjectType * GetPointer() const
T::Pointer GetData(const std::string &name)
virtual std::vector< std::string > GetAliases(const std::string &propertyName, const std::string &className="")=0
Get aliases for a specific property.
The ColorProperty class RGB color property.
Abstract base class for properties.
std::map< std::string, BaseProperty::Pointer > PropertyMap
QmitkPropertyItem * GetChild(int row) const
QmitkPropertyItemModel(QObject *parent=NULL)
static RenderingManager * GetInstance()
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
EnumIdsContainerType::const_iterator EnumConstIterator
int columnCount(const QModelIndex &parent=QModelIndex()) const override
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
static QColor MitkToQt(const mitk::Color &color)
void SetPropertyList(mitk::PropertyList *propertyList, const QString &className="")
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
static mitk::Color QtToMitk(const QColor &color)
Qt::ItemFlags flags(const QModelIndex &index) const override
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
void OnPreferencesChanged()
const PropertyMap * GetMap() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.