20 #include <QApplication>
23 const double scale_default_height_factor{1.2};
29 : QStyledItemDelegate(parent)
48 const QModelIndex& index)
const
51 editor->setParent(parent);
54 return editor.release();
56 return QStyledItemDelegate::createEditor(parent, option, index);
64 if (
auto customEditor =
dynamic_cast<CustomEditor*
>(editor))
65 customEditor->setData(index.data());
67 QStyledItemDelegate::setEditorData(editor, index);
71 const QModelIndex& index)
const
76 if (
auto customEditor =
dynamic_cast<CustomEditor*
>(editor)) {
77 model->setData(index, customEditor->data());
79 QStyledItemDelegate::setModelData(editor, model, index);
86 const QModelIndex& index)
const
88 QSize result = QStyledItemDelegate::sizeHint(option, index);
89 result.setHeight(
static_cast<int>(result.height() * scale_default_height_factor));
98 const QModelIndex& index)
const
100 QStyledItemDelegate::updateEditorGeometry(editor, option, index);
101 editor->setGeometry(option.rect);
106 auto editor = qobject_cast<CustomEditor*>(sender());
107 emit commitData(editor);
108 if (!editor->is_persistent())
109 emit closeEditor(editor);
113 const QModelIndex& index)
const
115 QStyledItemDelegate::initStyleOption(option, index);
Base class for all custom variant editors.
void dataChanged(QVariant value)
Emmits signal when data was changed in an editor.
Generates default cell decorations for Qt trees and tables.
Default editor factory for cell editors in Qt trees and tables.
void setEditorFactory(std::unique_ptr< EditorFactoryInterface > editor_factory)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Increases height of the row by 20% wrt the default.
void setEditorData(QWidget *editor, const QModelIndex &index) const override
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Makes an editor occupying whole available space in a cell.
~ViewModelDelegate() override
ViewModelDelegate(QObject *parent=nullptr)
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
std::unique_ptr< EditorFactoryInterface > m_editor_factory
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void onCustomEditorDataChanged()
void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override
void setCellDecoration(std::unique_ptr< CellDecoratorInterface > cell_decoration)
std::unique_ptr< CellDecoratorInterface > m_cell_decoration
materialitems.h Collection of materials to populate MaterialModel.