Skip to content

Commit

Permalink
Re #10576. Set a shortcut for fixing parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 9, 2015
1 parent ee6a7ad commit 3bf285d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -5,6 +5,9 @@
#include <QPushButton>
#include <QMenu>
#include <QAction>
#include <QDoubleValidator>
#include <QEvent>
#include <QKeyEvent>

namespace MantidQt
{
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<QKeyEvent*>(evn);
if ( keyEvent->key() == Qt::Key_F )
{
fixParameter();
return true;
}
}
return false;
}

} // MDF
} // CustomInterfaces
} // MantidQt
Expand Down

0 comments on commit 3bf285d

Please sign in to comment.