Commit e01cacbf authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

Re #5108. Added new Fit dialog

parent b71b6101
......@@ -72,6 +72,13 @@ void CompositeFunction::init()
std::string CompositeFunction::asString()const
{
std::ostringstream ostr;
// if empty just return function name
if (nFunctions() == 0)
{
return "name=" + name();
}
if (name() != "CompositeFunction")
{
ostr << "composite=" <<name() << ";";
......
......@@ -75,6 +75,23 @@ public:
TS_ASSERT_EQUALS(fun1_p->getParameter("A"), 3.0);
TS_ASSERT_EQUALS(fun1_p->getParameter("B"), 2.0);
}
void testSharedPointer()
{
FunctionProperty prop("fun");
std::string error;
boost::shared_ptr<FunctionPropertyTest_Function> fun_p(new FunctionPropertyTest_Function);
TS_ASSERT(fun_p);
fun_p->setParameter("A",3);
prop = fun_p;
boost::shared_ptr<IFunction> fun1_p = prop;
TS_ASSERT(fun1_p);
TS_ASSERT_EQUALS(fun_p,fun1_p);
TS_ASSERT_EQUALS(fun1_p->asString(),"name=FunctionPropertyTest_Function,A=3,B=2");
TS_ASSERT_EQUALS(fun1_p->getParameter("A"), 3.0);
TS_ASSERT_EQUALS(fun1_p->getParameter("B"), 2.0);
}
private:
};
......
......@@ -293,7 +293,8 @@ std::string Convolution::asString()const
{
if (nFunctions() != 2)
{
throw std::runtime_error("Convolution function is incomplete");
//throw std::runtime_error("Convolution function is incomplete");
return CompositeFunction::asString();
}
std::ostringstream ostr;
ostr<<"composite=Convolution;";
......
......@@ -45,7 +45,6 @@ set ( UI_FILES inc/MantidQtCustomDialogs/CreateSampleShapeDialog.ui
inc/MantidQtCustomDialogs/StartLiveDataDialog.ui
inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.ui
inc/MantidQtCustomDialogs/FitDialog.ui
inc/MantidQtCustomDialogs/FitDialog1.ui
)
include_directories ( inc )
......
......@@ -5,12 +5,13 @@
// Includes
//------------------------------------------------------------------------------
#include "MantidQtAPI/AlgorithmDialog.h"
#include "ui_FitDialog1.h"
#include "ui_FitDialog.h"
//------------------------------------------------------------------------------
// Qt Forward declarations
//------------------------------------------------------------------------------
class QVBoxLayout;
class QSpinBox;
namespace MantidQt
{
......@@ -25,6 +26,12 @@ namespace MantidQt
namespace CustomDialogs
{
//------------------------------------------------------------------------------
// Local Forward declarations
//------------------------------------------------------------------------------
class InputWorkspaceWidget;
class DynamicPropertiesWidget;
/**
This class gives specialised dialog for the Load algorithm. It requires that the specific
load algorithm has at least 2 properties with these names:
......@@ -81,18 +88,114 @@ namespace MantidQt
virtual void parseInput();
/// Tie static widgets to their properties
void tieStaticWidgets(const bool readHistory);
/// Create InputWorkspaceWidgets and populate the tabs of the tab widget
void createInputWorkspaceWidgets();
/// Clears all of the widgets from the old layout
void removeOldInputWidgets();
/// Create
void createDynamicLayout();
/// Return property value stored in history
QString getStoredPropertyValue(const QString& propName) const;
/// Get allowed values for a property
QStringList getAllowedPropertyValues(const QString& propName) const;
/// Is the function MD?
bool isMD() const;
private:
/// Form
Ui::FitDialog m_form;
/// List of static property names
QStringList m_staticProperties;
QMap<QString,QWidget*> m_dynamicLabels;
QMap<QString,QWidget*> m_dynamicEditors;
QList<QWidget*> m_tabs;
friend class InputWorkspaceWidget;
};
/**
* Widget for inputting workspace information.
*/
class InputWorkspaceWidget: public QWidget
{
Q_OBJECT
public:
/// Constructor
InputWorkspaceWidget(FitDialog* parent, int domainIndex = 0);
/// Return property value stored in history
QString getStoredPropertyValue(const QString& propName) const
{return m_fitDialog->getStoredPropertyValue(propName);}
/// Get allowed values for a property
QStringList getAllowedPropertyValues(const QString& propName) const
{return m_fitDialog->getAllowedPropertyValues(propName);}
/// Get workspace name
QString getWorkspaceName() const ;
/// Return the domain index
int getDomainIndex() const {return m_domainIndex;}
/// Set a property
void setPropertyValue(const QString& propName, const QString& propValue);
/// Set all workspace properties
void setProperties();
protected slots:
/// Set the dynamic properties
void setDynamicProperties();
protected:
/// Is ws name set?
bool isWSNameSet() const;
/// Is the workspace MW?
bool isMatrixWorkspace() const;
/// Is the workspace MD?
bool isMDWorkspace() const;
/// is current workspace supported by Fit?
bool isWorkspaceSupported() const;
/// Parent FitDialog
FitDialog *m_fitDialog;
/// In multidomain fitting it is index of domain created from this workspace
/// In single domain case == 0
int m_domainIndex;
/// Name of the property for the input workspace
QString m_wsPropName;
/// Workspace name widget
QComboBox *m_workspaceName;
/// Dynamic propeties widget
DynamicPropertiesWidget *m_dynamicProperties;
/// The main layout
QVBoxLayout *m_layout;
};
/**
* Base class for input workspace's dynamic properties widget
*/
class DynamicPropertiesWidget: public QWidget
{
public:
/// Constructor
DynamicPropertiesWidget(InputWorkspaceWidget* parent):QWidget(parent),m_wsWidget(parent){}
/// Initialize the child widgets with stored and allowed values
virtual void init() = 0;
/// Set all workspace properties
virtual void setProperties() = 0;
protected:
/// Parent InputWorkspaceWidget
InputWorkspaceWidget *m_wsWidget;
};
/**
* Widgets to set properties for a MatrixWorkspace: WorkspaceIndex, StartX, EndX
*/
class MWPropertiesWidget: public DynamicPropertiesWidget
{
public:
MWPropertiesWidget(InputWorkspaceWidget* parent);
/// Initialize the child widgets with stored and allowed values
virtual void init();
/// Set all workspace properties
void setProperties();
protected:
QSpinBox *m_workspaceIndex;
QLineEdit *m_startX;
QLineEdit *m_endX;
};
}
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>303</width>
<height>368</height>
<width>717</width>
<height>501</height>
</rect>
</property>
<property name="windowTitle">
......@@ -134,127 +134,139 @@
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<widget class="QScrollArea" name="scrollArea_2">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<widget class="QWidget" name="widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>283</width>
<height>323</height>
<width>697</width>
<height>456</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
<layout class="QVBoxLayout" name="staticLayout">
<item>
<layout class="QGridLayout" name="topLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Function</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leFunction"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Input workspace</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbInputWorkspace"/>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="bottomLayout">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Max iterations</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leMaxIterations"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Minimizer</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="cbMinimizer"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Cost function</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cbCostFunction"/>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="chbCreateOutput">
<property name="text">
<string>Create output</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Output</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="leOutput"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Ties</string>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="MantidQt::MantidWidgets::FunctionBrowser" name="function" native="true"/>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>InputWorkspace</string>
</attribute>
</widget>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leTies"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Constraints</string>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>466</width>
<height>387</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Ties</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leTies"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Constraints</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leConstraints"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Max iterations</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leMaxIterations"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Minimizer</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="cbMinimizer"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Cost function</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cbCostFunction"/>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="chbCreateOutput">
<property name="text">
<string>Create output</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Output</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="leOutput"/>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leConstraints"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</widget>
</widget>
</item>
</layout>
</widget>
......@@ -262,6 +274,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MantidQt::MantidWidgets::FunctionBrowser</class>
<extends>QWidget</extends>
<header>MantidQtMantidWidgets/FunctionBrowser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FitDialog</class>
<widget class="QWidget" name="FitDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>717</width>
<height>501</height>
</rect>
</property>
<property name="windowTitle">
<string>Fit Dialog</string>
</property>
<layout class="QVBoxLayout" name="dialogLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="palette">
<palette>
<active>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">