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

mv from utils to anon namespace

parent 48a1bd40
No related branches found
No related tags found
1 merge request!427Reduce include dependences in GUI; break cyclic dependence between View and Model
...@@ -17,13 +17,11 @@ ...@@ -17,13 +17,11 @@
#include "GUI/Items/RealDataItem.h" #include "GUI/Items/RealDataItem.h"
#include "GUI/Models/Data/RealDataModel.h" #include "GUI/Models/Data/RealDataModel.h"
#include "GUI/Models/Instrument/InstrumentModel.h" #include "GUI/Models/Instrument/InstrumentModel.h"
#include "GUI/Views/ImportDataWidgets/ImportDataUtils.h"
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
using namespace GUI::View;
namespace { namespace {
bool QuestionOnInstrumentReshaping(const QString& message) bool QuestionOnInstrumentReshaping(const QString& message)
{ {
QMessageBox msgBox; QMessageBox msgBox;
...@@ -42,6 +40,29 @@ bool QuestionOnInstrumentReshaping(const QString& message) ...@@ -42,6 +40,29 @@ bool QuestionOnInstrumentReshaping(const QString& message)
return msgBox.clickedButton() == modifyInstrumentButton; return msgBox.clickedButton() == modifyInstrumentButton;
} }
QString printShapeMessage(const std::vector<int>& instrument_shape,
const std::vector<int>& data_shape)
{
auto to_str = [](const std::vector<int>& shape) {
std::string result;
for (size_t i = 0, size = shape.size(); i < size; ++i) {
result += std::to_string(shape[i]);
if (i + 1 != size)
result += ", ";
}
return result;
};
std::string message_string = "instrument [";
message_string += to_str(instrument_shape);
message_string += "], data [";
message_string += to_str(data_shape);
message_string += "]";
return QString::fromStdString(std::move(message_string));
}
} // namespace } // namespace
LinkInstrumentManager::LinkInstrumentManager(InstrumentModel* instrumentModel, LinkInstrumentManager::LinkInstrumentManager(InstrumentModel* instrumentModel,
...@@ -65,7 +86,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData ...@@ -65,7 +86,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
if (!instrumentItem) if (!instrumentItem)
return true; return true;
if (!ImportDataUtils::Compatible(*instrumentItem, *realDataItem)) { if (instrumentItem->shape().size() != realDataItem->shape().size()) {
if (parent) if (parent)
QMessageBox::warning(parent, "Can't link to instrument", QMessageBox::warning(parent, "Can't link to instrument",
"Can't link, data is incompatible with the instrument."); "Can't link, data is incompatible with the instrument.");
...@@ -84,7 +105,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData ...@@ -84,7 +105,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
QString message = QString message =
realDataItem->holdsDimensionalData() realDataItem->holdsDimensionalData()
? "Experimental data carries information on the range/points of measurement." ? "Experimental data carries information on the range/points of measurement."
: ImportDataUtils::printShapeMessage(instrumentItem->shape(), realDataItem->shape()); : printShapeMessage(instrumentItem->shape(), realDataItem->shape());
if (!QuestionOnInstrumentReshaping(message)) if (!QuestionOnInstrumentReshaping(message))
return false; return false;
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
#include "Device/Data/OutputData.h" #include "Device/Data/OutputData.h"
#include "Device/InputOutput/DataFormatUtils.h" #include "Device/InputOutput/DataFormatUtils.h"
#include "GUI/Views/Loaders/QREDataLoader.h" #include "GUI/Views/Loaders/QREDataLoader.h"
#include "GUI/Items/InstrumentItems.h"
#include "GUI/Items/RealDataItem.h" #include "GUI/Items/RealDataItem.h"
#include "GUI/utils/OutputDataUtils.h" #include "GUI/utils/OutputDataUtils.h"
#include "GUI/Models/Data/ImportDataInfo.h"
#include <QApplication> #include <QApplication>
#include <QMessageBox> #include <QMessageBox>
...@@ -29,16 +29,6 @@ const QString filter_string_ba = "Intensity File (*.int *.gz *.tif *.tiff *.txt ...@@ -29,16 +29,6 @@ const QString filter_string_ba = "Intensity File (*.int *.gz *.tif *.tiff *.txt
const QString filter_string_ascii = "Intensity File (*.int *.int.gz *.txt *.csv *.dat *.ascii);;" const QString filter_string_ascii = "Intensity File (*.int *.int.gz *.txt *.csv *.dat *.ascii);;"
"Ascii column-wise data (*.*)"; "Ascii column-wise data (*.*)";
int rank(const RealDataItem& item)
{
return static_cast<int>(item.shape().size());
}
int rank(const InstrumentItem& item)
{
return static_cast<int>(item.shape().size());
}
//! Imports for 2D or 1D data, using given loader. //! Imports for 2D or 1D data, using given loader.
//! Allocates OutputData, and returns owning pointer. //! Allocates OutputData, and returns owning pointer.
//! Currently used for all 2D, and some 1D data files. //! Currently used for all 2D, and some 1D data files.
...@@ -135,30 +125,3 @@ QString GUI::View::ImportDataUtils::Import1dData(RealDataItem* realDataItem, ...@@ -135,30 +125,3 @@ QString GUI::View::ImportDataUtils::Import1dData(RealDataItem* realDataItem,
return QString(); return QString();
} }
bool GUI::View::ImportDataUtils::Compatible(const InstrumentItem& instrumentItem,
const RealDataItem& realDataItem)
{
return rank(instrumentItem) == rank(realDataItem);
}
QString GUI::View::ImportDataUtils::printShapeMessage(const std::vector<int>& instrument_shape,
const std::vector<int>& data_shape)
{
auto to_str = [](const std::vector<int>& shape) {
std::string result;
for (size_t i = 0, size = shape.size(); i < size; ++i) {
result += std::to_string(shape[i]);
if (i + 1 != size)
result += ", ";
}
return result;
};
std::string message_string = "instrument [";
message_string += to_str(instrument_shape);
message_string += "], data [";
message_string += to_str(data_shape);
message_string += "]";
return QString::fromStdString(std::move(message_string));
}
...@@ -16,10 +16,8 @@ ...@@ -16,10 +16,8 @@
#define BORNAGAIN_GUI_VIEWS_IMPORTDATAWIDGETS_IMPORTDATAUTILS_H #define BORNAGAIN_GUI_VIEWS_IMPORTDATAWIDGETS_IMPORTDATAUTILS_H
#include "Device/Histo/IntensityDataIOFactory.h" #include "Device/Histo/IntensityDataIOFactory.h"
#include "GUI/Models/Data/ImportDataInfo.h"
#include <QString> #include <QString>
#include <memory> #include <memory>
#include <vector>
template <class T> class OutputData; template <class T> class OutputData;
class RealDataItem; class RealDataItem;
...@@ -44,12 +42,6 @@ std::unique_ptr<OutputData<double>> Import2dData(const QString& fileName, ...@@ -44,12 +42,6 @@ std::unique_ptr<OutputData<double>> Import2dData(const QString& fileName,
//! (or null if none selected). //! (or null if none selected).
QString Import1dData(RealDataItem* realDataItem, const AbstractDataLoader* selectedLoader); QString Import1dData(RealDataItem* realDataItem, const AbstractDataLoader* selectedLoader);
//! Check whether data item is compatible with instrument (same rank)
bool Compatible(const InstrumentItem& instrumentItem, const RealDataItem& realDataItem);
//! Composes a message with the shapes of InstrumentItem and RealDataItem.
QString printShapeMessage(const std::vector<int>& instrument_shape,
const std::vector<int>& data_shape);
}; // namespace GUI::View::ImportDataUtils }; // namespace GUI::View::ImportDataUtils
#endif // BORNAGAIN_GUI_VIEWS_IMPORTDATAWIDGETS_IMPORTDATAUTILS_H #endif // BORNAGAIN_GUI_VIEWS_IMPORTDATAWIDGETS_IMPORTDATAUTILS_H
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