From 3bf285d4abcf5301a154912d40fe023b3b13fed1 Mon Sep 17 00:00:00 2001 From: Roman Tolchenov Date: Thu, 9 Apr 2015 10:22:25 +0100 Subject: [PATCH] Re #10576. Set a shortcut for fixing parameters. --- .../MultiDatasetFit/MDFLocalParameterEditor.h | 1 + .../MDFLocalParameterEditor.cpp | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFLocalParameterEditor.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFLocalParameterEditor.h index 8c84bf665470..79595f3e0ce1 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFLocalParameterEditor.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFLocalParameterEditor.h @@ -32,6 +32,7 @@ private slots: void fixAll(); void unfixAll(); private: + bool eventFilter(QObject *widget, QEvent *evn); QLineEdit* m_editor; QAction *m_fixAction; int m_index; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit/MDFLocalParameterEditor.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit/MDFLocalParameterEditor.cpp index 27c59601cf08..4484eb5bd9cd 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit/MDFLocalParameterEditor.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit/MDFLocalParameterEditor.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include namespace MantidQt { @@ -26,8 +29,14 @@ LocalParameterEditor::LocalParameterEditor(QWidget *parent, int index, bool fixe m_editor = new QLineEdit(parent); m_editor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + auto validator = new QDoubleValidator(this); + validator->setDecimals(16); + m_editor->setValidator(validator); + m_editor->setToolTip("Edit local parameter value. Press F to fix/unfix it."); + auto button = new QPushButton("Set"); button->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding); + this->setFocusPolicy(Qt::NoFocus); layout->addWidget(m_editor); layout->addWidget(button); @@ -60,6 +69,7 @@ LocalParameterEditor::LocalParameterEditor(QWidget *parent, int index, bool fixe button->setMenu(setMenu); + m_editor->installEventFilter(this); } /// Send a signal to set all parameters to the value in the editor. @@ -89,6 +99,21 @@ void LocalParameterEditor::unfixAll() emit setAllFixed(false); } +/// Filter events in the line editor to emulate a shortcut (F to fix/unfix). +bool LocalParameterEditor::eventFilter(QObject *widget, QEvent *evn) +{ + if ( evn->type() == QEvent::KeyPress ) + { + auto keyEvent = static_cast(evn); + if ( keyEvent->key() == Qt::Key_F ) + { + fixParameter(); + return true; + } + } + return false; +} + } // MDF } // CustomInterfaces } // MantidQt