Skip to content
Snippets Groups Projects
ReflMainViewPresenter.cpp 37.3 KiB
Newer Older
      const std::string newName = pNf->newObjectName();

      if(m_workspaceList.find(name) == m_workspaceList.end())
        return;

      m_workspaceList.erase(name);
      m_workspaceList.insert(newName);
      if(m_view)
        m_view->setTableList(m_workspaceList);
    }

    /**
    Handle ADS replace events
    */
    void ReflMainViewPresenter::handleReplaceEvent(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf)
    {
      const std::string name = pNf->objectName();
      //Erase it
      m_workspaceList.erase(name);

      //If it's a table workspace, bring it back
      if(isValidModel(pNf->object()))
        m_workspaceList.insert(name);

      if(m_view)
        m_view->setTableList(m_workspaceList);

    /** Returns how many rows there are in a given group
        @param groupId : The id of the group to count the rows of
        @returns The number of rows in the group
     */
    size_t ReflMainViewPresenter::numRowsInGroup(int groupId) const
    {
      size_t count = 0;
      for(size_t i = 0; i < m_model->rowCount(); ++i)
        if(m_model->Int(i, COL_GROUP) == groupId)
          count++;
      return count;
    }

    /** Expands the current selection to all the rows in the selected groups */
    void ReflMainViewPresenter::expandSelection()
    {
      std::set<int> groupIds;

      std::set<size_t> rows = m_view->getSelectedRows();
      for(auto row = rows.begin(); row != rows.end(); ++row)
        groupIds.insert(m_model->Int(*row, COL_GROUP));

      std::set<size_t> selection;

      for(size_t i = 0; i < m_model->rowCount(); ++i)
        if(groupIds.find(m_model->Int(i, COL_GROUP)) != groupIds.end())
          selection.insert(i);

      m_view->setSelection(selection);
    }

    /** Shows the Refl Options dialog */
    void ReflMainViewPresenter::showOptionsDialog()
    {
      auto options = new QtReflOptionsDialog(m_view, m_view->getPresenter());
      //By default the dialog is only destroyed when ReflMainView is and so they'll stack up.
      //This way, they'll be deallocated as soon as they've been closed.
      options->setAttribute(Qt::WA_DeleteOnClose, true);
      options->exec();
    }

    /** Gets the options used by the presenter
        @returns The options used by the presenter
     */
    const std::map<std::string,QVariant>& ReflMainViewPresenter::options() const
    {
      return m_options;
    }

    /** Sets the options used by the presenter
        @param options : The new options for the presenter to use
     */
    void ReflMainViewPresenter::setOptions(const std::map<std::string,QVariant>& options)
      //Overwrite the given options
      for(auto it = options.begin(); it != options.end(); ++it)
        m_options[it->first] = it->second;

      //Save any changes to disk
      QSettings settings;
      settings.beginGroup(ReflSettingsGroup);
      for(auto it = m_options.begin(); it != m_options.end(); ++it)
        settings.setValue(QString::fromStdString(it->first), it->second);
      settings.endGroup();

    /** Load options from disk if possible, or set to defaults */
    void ReflMainViewPresenter::initOptions()
    {
      m_options.clear();

      //Set defaults
      m_options["WarnProcessAll"] = true;
      m_options["WarnDiscardChanges"] = true;
      m_options["RoundAngle"] = false;
      m_options["RoundQMin"] = false;
      m_options["RoundQMax"] = false;
      m_options["RoundDQQ"] = false;
      m_options["RoundAnglePrecision"] = 3;
      m_options["RoundQMinPrecision"] = 3;
      m_options["RoundQMaxPrecision"] = 3;
      m_options["RoundDQQPrecision"] = 3;
      //Load saved values from disk
      QSettings settings;
      settings.beginGroup(ReflSettingsGroup);
      QStringList keys = settings.childKeys();
      for(auto it = keys.begin(); it != keys.end(); ++it)
        m_options[it->toStdString()] = settings.value(*it);
      settings.endGroup();