-
Notifications
You must be signed in to change notification settings - Fork 122
/
MultiDatasetFit.h
325 lines (291 loc) · 8.78 KB
/
MultiDatasetFit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#ifndef MULTIDATASETFIT_H_
#define MULTIDATASETFIT_H_
#include "MantidQtCustomInterfaces/DllConfig.h"
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidAPI/AlgorithmObserver.h"
#include "MantidQtAPI/WorkspaceObserver.h"
#include "ui_MultiDatasetFit.h"
#include "ui_AddWorkspace.h"
#include "ui_EditLocalParameterDialog.h"
#include <QStyledItemDelegate>
#include <boost/shared_ptr.hpp>
#include <QMap>
#include <vector>
// Forward declarations
class QwtPlot;
class QwtPlotZoomer;
class QwtPlotPanner;
class QwtPlotMagnifier;
class QTableWidget;
class QComboBox;
class QPushButton;
namespace Mantid
{
namespace API
{
class IFunction;
class IAlgorithm;
class MatrixWorkspace;
}
}
namespace MantidQt
{
// Forward declarations
namespace MantidWidgets
{
class FunctionBrowser;
class RangeSelector;
class FitOptionsBrowser;
}
namespace API
{
class AlgorithmRunner;
}
namespace CustomInterfaces
{
// Forward declarations
class PlotController;
class DatasetPlotData;
class DataController;
/**
* Class MultiDatasetFitDialog implements a dialog for setting up a multi-dataset fit
* and displaying the results.
*/
class MANTIDQT_CUSTOMINTERFACES_DLL MultiDatasetFit: public API::UserSubWindow
{
Q_OBJECT
public:
/// The name of the interface as registered into the factory
static std::string name() { return "Multi dataset fitting"; }
// This interface's categories.
static QString categoryInfo() { return "General"; }
/// Constructor
MultiDatasetFit(QWidget *parent = NULL);
~MultiDatasetFit();
/// Get the name of the output workspace
QString getOutputWorkspaceName() const {return QString::fromStdString(m_outputWorkspaceName);}
/// Workspace name for the i-th spectrum
std::string getWorkspaceName(int i) const;
/// Workspace index of the i-th spectrum
int getWorkspaceIndex(int i) const;
/// Get the fitting range for the i-th spectrum
std::pair<double,double> getFittingRange(int i) const;
/// Total number of spectra (datasets).
int getNumberOfSpectra() const;
/// Display info about the plot.
void showPlotInfo();
/// Check that the data sets in the table are valid
void checkSpectra();
/// Get value of a local parameter
double getLocalParameterValue(const QString& parName, int i) const;
public slots:
void setLocalParameterValue(const QString& parName, int i, double value);
void reset();
private slots:
void fit();
void editLocalParameterValues(const QString& parName);
void finishFit(bool);
void enableZoom();
void enablePan();
void enableRange();
protected:
/// To be overridden to set the appropriate layout
virtual void initLayout();
private:
void createPlotToolbar();
boost::shared_ptr<Mantid::API::IFunction> createFunction() const;
void updateParameters(const Mantid::API::IFunction& fun);
void showInfo(const QString& text);
bool eventFilter(QObject *widget, QEvent *evn);
void showFunctionBrowserInfo();
void showFitOptionsBrowserInfo();
void showTableInfo();
void removeSpectra(QList<int> rows);
void loadSettings();
void saveSettings() const;
/// The form generated by Qt Designer
Ui::MultiDatasetFit m_uiForm;
/// Controls the plot and plotted data.
PlotController *m_plotController;
/// Contains all logic of dealing with data sets.
DataController *m_dataController;
/// Function editor
MantidWidgets::FunctionBrowser *m_functionBrowser;
/// Browser for setting other Fit properties
MantidWidgets::FitOptionsBrowser *m_fitOptionsBrowser;
/// Name of the output workspace
std::string m_outputWorkspaceName;
/// Fit algorithm runner
boost::shared_ptr<API::AlgorithmRunner> m_fitRunner;
};
/*==========================================================================================*/
/**
* A dialog for selecting a workspace from the ADS.
*/
class AddWorkspaceDialog: public QDialog
{
Q_OBJECT
public:
AddWorkspaceDialog(QWidget *parent);
QString workspaceName() const {return m_workspaceName;}
std::vector<int> workspaceIndices() const {return m_wsIndices;}
private slots:
void accept();
void reject();
void workspaceNameChanged(const QString&);
void selectAllSpectra(int state);
private:
/// Name of the selected workspace
QString m_workspaceName;
/// Selected workspace index
std::vector<int> m_wsIndices;
/// Maximum index in the selected workspace
int m_maxIndex;
Ui::AddWorkspace m_uiForm;
};
/*==========================================================================================*/
/**
* A class for controlling the plot widget and the displayed data.
*/
class PlotController: public QObject
{
Q_OBJECT
public:
PlotController(MultiDatasetFit *parent, QwtPlot *plot, QTableWidget *table, QComboBox *plotSelector, QPushButton *prev, QPushButton *next);
~PlotController();
void clear();
void update();
int getCurrentIndex() const {return m_currentIndex;}
bool isZoomEnabled() const;
bool isPanEnabled() const;
bool isRangeSelectorEnabled() const;
signals:
void currentIndexChanged(int);
void fittingRangeChanged(int, double, double);
public slots:
void enableZoom();
void enablePan();
void enableRange();
void updateRange(int index);
private slots:
void tableUpdated();
void prevPlot();
void nextPlot();
void plotDataSet(int);
void updateFittingRange(double startX, double endX);
private:
MultiDatasetFit *owner() const {return static_cast<MultiDatasetFit*>(parent());}
void disableAllTools();
template<class Tool>
void enableTool(Tool* tool, int cursor);
bool eventFilter(QObject *widget, QEvent *evn);
void resetRange();
void zoomToRange();
boost::shared_ptr<DatasetPlotData> getData(int i);
/// The plot widget
QwtPlot *m_plot;
///@name Plot tools
///@{
/// The zoomer
QwtPlotZoomer *m_zoomer;
/// The panner
QwtPlotPanner *m_panner;
/// The magnifier
QwtPlotMagnifier *m_magnifier;
/// The fitting range selector
MantidWidgets::RangeSelector* m_rangeSelector;
///@}
/// The workspace table
QTableWidget *m_table;
QComboBox *m_plotSelector;
QPushButton *m_prevPlot;
QPushButton *m_nextPlot;
QMap<int,boost::shared_ptr<DatasetPlotData>> m_plotData;
int m_currentIndex;
};
/*==========================================================================================*/
class LocalParameterEditor: public QWidget
{
Q_OBJECT
public:
LocalParameterEditor(QWidget *parent = NULL);
~LocalParameterEditor();
signals:
void setAllValues(double);
private slots:
void buttonPressed();
private:
QLineEdit* m_editor;
};
class LocalParameterItemDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
LocalParameterItemDelegate(QObject *parent = NULL);
QWidget* createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
void setEditorData(QWidget * editor, const QModelIndex & index) const;
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
signals:
void setAllValues(double);
private:
bool eventFilter(QObject * obj, QEvent * ev);
mutable LocalParameterEditor* m_currentEditor;
};
/*==========================================================================================*/
/**
* A dialog for displaying and editing values of local parameters.
*/
class EditLocalParameterDialog: public QDialog
{
Q_OBJECT
public:
EditLocalParameterDialog(MultiDatasetFit *parent, const QString &parName);
QList<double> getValues() const;
private slots:
void valueChanged(int,int);
void setAllValues(double);
private:
Ui::EditLocalParameterDialog m_uiForm;
QString m_parName;
QList<double> m_values;
};
/*==========================================================================================*/
/**
* A class for controlling the plot widget and the displayed data.
*/
class DataController: public QObject
{
Q_OBJECT
public:
DataController(MultiDatasetFit *parent, QTableWidget *dataTable);
std::string getWorkspaceName(int i) const;
int getWorkspaceIndex(int i) const;
int getNumberOfSpectra() const;
void checkSpectra();
std::pair<double,double> getFittingRange(int i) const;
signals:
void dataTableUpdated();
void dataSetUpdated(int i);
void hasSelection(bool);
void spectraRemoved(QList<int>);
void spectraAdded(int n);
public slots:
void setFittingRangeGlobal(bool);
void setFittingRange(int, double, double);
private slots:
void addWorkspace();
void workspaceSelectionChanged();
void removeSelectedSpectra();
void updateDataset(int, int);
private:
MultiDatasetFit *owner() const {return static_cast<MultiDatasetFit*>(parent());}
void addWorkspaceSpectrum(const QString &wsName, int wsIndex, const Mantid::API::MatrixWorkspace& ws);
void removeSpectra(QList<int> rows);
/// Table with data set names and other data.
QTableWidget *m_dataTable;
/// Flag for setting the fitting range.
bool m_isFittingRangeGlobal;
};
} // CustomInterfaces
} // MantidQt
#endif /*MULTIDATASETFITDIALOG_H_*/