26 QAbstractTableModel(parent), m_modified(false)
36 if (pChecker != m_Checker)
38 emit beginResetModel();
49 m_ParameterNames = names;
65 return m_Checker->GetNumberOfConstraints();
82 data(
const QModelIndex& index,
int role)
const 91 if (static_cast<unsigned int>(index.row()) < m_Checker->GetNumberOfConstraints())
94 static_cast<unsigned int>(index.row()));
96 switch (index.column())
99 if (role == Qt::DisplayRole)
103 for (mitk::SimpleBarrierConstraintChecker::ParameterIndexVectorType::const_iterator pos =
106 names.append(QString::fromStdString(this->m_ParameterNames[*pos]));
109 result = QVariant(names);
111 else if (role == Qt::EditRole)
115 for (mitk::ModelTraitsInterface::ParameterNamesType::const_iterator pos =
116 this->m_ParameterNames.begin(); pos != this->m_ParameterNames.end(); ++pos)
118 names.append(QString::fromStdString(*pos));
121 result = QVariant(names);
123 else if (role == Qt::ToolTipRole)
125 result = QVariant(
"Parameters that are relevant for this constraint. If more then one parameter is specified, it is the sum of all parameters.");
131 if (role == Qt::DisplayRole)
135 result = QVariant(QString(
"upper"));
139 result = QVariant(QString(
"lower"));
142 else if (role == Qt::EditRole)
146 result = QVariant(1);
150 result = QVariant(0);
153 else if (role == Qt::ToolTipRole)
155 result = QVariant(
"Type of boundary constraint.");
161 if (role == Qt::DisplayRole || role == Qt::EditRole)
163 result = QVariant(constraint.
barrier);
165 else if (role == Qt::ToolTipRole)
167 result = QVariant(
"Barrier value for the constraint.");
173 if (role == Qt::DisplayRole || role == Qt::EditRole)
175 result = QVariant(constraint.
width);
177 else if (role == Qt::ToolTipRole)
179 result = QVariant(
"Width of the penalty zone before the barrier value. Must be >=0.0.");
191 flags(
const QModelIndex& index)
const 193 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
195 if (static_cast<unsigned int>(index.row()) < m_Checker->GetNumberOfConstraints())
199 flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
208 headerData(
int section, Qt::Orientation orientation,
int role)
const 210 if ((Qt::DisplayRole == role) &&
211 (Qt::Horizontal == orientation))
215 return QVariant(
"Parameters");
219 return QVariant(
"Type");
223 return QVariant(
"Value");
227 return QVariant(
"Width");
236 setData(
const QModelIndex& index,
const QVariant& value,
int role)
238 if (!index.isValid() || (m_Checker->GetNumberOfConstraints() <=
static_cast<unsigned int>(index.row()))
244 if (Qt::EditRole == role)
247 static_cast<unsigned int>(index.row()));
249 switch (index.column())
253 QStringList selectedNames = value.toStringList();
256 for (mitk::SimpleBarrierConstraintChecker::ParameterIndexVectorType::size_type pos = 0;
257 pos < this->m_ParameterNames.size(); ++pos)
259 if (selectedNames.contains(QString::fromStdString(this->m_ParameterNames[pos])))
265 emit dataChanged(index, index);
271 emit dataChanged(index, index);
275 constraint.
barrier = value.toDouble();
276 emit dataChanged(index, index);
280 constraint.
width = value.toDouble();
281 emit dataChanged(index, index);
285 emit beginResetModel();
287 m_Checker->GetConstraint(static_cast<unsigned int>(index.row())) = constraint;
291 emit endResetModel();
301 emit beginResetModel();
302 m_Checker->SetLowerBarrier(0, 0.0);
304 emit endResetModel();
309 if (!index.isValid() || (m_Checker->GetNumberOfConstraints() <=
static_cast<unsigned int>(index.row()))
315 emit beginResetModel();
316 m_Checker->DeleteConstraint(static_cast<unsigned int>(index.row()));
318 emit endResetModel();
const int INDEX_CONSTRAINT_TYPE
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
This class implements constraints as simple barrier functions.
const int INDEX_CONSTRAINT_WIDTH
QVariant data(const QModelIndex &index, int role) const override
const int INDEX_CONSTRAINT_THRESHOLD
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
const int INDEX_CONSTRAINT_PARAMS
void setChecker(mitk::SimpleBarrierConstraintChecker *pChecker, const mitk::ModelTraitsInterface::ParameterNamesType &names)
std::vector< ParameterNameType > ParameterNamesType
const int NUMBER_OF_CONSTRAINT_ASPECTS
void deleteConstraint(const QModelIndex &index)
QmitkSimpleBarrierModel(QObject *parent=nullptr)
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
ParameterIndexVectorType parameters