Esempio n. 1
0
/** Remove a function
 * @param i :: The index of the function to remove
 */
void CompositeFunction::removeFunction(size_t i) {
  if (i >= nFunctions()) {
    throw std::out_of_range("Function index (" + std::to_string(i) +
                            ") out of range (" + std::to_string(nFunctions()) +
                            ").");
  }

  IFunction_sptr fun = getFunction(i);
  // Reduction in parameters
  size_t dnp = fun->nParams();

  for (size_t j = 0; j < nParams();) {
    ParameterTie *tie = getTie(j);
    if (tie && tie->findParametersOf(fun.get())) {
      removeTie(j);
    } else {
      j++;
    }
  }

  // Shift down the function indeces for parameters
  for (auto it = m_IFunction.begin(); it != m_IFunction.end();) {

    if (*it == i) {
      it = m_IFunction.erase(it);
    } else {
      if (*it > i) {
        *it -= 1;
      }
      ++it;
    }
  }

  m_nParams -= dnp;
  // Shift the parameter offsets down by the total number of i-th function's
  // params
  for (size_t j = i + 1; j < nFunctions(); j++) {
    m_paramOffsets[j] -= dnp;
  }
  m_paramOffsets.erase(m_paramOffsets.begin() + i);

  m_functions.erase(m_functions.begin() + i);
}
Esempio n. 2
0
/**
 * 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);
}
Esempio n. 4
0
void Gaussian::unfixIntensity() { removeTie("Height"); }