Commit e8bdb282 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

rm loader-specific filling of plots

parent 003d5a86
...@@ -73,9 +73,6 @@ public: ...@@ -73,9 +73,6 @@ public:
//! in here. //! in here.
virtual void deserialize(const QByteArray& data); virtual void deserialize(const QByteArray& data);
//! Plots the graph as a preview
virtual void previewOfGraph(QCustomPlot* plotWidget) const = 0;
//! Sets the file contents to be imported. If the file was a compressed file, here already the //! Sets the file contents to be imported. If the file was a compressed file, here already the
//! decompressed content will be overhanded. //! decompressed content will be overhanded.
virtual void setFileContents(const QByteArray& fileContent) = 0; virtual void setFileContents(const QByteArray& fileContent) = 0;
......
...@@ -31,40 +31,6 @@ QString AutomaticDataLoader1D::persistentClassName() const ...@@ -31,40 +31,6 @@ QString AutomaticDataLoader1D::persistentClassName() const
return "AutomaticDataLoader1D"; return "AutomaticDataLoader1D";
} }
void AutomaticDataLoader1D::previewOfGraph(QCustomPlot* plotWidget) const
{
auto outputData = m_item->specularDataItem()->getOutputData();
if (!outputData)
return;
auto size = outputData->axis(0).size();
auto dataValues = outputData->getRawDataVector();
if (size == 0)
return;
if (size != dataValues.size())
return;
QVector<double> qVec;
QVector<double> rVec;
auto& axis = outputData->axis(0);
for (size_t i = 0; i < size; i++) {
qVec << axis.binCenter(i); // axis.bincenter is same as operator[] for pointwise.
// getAxisValue() calls opertor[]
rVec << dataValues[i];
}
auto graph = plotWidget->addGraph();
graph->addData(qVec, rVec);
plotWidget->rescaleAxes();
plotWidget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
plotWidget->xAxis->setLabel("Q [1/nm]");
plotWidget->yAxis->setLabel("R");
}
AbstractDataLoader* AutomaticDataLoader1D::clone() const AbstractDataLoader* AutomaticDataLoader1D::clone() const
{ {
auto loader = new AutomaticDataLoader1D(); auto loader = new AutomaticDataLoader1D();
......
...@@ -23,7 +23,6 @@ class AutomaticDataLoader1D : public AbstractDataLoader1D { ...@@ -23,7 +23,6 @@ class AutomaticDataLoader1D : public AbstractDataLoader1D {
public: public:
virtual QString name() const override; virtual QString name() const override;
virtual QString persistentClassName() const override; virtual QString persistentClassName() const override;
virtual void previewOfGraph(QCustomPlot* plotWidget) const override;
virtual AbstractDataLoader* clone() const override; virtual AbstractDataLoader* clone() const override;
virtual void setFileContents(const QByteArray& fileContent) override; virtual void setFileContents(const QByteArray& fileContent) override;
virtual QByteArray fileContent() const override; virtual QByteArray fileContent() const override;
......
...@@ -90,44 +90,6 @@ QString QREDataLoader::persistentClassName() const ...@@ -90,44 +90,6 @@ QString QREDataLoader::persistentClassName() const
return "QREDataLoader"; return "QREDataLoader";
} }
void QREDataLoader::previewOfGraph(QCustomPlot* plotWidget) const
{
// -- create plot
int dRCol = m_importResult.importSettings.columnDefinitions[DataType::dR].column;
QVector<double> qVec;
QVector<double> rVec;
QVector<double> eVec;
const bool addError = m_importResult.importSettings.columnDefinitions[DataType::dR].enabled
&& (m_importResult.maxColumnCount > dRCol);
for (const auto d : m_importResult.qValues)
qVec << d;
for (const auto d : m_importResult.rValues)
rVec << d;
if (addError)
for (const auto d : m_importResult.eValues)
eVec << d;
auto graph = plotWidget->addGraph();
graph->addData(qVec, rVec);
if (!eVec.empty()) {
auto errorBars = new QCPErrorBars(plotWidget->xAxis, plotWidget->yAxis);
errorBars->setData(eVec);
errorBars->setDataPlottable(graph);
}
plotWidget->rescaleAxes();
plotWidget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
plotWidget->xAxis->setLabel("Q [1/nm]");
plotWidget->yAxis->setLabel("R");
}
void QREDataLoader::populateImportSettingsWidget(QWidget* parent) void QREDataLoader::populateImportSettingsWidget(QWidget* parent)
{ {
if (m_propertiesWidget == nullptr) if (m_propertiesWidget == nullptr)
......
...@@ -29,7 +29,6 @@ public: ...@@ -29,7 +29,6 @@ public:
QREDataLoader(); QREDataLoader();
virtual QString name() const override; virtual QString name() const override;
virtual QString persistentClassName() const override; virtual QString persistentClassName() const override;
virtual void previewOfGraph(QCustomPlot* plotWidget) const override;
virtual void populateImportSettingsWidget(QWidget* parent) override; virtual void populateImportSettingsWidget(QWidget* parent) override;
virtual void initWithDefaultImportSettings() override; virtual void initWithDefaultImportSettings() override;
virtual void applyImportSettings() override; virtual void applyImportSettings() override;
......
...@@ -53,11 +53,6 @@ void UserDefinedDataLoader1D::deserialize(const QByteArray& data) ...@@ -53,11 +53,6 @@ void UserDefinedDataLoader1D::deserialize(const QByteArray& data)
m_wrappedLoader->deserialize(data); m_wrappedLoader->deserialize(data);
} }
void UserDefinedDataLoader1D::previewOfGraph(QCustomPlot* plotWidget) const
{
m_wrappedLoader->previewOfGraph(plotWidget);
}
AbstractDataLoader* UserDefinedDataLoader1D::clone() const AbstractDataLoader* UserDefinedDataLoader1D::clone() const
{ {
auto cloned = dynamic_cast<AbstractDataLoader1D*>(m_wrappedLoader->clone()); auto cloned = dynamic_cast<AbstractDataLoader1D*>(m_wrappedLoader->clone());
......
...@@ -31,7 +31,6 @@ public: ...@@ -31,7 +31,6 @@ public:
virtual QString persistentClassName() const override; virtual QString persistentClassName() const override;
virtual QByteArray serialize() const override; virtual QByteArray serialize() const override;
virtual void deserialize(const QByteArray& data) override; virtual void deserialize(const QByteArray& data) override;
virtual void previewOfGraph(QCustomPlot* plotWidget) const override;
virtual AbstractDataLoader* clone() const override; virtual AbstractDataLoader* clone() const override;
virtual void setFileContents(const QByteArray& fileContent) override; virtual void setFileContents(const QByteArray& fileContent) override;
virtual void guessSettings() override; virtual void guessSettings() override;
......
...@@ -62,9 +62,6 @@ SpecularDataImportWidget::SpecularDataImportWidget(QWidget* parent) ...@@ -62,9 +62,6 @@ SpecularDataImportWidget::SpecularDataImportWidget(QWidget* parent)
connect(m_ui->calculatedDataCheckBox, &QCheckBox::stateChanged, this, connect(m_ui->calculatedDataCheckBox, &QCheckBox::stateChanged, this,
&SpecularDataImportWidget::updatePreview); &SpecularDataImportWidget::updatePreview);
connect(m_ui->plotWidget, &QCustomPlot::axisClick, this,
&SpecularDataImportWidget::onAxisClick);
connect(m_ui->specularDataCanvas->customPlot(), &QCustomPlot::axisClick, this, connect(m_ui->specularDataCanvas->customPlot(), &QCustomPlot::axisClick, this,
&SpecularDataImportWidget::onPlotAxisClicked); &SpecularDataImportWidget::onPlotAxisClicked);
...@@ -116,52 +113,6 @@ void SpecularDataImportWidget::onContextMenuRequest(const QPoint& point) ...@@ -116,52 +113,6 @@ void SpecularDataImportWidget::onContextMenuRequest(const QPoint& point)
menu.exec(point); menu.exec(point);
} }
void SpecularDataImportWidget::onAxisClick(QCPAxis* axis, QCPAxis::SelectablePart /*part*/,
QMouseEvent* event)
{
const auto setLog = [=](bool is_log_scale) {
if (is_log_scale) {
axis->setNumberFormat("eb");
axis->setNumberPrecision(0);
axis->setScaleType(QCPAxis::stLogarithmic);
QSharedPointer<QCPAxisTicker> ticker(new QCPAxisTickerLog);
axis->setTicker(ticker);
} else {
axis->setNumberFormat("g");
axis->setNumberPrecision(6);
axis->setScaleType(QCPAxis::stLinear);
QSharedPointer<QCPAxisTicker> ticker(new QCPAxisTicker);
axis->setTicker(ticker);
}
m_ui->plotWidget->rescaleAxes();
m_ui->plotWidget->replot();
};
if (event->button() == Qt::RightButton && axis->axisType() == QCPAxis::atLeft) {
QMenu menu;
QAction* lin = new QAction("Linear");
connect(lin, &QAction::triggered, [=]() { setLog(false); });
lin->setCheckable(true);
lin->setChecked(axis->scaleType() == QCPAxis::stLinear);
QAction* log = new QAction("Logarithmic");
connect(log, &QAction::triggered, [=]() { setLog(true); });
log->setCheckable(true);
log->setChecked(axis->scaleType() == QCPAxis::stLogarithmic);
auto ag = new QActionGroup(&menu);
ag->addAction(lin);
ag->addAction(log);
menu.addAction(lin);
menu.addAction(log);
menu.exec(event->globalPos());
}
}
void SpecularDataImportWidget::onPlotAxisClicked(QCPAxis* axis, QCPAxis::SelectablePart /*part*/, void SpecularDataImportWidget::onPlotAxisClicked(QCPAxis* axis, QCPAxis::SelectablePart /*part*/,
QMouseEvent* event) QMouseEvent* event)
{ {
...@@ -291,14 +242,10 @@ void SpecularDataImportWidget::onFormatSelectionChanged() ...@@ -291,14 +242,10 @@ void SpecularDataImportWidget::onFormatSelectionChanged()
void SpecularDataImportWidget::updatePreview() void SpecularDataImportWidget::updatePreview()
{ {
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
m_ui->plotWidget->clearGraphs();
if (m_loader) { if (m_loader) {
m_loader->previewOfGraph(m_ui->plotWidget);
auto oldModel = m_ui->dataResultView->selectionModel(); // sic!! according to Qt docu auto oldModel = m_ui->dataResultView->selectionModel(); // sic!! according to Qt docu
// of QAbstractItemView::setModel // of QAbstractItemView::setModel
auto resultModel = m_loader->createResultModel(); auto resultModel = m_loader->createResultModel();
if (resultModel != nullptr) { if (resultModel != nullptr) {
...@@ -358,7 +305,6 @@ void SpecularDataImportWidget::updatePreview() ...@@ -358,7 +305,6 @@ void SpecularDataImportWidget::updatePreview()
delete oldModel; delete oldModel;
} }
m_ui->plotWidget->replot();
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
</widget> </widget>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab_4"> <widget class="QWidget" name="tab_4">
<attribute name="title"> <attribute name="title">
...@@ -245,9 +245,6 @@ ...@@ -245,9 +245,6 @@
<item> <item>
<widget class="StyledToolBar" name="plotToolBar" native="true"/> <widget class="StyledToolBar" name="plotToolBar" native="true"/>
</item> </item>
<item>
<widget class="QCustomPlot" name="plotWidget" native="true"/>
</item>
<item> <item>
<widget class="SpecularDataCanvas" name="specularDataCanvas" native="true"/> <widget class="SpecularDataCanvas" name="specularDataCanvas" native="true"/>
</item> </item>
...@@ -259,12 +256,6 @@ ...@@ -259,12 +256,6 @@
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>QCustomPlot</class>
<extends>QWidget</extends>
<header>qcustomplot.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>SpecularDataCanvas</class> <class>SpecularDataCanvas</class>
<extends>QWidget</extends> <extends>QWidget</extends>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment