27 #include <boost/polymorphic_cast.hpp>
29 using boost::polymorphic_downcast;
34 : QAbstractItemModel(parent)
35 , m_parameterContainer(fitParContainer)
48 throw Error(
"FitParameterModel::FitParameterModel() -> Error. "
49 "Wrong item reported.");
65 return Qt::NoItemFlags;
67 Qt::ItemFlags result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
70 result |= Qt::ItemIsEditable;
72 result |= Qt::ItemIsDragEnabled;
73 const bool allow_one_fit_parameter_to_have_more_than_one_link =
true;
74 if (allow_one_fit_parameter_to_have_more_than_one_link) {
79 result |= Qt::ItemIsDropEnabled;
85 result |= Qt::ItemIsDropEnabled;
101 QVector<FitParameterItem*> fitParamItems =
102 polymorphic_downcast<FitParameterContainerItem*>(parent_item)->fitParameterItems();
103 if (row < fitParamItems.size()) {
108 itemToPack = fitParItem;
111 itemToPack = fitParItem->
typeItem();
123 itemToPack =
nullptr;
125 return createIndex(row, column, itemToPack);
128 QVector<FitParameterLinkItem*> links =
129 polymorphic_downcast<FitParameterItem*>(parent_item)->linkItems();
130 if (row < links.size()) {
132 return createIndex(row, column, linkItem->linkItem());
135 return QModelIndex();
141 return QModelIndex();
143 if (!child.isValid())
144 return QModelIndex();
149 return QModelIndex();
153 return QModelIndex();
154 return createIndex(fitPar->
parentRow(), 0, fitPar);
158 return QModelIndex();
176 return polymorphic_downcast<FitParameterItem*>(parent_item)->linkItems().size();
194 return !polymorphic_downcast<FitParameterItem*>(parentItem)->linkItems().empty();
209 if (role == Qt::DisplayRole || role == Qt::EditRole) {
211 return item->displayName();
213 return linkItem->title();
214 return item->value();
216 if (role == Qt::ForegroundRole && !item->isEditable())
217 return QVariant(QColor(Qt::gray));
219 return item->value();
229 if (!
index.isValid())
232 if (role == Qt::EditRole) {
233 item->setValue(value);
251 QModelIndex
index = indexes.first();
252 if (
index.isValid()) {
254 QString path = item->value().toString();
257 data.setNum(
reinterpret_cast<qlonglong
>(parameterItem));
265 int column,
const QModelIndex& parent)
const
270 bool drop_is_possible(
false);
272 drop_is_possible =
true;
273 if (!
parent.isValid() && row == -1 && column == -1)
274 drop_is_possible =
true;
275 return drop_is_possible;
279 int column,
const QModelIndex& parent)
304 if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
306 if (role == Qt::ToolTipRole)
312 const QModelIndex& bottomRight,
313 const QVector<int>& roles)
315 Q_UNUSED(bottomRight);
317 auto*
sourceModel = qobject_cast<JobModel*>(sender());
323 if (itemIndex.isValid())
324 emit dataChanged(itemIndex, itemIndex, roles);
348 connect(
sourceModel, &QAbstractItemModel::dataChanged,
this,
350 connect(
sourceModel, &QAbstractItemModel::rowsRemoved,
this,
352 connect(
sourceModel, &QAbstractItemModel::modelAboutToBeReset,
this,
355 disconnect(
sourceModel, &QAbstractItemModel::dataChanged,
this,
357 disconnect(
sourceModel, &QAbstractItemModel::rowsRemoved,
this,
359 disconnect(
sourceModel, &QAbstractItemModel::modelAboutToBeReset,
this,
365 const QString& tooltip)
374 return QModelIndex();
379 return createIndex(item->
parentRow(), 0, item);
381 auto* fitParam = polymorphic_downcast<FitParameterItem*>(parent_item);
382 std::optional<int> col;
383 if (item == fitParam->typeItem())
385 else if (item == fitParam->startValueItem())
387 else if (item == fitParam->minimumItem())
389 else if (item == fitParam->maximumItem())
392 return createIndex(parent_item->parentRow(), col.value(), item);
394 QVector<FitParameterLinkItem*> links =
395 polymorphic_downcast<FitParameterItem*>(parent_item->parentItem())->linkItems();
396 int index = links.indexOf(polymorphic_downcast<FitParameterLinkItem*>(parent_item));
397 return createIndex(
index, 0, item);
400 return QModelIndex();
408 if (
index.isValid()) {
Defines class FitParameterContainerItem.
Defines namespace FitParameterHelper.
Defines class FitParameterItem.
Defines class FitParameterLinkItem.
Defines class FitParameterModel.
Defines namespace GUI::Model::Path.
Defines reader and writer classes for SessionModel.
The FitParameterContainerItem class is a collection of all defined fit parameters in JobItem.
void createFitParameter(ParameterItem *parameterItem)
Creates fit parameter from given ParameterItem, sets starting value to the value of ParameterItem,...
void addToFitParameter(ParameterItem *parameterItem, const QString &fitParName)
Adds given parameterItem to the existing fit parameter with display name fitParName....
FitParameterItems is a collection of items to define fit parameters in GUI.
SessionItem * minimumItem() const
SessionItem * maximumItem() const
SessionItem * typeItem() const
SessionItem * startValueItem() const
The FitParameterLinkItem class holds a link to ParameterItem in tuning tree.
int columnCount(const QModelIndex &parent) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent) const override
QModelIndex indexOfItem(SessionItem *item) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void onSourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
SessionItem * itemForIndex(const QModelIndex &index) const
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
void onSourceAboutToBeReset()
SessionModel * sourceModel() const
FitParameterModel(FitParameterContainerItem *fitParContainer, QObject *parent=nullptr)
QMap< int, QString > m_columnToolTips
bool setData(const QModelIndex &index, const QVariant &value, int role) override
~FitParameterModel() override
QModelIndex parent(const QModelIndex &child) const override
QStringList mimeTypes() const override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
void addColumn(EColumn id, const QString &name, const QString &tooltip)
FitParameterContainerItem * m_parameterContainer
void connectModel(QAbstractItemModel *sourceModel, bool isConnect=true) const
QMimeData * mimeData(const QModelIndexList &indexes) const override
void onSourceRowsRemoved(const QModelIndex &parent, int first, int last)
QMap< int, QString > m_columnNames
bool isValidSourceItem(SessionItem *item) const
Returns true if given item still exists in source model.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=nullptr)
The ParameterItem class represent a tuning value in a parameter tuning tree.
Base class for a GUI data item.
int numberOfChildren() const
Returns total number of children.
bool hasModelType() const
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
SessionModel * model() const
Returns model of this item.
SessionItem * parentItem() const
Returns parent of this item.
int parentRow()
Returns the index of the given item within its parent. Returns -1 when no parent is set.
QModelIndex index() const
Returns model index of this item.
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
SessionItem * itemForIndex(const QModelIndex &index) const
ParameterItem * getParameterItem(FitParameterContainerItem *container, const QString &link)
Returns ParameterItem corresponding to given link.
bool isValidItem(SessionModel *model, SessionItem *item, const QModelIndex &parent)
Iterates through all the model and returns true if item is found. This is to.
QString const & name(EShape k)
constexpr auto LinkMimeType