16 #include "Device/Data/DataUtils.h"
17 #include "Device/Data/Datafield.h"
31 #include <QFileDialog>
32 #include <QItemSelectionModel>
38 #include <QVBoxLayout>
42 , m_itemTree(new QTreeView(this))
45 , m_document(document)
46 , m_import1dDataAction(new QAction(this))
47 , m_import2dDataAction(new QAction(this))
48 , m_renameDataAction(new QAction(this))
49 , m_removeDataAction(new QAction(this))
51 setProperty(
"stylable",
true);
52 setAttribute(Qt::WA_StyledBackground,
true);
54 setMinimumSize(250, 600);
55 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
56 setWindowTitle(
"RealDataSelectorWidget");
89 m_itemTree->setContextMenuPolicy(Qt::CustomContextMenu);
92 auto* splitter =
new QSplitter;
93 splitter->setOrientation(Qt::Vertical);
96 splitter->setChildrenCollapsible(
true);
98 auto* mainLayout =
new QVBoxLayout;
99 mainLayout->setMargin(0);
100 mainLayout->setSpacing(0);
101 mainLayout->setContentsMargins(0, 0, 0, 0);
102 mainLayout->addWidget(splitter);
104 setLayout(mainLayout);
106 connect(
m_itemTree, &QTreeView::customContextMenuRequested,
this,
118 connect(
m_itemTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this,
136 return QSize(200, 400);
141 return QSize(128, 200);
151 m_itemTree->selectionModel()->clearSelection();
154 m_itemTree->selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
159 return m_itemTree->selectionModel()->currentIndex();
181 auto* removeAction =
new QAction(
this);
182 removeAction->setText(
"Remove");
183 removeAction->setIcon(QIcon(
":/images/delete.svg"));
184 removeAction->setIconText(
"Remove");
185 removeAction->setToolTip(
"Remove this data");
188 return {removeAction};
204 menu.setToolTipsVisible(
true);
206 if (realDataItemAtPoint !=
nullptr) {
219 QMap<QString, AbstractDataLoader1D*> loaderOfFilter;
222 const QString filter =
223 loader->name() +
" (*.txt *.csv *.dat)";
224 loaderOfFilter[filter] = loader;
226 if (!filters.isEmpty())
230 filters +=
";;Other (*.*)";
235 const QStringList fileNames = QFileDialog::getOpenFileNames(
236 Q_NULLPTR,
"Open Intensity Files", dirname, filters, &selectedFilter,
238 : QFileDialog::DontUseNativeDialog);
240 if (fileNames.isEmpty())
246 const AbstractDataLoader* selectedLoader = loaderOfFilter.value(selectedFilter,
nullptr);
247 for (
const auto& fileName : fileNames) {
252 const QString errorText =
254 if (errorText.isEmpty())
259 QString(
"The file '%1' could not be imported.")
260 .arg(QDir::toNativeSeparators(fileName)),
268 QMap<QString, IOFactory::LoaderSelector> loaderOfFilter;
271 const auto addFilter = [&](IOFactory::LoaderSelector loaderSelector,
const QString& filter) {
272 if (!filters.isEmpty())
275 loaderOfFilter[filter] = loaderSelector;
277 addFilter(IOFactory::tiff,
"TIFF (*.tif *.tiff *.tif.gz)");
278 addFilter(IOFactory::nicos,
"Nicos/SANSDRaw (*.001)");
279 addFilter(IOFactory::bornagain,
"BornAgain (*.int.gz)");
280 addFilter(IOFactory::automatic,
"CSV (*.txt *.csv *.dat)");
281 addFilter(IOFactory::automatic,
"All (*.*)");
286 const QStringList fileNames = QFileDialog::getOpenFileNames(
287 Q_NULLPTR,
"Open Intensity Files", dirname, filters, &selectedFilter,
289 : QFileDialog::DontUseNativeDialog);
290 if (fileNames.isEmpty())
296 const auto selectedLoader = loaderOfFilter.value(selectedFilter, IOFactory::automatic);
298 for (
const auto& fileName : fileNames) {
299 std::unique_ptr<Datafield> data =
307 if (data->rank() != 2)
308 throw Error(
"The content could not be interpreted correctly as 2-dimensional.");
312 }
catch (std::exception& ex) {
315 const QString message = QString(
"Error while trying to read file\n\n'%1'\n\n%2")
317 .arg(QString::fromStdString(std::string(ex.what())));
355 QSet<int> visibleRanks;
Defines class AbstractDataLoader1D.
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class DataLoaders1D.
Defines ImportDataUtils namespace.
Defines class GUIHelpers functions.
Defines class ProjectManager.
Defines class RealDataItem.
Defines class RealDataModel.
Defines class RealDataTreeModel.
Abstract base class for all data loaders (classes to import real data).
bool useNativeFileDialog() const
static DataLoaders1D & instance()
The one and only instance.
Project document class handles all data related to the opened project (sample, job,...
Functionalities functionalities() const
void modified()
Emitted for any modifications in the document.
void setRecentlyUsedImportFilter1D(const QString &filter)
static ProjectManager * instance()
void setImportDirFromFilePath(const QString &filePath)
Sets user import directory in system settings.
QString recentlyUsedImportFilter2D() const
void setRecentlyUsedImportFilter2D(const QString &filter)
QString userImportDir() const
Returns directory name which was used by the user to import files.
QString recentlyUsedImportFilter1D() const
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
void setDataName(const QString &name)
void setNativeFileName(const QString &filename)
The name from where the native data was originally imported.
void setDatafield(Datafield *data)
Sets Datafield to underlying item. Creates it if not existing.
Tree model for real data item selection. Used for the tree in the import view.
QModelIndex indexForItem(RealDataItem *item) const
RealDataItem * insertIntensityDataItem()
bool isHeadline(const QModelIndex &index) const
RealDataItem * topMostItem() const
The topmost visible item. Can be null of course.
RealDataItem * insertSpecularDataItem()
RealDataItem * itemForIndex(const QModelIndex &index) const
void removeItem(RealDataItem *item)
void setVisibleRanks(QSet< int > visibleRanks)
QModelIndex indexOfHeadline(int rank) const
QString baseName(const QString &fileName)
Returns base name of file.
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.