30 #include <QStringList>
31 #include <itkCommand.h>
35 : QAbstractTableModel(parent),
36 m_PropertyList(nullptr),
38 m_SortDescending(false),
59 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
64 if (index.data(Qt::EditRole).isValid())
65 flags |= Qt::ItemIsEditable;
67 if (index.data(Qt::CheckStateRole).isValid())
68 flags |= Qt::ItemIsUserCheckable;
76 if (role != Qt::DisplayRole)
79 if (orientation == Qt::Horizontal)
108 if (role == Qt::DisplayRole)
116 if (
const mitk::ColorProperty *colorProp = dynamic_cast<const mitk::ColorProperty *>(baseProp))
119 QColor qcol((
int)(col.GetRed() * 255), (
int)(col.GetGreen() * 255), (
int)(col.GetBlue() * 255));
120 if (role == Qt::DisplayRole)
121 data.setValue<QColor>(qcol);
122 else if (role == Qt::EditRole)
123 data.setValue<QColor>(qcol);
128 if (role == Qt::CheckStateRole)
129 data = boolProp->GetValue() ? Qt::Checked : Qt::Unchecked;
134 if (role == Qt::DisplayRole)
135 data.setValue<QString>(QString::fromStdString(stringProp->GetValue()));
136 else if (role == Qt::EditRole)
137 data.setValue<QString>(QString::fromStdString(stringProp->GetValue()));
140 else if (
mitk::IntProperty *intProp = dynamic_cast<mitk::IntProperty *>(baseProp))
142 if (role == Qt::DisplayRole)
143 data.setValue<
int>(intProp->GetValue());
144 else if (role == Qt::EditRole)
145 data.setValue<
int>(intProp->GetValue());
150 if (role == Qt::DisplayRole)
151 data.setValue<
float>(floatProp->GetValue());
152 else if (role == Qt::EditRole)
153 data.setValue<
float>(floatProp->GetValue());
158 if (role == Qt::DisplayRole)
159 data.setValue<QString>(QString::fromStdString(baseProp->
GetValueAsString()));
160 else if (role == Qt::EditRole)
163 for (
auto it = enumerationProp->Begin(); it != enumerationProp->End(); it++)
165 values << QString::fromStdString(it->second);
167 data.setValue<QStringList>(values);
173 if (role == Qt::DisplayRole)
174 data.setValue<QString>(QString::fromStdString(
m_SelectedProperties[index.row()].second->GetValueAsString()));
232 int row = this->
FindProperty(dynamic_cast<const mitk::BaseProperty *>(caller));
234 QModelIndex indexOfChangedProperty = index(row, 1);
236 emit dataChanged(indexOfChangedProperty, indexOfChangedProperty);
246 int row = this->
FindProperty(dynamic_cast<const mitk::BaseProperty *>(caller));
256 (role == Qt::EditRole || Qt::CheckStateRole))
268 QColor qcolor = value.value<QColor>();
269 if (!qcolor.isValid())
273 col.SetRed(qcolor.red() / 255.0);
274 col.SetGreen(qcolor.green() / 255.0);
275 col.SetBlue(qcolor.blue() / 255.0);
276 colorProp->SetColor(col);
285 boolProp->SetValue(value.toInt() == Qt::Checked ?
true :
false);
294 stringProp->SetValue((value.value<QString>()).toStdString());
301 else if (
mitk::IntProperty *intProp = dynamic_cast<mitk::IntProperty *>(baseProp))
304 if (intValue != intProp->GetValue())
306 intProp->SetValue(intValue);
316 float floatValue = value.value<
float>();
317 if (floatValue != floatProp->GetValue())
319 floatProp->SetValue(floatValue);
329 std::string activatedItem = value.value<QString>().toStdString();
330 if (activatedItem != enumerationProp->GetValueAsString())
332 if (enumerationProp->IsValidEnumerationValue(activatedItem))
334 enumerationProp->SetValue(activatedItem);
346 emit dataChanged(index, index);
355 bool sortDescending = (order == Qt::DescendingOrder) ?
true :
false;
373 QAbstractTableModel::beginResetModel();
374 QAbstractTableModel::endResetModel();
386 std::vector<PropertyDataSet>::const_iterator propertyIterator;
391 if (propertyIterator->second == _Property)
410 _PropertyDataSet.second->AddObserver(itk::ModifiedEvent(), _PropertyDataSetModifiedCommand));
417 _PropertyDataSet.second->AddObserver(itk::DeleteEvent(), _PropertyDataSetDeleteCommand));
445 std::vector<PropertyDataSet> allPredicates;
451 allPredicates.push_back(*it);
457 std::vector<PropertyDataSet> subSelection;
459 for (
auto it = allPredicates.begin(); it != allPredicates.end(); it++)
463 subSelection.push_back((*it));
465 allPredicates.clear();
466 allPredicates = subSelection;
471 for (
auto it = allPredicates.begin(); it != allPredicates.end(); it++)
473 tmpPropertyDataSet = *it;
481 QAbstractTableModel::beginResetModel();
482 QAbstractTableModel::endResetModel();
493 : m_CompareCriteria(_CompareCriteria), m_CompareOperator(_CompareOperator)
500 switch (m_CompareCriteria)
503 if (m_CompareOperator == Less)
504 return (_Left.second->GetValueAsString() < _Right.second->GetValueAsString());
506 return (_Left.second->GetValueAsString() > _Right.second->GetValueAsString());
511 if (m_CompareOperator == Less)
512 return (_Left.first < _Right.first);
514 return (_Left.first > _Right.first);
519 const std::string &_FilterKeyWord)
void RemoveListener(const AbstractDelegate &delegate) const
void AddListener(const AbstractDelegate &delegate) const
itk::SmartPointer< Self > Pointer
std::vector< PropertyDataSet > m_SelectedProperties
Store the properties in a vector so that they may be sorted.
virtual void SetFilterPropertiesKeyWord(std::string _FilterKeyWord)
Set a keyword for filtering of properties. Only properties beginning with this string will be shown...
itkObjectEvent ObjectDelete
AddEvent is emitted when the object pointed to gets deleted.
QmitkPropertiesTableModel(QObject *parent=nullptr, mitk::PropertyList::Pointer _PropertyList=nullptr)
bool operator()(const PropertyDataSet &_Left, const PropertyDataSet &_Right) const
The reimplemented compare function.
Key-value list holding instances of BaseProperty.
virtual void PropertyModified(const itk::Object *caller, const itk::EventObject &event)
Called when a single property was changed. Send a model changed event to the Qt-outer world...
CompareOperator
Specifies Ascending/descending ordering.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view...
mitk::PropertyList::Pointer GetPropertyList() const
static const int PROPERTY_NAME_COLUMN
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view...
ObjectType * GetPointer() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view...
A struct that inherits from std::binary_function. You can use it in std::sort algorithm for sorting t...
The ColorProperty class RGB color property.
void RemoveSelectedProperty(unsigned int _Index)
mitk::WeakPointer< mitk::PropertyList > m_PropertyList
Abstract base class for properties.
std::pair< std::string, mitk::BaseProperty::Pointer > PropertyDataSet
bool setData(const QModelIndex &index, const QVariant &value, int role) override
CompareCriteria
Specifies field of the property with which it will be sorted.
static RenderingManager * GetInstance()
int FindProperty(const mitk::BaseProperty *_Property) const
Searches for the specified property and returns the row of the element in this QTableModel. If any errors occur, the function returns -1.
virtual std::string GetValueAsString() const
std::vector< unsigned long > m_PropertyModifiedObserverTags
Holds all tags of Modified Event Listeners. We need it to remove them again.
bool operator()(const PropertyDataSet &_Elem) const
The reimplemented compare function.
virtual ~QmitkPropertiesTableModel()
Standard dtor. Nothing to do here.
bool m_SortDescending
The property is true when the property list is sorted in descending order.
virtual void PropertyDelete(const itk::Object *caller, const itk::EventObject &event)
Called when a single property was changed. Send a model changed event to the Qt-outer world...
virtual void PropertyListDelete(const itk::Object *_PropertyList)
Gets called when the list is about to be deleted.
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Reimplemented sort function from QAbstractTableModel to enable sorting on the table.
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
bool m_BlockEvents
Indicates if this class should neglect all incoming events because the class itself triggered the eve...
void SetPropertyList(mitk::PropertyList *_PropertyList)
PropertyDataSetCompareFunction(CompareCriteria _CompareCriteria=CompareByName, CompareOperator _CompareOperator=Less)
Creates a PropertyDataSetCompareFunction. A CompareCriteria and a CompareOperator must be given...
std::string m_FilterKeyWord
If set to any value, only properties containing the specified keyword in their name will be shown...
PropertyListElementFilterFunction(const std::string &m_FilterKeyWord)
static const int PROPERTY_VALUE_COLUMN
int columnCount(const QModelIndex &parent) const override
void AddSelectedProperty(PropertyDataSet &_PropertyDataSet)
std::vector< unsigned long > m_PropertyDeleteObserverTags
Holds all tags of Modified Event Listeners. We need it to remove them again.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
const PropertyMap * GetMap() const
Qt::ItemFlags flags(const QModelIndex &index) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.