interface/qt: add assignable editor delegate

This commit is contained in:
jussi 2019-10-14 10:50:48 +03:00
parent 9ed25c03ac
commit b835e7ca97
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#include "AssignableEditorDelegate.h"
#include "AssignableData.h"
#include <EnumEditor.h>
#include <IntRangeEditor.h>
#include <QDebug>
AssignableEditorDelegate::AssignableEditorDelegate(QObject *parent) : QStyledItemDelegate(parent) {
}
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());
qDebug() << data.m_rangeInfo.int_range.max;
switch (data.m_valueCategory) {
case TC_ASSIGNABLE_RANGE:
return new IntRangeEditor(parent);
case TC_ASSIGNABLE_ENUM:
return new EnumEditor(parent);
default:
return nullptr;
}
}
void AssignableEditorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
editor->setGeometry(option.rect);
}
void AssignableEditorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <QStyledItemDelegate>
class AssignableEditorDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
AssignableEditorDelegate(QObject *parent = nullptr);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
};