test_sdk/gui/gtl_gui_spec_meas_delegate.h

139 lines
4.3 KiB
C
Raw Normal View History

#ifndef GTL_GUI_SPEC_MEAS_DELEGATE_H
#define GTL_GUI_SPEC_MEAS_DELEGATE_H
#include <QStyledItemDelegate>
#include <QWidget>
#include <QComboBox>
#include <QLabel>
#include <QDoubleSpinBox>
#include <QHBoxLayout>
#include <QMetaEnum>
#include "gui_global.h"
#include "math/gtl_math_spec_meas.h"
namespace gtl {
namespace gui {
class GTL_GUI_EXPORT spec_meas_chan_widget : public QWidget
{
Q_OBJECT
public:
spec_meas_chan_widget(QWidget *parent=nullptr, QAbstractItemModel *model = nullptr) :
QWidget(parent),
comboBox(new QComboBox)
{
if(model)
{
QHBoxLayout *layout = new QHBoxLayout(this);
comboBox->setModel(model);
comboBox->setContentsMargins(0,0,0,0);
layout->setContentsMargins(0,0,0,0);
layout->addWidget(comboBox);
connect(comboBox, &QComboBox::currentIndexChanged, [=]{emit chan_changed();});
}
}
QString currentText()
{
return comboBox->currentText();
}
int currentIdx()
{
int idx = comboBox->currentIndex();
return idx;
}
void setCurrentIndex(QString name)
{
int idx = comboBox->findText(name);
if(idx != comboBox->currentIndex())
{
if(idx >= 0 && idx < comboBox->count())
comboBox->setCurrentIndex(idx);
emit chan_changed();
}
}
void setCurrentIndex(int idx)
{
if(idx != comboBox->currentIndex())
{
if(idx >= 0 && idx < comboBox->count())
comboBox->setCurrentIndex(idx);
emit chan_changed();
}
}
signals:
void chan_changed();
private:
QComboBox *comboBox;
};
class GTL_GUI_EXPORT spec_meas_param_widget : public QWidget
{
Q_OBJECT
public:
spec_meas_param_widget(QWidget *parent=nullptr) :
QWidget(parent)
{
comboBox = new QComboBox;
QMetaEnum meta_enum = QMetaEnum::fromType<gtl::math::spec_meas::types>();
for(int i = 0; i < meta_enum.keyCount(); i++)
comboBox->addItem(meta_enum.valueToKey(i));
comboBox->setContentsMargins(0,0,0,0);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0,0,0,0);
layout->addWidget(comboBox);
connect(comboBox, &QComboBox::currentIndexChanged, [=]{emit param_changed();});
}
int currentIndex()
{
return comboBox->currentIndex();
}
void setCurrentIndex(int index)
{
comboBox->setCurrentIndex(index);
return;
}
private:
QComboBox *comboBox;
signals:
void param_changed();
};
class GTL_GUI_EXPORT spec_meas_delegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit spec_meas_delegate(QObject *parent = nullptr, QAbstractItemModel *channels = nullptr);
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
QAbstractItemModel *_channels = nullptr;
};
} // namespace gui
} // namespace gtl
#endif // GTL_GUI_SPEC_MEAS_DELEGATE_H