diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit.h index e7bb2158cd7e..bc4f63f26f70 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit.h @@ -9,6 +9,8 @@ #include "ui_AddWorkspace.h" #include "ui_EditLocalParameterDialog.h" +#include + #include #include #include @@ -228,6 +230,36 @@ private slots: 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. @@ -238,9 +270,8 @@ class EditLocalParameterDialog: public QDialog public: EditLocalParameterDialog(MultiDatasetFit *parent, const QString &parName); private slots: - //void accept(); - //void reject(); void valueChanged(int,int); + void setAllValues(double); private: MultiDatasetFit *owner() const {return static_cast(parent());} Ui::EditLocalParameterDialog m_uiForm; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp index d2f78f8aea27..29d32eee65a1 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp @@ -652,6 +652,74 @@ void PlotController::updateRange(int index) /* EditLocalParameterDialog */ /*==========================================================================================*/ +LocalParameterEditor::LocalParameterEditor(QWidget *parent):QWidget(parent) +{ + auto layout = new QHBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(0); + layout->setContentsMargins(0,0,0,0); + + m_editor = new QLineEdit(parent); + m_editor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + auto button = new QPushButton("All"); + button->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding); + this->setFocusPolicy(Qt::NoFocus); + layout->addWidget(m_editor); + layout->addWidget(button); + layout->setStretch(0,1); + layout->setStretch(1,0); + this->setFocusProxy(m_editor); + this->setFocusPolicy(Qt::StrongFocus); + connect(button,SIGNAL(clicked()),this,SLOT(buttonPressed())); +} + +LocalParameterEditor::~LocalParameterEditor() +{ +} + +void LocalParameterEditor::buttonPressed() +{ + double value = m_editor->text().toDouble(); + emit setAllValues(value); +} + +/*==========================================================================================*/ +LocalParameterItemDelegate::LocalParameterItemDelegate(QObject *parent): + QStyledItemDelegate(parent), + m_currentEditor(NULL) +{ +} + +QWidget* LocalParameterItemDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const +{ + m_currentEditor = new LocalParameterEditor(parent); + connect(m_currentEditor,SIGNAL(setAllValues(double)),this,SIGNAL(setAllValues(double))); + m_currentEditor->installEventFilter(const_cast(this)); + return m_currentEditor; +} + +void LocalParameterItemDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const +{ + QStyledItemDelegate::setEditorData(editor->layout()->itemAt(0)->widget(), index); +} + +void LocalParameterItemDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const +{ + QStyledItemDelegate::setModelData(editor->layout()->itemAt(0)->widget(), model, index); +} + +bool LocalParameterItemDelegate::eventFilter(QObject * obj, QEvent * ev) +{ + if ( ev->type() == QEvent::WindowDeactivate ) + { + emit commitData(m_currentEditor); + return true; + } + return QStyledItemDelegate::eventFilter(obj,ev); +} + +/*==========================================================================================*/ + EditLocalParameterDialog::EditLocalParameterDialog(MultiDatasetFit *parent, const QString &parName): QDialog(parent),m_parName(parName) { @@ -671,6 +739,9 @@ EditLocalParameterDialog::EditLocalParameterDialog(MultiDatasetFit *parent, cons cell = new QTableWidgetItem( QString::number(multifit->getLocalParameterValue(parName,i)) ); m_uiForm.tableWidget->setItem( i, 1, cell ); } + auto deleg = new LocalParameterItemDelegate(this); + m_uiForm.tableWidget->setItemDelegateForColumn(1,deleg); + connect(deleg,SIGNAL(setAllValues(double)),this,SLOT(setAllValues(double))); } /** @@ -696,6 +767,16 @@ void EditLocalParameterDialog::valueChanged(int row, int col) } } +void EditLocalParameterDialog::setAllValues(double value) +{ + int n = owner()->getNumberOfSpectra(); + for(int i = 0; i < n; ++i) + { + owner()->setLocalParameterValue(m_parName,i,value); + m_uiForm.tableWidget->item(i,1)->setText( QString::number(value) ); + } +} + /*==========================================================================================*/ /* MultiDatasetFit */ /*==========================================================================================*/