145 lines
4.7 KiB
C
145 lines
4.7 KiB
C
|
|
||
|
#ifndef GTL_GUI_OSC_MEAS_DELEGATE_H
|
||
|
#define GTL_GUI_OSC_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_osc_meas.h"
|
||
|
|
||
|
namespace gtl {
|
||
|
namespace gui {
|
||
|
namespace osc{
|
||
|
|
||
|
|
||
|
class GTL_GUI_EXPORT meas_chan_widget : public QWidget
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
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 meas_param_widget : public QWidget
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
meas_param_widget(QWidget *parent=nullptr) :
|
||
|
QWidget(parent)
|
||
|
{
|
||
|
comboBox = new QComboBox;
|
||
|
QMetaEnum meta_enum = QMetaEnum::fromType<gtl::math::osc_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)
|
||
|
{
|
||
|
if(index >= 0 && index < comboBox->count())
|
||
|
comboBox->setCurrentIndex(index);
|
||
|
emit param_changed();
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
QComboBox *comboBox;
|
||
|
|
||
|
signals:
|
||
|
void param_changed();
|
||
|
};
|
||
|
|
||
|
class GTL_GUI_EXPORT meas_delegate : public QStyledItemDelegate
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
|
explicit 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_OSC_MEAS_DELEGATE_H
|