/// Filter events in the line editor to emulate a shortcut (F to fix/unfix). bool LocalParameterEditor::eventFilter(QObject *, QEvent *evn) { if ( evn->type() == QEvent::KeyPress ) { auto keyEvent = static_cast<QKeyEvent*>(evn); if ( keyEvent->key() == Qt::Key_F ) { fixParameter(); return true; } } return false; }
/// Filter events in the line editor to emulate a shortcut (F to fix/unfix). bool LocalParameterEditor::eventFilter(QObject *, QEvent *evn) { if (evn->type() == QEvent::KeyPress) { auto keyEvent = static_cast<QKeyEvent *>(evn); if (keyEvent->key() == Qt::Key_F && keyEvent->modifiers() == Qt::ControlModifier && m_tie.isEmpty()) { fixParameter(); return true; } if (m_tie.isEmpty()) { m_value = m_editor->text(); } else { m_tie = m_editor->text(); emit setTie(m_index, m_tie); } } return false; }
void testFunctionRootFind(std::function<double(double)> f, double StartValue, double ExpectedResult) { // linear function auto x = std::make_shared<ComPWA::FitParameter>("x", StartValue); x->fixParameter(false); ComPWA::ParameterList Params; Params.addParameter(x); auto LinearRootFind = std::make_shared<FunctionRootEstimator>(f, Params); auto Minimizer = std::make_shared<ComPWA::Optimizer::Minuit2::MinuitIF>( LinearRootFind, Params); auto Result = Minimizer->exec(Params); LOG(DEBUG) << Result->finalParameters().doubleParameter(0)->value(); BOOST_CHECK(std::abs(Result->finalParameters().doubleParameter(0)->value() - ExpectedResult) < 1e-4); }
/** * Create and connect actions */ void FunctionBrowser::createActions() { m_actionAddFunction = new QAction("Add function",this); connect(m_actionAddFunction,SIGNAL(triggered()),this,SLOT(addFunction())); m_actionRemoveFunction = new QAction("Remove function",this); connect(m_actionRemoveFunction,SIGNAL(triggered()),this,SLOT(removeFunction())); m_actionFixParameter = new QAction("Fix",this); connect(m_actionFixParameter,SIGNAL(triggered()),this,SLOT(fixParameter())); m_actionRemoveTie = new QAction("Remove tie",this); connect(m_actionRemoveTie,SIGNAL(triggered()),this,SLOT(removeTie())); m_actionAddTie = new QAction("Add tie",this); connect(m_actionAddTie,SIGNAL(triggered()),this,SLOT(addTie())); m_actionFromClipboard = new QAction("Copy from clipboard",this); connect(m_actionFromClipboard,SIGNAL(triggered()),this,SLOT(copyFromClipboard())); m_actionToClipboard = new QAction("Copy to clipboard",this); connect(m_actionToClipboard,SIGNAL(triggered()),this,SLOT(copyToClipboard())); m_actionConstraints = new QAction("Custom",this); connect(m_actionConstraints,SIGNAL(triggered()),this,SLOT(addConstraints())); m_actionConstraints10 = new QAction("10%",this); connect(m_actionConstraints10,SIGNAL(triggered()),this,SLOT(addConstraints10())); m_actionConstraints50 = new QAction("50%",this); connect(m_actionConstraints50,SIGNAL(triggered()),this,SLOT(addConstraints50())); m_actionRemoveConstraints = new QAction("Remove constraints",this); connect(m_actionRemoveConstraints,SIGNAL(triggered()),this,SLOT(removeConstraints())); m_actionRemoveConstraint = new QAction("Remove",this); connect(m_actionRemoveConstraint,SIGNAL(triggered()),this,SLOT(removeConstraint())); }
/// Constructor /// @param parent :: Parent widget. /// @param index :: Index of the spectrum which parameter is edited. /// @param fixed :: Is the parameter fixed initially? /// @param tie :: Parameter's current tie (or empty string). LocalParameterEditor::LocalParameterEditor(QWidget *parent, int index, bool fixed, QString tie): QWidget(parent), m_index(index),m_fixed(fixed), m_tie(tie) { 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 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); layout->setStretch(0,1); layout->setStretch(1,0); this->setFocusProxy(m_editor); this->setFocusPolicy(Qt::StrongFocus); auto setMenu = new QMenu(this); QAction *action = new QAction("Set to all",this); action->setToolTip("Set all parameters to this value"); connect(action,SIGNAL(activated()),this,SLOT(setAll())); setMenu->addAction(action); setMenu->addSeparator(); m_fixAction = new QAction(m_fixed? "Unfix" : "Fix", this); m_fixAction->setToolTip("Fix value of this parameter"); connect(m_fixAction,SIGNAL(activated()),this,SLOT(fixParameter())); setMenu->addAction(m_fixAction); action = new QAction("Fix all",this); action->setToolTip("Fix all parameters."); connect(action,SIGNAL(activated()),this,SLOT(fixAll())); setMenu->addAction(action); action = new QAction("Unfix all",this); action->setToolTip("Unfix all parameters."); connect(action,SIGNAL(activated()),this,SLOT(unfixAll())); setMenu->addAction(action); setMenu->addSeparator(); action = new QAction("Set tie",this); action->setToolTip("Set a tie for this parameter."); connect(action,SIGNAL(activated()),this,SLOT(setTie())); setMenu->addAction(action); action = new QAction("Remove tie",this); action->setToolTip("Remove the tie for this parameter."); connect(action,SIGNAL(activated()),this,SLOT(removeTie())); setMenu->addAction(action); action = new QAction("Set tie to all",this); action->setToolTip("Set this tie for all parameters."); connect(action,SIGNAL(activated()),this,SLOT(setTieAll())); setMenu->addAction(action); action = new QAction("Remove all ties",this); action->setToolTip("Remove ties for all parameters."); connect(action,SIGNAL(activated()),this,SLOT(removeAllTies())); setMenu->addAction(action); button->setMenu(setMenu); m_editor->installEventFilter(this); }
/// Toggle the fix state of the current parameter. void LocalParameterEditor::fixParameter() { m_fixed = !m_fixed; m_fixAction->setText( m_fixed? "Unfix" : "Fix" ); emit fixParameter(m_index, m_fixed); }
void Gaussian::fixCentre() { fixParameter("PeakCentre"); }
void Lorentzian::fixIntensity() { fixParameter("Amplitude"); }
void Lorentzian::fixCentre() { fixParameter("PeakCentre"); }