28 #include "ui_SpecularDataImportWidget.h"
31 #include <QFileDialog>
33 #include <QStringListModel>
34 #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 QAction* lin =
new QAction(
"Linear");
119 lin->setCheckable(
true);
122 QAction* 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());
161 m_ui->formatSelectionComboBox->addItem(loader->name());
172 for (
auto child :
m_ui->propertiesWidget->children()) {
176 if (
m_ui->propertiesWidget->layout())
177 delete m_ui->propertiesWidget->layout();
183 const bool hasChildren = !
m_ui->propertiesWidget->children().empty();
185 m_ui->propertiesWidget->setVisible(hasChildren);
190 const QString
name =
m_ui->formatSelectionComboBox->currentText();
193 if (
name == loader->name())
203 QSignalBlocker b(
m_ui->formatSelectionComboBox);
207 "Changing the loader is not possible because the original file "
208 "contents are not available any more.");
221 QApplication::setOverrideCursor(Qt::WaitCursor);
224 QApplication::restoreOverrideCursor();
234 QApplication::setOverrideCursor(Qt::WaitCursor);
237 auto oldModel =
m_ui->dataResultView->selectionModel();
240 if (resultModel !=
nullptr) {
245 const auto rawSections =
248 const auto processedSections = resultModel->sectionsOfColumnType(
251 QSignalBlocker b1(
m_ui->originalRowCheckBox);
252 QSignalBlocker b2(
m_ui->rawDataCheckBox);
253 QSignalBlocker b3(
m_ui->calculatedDataCheckBox);
255 if (originalSections.isEmpty()) {
256 m_ui->originalRowCheckBox->setChecked(
false);
257 m_ui->originalRowCheckBox->setEnabled(
false);
259 m_ui->originalRowCheckBox->setEnabled(
true);
261 if (rawSections.isEmpty()) {
262 m_ui->rawDataCheckBox->setChecked(
false);
263 m_ui->rawDataCheckBox->setEnabled(
false);
265 m_ui->rawDataCheckBox->setEnabled(
true);
267 if (processedSections.isEmpty()) {
268 m_ui->calculatedDataCheckBox->setChecked(
false);
269 m_ui->calculatedDataCheckBox->setEnabled(
false);
271 m_ui->calculatedDataCheckBox->setEnabled(
true);
273 m_ui->dataResultView->setModel(resultModel);
274 auto horHeader =
m_ui->dataResultView->horizontalHeader();
276 for (
int section : originalSections)
277 horHeader->setSectionHidden(section, !
m_ui->originalRowCheckBox->isChecked());
279 for (
int section : rawSections)
280 horHeader->setSectionHidden(section, !
m_ui->rawDataCheckBox->isChecked());
282 for (
int section : processedSections)
283 horHeader->setSectionHidden(section, !
m_ui->calculatedDataCheckBox->isChecked());
286 const bool hasLinesColumn =
289 m_ui->dataResultView->verticalHeader()->setHidden(hasLinesColumn);
291 m_ui->dataResultView->resizeColumnsToContents();
293 m_ui->dataResultView->setModel(
nullptr);
299 m_ui->warningsIcon->show();
300 m_ui->warningsLabel->show();
301 m_ui->warningsListWidget->show();
302 m_ui->warningsListWidget->clear();
307 if (nLineRelatedWarnings == 1)
308 warnings <<
"1 line related warning. Please check the data tab on the right for more "
310 else if (nLineRelatedWarnings > 1)
313 "%1 line related warnings. Please check the data tab on the right for more "
315 .arg(nLineRelatedWarnings);
317 if (warnings.size() > 1)
318 for (
auto& w : warnings)
321 for (
auto& w : warnings)
322 new QListWidgetItem(w,
m_ui->warningsListWidget);
325 m_ui->warningsIcon->hide();
326 m_ui->warningsLabel->hide();
327 m_ui->warningsListWidget->hide();
330 QApplication::restoreOverrideCursor();
336 QString
name = QInputDialog::getText(
337 this,
"New format",
"Please enter a name for the new format", QLineEdit::Normal,
"", &ok);
338 if (!ok ||
name.isEmpty())
344 m_ui->formatSelectionComboBox->setCurrentText(
name);
351 QApplication::setOverrideCursor(Qt::WaitCursor);
353 QApplication::restoreOverrideCursor();
Defines class AbstractDataLoader1D.
Defines class AbstractDataLoaderResultModel.
Defines class AbstractDataLoader.
#define ASSERT(condition)
Defines namespace DataItemUtils.
Defines class DataLoaders1D.
Defines class MainWindow.
Defines class ProjectManager.
Defines InstrumentItems classes.
Defines class QREDataLoader.
Defines class RealDataItem.
Defines class SpecularDataItem.
Base class for data loaders for 1D import.
QVector< int > sectionsOfColumnType(ColumnType type) const
The table header sections which belong to the given column type.
Base class for all data loaders (classes which can 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.
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).
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.
virtual int numErrors() const
Number of errors found while processing the content.
virtual void processContents()=0
Process the file contents.
virtual void initWithDefaultImportSettings()
Set import settings to defaults.
virtual QByteArray fileContent() const
Returns the original file content.
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.
void cloneAsUserDefinedLoader(AbstractDataLoader *loader, const QString &name)
Clone the loader and create a user defined loader with its current settings and the given name.
static DataLoaders1D & instance()
The one and only instance.
static MainWindow * instance()
Returns the one and only instance of this class.
The RealDataItem class represents intensity data imported from file and intended for fitting.
AbstractDataLoader * dataLoader() const
QString nativeFileName() const
void setDataLoader(AbstractDataLoader *loader)
Takes ownership of loader.
void setLog(bool log_flag)
SpecularDataItem * specularDataItem(SessionItem *parent)
Returns SpecularDataItem contained as a child in givent parent.
void information(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
QString const & name(EShape k)