mirror of
https://github.com/jankae/LibreVNA.git
synced 2025-12-06 07:12:10 +01:00
rework editor creation for MarkerTraceDelegate
Some checks failed
Build / PC_Application_Ubuntu (push) Has been cancelled
Build / PC_Application_RPi5 (push) Has been cancelled
Build / PC_Application_Windows (push) Has been cancelled
Build / PC_Application_OSX (push) Has been cancelled
Build / PC_Application_OSX_13 (push) Has been cancelled
Build / Embedded_Firmware (push) Has been cancelled
HIL_Tests / Get_Repository (push) Has been cancelled
Unit_Tests / Tests (push) Has been cancelled
HIL_Tests / PC_Application_RPi5 (push) Has been cancelled
HIL_Tests / Embedded_Firmware (push) Has been cancelled
HIL_Tests / HIL (push) Has been cancelled
Some checks failed
Build / PC_Application_Ubuntu (push) Has been cancelled
Build / PC_Application_RPi5 (push) Has been cancelled
Build / PC_Application_Windows (push) Has been cancelled
Build / PC_Application_OSX (push) Has been cancelled
Build / PC_Application_OSX_13 (push) Has been cancelled
Build / Embedded_Firmware (push) Has been cancelled
HIL_Tests / Get_Repository (push) Has been cancelled
Unit_Tests / Tests (push) Has been cancelled
HIL_Tests / PC_Application_RPi5 (push) Has been cancelled
HIL_Tests / Embedded_Firmware (push) Has been cancelled
HIL_Tests / HIL (push) Has been cancelled
This commit is contained in:
parent
f0c7f289cb
commit
d882bca547
|
|
@ -1480,6 +1480,35 @@ void Marker::setNumber(int value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *Marker::getTraceEditor(QAbstractItemDelegate *delegate)
|
||||||
|
{
|
||||||
|
auto c = new QComboBox;
|
||||||
|
for(auto t : model->getModel().getTraces()) {
|
||||||
|
c->addItem(t->name());
|
||||||
|
if(parentTrace == t) {
|
||||||
|
// select this item
|
||||||
|
c->setCurrentIndex(c->count() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connect(c, qOverload<int>(&QComboBox::currentIndexChanged), [=](int) {
|
||||||
|
emit delegate->commitData(c);
|
||||||
|
});
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Marker::updateTraceFromEditor(QWidget *w)
|
||||||
|
{
|
||||||
|
QComboBox *c = (QComboBox*) w;
|
||||||
|
for(auto t : model->getModel().getTraces()) {
|
||||||
|
if(c->currentText() == t->name()) {
|
||||||
|
if(parentTrace != t) {
|
||||||
|
assignTrace(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *Marker::getTypeEditor(QAbstractItemDelegate *delegate)
|
QWidget *Marker::getTypeEditor(QAbstractItemDelegate *delegate)
|
||||||
{
|
{
|
||||||
auto c = new QComboBox;
|
auto c = new QComboBox;
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,10 @@ public:
|
||||||
Last,
|
Last,
|
||||||
};
|
};
|
||||||
Type getType() const;
|
Type getType() const;
|
||||||
|
QWidget *getTraceEditor(QAbstractItemDelegate *delegate = nullptr);
|
||||||
|
void updateTraceFromEditor(QWidget *w);
|
||||||
QWidget *getTypeEditor(QAbstractItemDelegate *delegate = nullptr);
|
QWidget *getTypeEditor(QAbstractItemDelegate *delegate = nullptr);
|
||||||
void updateTypeFromEditor(QWidget *c);
|
void updateTypeFromEditor(QWidget *w);
|
||||||
SIUnitEdit* getSettingsEditor();
|
SIUnitEdit* getSettingsEditor();
|
||||||
QWidget *getRestrictEditor();
|
QWidget *getRestrictEditor();
|
||||||
void adjustSettings(double value);
|
void adjustSettings(double value);
|
||||||
|
|
|
||||||
|
|
@ -436,41 +436,17 @@ QSize MarkerTraceDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIn
|
||||||
|
|
||||||
QWidget *MarkerTraceDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
QWidget *MarkerTraceDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
auto model = (MarkerModel*) index.model();
|
auto marker = static_cast<const MarkerModel*>(index.model())->markerFromIndex(index);
|
||||||
auto c = new QComboBox(parent);
|
auto editor = marker->getTraceEditor(const_cast<MarkerTraceDelegate*>(this));
|
||||||
c->setMaximumHeight(rowHeight);
|
editor->setMaximumHeight(rowHeight);
|
||||||
connect(c, qOverload<int>(&QComboBox::currentIndexChanged), [c](int) {
|
editor->setParent(parent);
|
||||||
c->clearFocus();
|
return editor;
|
||||||
});
|
|
||||||
auto traces = model->getModel().getTraces();
|
|
||||||
for(auto t : traces) {
|
|
||||||
MarkerWidgetTraceInfo info;
|
|
||||||
info.trace = t;
|
|
||||||
c->addItem(t->name(), QVariant::fromValue(info));
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkerTraceDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
void MarkerTraceDelegate::setModelData(QWidget *editor, QAbstractItemModel *, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
auto marker = static_cast<const MarkerModel*>(index.model())->markerFromIndex(index);
|
auto marker = static_cast<const MarkerModel*>(index.model())->markerFromIndex(index);
|
||||||
auto c = (QComboBox*) editor;
|
marker->updateTraceFromEditor(editor);
|
||||||
MarkerWidgetTraceInfo markerInfo;
|
|
||||||
markerInfo.trace = marker->trace();
|
|
||||||
for(int i=0;i<c->count();i++) {
|
|
||||||
auto info = qvariant_cast<MarkerWidgetTraceInfo>(c->itemData(i));
|
|
||||||
if(info == markerInfo) {
|
|
||||||
c->setCurrentIndex(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarkerTraceDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
auto markerModel = (MarkerModel*) model;
|
|
||||||
auto c = (QComboBox*) editor;
|
|
||||||
markerModel->setData(index, c->itemData(c->currentIndex()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize MarkerSettingsDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
|
QSize MarkerSettingsDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ class MarkerTraceDelegate : public QStyledItemDelegate
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const override;
|
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const override;
|
||||||
QWidget *createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
QWidget *createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
||||||
void setEditorData(QWidget * editor, const QModelIndex & index) const override;
|
|
||||||
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
|
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue