<commit_before>#ifndef __FLY_CAP_SETTING_EDITOR_H__
#define __FLY_CAP_SETTING_EDITOR_H__

#include <map>
#include <mutex>
#include <QLabel>
#include <QCheckBox>
#include <QMessageBox>
#include <QXmlStreamWriter>
#include <QFile>
#include "mio/qt/advSliderWidget/advSliderWidget.h"
#include "mio/altro/ptGreyFlyCap2.h"
#include "mio/altro/freqBuffer.h"
#include "mio/altro/io.h"
#include "mio/qt/qtXml.h"


namespace mio{

class UiPropertySetter : public QWidget{
  Q_OBJECT

  bool is_init_;
  QHBoxLayout *layout_;
  QLabel *label_;
  AdvSlider *val_a_slider_;
  DblAdvSlider *abs_val_slider_;
  QCheckBox *chb_auto_, *chb_on_off_, *chb_one_push_;
  FlyCapture2::PropertyInfo prop_info_;
  FlyCapture2::Property prop_;
  FlyCapture2::Camera *cam_;
  std::mutex *cam_mtx_;
  mio::CFreqBuffer<double> abs_val_freq_buf_;
  mio::CFreqBuffer<int> val_a_freq_buf_;
  int dbg_count_;
  bool from_update_ui_;

  static void AbsValFreqBufCallBack(double value, void *user_data){
    static_cast<mio::UiPropertySetter*>(user_data)->SetCameraProp();
  }

  static void ValAFreqBufCallBack(int value, void *user_data){
    static_cast<mio::UiPropertySetter*>(user_data)->SetCameraProp();
  }

  public:
    UiPropertySetter(int id) : is_init_(false), dbg_count_(0), from_update_ui_(false){
      layout_ = nullptr;
      label_ = nullptr;
      val_a_slider_ = nullptr;
      abs_val_slider_ = nullptr;
      chb_auto_ = chb_on_off_ = chb_one_push_ = nullptr;
    }

    ~UiPropertySetter(){
      if(label_) delete label_;
      if(abs_val_slider_){
        abs_val_freq_buf_.Uninit();
        disconnect(abs_val_slider_, SIGNAL(valueChanged(double)), this, SLOT(SetCameraProp()));
        delete abs_val_slider_;
      }
      if(val_a_slider_){
        val_a_freq_buf_.Uninit();
        disconnect(val_a_slider_, SIGNAL(valueChanged(int)), this, SLOT(SetCameraProp()));
        delete val_a_slider_;
      }
      if(chb_auto_){
        disconnect(chb_auto_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
        delete chb_auto_;
      }
      if(chb_on_off_){
        disconnect(chb_on_off_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
        delete chb_on_off_;
      }
      if(chb_one_push_){
        disconnect(chb_one_push_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
        delete chb_one_push_;
      }
      if(layout_) delete layout_;
    }

    void SetCamera(FlyCapture2::Camera *cam, std::mutex *cam_mtx){
      cam_ = cam;
      cam_mtx_ = cam_mtx;
    }

    FlyCapture2::PropertyInfo GetPropertyInfo(){
      return prop_info_;
    }

    FlyCapture2::Property GetProperty(){
      return prop_;
    }

    void Setup(const QString label, const FlyCapture2::PropertyInfo &prop_info, const FlyCapture2::Property &prop){
      STD_LOG_ERR_EM(!is_init_, "called this function twice")
      prop_info_ = prop_info;
      prop_ = prop;

      layout_ = new QHBoxLayout();
      label_ = new QLabel();
      label_->setText(label);
      layout_->addWidget(label_);

      if(prop_info.manualSupported){
        const size_t kFreq = 5, kBufSize = 5, kNumDecimal = 1;
        if(prop_info.absValSupported){
          abs_val_slider_ = new DblAdvSlider(prop_info.absMin, prop_info.absMax, prop.absValue,
                                             kNumDecimal, prop_info.absMin, prop_info.absMax);
          layout_->addWidget(abs_val_slider_);
          abs_val_freq_buf_.Init(AbsValFreqBufCallBack, kFreq, kBufSize, static_cast<void*>(this));
          connect(abs_val_slider_, SIGNAL(valueChanged(double)), this, SLOT(AbsValSliderValueChanged(double)));
        }
        else{
          val_a_slider_ = new AdvSlider(prop_info.min, prop_info.max, prop.valueA,
                                      prop_info.min, prop_info.max);
          layout_->addWidget(val_a_slider_);
          val_a_freq_buf_.Init(ValAFreqBufCallBack, kFreq, kBufSize, static_cast<void*>(this));
          connect(val_a_slider_, SIGNAL(valueChanged(int)), this, SLOT(ValASliderValueChanged(int)));
        }
      }
      if(prop_info.autoSupported){
        chb_auto_ = new QCheckBox();
        chb_auto_->setText("auto");
        chb_auto_->setCheckState(prop.autoManualMode ? Qt::Checked : Qt::Unchecked);
        layout_->addWidget(chb_auto_);
        connect(chb_auto_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
      }
      if(prop_info.onOffSupported){
        chb_on_off_ = new QCheckBox();<commit_msg>updated frequency buffer arguments to handle new format<commit_after>#ifndef __FLY_CAP_SETTING_EDITOR_H__
#define __FLY_CAP_SETTING_EDITOR_H__

#include <map>
#include <mutex>
#include <QLabel>
#include <QCheckBox>
#include <QMessageBox>
#include <QXmlStreamWriter>
#include <QFile>
#include "mio/qt/advSliderWidget/advSliderWidget.h"
#include "mio/altro/ptGreyFlyCap2.h"
#include "mio/altro/freqBuffer.h"
#include "mio/altro/io.h"
#include "mio/qt/qtXml.h"


namespace mio{

class UiPropertySetter : public QWidget{
  Q_OBJECT

  bool is_init_;
  QHBoxLayout *layout_;
  QLabel *label_;
  AdvSlider *val_a_slider_;
  DblAdvSlider *abs_val_slider_;
  QCheckBox *chb_auto_, *chb_on_off_, *chb_one_push_;
  FlyCapture2::PropertyInfo prop_info_;
  FlyCapture2::Property prop_;
  FlyCapture2::Camera *cam_;
  std::mutex *cam_mtx_;
  mio::CFreqBuffer<double> abs_val_freq_buf_;
  mio::CFreqBuffer<int> val_a_freq_buf_;
  int dbg_count_;
  bool from_update_ui_;

  static void AbsValFreqBufCallBack(double value, void *user_data){
    static_cast<mio::UiPropertySetter*>(user_data)->SetCameraProp();
  }

  static void ValAFreqBufCallBack(int value, void *user_data){
    static_cast<mio::UiPropertySetter*>(user_data)->SetCameraProp();
  }

  public:
    UiPropertySetter(int id) : is_init_(false), dbg_count_(0), from_update_ui_(false){
      layout_ = nullptr;
      label_ = nullptr;
      val_a_slider_ = nullptr;
      abs_val_slider_ = nullptr;
      chb_auto_ = chb_on_off_ = chb_one_push_ = nullptr;
    }

    ~UiPropertySetter(){
      if(label_) delete label_;
      if(abs_val_slider_){
        abs_val_freq_buf_.Uninit();
        disconnect(abs_val_slider_, SIGNAL(valueChanged(double)), this, SLOT(SetCameraProp()));
        delete abs_val_slider_;
      }
      if(val_a_slider_){
        val_a_freq_buf_.Uninit();
        disconnect(val_a_slider_, SIGNAL(valueChanged(int)), this, SLOT(SetCameraProp()));
        delete val_a_slider_;
      }
      if(chb_auto_){
        disconnect(chb_auto_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
        delete chb_auto_;
      }
      if(chb_on_off_){
        disconnect(chb_on_off_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
        delete chb_on_off_;
      }
      if(chb_one_push_){
        disconnect(chb_one_push_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
        delete chb_one_push_;
      }
      if(layout_) delete layout_;
    }

    void SetCamera(FlyCapture2::Camera *cam, std::mutex *cam_mtx){
      cam_ = cam;
      cam_mtx_ = cam_mtx;
    }

    FlyCapture2::PropertyInfo GetPropertyInfo(){
      return prop_info_;
    }

    FlyCapture2::Property GetProperty(){
      return prop_;
    }

    void Setup(const QString label, const FlyCapture2::PropertyInfo &prop_info, const FlyCapture2::Property &prop){
      STD_LOG_ERR_EM(!is_init_, "called this function twice")
      prop_info_ = prop_info;
      prop_ = prop;

      layout_ = new QHBoxLayout();
      label_ = new QLabel();
      label_->setText(label);
      layout_->addWidget(label_);

      if(prop_info.manualSupported){
        const size_t kFreq = 5, kBufSize = 5, kNumDecimal = 1;
        if(prop_info.absValSupported){
          abs_val_slider_ = new DblAdvSlider(prop_info.absMin, prop_info.absMax, prop.absValue,
                                             kNumDecimal, prop_info.absMin, prop_info.absMax);
          layout_->addWidget(abs_val_slider_);
          abs_val_freq_buf_.Init(AbsValFreqBufCallBack, kFreq, kBufSize, false, static_cast<void*>(this));
          connect(abs_val_slider_, SIGNAL(valueChanged(double)), this, SLOT(AbsValSliderValueChanged(double)));
        }
        else{
          val_a_slider_ = new AdvSlider(prop_info.min, prop_info.max, prop.valueA,
                                      prop_info.min, prop_info.max);
          layout_->addWidget(val_a_slider_);
          val_a_freq_buf_.Init(ValAFreqBufCallBack, kFreq, kBufSize, false, static_cast<void*>(this));
          connect(val_a_slider_, SIGNAL(valueChanged(int)), this, SLOT(ValASliderValueChanged(int)));
        }
      }
      if(prop_info.autoSupported){
        chb_auto_ = new QCheckBox();
        chb_auto_->setText("auto");
        chb_auto_->setCheckState(prop.autoManualMode ? Qt::Checked : Qt::Unchecked);
        layout_->addWidget(chb_auto_);
        connect(chb_auto_, SIGNAL(clicked()), this, SLOT(SetCameraProp()));
      }
      if(prop_info.onOffSupported){
        chb_on_off_ = new QCheckBox();
{'fraction_non_alphanumeric': 0.11436289959477713, 'fraction_numerical': 0.002926609635299415, 'mean_word_length': 3.505578093306288, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5491000', 'n_tokens_mistral': 3076, 'n_tokens_neox': 3025, 'n_words': 500}