26 #include <QStringList> 27 #include <itkCommand.h> 31 : QAbstractTableModel(parent),
32 m_PropertyList(nullptr),
34 m_SortDescending(false),
55 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
60 if (index.data(Qt::EditRole).isValid())
61 flags |= Qt::ItemIsEditable;
63 if (index.data(Qt::CheckStateRole).isValid())
64 flags |= Qt::ItemIsUserCheckable;
72 if (role != Qt::DisplayRole)
75 if (orientation == Qt::Horizontal)
104 if (role == Qt::DisplayRole)
112 if (
const mitk::ColorProperty *colorProp = dynamic_cast<const mitk::ColorProperty *>(baseProp))
115 QColor qcol((
int)(col.GetRed() * 255), (
int)(col.GetGreen() * 255), (
int)(col.GetBlue() * 255));
116 if (role == Qt::DisplayRole)
117 data.setValue<QColor>(qcol);
118 else if (role == Qt::EditRole)
119 data.setValue<QColor>(qcol);
124 if (role == Qt::CheckStateRole)
125 data = boolProp->GetValue() ? Qt::Checked : Qt::Unchecked;
130 if (role == Qt::DisplayRole)
131 data.setValue<QString>(QString::fromStdString(stringProp->GetValue()));
132 else if (role == Qt::EditRole)
133 data.setValue<QString>(QString::fromStdString(stringProp->GetValue()));
136 else if (
mitk::IntProperty *intProp = dynamic_cast<mitk::IntProperty *>(baseProp))
138 if (role == Qt::DisplayRole)
139 data.setValue<
int>(intProp->GetValue());
140 else if (role == Qt::EditRole)
141 data.setValue<
int>(intProp->GetValue());
146 if (role == Qt::DisplayRole)
147 data.setValue<
float>(floatProp->GetValue());
148 else if (role == Qt::EditRole)
149 data.setValue<
float>(floatProp->GetValue());
154 if (role == Qt::DisplayRole)
155 data.setValue<QString>(QString::fromStdString(baseProp->
GetValueAsString()));
156 else if (role == Qt::EditRole)
159 for (
auto it = enumerationProp->Begin(); it != enumerationProp->End(); it++)
161 values << QString::fromStdString(it->second);
163 data.setValue<QStringList>(values);
169 if (role == Qt::DisplayRole)
170 data.setValue<QString>(QString::fromStdString(
m_SelectedProperties[index.row()].second->GetValueAsString()));
203 auto command = itk::SimpleMemberCommand<QmitkPropertiesTableModel>::New();
226 int row = this->
FindProperty(dynamic_cast<const mitk::BaseProperty *>(caller));
228 QModelIndex indexOfChangedProperty = index(row, 1);
230 emit dataChanged(indexOfChangedProperty, indexOfChangedProperty);
240 int row = this->
FindProperty(dynamic_cast<const mitk::BaseProperty *>(caller));
251 (role == Qt::EditRole || role == Qt::CheckStateRole))
265 QColor qcolor = value.value<QColor>();
266 if (!qcolor.isValid())
270 col.SetRed(qcolor.red() / 255.0);
271 col.SetGreen(qcolor.green() / 255.0);
272 col.SetBlue(qcolor.blue() / 255.0);
273 colorProp->SetColor(col);
274 propertyList->InvokeEvent(itk::ModifiedEvent());
275 propertyList->Modified();
282 boolProp->SetValue(value.toInt() == Qt::Checked ? true :
false);
283 propertyList->InvokeEvent(itk::ModifiedEvent());
284 propertyList->Modified();
291 stringProp->SetValue((value.value<QString>()).toStdString());
292 propertyList->InvokeEvent(itk::ModifiedEvent());
293 propertyList->Modified();
298 else if (
mitk::IntProperty *intProp = dynamic_cast<mitk::IntProperty *>(baseProp))
301 if (intValue != intProp->GetValue())
303 intProp->SetValue(intValue);
304 propertyList->InvokeEvent(itk::ModifiedEvent());
305 propertyList->Modified();
313 float floatValue = value.value<
float>();
314 if (floatValue != floatProp->GetValue())
316 floatProp->SetValue(floatValue);
317 propertyList->InvokeEvent(itk::ModifiedEvent());
318 propertyList->Modified();
326 std::string activatedItem = value.value<QString>().toStdString();
327 if (activatedItem != enumerationProp->GetValueAsString())
329 if (enumerationProp->IsValidEnumerationValue(activatedItem))
331 enumerationProp->SetValue(activatedItem);
332 propertyList->InvokeEvent(itk::ModifiedEvent());
333 propertyList->Modified();
343 emit dataChanged(index, index);
352 bool sortDescending = (order == Qt::DescendingOrder) ?
true :
false;
370 QAbstractTableModel::beginResetModel();
371 QAbstractTableModel::endResetModel();
383 std::vector<PropertyDataSet>::const_iterator propertyIterator;
388 if (propertyIterator->second == _Property)
403 itk::MemberCommand<QmitkPropertiesTableModel>::Pointer _PropertyDataSetModifiedCommand =
404 itk::MemberCommand<QmitkPropertiesTableModel>::New();
407 _PropertyDataSet.second->AddObserver(itk::ModifiedEvent(), _PropertyDataSetModifiedCommand));
410 itk::MemberCommand<QmitkPropertiesTableModel>::Pointer _PropertyDataSetDeleteCommand =
411 itk::MemberCommand<QmitkPropertiesTableModel>::New();
414 _PropertyDataSet.second->AddObserver(itk::DeleteEvent(), _PropertyDataSetDeleteCommand));
442 std::vector<PropertyDataSet> allPredicates;
448 for (
auto it = propertyList->GetMap()->begin(); it != propertyList->GetMap()->end(); it++)
450 allPredicates.push_back(*it);
456 std::vector<PropertyDataSet> subSelection;
458 for (
auto it = allPredicates.begin(); it != allPredicates.end(); it++)
462 subSelection.push_back((*it));
464 allPredicates.clear();
465 allPredicates = subSelection;
470 for (
auto it = allPredicates.begin(); it != allPredicates.end(); it++)
472 tmpPropertyDataSet = *it;
480 QAbstractTableModel::beginResetModel();
481 QAbstractTableModel::endResetModel();
492 : m_CompareCriteria(_CompareCriteria), m_CompareOperator(_CompareOperator)
503 return (_Left.second->GetValueAsString() < _Right.second->GetValueAsString());
505 return (_Left.second->GetValueAsString() > _Right.second->GetValueAsString());
511 return (_Left.first < _Right.first);
513 return (_Left.first > _Right.first);
518 const std::string &_FilterKeyWord)
itk::SmartPointer< T > Lock() const
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...
std::string m_FilterKeyWord
QmitkPropertiesTableModel(QObject *parent=nullptr, mitk::PropertyList::Pointer _PropertyList=nullptr)
bool operator()(const PropertyDataSet &_Elem) const
The reimplemented compare function.
Key-value list holding instances of BaseProperty.
CompareCriteria
Specifies field of the property with which it will be sorted.
CompareOperator m_CompareOperator
CompareOperator
Specifies Ascending/descending ordering.
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...
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...
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...
virtual void PropertyListDelete()
Gets called when the list is about to be deleted.
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
virtual std::string GetValueAsString() const
Abstract base class for properties.
std::pair< std::string, mitk::BaseProperty::Pointer > PropertyDataSet
bool setData(const QModelIndex &index, const QVariant &value, int role) override
unsigned long m_PropertyListDeleteObserverTag
static RenderingManager * GetInstance()
bool IsExpired() const noexcept
mitk::PropertyList::Pointer GetPropertyList() const
std::vector< unsigned long > m_PropertyModifiedObserverTags
Holds all tags of Modified Event Listeners. We need it to remove them again.
~QmitkPropertiesTableModel() override
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...
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)
CompareCriteria m_CompareCriteria
bool operator()(const PropertyDataSet &_Left, const PropertyDataSet &_Right) const
The reimplemented compare function.
static const int PROPERTY_VALUE_COLUMN
int columnCount(const QModelIndex &parent) const override
void AddSelectedProperty(PropertyDataSet &_PropertyDataSet)
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.
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)
Qt::ItemFlags flags(const QModelIndex &index) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view...