Skip to content
Snippets Groups Projects
Commit aad39187 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

delete ModelPath

parent cb1f1ada
No related branches found
No related tags found
1 merge request!1146GUI: rm SessionItem from descriptors
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Model/ModelPath.cpp
//! @brief Implements class ModelPath
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/Model/Model/ModelPath.h"
#include "GUI/Model/Model/SessionModel.h"
//! Iterates through all the model and returns true if item is found. This is to
bool GUI::Model::Path::isValidItem(SessionModel* model, SessionItem* item,
const QModelIndex& parent)
{
for (int i_row = 0; i_row < model->rowCount(parent); ++i_row) {
QModelIndex index = model->index(i_row, 0, parent);
SessionItem* curr = model->itemForIndex(index);
if (curr == item || isValidItem(model, item, index))
return true;
}
return false;
}
SessionItem* GUI::Model::Path::ancestor(SessionItem* item, const QString& requiredModelType)
{
SessionItem* cur = item;
while (cur && cur->modelType() != requiredModelType)
cur = cur->itemParent();
return cur;
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Model/ModelPath.h
//! @brief Defines namespace GUI::Model::Path
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_MODEL_MODEL_MODELPATH_H
#define BORNAGAIN_GUI_MODEL_MODEL_MODELPATH_H
#include <QString>
#include <memory>
#include <vector>
class QModelIndex;
class SessionItem;
class SessionModel;
namespace GUI::Model::Path {
bool isValidItem(SessionModel* model, SessionItem* item, const QModelIndex& parent);
//! Returns ancestor of given modelType for given item.
//!
//! For example, returns corresponding jobItem owning ParameterItem via ParameterContainer.
SessionItem* ancestor(SessionItem* item, const QString& requiredModelType);
} // namespace GUI::Model::Path
#endif // BORNAGAIN_GUI_MODEL_MODEL_MODELPATH_H
......@@ -16,7 +16,6 @@
#include "GUI/Model/Data/DataItem.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Model/Model/ApplicationModels.h"
#include "GUI/Model/Model/ModelPath.h"
#include "GUI/Support/IO/ProjectUtils.h"
#include "GUI/Support/IO/SaveLoadInterface.h"
#include "GUI/Util/MessageService.h"
......@@ -27,8 +26,11 @@ namespace {
JobItem* parentJobItem(SaveLoadInterface* item)
{
auto* session_item = dynamic_cast<SessionItem*>(item); // sidecast
return dynamic_cast<JobItem*>(GUI::Model::Path::ancestor(session_item, JobItem::M_TYPE));
auto* cur = dynamic_cast<SessionItem*>(item); // sidecast
while (cur && cur->modelType() != JobItem::M_TYPE)
cur = cur->itemParent();
return dynamic_cast<JobItem*>(cur);
}
} // namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment