#include "gtl_gui_spec_series.h" #include "gui/spgr/gtl_gui_spgr_widget.h" namespace gtl { namespace gui { spec_series::spec_series(bool is_updating, gtl::math::spec::types type, gtl::analog_data* ai, ::chart::axis_horz* axis_x, ::chart::axis_vert* axis_y) : chart_series(ai, axis_x, axis_y) { _is_updating = is_updating; _spec = new gtl::math::spec(type, ai); _measures = SpecMeasParamsListPtr(new QListSpecMeasParams); connect(_spec, >l::math::spec::changed, this, &spec_series::update); connect(_spec, >l::math::spec::initialized, this, &spec_series::update); connect(_spec, >l::math::spec::frequency_changed, this, &spec_series::initialized); connect(axis_x, &::chart::axis_horz::signal_range_changed, this, &spec_series::measure); } spec_series::~spec_series() { _spec->disconnect(); axis_x()->disconnect(); if(_spgr) delete _spgr; _spgr = nullptr; delete _spec; } qreal spec_series::frequency() const { return _spec->frequency(); } qreal spec_series::resolution() const { return _spec->resolution(); } int spec_series::window() const { return static_cast(_spec->window()); } int spec_series::lines() const { return _spec->lines(); } int spec_series::average() const { return _spec->average(); } qreal spec_series::overlap() const { return _spec-> overlap(); } int spec_series::unit() const { return static_cast(_spec->unit()); } void spec_series::set_frequency(qreal value) { _spec->set_frequency(value); } void spec_series::set_resolution(qreal value) { _spec->set_resolution(value); } void spec_series::set_window(int value) { _spec->set_window(static_cast(value)); } void spec_series::set_lines(int value) { _spec->set_lines(value); } void spec_series::set_average(int value) { _spec->set_average(value); } void spec_series::set_overlap(qreal value) { _spec->set_overlap(value); } void spec_series::set_unit(int value) { _spec->set_unit(static_cast(value)); } void spec_series::set_measures(spec_meas_model* model) { if(!model) return; _measures->clear(); for(int i = 0; i < model->measures()->count(); i++) if(model->measures()->at(i).ad == _ad) _measures->append(model->measures()->at(i)); measure(); } gtl::gui::spgr::widget* spec_series::create_spgr(QWidget *parent) { _spgr = new gtl::gui::spgr::widget(parent, _spec); return _spgr; } void spec_series::set_type(math::spec::types type) { _spec->set_type(type); } void spec_series::update() { set_y(&(*_spec)[0], _spec->size(), _spec->resolution()); measure(); if(_spgr && _spgr->isHidden()) { delete _spgr; _spgr = nullptr; } emit data_changed(); } void spec_series::measure() { if(!_measures) return; if(!_measures->count()) return; if(_spec->empty()) return; _ad->lock_device(); int meas_cnt = 0; std::vector::iterator l = _spec->begin() + axis_x()->min()/_spec->resolution(); std::vector::iterator r = _spec->begin() + axis_x()->max()/_spec->resolution(); for(int i = 0; i < _measures->count(); i++) { if(_measures->at(i).ad == _ad) { meas_cnt++; math::spec_meas::params *p = const_cast(&_measures->at(i)); switch (p->type) { case math::spec_meas::types::rms: p->value = math::spec_meas::rms(l, r); break; case math::spec_meas::types::max: p->value = math::spec_meas::max(l, r); break; case math::spec_meas::types::freq_max: p->value = math::spec_meas::freq_max(l, r, _spec->resolution()); break; default: break; } } } if(meas_cnt) emit measures_changed(_measures); _ad->unlock_device(); } } }