16 #include "Device/Data/Datafield.h"
17 #include "Device/IO/DataFormatUtils.h"
22 #include <QApplication>
23 #include <QMessageBox>
27 const QString filter_string_ba =
"Intensity File (*.int *.gz *.tif *.tiff *.txt *.csv);;"
29 const QString filter_string_ascii =
"Intensity File (*.int *.int.gz *.txt *.csv *.dat *.ascii);;"
30 "Ascii column-wise data (*.*)";
36 std::unique_ptr<Datafield> ImportKnownData(
const QString& fileName,
37 IOFactory::LoaderSelector loader = IOFactory::automatic)
40 std::unique_ptr<Datafield> result;
42 std::unique_ptr<Datafield> data(IOFactory::readDatafield(fileName.toStdString(), loader));
44 }
catch (std::exception& ex) {
45 QString message = QString(
"Error while trying to read file\n\n'%1'\n\n%2")
47 .arg(QString::fromStdString(std::string(ex.what())));
56 std::unique_ptr<Datafield>
59 return ImportKnownData(fileName, loader);
66 const std::string fileNameStdString = fileName.toStdString();
68 if (selectedLoader ==
nullptr) {
69 if (DataUtils::Format::isCompressed(fileNameStdString)
70 || DataUtils::Format::isIntFile(fileNameStdString)
71 || DataUtils::Format::isTiffFile(fileNameStdString)) {
78 }
catch (std::exception& ex) {
80 const bool tryWithLoaders =
81 (DataUtils::Format::isIntFile(fileNameStdString)
82 && !DataUtils::Format::isCompressed(
87 return QString::fromLatin1(ex.what());
95 const bool ok = file.open(QFile::ReadOnly | QIODevice::Text);
97 return "File could not be opened.";
99 QByteArray fileContent = file.readAll();
102 if (fileContent.isEmpty())
103 return "The imported file is empty.";
105 if (DataUtils::Format::isCompressed(fileNameStdString)) {
110 if (selectedLoader ==
nullptr)
113 loader = selectedLoader->
clone();
117 QApplication::setOverrideCursor(Qt::WaitCursor);
121 QApplication::restoreOverrideCursor();
Defines namespace GUI::Util::IO.
Defines ImportDataInfo helper struct.
Defines ImportDataUtils namespace.
Defines class QREDataLoader.
Defines class RealDataItem.
Abstract base class for all data loaders (classes to import real data).
virtual void guessSettings()
Guess appropriate settings (for example the separator in a CSV file). Is called only once,...
virtual void setFileContents(const QByteArray &fileContent)=0
Sets the file contents to be imported. If the file was a compressed file, then the decompressed conte...
virtual void processContents()=0
Process the file contents. Can be called more than once, e.g. if the import settings have changed....
virtual void initWithDefaultImportSettings()
Set import settings to defaults.
virtual AbstractDataLoader * clone() const =0
Create a complete clone, including all internal states.
void setRealDataItem(RealDataItem *item)
Define the real data item on which the import shall work.
Carries information about loaded data.
Loader for experimental reflectometry CSV files that contain three columns with Q,...
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
void setImportData(ImportDataInfo info)
Sets imported data to underlying item. Creates it if not existing. This is used for 1D import....
QString nativeFileName() const
void setDataLoader(AbstractDataLoader *loader)
Takes ownership of loader.
std::unique_ptr< Datafield > binifyAxes(const Datafield &data)
Creates Datafield with bin-valued axes.
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
QString Import1dData(RealDataItem *realDataItem, const AbstractDataLoader *selectedLoader)
Imports 1D data into the given item.
std::unique_ptr< Datafield > Import2dData(const QString &fileName, IOFactory::LoaderSelector loader)
Imports 2D data, stores them as Datafield, and returns owning pointer.