Skip to content
Snippets Groups Projects
Commit d95e23e2 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

mv fct to local ns

parent 56ae0160
No related branches found
No related tags found
1 merge request!583shuffle GUI/Model subdirectories
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "GUI/Model/Data/DataItem.h" #include "GUI/Model/Data/DataItem.h"
#include "GUI/Model/Session/ModelPath.h" #include "GUI/Model/Session/ModelPath.h"
#include "GUI/Model/Session/SessionModel.h" #include "GUI/Model/Session/SessionModel.h"
#include "GUI/Model/Instrument/InstrumentItems.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Util/ComboProperty.h" #include "GUI/Util/ComboProperty.h"
#include "GUI/Util/Error.h" #include "GUI/Util/Error.h"
#include <QColor> #include <QColor>
...@@ -41,8 +43,33 @@ struct ColorNameComparator { ...@@ -41,8 +43,33 @@ struct ColorNameComparator {
ComboProperty defaultColorCombo(); ComboProperty defaultColorCombo();
// TODO cover with unit tests and simplify
QModelIndex getIndexFromPath(const SessionModel* model, const QString& path)
{
if (!model)
return {};
QStringList parts = path.split("/");
SessionItem* t = model->rootItem();
for (int i = 0; i < parts.length(); i++) {
if (t->modelType() == JobItem::M_TYPE && parts[i] == "GISASInstrument") {
t = dynamic_cast<JobItem*>(t)->instrumentItem();
continue;
}
for (int j = 0; j < t->numberOfChildren(); j++) {
if (t->childAt(j)->itemName() == parts[i]) {
t = t->childAt(j);
break;
}
}
}
return t->index();
}
} // namespace } // namespace
DataProperties::DataProperties(const QString& model_type) : SessionItem(model_type) DataProperties::DataProperties(const QString& model_type) : SessionItem(model_type)
{ {
addProperty(P_DATALINK, QString()); addProperty(P_DATALINK, QString());
...@@ -58,7 +85,7 @@ DataItem* DataProperties::dataItem() ...@@ -58,7 +85,7 @@ DataItem* DataProperties::dataItem()
{ {
SessionModel* hosting_model = this->model(); SessionModel* hosting_model = this->model();
const QString& path = getItemValue(P_DATALINK).toString(); const QString& path = getItemValue(P_DATALINK).toString();
auto item_index = GUI::Model::Path::getIndexFromPath(hosting_model, path); auto item_index = getIndexFromPath(hosting_model, path);
if (!item_index.isValid()) { if (!item_index.isValid()) {
std::stringstream os; std::stringstream os;
os << "Error in DataProperties::dataItem: index produced by path"; os << "Error in DataProperties::dataItem: index produced by path";
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
// ************************************************************************************************ // ************************************************************************************************
#include "GUI/Model/Session/ModelPath.h" #include "GUI/Model/Session/ModelPath.h"
#include "GUI/Model/Instrument/InstrumentItems.h" #include "GUI/Model/Session/SessionModel.h"
#include "GUI/Model/Job/JobItem.h" #include <QModelIndex>
#include <QStringList>
QString GUI::Model::Path::getPathFromIndex(const QModelIndex& index) QString GUI::Model::Path::getPathFromIndex(const QModelIndex& index)
{ {
...@@ -31,30 +32,6 @@ QString GUI::Model::Path::getPathFromIndex(const QModelIndex& index) ...@@ -31,30 +32,6 @@ QString GUI::Model::Path::getPathFromIndex(const QModelIndex& index)
return namePath.join("/"); return namePath.join("/");
} }
// TODO cover with unit tests and simplify
QModelIndex GUI::Model::Path::getIndexFromPath(const SessionModel* model, const QString& path)
{
if (!model)
return {};
QStringList parts = path.split("/");
SessionItem* t = model->rootItem();
for (int i = 0; i < parts.length(); i++) {
if (t->modelType() == JobItem::M_TYPE && parts[i] == "GISASInstrument") {
t = dynamic_cast<JobItem*>(t)->instrumentItem();
continue;
}
for (int j = 0; j < t->numberOfChildren(); j++) {
if (t->childAt(j)->itemName() == parts[i]) {
t = t->childAt(j);
break;
}
}
}
return t->index();
}
//! Iterates through all the model and returns true if item is found. This is to //! Iterates through all the model and returns true if item is found. This is to
bool GUI::Model::Path::isValidItem(SessionModel* model, SessionItem* item, bool GUI::Model::Path::isValidItem(SessionModel* model, SessionItem* item,
......
...@@ -30,8 +30,6 @@ QString getPathFromIndex(const QModelIndex& index); ...@@ -30,8 +30,6 @@ QString getPathFromIndex(const QModelIndex& index);
QString getPathFromItem(SessionItem* item); QString getPathFromItem(SessionItem* item);
QModelIndex getIndexFromPath(const SessionModel* model, const QString& path);
bool isValidItem(SessionModel* model, SessionItem* item, const QModelIndex& parent); bool isValidItem(SessionModel* model, SessionItem* item, const QModelIndex& parent);
//! Returns ancestor of given modelType for given item. //! Returns ancestor of given modelType for given item.
......
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