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

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

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

#include <QmitkNumberPropertySlider.h>

#include <mitkPropertyObserver.h>
#include <mitkProperties.h>

#include <mitkRenderingManager.h>

#define DT_SHORT   1
#define DT_INT     2
#define DT_FLOAT   3
#define DT_DOUBLE  4

#define ROUND(x)       (((x) > 0) ?   int((x) + 0.5) :   int((x) - 0.5))
#define ROUND_SHORT(x) (((x) > 0) ? short((x) + 0.5) : short((x) - 0.5))

class QmitkNumberPropertySlider::Impl
{
public:

  Impl(QmitkNumberPropertySlider* q);

  void DisplayNumber();
  void adjustFactors(short, bool);

  class Editor : public mitk::PropertyEditor
  {
  public:
    Editor(mitk::IntProperty*, Impl* impl);
    Editor(mitk::FloatProperty*, Impl* impl);
    Editor(mitk::DoubleProperty*, Impl* impl);

    virtual void PropertyChanged();
    virtual void PropertyRemoved();

    void BeginModifyProperty()
    { mitk::PropertyEditor::BeginModifyProperty(); }
    void EndModifyProperty()
    { mitk::PropertyEditor::EndModifyProperty(); }

    union {
      mitk::GenericProperty<int>*     m_IntProperty;
      mitk::GenericProperty<float>*   m_FloatProperty;
      mitk::GenericProperty<double>*  m_DoubleProperty;
    };

    const int m_DataType;

  private:
    Impl* m_Impl;
  };

  std::auto_ptr<Editor> m_PropEditor;

  short m_DecimalPlaces;            // how many decimal places are shown
  double m_FactorPropertyToSlider; // internal conversion factor. neccessary because slider ranges work only with ints
  double m_FactorSliderToDisplay;  // internal conversion factor. neccessary because slider ranges work only with ints
  bool m_ShowPercents;              // whether values are given in percent (0.5 -> 50%)

  bool m_SelfChangeLock;

private:

  void initialize();

  QmitkNumberPropertySlider* q;
};

QmitkNumberPropertySlider::QmitkNumberPropertySlider::Impl::Editor::Editor(mitk::IntProperty* property, Impl* impl)
  : mitk::PropertyEditor(property)
  , m_IntProperty(property)
  , m_DataType(DT_INT)
  , m_Impl(impl)
{
}

QmitkNumberPropertySlider::QmitkNumberPropertySlider::Impl::Editor::Editor(mitk::FloatProperty* property, Impl* impl)
  : mitk::PropertyEditor( property )
  , m_FloatProperty(property)
  , m_DataType(DT_FLOAT)
  , m_Impl(impl)
{
}

QmitkNumberPropertySlider::QmitkNumberPropertySlider::Impl::Editor::Editor(mitk::DoubleProperty* property, Impl* impl)
  : mitk::PropertyEditor( property )
  , m_DoubleProperty(property)
  , m_DataType(DT_DOUBLE)
  , m_Impl(impl)
{
}

QmitkNumberPropertySlider::~QmitkNumberPropertySlider()
{
}

void QmitkNumberPropertySlider::SetProperty(mitk::IntProperty* property)
{
  if (property == NULL)
  {
    d->m_PropEditor.reset();
    this->setEnabled(false);
  }
  else
  {
    d->m_PropEditor.reset(new Impl::Editor(property, d.get()));<commit_msg>Windows compile fix<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

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

#include <QmitkNumberPropertySlider.h>

#include <mitkPropertyObserver.h>
#include <mitkProperties.h>

#include <mitkRenderingManager.h>

#define DT_SHORT   1
#define DT_INT     2
#define DT_FLOAT   3
#define DT_DOUBLE  4

#define ROUND(x)       (((x) > 0) ?   int((x) + 0.5) :   int((x) - 0.5))
#define ROUND_SHORT(x) (((x) > 0) ? short((x) + 0.5) : short((x) - 0.5))

class QmitkNumberPropertySlider::Impl
{
public:

  Impl(QmitkNumberPropertySlider* q);

  void DisplayNumber();
  void adjustFactors(short, bool);

  class Editor : public mitk::PropertyEditor
  {
  public:
    Editor(mitk::IntProperty*, Impl* impl);
    Editor(mitk::FloatProperty*, Impl* impl);
    Editor(mitk::DoubleProperty*, Impl* impl);

    virtual void PropertyChanged();
    virtual void PropertyRemoved();

    void BeginModifyProperty()
    { mitk::PropertyEditor::BeginModifyProperty(); }
    void EndModifyProperty()
    { mitk::PropertyEditor::EndModifyProperty(); }

    union {
      mitk::GenericProperty<int>*     m_IntProperty;
      mitk::GenericProperty<float>*   m_FloatProperty;
      mitk::GenericProperty<double>*  m_DoubleProperty;
    };

    const int m_DataType;

  private:
    Impl* m_Impl;
  };

  std::auto_ptr<Editor> m_PropEditor;

  short m_DecimalPlaces;            // how many decimal places are shown
  double m_FactorPropertyToSlider; // internal conversion factor. neccessary because slider ranges work only with ints
  double m_FactorSliderToDisplay;  // internal conversion factor. neccessary because slider ranges work only with ints
  bool m_ShowPercents;              // whether values are given in percent (0.5 -> 50%)

  bool m_SelfChangeLock;

private:

  void initialize();

  QmitkNumberPropertySlider* q;
};

QmitkNumberPropertySlider::Impl::Editor::Editor(mitk::IntProperty* property, Impl* impl)
  : mitk::PropertyEditor(property)
  , m_IntProperty(property)
  , m_DataType(DT_INT)
  , m_Impl(impl)
{
}

QmitkNumberPropertySlider::Impl::Editor::Editor(mitk::FloatProperty* property, Impl* impl)
  : mitk::PropertyEditor( property )
  , m_FloatProperty(property)
  , m_DataType(DT_FLOAT)
  , m_Impl(impl)
{
}

QmitkNumberPropertySlider::Impl::Editor::Editor(mitk::DoubleProperty* property, Impl* impl)
  : mitk::PropertyEditor( property )
  , m_DoubleProperty(property)
  , m_DataType(DT_DOUBLE)
  , m_Impl(impl)
{
}

QmitkNumberPropertySlider::~QmitkNumberPropertySlider()
{
}

void QmitkNumberPropertySlider::SetProperty(mitk::IntProperty* property)
{
  if (property == NULL)
  {
    d->m_PropEditor.reset();
    this->setEnabled(false);
  }
  else
  {
    d->m_PropEditor.reset(new Impl::Editor(property, d.get()));
{'fraction_non_alphanumeric': 0.15408560311284047, 'fraction_numerical': 0.0056031128404669265, 'mean_word_length': 4.868493150684931, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '5219207', 'n_tokens_mistral': 2038, 'n_tokens_neox': 2006, 'n_words': 451}