interface/qt: implement value and option set in editor delegate

This commit is contained in:
jussi 2019-10-15 02:34:44 +03:00
parent 24fc653737
commit 8eca5b9b60
2 changed files with 32 additions and 4 deletions

View File

@ -11,15 +11,20 @@ AssignableEditorDelegate::AssignableEditorDelegate(QObject *parent) : QStyledIte
QWidget *AssignableEditorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// Check which type the editor should be
AssignableData data = qvariant_cast<AssignableData>(index.data());
AssignableData data = qvariant_cast<AssignableData>(index.model()->data(index));
qDebug() << data.m_rangeInfo.int_range.max;
qDebug() << data.m_valueCategory;
switch (data.m_valueCategory) {
case TC_ASSIGNABLE_RANGE:
return new IntRangeEditor(parent);
switch (data.m_rangeInfo.range_data_type) {
case TC_ASSIGNABLE_RANGE_INT:
return new IntRangeEditor(parent, data);
default:
return nullptr;
}
case TC_ASSIGNABLE_ENUM:
return new EnumEditor(parent);
return new EnumEditor(parent, data);
default:
return nullptr;
}
@ -30,5 +35,27 @@ void AssignableEditorDelegate::updateEditorGeometry(QWidget *editor, const QStyl
}
void AssignableEditorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
AssignableData data = qvariant_cast<AssignableData>(index.model()->data(index));
QStandardItemModel *s_model = qobject_cast<QStandardItemModel*>(model);
/*switch (data.m_valueCategory) {
case TC_ASSIGNABLE_ENUM: {
EnumEditor *ed = qobject_cast<EnumEditor*>(editor);
// Set the editor item text to current selection
s_model->itemFromIndex(index)->setText(ed->value());
break;
}
case TC_ASSIGNABLE_RANGE:
switch (data.m_rangeInfo.range_data_type) {
case TC_ASSIGNABLE_RANGE_INT: {
IntRangeEditor *ed = qobject_cast<IntRangeEditor*>(editor);
s_model->itemFromIndex(index)->setText(QString(ed->value()));
break;
}
default:
break;
}
default:
break;
}*/
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <QStyledItemDelegate>
#include <QStandardItem>
class AssignableEditorDelegate : public QStyledItemDelegate {
Q_OBJECT