<commit_before>// Copyright (C) 2017 - 2018 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and University of
// of Connecticut School of Medicine.
// All rights reserved.

// Copyright (C) 2016 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

#include <QSortFilterProxyModel>

#include "copasi/UI/CQParameterGroupView.h"
#include "copasi/UI/CQComboDelegate.h"
#include "copasi/UI/CQPushButtonDelegate.h"
#include "copasi/UI/CCopasiSelectionDialog.h"
#include "copasi/resourcesUI/CQIconResource.h"
#include "copasi/UI/copasiui3window.h"

#include "copasi/copasi.h"
#include "copasi/UI/qtUtilities.h"

#include "copasi/utilities/CCopasiParameterGroup.h"

#include "copasi/CopasiDataModel/CDataModel.h"
#include "copasi/UI/CQParameterGroupDM.h"
#include "copasi/model/CObjectLists.h"
#include "copasi/utilities/utility.h"
#include "copasi/core/CRootContainer.h"
#include "copasi/commandline/CConfigurationFile.h"

CQParameterGroupView::CQParameterGroupView(QWidget* parent):
  QTreeView(parent),
  mpParameterGroupDM(NULL),
  mpSortFilterDM(NULL),
  mpComboBoxDelegate(NULL),
  mpPushButtonDelegate(NULL)
{
  // create a new QListview to be displayed on the screen..and set its property
  mpParameterGroupDM = new CQParameterGroupDM(this);

  mpSortFilterDM = new QSortFilterProxyModel(this);
  mpSortFilterDM->setFilterKeyColumn(0);
  mpSortFilterDM->setFilterRole(Qt::UserRole + 1);
  mpSortFilterDM->setFilterRegExp(CRootContainer::getConfiguration()->enableAdditionalOptimizationParameters() ? "" : "basic");
  mpSortFilterDM->setSourceModel(mpParameterGroupDM);
  mpSortFilterDM->setSortRole(Qt::UserRole + 2);
  mpSortFilterDM->sort(0, Qt::DescendingOrder);

  setSortingEnabled(true);
  setModel(mpSortFilterDM);

  mpComboBoxDelegate = new CQComboDelegate(this);
  mpPushButtonDelegate = new CQPushButtonDelegate(CQIconResource::icon(CQIconResource::copasi), QString(),
      CQPushButtonDelegate::ToolButton, this);

  connect(mpParameterGroupDM, SIGNAL(signalCreateComboBox(const QModelIndex &)), this, SLOT(slotCreateComboBox(const QModelIndex &)));
  connect(mpParameterGroupDM, SIGNAL(signalCreatePushButton(const QModelIndex &)), this, SLOT(slotCreatePushButton(const QModelIndex &)));
  connect(mpParameterGroupDM, SIGNAL(signalCloseEditor(const QModelIndex &)), this, SLOT(slotCloseEditor(const QModelIndex &)));
  connect(mpPushButtonDelegate, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPushButtonClicked(const QModelIndex &)));
  connect(dynamic_cast<CopasiUI3Window *>(CopasiUI3Window::getMainWindow()), SIGNAL(signalPreferenceUpdated()), this, SLOT(slotPreferenceUpdated()));
}

CQParameterGroupView::~CQParameterGroupView()
{}

void CQParameterGroupView::setAdvanced(const bool & advanced)
{
  mpParameterGroupDM->setAdvanced(advanced);
}

void CQParameterGroupView::pushGroup(CCopasiParameterGroup * pGroup)
{
  mpParameterGroupDM->pushGroup(pGroup);

  this->expandAll();
  this->resizeColumnToContents(0);
}

void CQParameterGroupView::popGroup(CCopasiParameterGroup * pGroup)
{
  mpParameterGroupDM->popGroup(pGroup);

  this->expandAll();
  this->resizeColumnToContents(0);
}

void CQParameterGroupView::clearGroups()
{
  mpParameterGroupDM->clearGroups();
}

void CQParameterGroupView::slotPreferenceUpdated()
{
  mpSortFilterDM->setFilterRegExp(CRootContainer::getConfiguration()->enableAdditionalOptimizationParameters() ? "" : "basic");
}

void CQParameterGroupView::slotCreateComboBox(const QModelIndex & index)
{
  QModelIndex Source = index;

  while (Source.model()->inherits("QSortFilterProxyModel"))
    {
      Source = static_cast< const QSortFilterProxyModel *>(Source.model())->mapToSource(index);
    }

  this->setItemDelegateForRow(Source.row(), mpComboBoxDelegate);
  this->openPersistentEditor(Source);
  this->expandAll();
}

void CQParameterGroupView::slotCreatePushButton(const QModelIndex & index)
{
  QModelIndex Source = index;
<commit_msg>Bug 2922: The item delegates are reset to default on method change.<commit_after>// Copyright (C) 2019 - 2020 by <NAME>, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.

// Copyright (C) 2017 - 2018 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and University of
// of Connecticut School of Medicine.
// All rights reserved.

// Copyright (C) 2016 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

#include <QSortFilterProxyModel>

#include "copasi/UI/CQParameterGroupView.h"
#include "copasi/UI/CQComboDelegate.h"
#include "copasi/UI/CQPushButtonDelegate.h"
#include "copasi/UI/CCopasiSelectionDialog.h"
#include "copasi/resourcesUI/CQIconResource.h"
#include "copasi/UI/copasiui3window.h"

#include "copasi/copasi.h"
#include "copasi/UI/qtUtilities.h"

#include "copasi/utilities/CCopasiParameterGroup.h"

#include "copasi/CopasiDataModel/CDataModel.h"
#include "copasi/UI/CQParameterGroupDM.h"
#include "copasi/model/CObjectLists.h"
#include "copasi/utilities/utility.h"
#include "copasi/core/CRootContainer.h"
#include "copasi/commandline/CConfigurationFile.h"

CQParameterGroupView::CQParameterGroupView(QWidget* parent):
  QTreeView(parent),
  mpParameterGroupDM(NULL),
  mpSortFilterDM(NULL),
  mpComboBoxDelegate(NULL),
  mpPushButtonDelegate(NULL)
{
  // create a new QListview to be displayed on the screen..and set its property
  mpParameterGroupDM = new CQParameterGroupDM(this);

  mpSortFilterDM = new QSortFilterProxyModel(this);
  mpSortFilterDM->setFilterKeyColumn(0);
  mpSortFilterDM->setFilterRole(Qt::UserRole + 1);
  mpSortFilterDM->setFilterRegExp(CRootContainer::getConfiguration()->enableAdditionalOptimizationParameters() ? "" : "basic");
  mpSortFilterDM->setSourceModel(mpParameterGroupDM);
  mpSortFilterDM->setSortRole(Qt::UserRole + 2);
  mpSortFilterDM->sort(0, Qt::DescendingOrder);

  setSortingEnabled(true);
  setModel(mpSortFilterDM);

  mpComboBoxDelegate = new CQComboDelegate(this);
  mpPushButtonDelegate = new CQPushButtonDelegate(CQIconResource::icon(CQIconResource::copasi), QString(),
      CQPushButtonDelegate::ToolButton, this);

  connect(mpParameterGroupDM, SIGNAL(signalCreateComboBox(const QModelIndex &)), this, SLOT(slotCreateComboBox(const QModelIndex &)));
  connect(mpParameterGroupDM, SIGNAL(signalCreatePushButton(const QModelIndex &)), this, SLOT(slotCreatePushButton(const QModelIndex &)));
  connect(mpParameterGroupDM, SIGNAL(signalCloseEditor(const QModelIndex &)), this, SLOT(slotCloseEditor(const QModelIndex &)));
  connect(mpPushButtonDelegate, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPushButtonClicked(const QModelIndex &)));
  connect(dynamic_cast<CopasiUI3Window *>(CopasiUI3Window::getMainWindow()), SIGNAL(signalPreferenceUpdated()), this, SLOT(slotPreferenceUpdated()));
}

CQParameterGroupView::~CQParameterGroupView()
{}

void CQParameterGroupView::setAdvanced(const bool & advanced)
{
  mpParameterGroupDM->setAdvanced(advanced);
}

void CQParameterGroupView::pushGroup(CCopasiParameterGroup * pGroup)
{
  mpParameterGroupDM->pushGroup(pGroup);

  this->expandAll();
  this->resizeColumnToContents(0);
}

void CQParameterGroupView::popGroup(CCopasiParameterGroup * pGroup)
{
  mpParameterGroupDM->popGroup(pGroup);

  this->expandAll();
  this->resizeColumnToContents(0);
}

void CQParameterGroupView::clearGroups()
{
  // We need to remove/reset all custom delegates
  QAbstractItemDelegate * pDefault = this->itemDelegate();

  for (int i = 0; i < mpParameterGroupDM->rowCount(); ++i)
    {
      this->setItemDelegateForRow(i, pDefault);
    }

  mpParameterGroupDM->clearGroups();
}

void CQParameterGroupView::slotPreferenceUpdated()
{
  mpSortFilterDM->setFilterRegExp(CRootContainer::getConfiguration()->enableAdditionalOptimizationParameters() ? "" : "basic");
}

void CQParameterGroupView::slotCreateComboBox(const QModelIndex & index)
{
  QModelIndex Source = index;

  while (Source.model()->inherits("QSortFilterProxyModel"))
    {
      Source = static_cast< const QSortFilterProxyModel *>(Source.model())->mapToSource(index);
    }

  this->setItemDelegateForRow(Source.row(), mpComboBoxDelegate);
  this->openPersistentEditor(Source);
  this->expandAll();
}

void CQParameterGroupView::slotCreatePushButton(const QModelIndex & index)
{
  QModelIndex Source = index;

{'fraction_non_alphanumeric': 0.12210526315789473, 'fraction_numerical': 0.006432748538011696, 'mean_word_length': 7.05937794533459, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6418887', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2631, 'n_words': 467}