Mantid
Loading...
Searching...
No Matches
FunctionBrowser.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
18
19#include "MantidKernel/Logger.h"
20
21#include <QApplication>
22#include <QClipboard>
23#include <QHBoxLayout>
24#include <QMessageBox>
25
26#include <algorithm>
27#include <boost/lexical_cast.hpp>
28#include <utility>
29
30namespace {
31Mantid::Kernel::Logger g_log("Function Browser");
32} // namespace
33
35
36using namespace Mantid::API;
37using namespace Mantid::Kernel;
38
46FunctionBrowser::FunctionBrowser(QWidget *parent, bool multi, const std::vector<std::string> &categories)
47 : QWidget(parent) {
48 auto view = new FunctionTreeView(this, multi, categories);
49 m_presenter = std::make_unique<FunctionMultiDomainPresenter>(view);
50 QHBoxLayout *layout = new QHBoxLayout(this);
51 layout->setMargin(0);
52 layout->addWidget(view);
53 connect(m_presenter.get(), SIGNAL(functionStructureChanged()), this, SIGNAL(functionStructureChanged()));
54 connect(m_presenter.get(), SIGNAL(parameterChanged(const QString &, const QString &)), this,
55 SIGNAL(parameterChanged(const QString &, const QString &)));
56 connect(m_presenter.get(), SIGNAL(attributeChanged(const QString &)), this,
57 SIGNAL(attributeChanged(const QString &)));
58}
59
64
69
74void FunctionBrowser::setFunction(const QString &funStr) { m_presenter->setFunctionString(funStr); }
75
80void FunctionBrowser::setFunction(IFunction_sptr fun) { m_presenter->setFunction(std::move(fun)); }
81
88 return m_presenter->getFunctionByIndex(index);
89}
95void FunctionBrowser::setParameter(const QString &paramName, double value) {
96 m_presenter->setParameter(paramName, value);
97}
98
104void FunctionBrowser::setParameterError(const QString &paramName, double error) {
105 m_presenter->setParameterError(paramName, error);
106}
107
112double FunctionBrowser::getParameter(const QString &paramName) const { return m_presenter->getParameter(paramName); }
113
119void FunctionBrowser::updateParameters(const IFunction &fun) { m_presenter->updateParameters(fun); }
120
124QString FunctionBrowser::getFunctionString() { return m_presenter->getFunctionString(); }
125
127
128bool FunctionBrowser::hasFunction() const { return m_presenter->hasFunction(); }
129
131int FunctionBrowser::getNumberOfDatasets() const { return m_presenter->getNumberOfDatasets(); }
132
134QStringList FunctionBrowser::getDatasetNames() const { return m_presenter->getDatasetNames(); }
135
137QStringList FunctionBrowser::getDatasetDomainNames() const { return m_presenter->getDatasetDomainNames(); }
138
141void FunctionBrowser::setNumberOfDatasets(int n) { m_presenter->setNumberOfDatasets(n); }
142
146void FunctionBrowser::setDatasets(const QStringList &datasetNames) { m_presenter->setDatasets(datasetNames); }
147
151void FunctionBrowser::setDatasets(const QList<FunctionModelDataset> &datasets) { m_presenter->setDatasets(datasets); }
152
158double FunctionBrowser::getLocalParameterValue(const QString &parName, int i) const {
159 return m_presenter->getLocalParameterValue(parName, i);
160}
161
162void FunctionBrowser::setLocalParameterValue(const QString &parName, int i, double value) {
163 m_presenter->setLocalParameterValue(parName, i, value);
164}
165
166void FunctionBrowser::setLocalParameterValue(const QString &parName, int i, double value, double error) {
167 m_presenter->setLocalParameterValue(parName, i, value, error);
168}
169
171double FunctionBrowser::getLocalParameterError(const QString &parName, int i) const {
172 return m_presenter->getLocalParameterValue(parName, i);
173}
174
176
178void FunctionBrowser::setCurrentDataset(int i) { m_presenter->setCurrentDataset(i); }
179
182void FunctionBrowser::removeDatasets(const QList<int> &indices) { m_presenter->removeDatasets(indices); }
183
186void FunctionBrowser::addDatasets(const QStringList &names) { m_presenter->addDatasets(names); }
187
190
195void FunctionBrowser::setLocalParameterFixed(const QString &parName, int i, bool fixed) {
196 m_presenter->setLocalParameterFixed(parName, i, fixed);
197}
198
202bool FunctionBrowser::isLocalParameterFixed(const QString &parName, int i) const {
203 return m_presenter->isLocalParameterFixed(parName, i);
204}
205
209QString FunctionBrowser::getLocalParameterTie(const QString &parName, int i) const {
210 return m_presenter->getLocalParameterTie(parName, i);
211}
212
217void FunctionBrowser::setLocalParameterTie(const QString &parName, int i, QString tie) {
218 m_presenter->setLocalParameterTie(parName, i, tie);
219}
220
224 m_presenter->updateMultiDatasetParameters(fun);
225}
226
230 m_presenter->updateMultiDatasetAttributes(fun);
231}
232
234 auto const nRows = paramTable.rowCount();
235 if (nRows == 0)
236 return;
237
238 auto const globalParameterNames = getGlobalParameters();
239 for (auto &&name : globalParameterNames) {
240 auto valueColumn = paramTable.getColumn(name.toStdString());
241 auto errorColumn = paramTable.getColumn((name + "_Err").toStdString());
242 setParameter(name, valueColumn->toDouble(0));
243 setParameterError(name, errorColumn->toDouble(0));
244 }
245
246 auto const localParameterNames = getLocalParameters();
247 for (auto &&name : localParameterNames) {
248 auto valueColumn = paramTable.getColumn(name.toStdString());
249 auto errorColumn = paramTable.getColumn((name + "_Err").toStdString());
250 if (nRows > 1) {
251 for (size_t i = 0; i < nRows; ++i) {
252 setLocalParameterValue(name, static_cast<int>(i), valueColumn->toDouble(i), errorColumn->toDouble(i));
253 }
254 } else {
255 auto const i = getCurrentDataset();
256 setLocalParameterValue(name, i, valueColumn->toDouble(0), errorColumn->toDouble(0));
257 }
258 }
259}
260
262int FunctionBrowser::getCurrentDataset() const { return m_presenter->getCurrentDataset(); }
263
268void FunctionBrowser::setColumnSizes(int s0, int s1, int s2) { m_presenter->setColumnSizes(s0, s1, s2); }
269
274void FunctionBrowser::setStretchLastColumn(bool stretch) { m_presenter->setStretchLastColumn(stretch); }
275
280void FunctionBrowser::setErrorsEnabled(bool enabled) { m_presenter->setErrorsEnabled(enabled); }
281
286
287QStringList FunctionBrowser::getGlobalParameters() const { return m_presenter->getGlobalParameters(); }
288
289QStringList FunctionBrowser::getLocalParameters() const { return m_presenter->getLocalParameters(); }
290
291void FunctionBrowser::setGlobalParameters(const QStringList &globals) { m_presenter->setGlobalParameters(globals); }
292
293boost::optional<QString> FunctionBrowser::currentFunctionIndex() { return m_presenter->currentFunctionIndex(); }
294
295FunctionTreeView *FunctionBrowser::view() const { return dynamic_cast<FunctionTreeView *>(m_presenter->view()); }
296
297QString FunctionBrowser::getFitFunctionString() const { return m_presenter->getFitFunctionString(); }
298
299void FunctionBrowser::setBackgroundA0(double value) { m_presenter->setBackgroundA0(value); }
300
302
304
305} // namespace MantidQt::MantidWidgets
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
IFunction_sptr getFunctionByIndex(const QString &index)
Return a function with specified index.
void setParameterError(const QString &paramName, double error)
Update the function parameter error.
void clear() override
Clear the contents.
void removeDatasets(const QList< int > &indices)
Remove local parameter values for a number of datasets.
void parameterChanged(const QString &funcIndex, const QString &paramName)
void setCurrentDataset(int i) override
Set current dataset.
double getLocalParameterError(const QString &parName, int i) const
Get error of a local parameter.
void setNumberOfDatasets(int n) override
Set new number of the datasets.
void addDatasets(const QStringList &names)
Add some datasets to those already set.
void attributeChanged(const QString &attributeName)
QStringList getDatasetDomainNames() const override
Get the names of the dataset domains.
void setLocalParameterFixed(const QString &parName, int i, bool fixed) override
Fix/unfix local parameter.
void setDatasets(const QStringList &datasetNames) override
Sets the datasets being fitted.
void setStretchLastColumn(bool stretch)
Set the last column to stretch.
double getLocalParameterValue(const QString &parName, int i) const override
Get value of a local parameter.
void updateMultiDatasetAttributes(const IFunction &fun)
Update parameter values in the browser to match those of a function.
QString getLocalParameterTie(const QString &parName, int i) const override
Get the tie for a local parameter.
boost::optional< QString > currentFunctionIndex()
Return index of the current function, if one is selected.
void setLocalParameterValue(const QString &parName, int i, double value) override
Set value of a local parameter.
QStringList getGlobalParameters() const
Get a list of names of global parameters.
void setFunction(const QString &funStr) override
Set the function in the browser.
void clearErrors() override
Clear all errors.
void setLocalParameterTie(const QString &parName, int i, QString tie) override
Set a tie for a local parameter.
virtual ~FunctionBrowser() override
Destructor.
QStringList getDatasetNames() const override
Get the names of datasets.
int getNumberOfDatasets() const override
Get the number of datasets.
IFunction_sptr getGlobalFunction() override
Return the multidomain function if number of datasets is greater than 1.
std::unique_ptr< FunctionMultiDomainPresenter > m_presenter
void setParameter(const QString &paramName, double value)
Update the function parameter value.
void setColumnSizes(int s0, int s1, int s2=-1)
Resize the browser's columns.
bool hasFunction() const
Check if a function is set.
IFunction_sptr getFunction()
Return the function.
bool isLocalParameterFixed(const QString &parName, int i) const override
Check if a local parameter is fixed.
void setBackgroundA0(double value)
Set a parameter that is responsible for the background level.
void setErrorsEnabled(bool enabled) override
Set error display on/off.
void updateMultiDatasetParameters(const IFunction &fun) override
Update parameter values in the browser to match those of a function.
QString getFunctionString() override
Return FunctionFactory function string.
void setGlobalParameters(const QStringList &globals)
double getParameter(const QString &paramName) const
Get a value of a parameter.
int getCurrentDataset() const override
Get the index of the current dataset.
FunctionBrowser(QWidget *parent=nullptr, bool multi=false, const std::vector< std::string > &categories=std::vector< std::string >())
Constructor.
void updateParameters(const IFunction &fun) override
Update parameter values in the browser to match those of a function.
QStringList getLocalParameters() const
Get a list of names of local parameters.
Class FitPropertyBrowser implements QtPropertyBrowser to display and control fitting function paramet...
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
virtual Column_sptr getColumn(const std::string &name)=0
Gets the shared pointer to a column by name.
virtual size_t rowCount() const =0
Number of rows in the workspace.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732