<commit_before>/*=========================================================================

  Library:   CTK

  Copyright (c) Kitware Inc.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0.txt

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

=========================================================================*/

// Qt includes
#include <QDebug>
#include <QMap>
#include <QPushButton>
#include <QSettings>

// CTK includes
#include "ctkSettingsPanel.h"
#include "ctkSettingsDialog.h"
#include "ui_ctkSettingsDialog.h"
#include "ctkLogger.h"

static ctkLogger logger("org.commontk.libs.widgets.ctkSettingsDialog");

//-----------------------------------------------------------------------------
class ctkSettingsDialogPrivate: public Ui_ctkSettingsDialog
{
  Q_DECLARE_PUBLIC(ctkSettingsDialog);
protected:
  ctkSettingsDialog* const q_ptr;
public:
  ctkSettingsDialogPrivate(ctkSettingsDialog& object);
  void init();

  ctkSettingsPanel* panel(QTreeWidgetItem* item)const;
  QTreeWidgetItem* item(ctkSettingsPanel* panel)const;
  QTreeWidgetItem* item(const QString& label)const;

  void beginGroup(ctkSettingsPanel* panel);
  void endGroup(ctkSettingsPanel* panel);

  QSettings* Settings;

protected:
  QMap<QTreeWidgetItem*, ctkSettingsPanel*> Panels;
};

// --------------------------------------------------------------------------
ctkSettingsDialogPrivate::ctkSettingsDialogPrivate(ctkSettingsDialog& object)
  :q_ptr(&object)
{
  this->Settings = 0;
}

// --------------------------------------------------------------------------
void ctkSettingsDialogPrivate::init()
{
  Q_Q(ctkSettingsDialog);

  this->setupUi(q);

  q->setSettings(new QSettings(q));

  QObject::connect(this->SettingsTreeWidget,
    SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
    q, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
  QObject::connect(this->SettingsButtonBox, SIGNAL(clicked(QAbstractButton*)),
                   q, SLOT(onDialogButtonClicked(QAbstractButton*)));
}

// --------------------------------------------------------------------------
ctkSettingsPanel* ctkSettingsDialogPrivate::panel(QTreeWidgetItem* item)const
{
  return this->Panels.value(item, 0);
}

// --------------------------------------------------------------------------
QTreeWidgetItem* ctkSettingsDialogPrivate::item(ctkSettingsPanel* panel)const
{
  return this->Panels.key(panel, this->SettingsTreeWidget->invisibleRootItem());
}

// --------------------------------------------------------------------------
QTreeWidgetItem* ctkSettingsDialogPrivate::item(const QString& label)const
{
  QMap<QTreeWidgetItem*, ctkSettingsPanel*>::const_iterator it;
  for (it = this->Panels.constBegin(); it != this->Panels.constEnd(); ++it)
    {
    if (it.value()->windowTitle() == label)
      {
      return it.key();
      }
    }
  return this->SettingsTreeWidget->invisibleRootItem();
}

// --------------------------------------------------------------------------
ctkSettingsDialog::ctkSettingsDialog(QWidget* _parent)
  : Superclass(_parent)
  , d_ptr(new ctkSettingsDialogPrivate(*this))
{
  Q_D(ctkSettingsDialog);
  d->init();
}

// --------------------------------------------------------------------------
ctkSettingsDialog::~ctkSettingsDialog()
{
}

// --------------------------------------------------------------------------
QSettings* ctkSettingsDialog::settings()const
{
  Q_D(const ctkSettingsDialog);
  return d->Settings;
}

// --------------------------------------------------------------------------
void ctkSettingsDialog::setSettings(QSettings* settings)
{
  Q_D(ctkSettingsDialog);

  d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setEnabled(false);

  d->Settings = settings;
  foreach(ctkSettingsPanel* panel, d->Panels.values())
    {
    panel->setSettings(settings);
    }
}

// --------------------------------------------------------------------------
void ctkSettingsDialog
::addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel)
{
  Q_D(ctkSettingsDialog);
  QTreeWidgetItem* newPanelItem = new QTreeWidgetItem;
  newPanelItem->setText(0, panel->windowTitle());
  newPanelItem->setIcon(0, panel->windowIcon());

  d->Panels[newPanelItem] = panel;
  QTreeWidgetItem* parentItem = d->item(parentPanel);
  parentItem->addChild(newPanelItem);
  d->SettingsStackedWidget->addWidget(panel);

  this->adjustTreeWidgetToContents();

  connect(panel, SIGNAL(settingChanged(QString, QVariant)),
          this, SLOT(onSettingChanged(QString, QVariant)));
  panel->setSettings(this->settings());
}
<commit_msg>Typo in the signal slot signatures<commit_after>/*=========================================================================

  Library:   CTK

  Copyright (c) Kitware Inc.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0.txt

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

=========================================================================*/

// Qt includes
#include <QDebug>
#include <QMap>
#include <QPushButton>
#include <QSettings>

// CTK includes
#include "ctkSettingsPanel.h"
#include "ctkSettingsDialog.h"
#include "ui_ctkSettingsDialog.h"
#include "ctkLogger.h"

static ctkLogger logger("org.commontk.libs.widgets.ctkSettingsDialog");

//-----------------------------------------------------------------------------
class ctkSettingsDialogPrivate: public Ui_ctkSettingsDialog
{
  Q_DECLARE_PUBLIC(ctkSettingsDialog);
protected:
  ctkSettingsDialog* const q_ptr;
public:
  ctkSettingsDialogPrivate(ctkSettingsDialog& object);
  void init();

  ctkSettingsPanel* panel(QTreeWidgetItem* item)const;
  QTreeWidgetItem* item(ctkSettingsPanel* panel)const;
  QTreeWidgetItem* item(const QString& label)const;

  void beginGroup(ctkSettingsPanel* panel);
  void endGroup(ctkSettingsPanel* panel);

  QSettings* Settings;

protected:
  QMap<QTreeWidgetItem*, ctkSettingsPanel*> Panels;
};

// --------------------------------------------------------------------------
ctkSettingsDialogPrivate::ctkSettingsDialogPrivate(ctkSettingsDialog& object)
  :q_ptr(&object)
{
  this->Settings = 0;
}

// --------------------------------------------------------------------------
void ctkSettingsDialogPrivate::init()
{
  Q_Q(ctkSettingsDialog);

  this->setupUi(q);

  q->setSettings(new QSettings(q));

  QObject::connect(this->SettingsTreeWidget,
    SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
    q, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
  QObject::connect(this->SettingsButtonBox, SIGNAL(clicked(QAbstractButton*)),
                   q, SLOT(onDialogButtonClicked(QAbstractButton*)));
}

// --------------------------------------------------------------------------
ctkSettingsPanel* ctkSettingsDialogPrivate::panel(QTreeWidgetItem* item)const
{
  return this->Panels.value(item, 0);
}

// --------------------------------------------------------------------------
QTreeWidgetItem* ctkSettingsDialogPrivate::item(ctkSettingsPanel* panel)const
{
  return this->Panels.key(panel, this->SettingsTreeWidget->invisibleRootItem());
}

// --------------------------------------------------------------------------
QTreeWidgetItem* ctkSettingsDialogPrivate::item(const QString& label)const
{
  QMap<QTreeWidgetItem*, ctkSettingsPanel*>::const_iterator it;
  for (it = this->Panels.constBegin(); it != this->Panels.constEnd(); ++it)
    {
    if (it.value()->windowTitle() == label)
      {
      return it.key();
      }
    }
  return this->SettingsTreeWidget->invisibleRootItem();
}

// --------------------------------------------------------------------------
ctkSettingsDialog::ctkSettingsDialog(QWidget* _parent)
  : Superclass(_parent)
  , d_ptr(new ctkSettingsDialogPrivate(*this))
{
  Q_D(ctkSettingsDialog);
  d->init();
}

// --------------------------------------------------------------------------
ctkSettingsDialog::~ctkSettingsDialog()
{
}

// --------------------------------------------------------------------------
QSettings* ctkSettingsDialog::settings()const
{
  Q_D(const ctkSettingsDialog);
  return d->Settings;
}

// --------------------------------------------------------------------------
void ctkSettingsDialog::setSettings(QSettings* settings)
{
  Q_D(ctkSettingsDialog);

  d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setEnabled(false);

  d->Settings = settings;
  foreach(ctkSettingsPanel* panel, d->Panels.values())
    {
    panel->setSettings(settings);
    }
}

// --------------------------------------------------------------------------
void ctkSettingsDialog
::addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel)
{
  Q_D(ctkSettingsDialog);
  QTreeWidgetItem* newPanelItem = new QTreeWidgetItem;
  newPanelItem->setText(0, panel->windowTitle());
  newPanelItem->setIcon(0, panel->windowIcon());

  d->Panels[newPanelItem] = panel;
  QTreeWidgetItem* parentItem = d->item(parentPanel);
  parentItem->addChild(newPanelItem);
  d->SettingsStackedWidget->addWidget(panel);

  this->adjustTreeWidgetToContents();

  connect(panel, SIGNAL(settingChanged(QString,QVariant)),
          this, SLOT(onSettingChanged(QString,QVariant)));
  panel->setSettings(this->settings());
}

{'fraction_non_alphanumeric': 0.2924104916724843, 'fraction_numerical': 0.0015956916325920016, 'mean_word_length': 2.4603174603174605, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '344993', 'n_tokens_mistral': 2660, 'n_tokens_neox': 2598, 'n_words': 503}