26 #include "ui_SpecularDataImportWidget.h"
29 #include <QFileDialog>
31 #include <QStringListModel>
32 #include <QTextStream>
40 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
43 m_ui->warningsIcon->setFixedSize(20, 20);
44 m_ui->warningsIcon->setPixmap(QPixmap(
":/images/warning_16x16.png"));
46 m_ui->linkedInstrumentGroup->hide();
49 m_ui->createNewFormatButton->hide();
54 connect(
m_ui->formatSelectionComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
56 connect(
m_ui->createNewFormatButton, &QPushButton::clicked,
this,
59 connect(
m_ui->originalRowCheckBox, &QCheckBox::stateChanged,
this,
62 connect(
m_ui->rawDataCheckBox, &QCheckBox::stateChanged,
this,
65 connect(
m_ui->calculatedDataCheckBox, &QCheckBox::stateChanged,
this,
68 connect(
m_ui->specularDataCanvas->customPlot(), &QCustomPlot::axisClick,
this,
71 m_ui->specularDataCanvas->enableDeprecatedOnMousePress(
false);
73 m_ui->plotToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
74 for (
auto* action :
m_ui->specularDataCanvas->actionList())
75 m_ui->plotToolbar->addAction(action);
89 QSignalBlocker b(
m_ui->formatSelectionComboBox);
107 menu.addAction(action);
114 if (event->button() == Qt::RightButton && axis->axisType() == QCPAxis::atLeft) {
117 auto* lin =
new QAction(
"Linear");
119 lin->setCheckable(
true);
122 auto* log =
new QAction(
"Logarithmic");
124 log->setCheckable(
true);
127 auto* ag =
new QActionGroup(&menu);
134 menu.exec(event->globalPos());
155 QSignalBlocker b(
m_ui->formatSelectionComboBox);
156 m_ui->formatSelectionComboBox->clear();
158 m_ui->formatSelectionComboBox->addItem(loader->name());
160 m_ui->formatSelectionComboBox->addItem(loader->name());
170 for (
auto* child :
m_ui->propertiesWidget->children())
173 if (
m_ui->propertiesWidget->layout())
174 delete m_ui->propertiesWidget->layout();
179 const bool hasChildren = !
m_ui->propertiesWidget->children().empty();
181 m_ui->propertiesWidget->setVisible(hasChildren);
186 const QString
name =
m_ui->formatSelectionComboBox->currentText();
189 if (
name == loader->name())
198 QSignalBlocker b(
m_ui->formatSelectionComboBox);
202 "Changing the loader is not possible because the original file "
203 "contents are not available any more.");
216 QApplication::setOverrideCursor(Qt::WaitCursor);
219 QApplication::restoreOverrideCursor();
229 QApplication::setOverrideCursor(Qt::WaitCursor);
232 auto* oldModel =
m_ui->dataResultView->selectionModel();
235 if (resultModel !=
nullptr) {
239 const auto rawSections =
242 const auto processedSections = resultModel->sectionsOfColumnType(
245 QSignalBlocker b1(
m_ui->originalRowCheckBox);
246 QSignalBlocker b2(
m_ui->rawDataCheckBox);
247 QSignalBlocker b3(
m_ui->calculatedDataCheckBox);
249 if (originalSections.isEmpty()) {
250 m_ui->originalRowCheckBox->setChecked(
false);
251 m_ui->originalRowCheckBox->setEnabled(
false);
253 m_ui->originalRowCheckBox->setEnabled(
true);
255 if (rawSections.isEmpty()) {
256 m_ui->rawDataCheckBox->setChecked(
false);
257 m_ui->rawDataCheckBox->setEnabled(
false);
259 m_ui->rawDataCheckBox->setEnabled(
true);
261 if (processedSections.isEmpty()) {
262 m_ui->calculatedDataCheckBox->setChecked(
false);
263 m_ui->calculatedDataCheckBox->setEnabled(
false);
265 m_ui->calculatedDataCheckBox->setEnabled(
true);
267 m_ui->dataResultView->setModel(resultModel);
268 auto* horHeader =
m_ui->dataResultView->horizontalHeader();
270 for (
int section : originalSections)
271 horHeader->setSectionHidden(section, !
m_ui->originalRowCheckBox->isChecked());
273 for (
int section : rawSections)
274 horHeader->setSectionHidden(section, !
m_ui->rawDataCheckBox->isChecked());
276 for (
int section : processedSections)
277 horHeader->setSectionHidden(section, !
m_ui->calculatedDataCheckBox->isChecked());
280 const bool hasLinesColumn =
283 m_ui->dataResultView->verticalHeader()->setHidden(hasLinesColumn);
285 m_ui->dataResultView->resizeColumnsToContents();
287 m_ui->dataResultView->setModel(
nullptr);
293 m_ui->warningsIcon->show();
294 m_ui->warningsLabel->show();
295 m_ui->warningsListWidget->show();
296 m_ui->warningsListWidget->clear();
301 if (nLineRelatedWarnings == 1)
302 warnings <<
"1 line related warning. Please check the data tab on the right for more "
304 else if (nLineRelatedWarnings > 1)
307 "%1 line related warnings. Please check the data tab on the right for more "
309 .arg(nLineRelatedWarnings);
311 if (warnings.size() > 1)
312 for (
auto& w : warnings)
315 for (
auto& w : warnings)
316 new QListWidgetItem(w,
m_ui->warningsListWidget);
318 m_ui->warningsIcon->hide();
319 m_ui->warningsLabel->hide();
320 m_ui->warningsListWidget->hide();
323 QApplication::restoreOverrideCursor();
329 QString
name = QInputDialog::getText(
330 this,
"New format",
"Please enter a name for the new format", QLineEdit::Normal,
"", &ok);
331 if (!ok ||
name.isEmpty())
337 m_ui->formatSelectionComboBox->setCurrentText(
name);
344 QApplication::setOverrideCursor(Qt::WaitCursor);
346 QApplication::restoreOverrideCursor();
351 const auto* linkedInstrument =
355 if (linkedInstrument !=
nullptr)
Defines class AbstractDataLoaderResultModel.
Defines functions in namespace GUI::Model::DataItemUtils.
void cloneAsUserDefinedLoader(AbstractDataLoader1D *loader, const QString &name)
clones the loader as a user defined loader and puts it in DataLoaders1D store
Utility functions for data loaders.
Defines class DataLoaders1D.
Defines class InstrumentItem and all its children.
Defines class ProjectDocument.
Defines class RealDataItem.
SessionData * gSessionData
global pointer to the single instance
Defines struct SessionData.
Defines class SpecularDataItem.
Abstract base class for reflectometry data loaders.
QVector< int > sectionsOfColumnType(ColumnType type) const
The table header sections which belong to the given column type. Empty if this column type is not pre...
Abstract base class for all data loaders (classes to import real data).
virtual void applyImportSettings()
Read all values from the properties UI into the internal variables.
virtual void populateImportSettingsWidget(QWidget *parent)
Fills the widget on the import dialog pane. The implementation here in the base class does nothing (m...
virtual AbstractDataLoaderResultModel * createResultModel() const
Create a table model which contains the import information like original file content,...
virtual void guessSettings()
Guess appropriate settings (for example the separator in a CSV file). Is called only once,...
void importSettingsChanged()
Emitted whenever an import setting changed.
virtual QString name() const =0
The name shown in the format selection combo.
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 int numErrors() const
Number of errors found while processing the content. An error means that either a particular content ...
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 QByteArray fileContent() const
Returns the original file content. If not available any more (like for legacy project file import),...
virtual QStringList lineUnrelatedErrors() const
Errors not related to a particular line.
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.
static DataLoaders1D & instance()
The one and only instance.
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
void unlinkFromInstrument()
AbstractDataLoader * dataLoader() const
QString nativeFileName() const
void setDataLoader(AbstractDataLoader *loader)
Takes ownership of loader.
Base class for a GUI data item.
void setLog(bool log_flag)
static QMainWindow * mainWindow
SpecularDataItem * specularDataItem(SessionItem *parent)
Returns SpecularDataItem contained as a child in givent parent.
QString const & name(EShape k)
void information(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
std::optional< ProjectDocument * > projectDocument