20 #include <QApplication>
23 QWidget* createEditorFromIndex(
const QModelIndex& index, QWidget* parent);
29 const QModelIndex& index)
const
35 QStyledItemDelegate::paint(painter, option, index);
39 const QModelIndex& index)
const
41 auto result = createEditorFromIndex(index, parent);
43 if (
auto customEditor =
dynamic_cast<CustomEditor*
>(result)) {
50 result = QStyledItemDelegate::createEditor(parent, option, index);
58 const QModelIndex& index)
const
63 if (
auto customEditor =
dynamic_cast<CustomEditor*
>(editor))
64 model->setData(index, customEditor->editorData());
66 QStyledItemDelegate::setModelData(editor, model, index);
76 if (
auto customEditor =
dynamic_cast<CustomEditor*
>(editor))
77 customEditor->setData(index.data());
79 QStyledItemDelegate::setEditorData(editor, index);
85 const QModelIndex& index)
const
87 QSize result = QStyledItemDelegate::sizeHint(option, index);
88 result.setHeight(
static_cast<int>(result.height() * 1.2));
97 const QModelIndex& index)
const
99 QStyledItemDelegate::updateEditorGeometry(editor, option, index);
100 editor->setGeometry(option.rect);
107 CustomEditor* editor = qobject_cast<CustomEditor*>(sender());
109 emit commitData(editor);
115 const QModelIndex& index,
const QString& text)
const
117 QStyleOptionViewItem opt = option;
118 initStyleOption(&opt, index);
119 opt.text = displayText(text, option.locale);
120 const QWidget* widget = opt.widget;
121 QStyle* style = widget ? widget->style() : QApplication::style();
122 style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
126 QWidget* createEditorFromIndex(
const QModelIndex& index, QWidget* parent)
128 if (index.internalPointer()) {
129 auto item =
static_cast<SessionItem*
>(index.internalPointer());
#define ASSERT(condition)
Defines CustomEditors classes.
Defines classes releted to event filtering.
Defines PropertyEditorFactory namespace.
Defines class SessionItem.
Defines class SessionModelDelegate.
Base class for all custom variants editors.
void dataChanged(const QVariant &data)
Signal emit then user changed the data through the editor.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Increases height of the row by 20% wrt the default.
SessionModelDelegate(QObject *parent)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Propagates changed data from the editor to the model.
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Makes an editor occupying whole available space in a cell.
void onCustomEditorDataChanged(const QVariant &)
Notifies everyone that the editor has completed editing the data.
void paintCustomLabel(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QString &text) const
Paints custom text in a a place corresponding given index.
void setEditorData(QWidget *editor, const QModelIndex &index) const
Propagates the data change from the model to the editor (if it is still opened).
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Propagate tab events from focusProxy to parent.
bool hasStringRepresentation(const QModelIndex &index)
Returns true if the index data has known (custom) convertion to string.
QString toString(const QModelIndex &index)
Provides string representation of index data.
QWidget * CreateEditor(const SessionItem &item, QWidget *parent=nullptr)
Creates an editor suitable for editing of item.value()