Public Member Functions

TreeViewDelegate Class Reference

Delegate used by ProjectTreeView. More...

#include <treeview.h>

Inheritance diagram for TreeViewDelegate:
Inheritance graph
[legend]
Collaboration diagram for TreeViewDelegate:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TreeViewDelegate (QObject *parent=0)
QWidgetcreateEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setEditorData (QWidget *editor, const QModelIndex &index) const
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const

Detailed Description

Delegate used by ProjectTreeView.

This is mainly used to show a QTextEdit when one doubleclicks a description of a sensor or sensor channel.


Constructor & Destructor Documentation

TreeViewDelegate::TreeViewDelegate ( QObject parent = 0  ) 

: QStyledItemDelegate(parent){};


Member Function Documentation

QWidget * TreeViewDelegate::createEditor ( QWidget parent,
const QStyleOptionViewItem option,
const QModelIndex index 
) const

{
    if (index.column() == 2) {
        QTextEdit *textEdit = new QTextEdit(parent);
        return textEdit;
    } else {
        return QStyledItemDelegate::createEditor(parent, option, index);
    }
}

void TreeViewDelegate::setEditorData ( QWidget editor,
const QModelIndex index 
) const

{
    // Workaround omdat userProperty() van QTextEdit HTML is en niet plainText,
    // en er geen manier bestaat blijkbaar om die dynamisch aan te passen
    if (QTextEdit *textEdit = dynamic_cast<QTextEdit*>(editor)) {
        Q_ASSERT(index.column() == 2);
        textEdit->setPlainText(index.data(Qt::EditRole).toString());
    } else {
        QStyledItemDelegate::setEditorData(editor, index);
    }
}

void TreeViewDelegate::setModelData ( QWidget editor,
QAbstractItemModel model,
const QModelIndex index 
) const

{
    // Workaround omdat userProperty() van QTextEdit HTML is en niet plainText,
    // en er geen manier bestaat blijkbaar om die dynamisch aan te passen
    if (QTextEdit *textEdit = dynamic_cast<QTextEdit*>(editor)) {
        Q_ASSERT(index.column() == 2);
        model->setData(index, textEdit->toPlainText(), Qt::EditRole);
    } else {
        QStyledItemDelegate::setModelData(editor, model, index);
    }
}

void TreeViewDelegate::updateEditorGeometry ( QWidget editor,
const QStyleOptionViewItem option,
const QModelIndex index 
) const

{
    if (dynamic_cast<QTextEdit*>(editor)) {
        QRect r = option.rect;
        QSize e = editor->minimumSizeHint();
        r.setHeight(qMax(r.height(), e.height()));
        r.setWidth(qMax(r.width(), e.width()));
        editor->setGeometry(r);
    } else
        QStyledItemDelegate::updateEditorGeometry(editor, option, index);
}


The documentation for this class was generated from the following files: