Public Types | Signals | Public Member Functions | Properties | Friends

QxtItemDelegate Class Reference
[QxtGui]

An extended QItemDelegate with additional signals and optional decoration. More...

#include <qxtitemdelegate.h>

Collaboration diagram for QxtItemDelegate:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Role { ProgressValueRole = Qt::UserRole + 328, ProgressMinimumRole, ProgressMaximumRole }

Signals

void editingStarted (const QModelIndex &index)
void editingFinished (const QModelIndex &index)

Public Member Functions

 QxtItemDelegate (QObject *parent=0)
virtual ~QxtItemDelegate ()
Qxt::DecorationStyle decorationStyle () const
void setDecorationStyle (Qxt::DecorationStyle style)
Qt::TextElideMode elideMode () const
void setElideMode (Qt::TextElideMode mode)
QString progressTextFormat () const
void setProgressTextFormat (const QString &format)
bool isProgressTextVisible () const
void setProgressTextVisible (bool visible)
virtual QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
virtual void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const

Properties

Qxt::DecorationStyle decorationStyle
 This property holds the top level index decoration style.
Qt::TextElideMode elideMode
 This property holds the text elide mode.
QString progressTextFormat
 This property holds the format of optional progress text.
bool progressTextVisible
 This property holds whether progress text is visible.

Friends

class QxtItemDelegatePrivate

Detailed Description

An extended QItemDelegate with additional signals and optional decoration.

QxtItemDelegate provides signals for starting and finishing of editing and an optional decoration for top level indices in a QTreeView.

QxtItemDelegate can also draw a progress bar for indices providing appropriate progress data. Just like QProgressBar, QxtItemDelegate can show a busy indicator. If minimum and maximum both are set to 0, a busy indicator is shown instead of a percentage of steps.

Definition at line 35 of file qxtitemdelegate.h.


Member Enumeration Documentation

This enum defines custom roles used by QxtItemDelegate.

Enumerator:
ProgressValueRole 

The progress value.

ProgressMinimumRole 

The minimum progress value. The default value 0 is used if no value is provided for ProgressMinimumRole.

ProgressMaximumRole 

The maximum progress value. The default value 100 is used if no value is provided for ProgressMaximumRole.

Definition at line 48 of file qxtitemdelegate.h.


Constructor & Destructor Documentation

QxtItemDelegate::QxtItemDelegate ( QObject *  parent = 0 ) [explicit]

Constructs a new QxtItemDelegate with parent.

Definition at line 271 of file qxtitemdelegate.cpp.

References QXT_INIT_PRIVATE.

                                                : QItemDelegate(parent)
{
    QXT_INIT_PRIVATE(QxtItemDelegate);
    connect(this, SIGNAL(closeEditor(QWidget*)), &qxt_d(), SLOT(closeEditor(QWidget*)));
}
QxtItemDelegate::~QxtItemDelegate (  ) [virtual]

Destructs the item delegate.

Definition at line 280 of file qxtitemdelegate.cpp.

{}

Member Function Documentation

QWidget * QxtItemDelegate::createEditor ( QWidget *  parent,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const [virtual]

Definition at line 377 of file qxtitemdelegate.cpp.

References editingStarted().

{
    QWidget* editor = QItemDelegate::createEditor(parent, option, index);
    qxt_d().setCurrentEditor(editor, index);
    emit const_cast<QxtItemDelegate*>(this)->editingStarted(index);
    return editor;
}
Qxt::DecorationStyle QxtItemDelegate::decorationStyle (  ) const
QxtItemDelegate::editingFinished ( const QModelIndex &  index ) [signal]

This signal is emitted after the editing of index has been finished.

See also:
editingStarted()

Referenced by setModelData().

QxtItemDelegate::editingStarted ( const QModelIndex &  index ) [signal]

This signal is emitted after the editing of index has been started.

See also:
editingFinished()

Referenced by createEditor().

Qt::TextElideMode QxtItemDelegate::elideMode (  ) const
bool QxtItemDelegate::isProgressTextVisible (  ) const

Definition at line 364 of file qxtitemdelegate.cpp.

{
    return qxt_d().textVisible;
}
void QxtItemDelegate::paint ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const [virtual]

Definition at line 398 of file qxtitemdelegate.cpp.

References Qxt::Buttonlike, Qxt::Menulike, Qxt::NoDecoration, and ProgressValueRole.

{
    const QAbstractItemModel* model = index.model();
    const QTreeView* tree = qobject_cast<QTreeView*>(parent());
    const bool topLevel = !index.parent().isValid();

    if (tree && model && topLevel && qxt_d().style != Qxt::NoDecoration)
    {
        QStyleOptionViewItem opt;
        opt.QStyleOption::operator=(option);
        opt.showDecorationSelected = false;

        QModelIndex valid = model->index(index.row(), 0);
        QModelIndex sibling = valid;
        while (sibling.isValid())
        {
            opt.rect |= tree->visualRect(sibling);
            sibling = sibling.sibling(sibling.row(), sibling.column() + 1);
        }

        switch (qxt_d().style)
        {
        case Qxt::Buttonlike:
            qxt_d().paintButton(painter, opt, valid, tree);
            break;
        case Qxt::Menulike:
            qxt_d().paintMenu(painter, opt, valid, tree);
            break;
        default:
            qWarning("QxtItemDelegate::paint() unknown decoration style");
            QItemDelegate::paint(painter, opt, valid);
            break;
        }
    }
    else
    {
        QItemDelegate::paint(painter, option, index);

        const QVariant data = index.data(ProgressValueRole);
        if (data.isValid() && data.canConvert(QVariant::Int))
            qxt_d().paintProgress(painter, option, index);
    }
}
QString QxtItemDelegate::progressTextFormat (  ) const
void QxtItemDelegate::setDecorationStyle ( Qxt::DecorationStyle  style )

Definition at line 303 of file qxtitemdelegate.cpp.

{
    qxt_d().style = style;
}
void QxtItemDelegate::setElideMode ( Qt::TextElideMode  mode )

Definition at line 324 of file qxtitemdelegate.cpp.

{
    qxt_d().elide = mode;
}
void QxtItemDelegate::setModelData ( QWidget *  editor,
QAbstractItemModel *  model,
const QModelIndex &  index 
) const [virtual]

Definition at line 388 of file qxtitemdelegate.cpp.

References editingFinished().

{
    QItemDelegate::setModelData(editor, model, index);
    qxt_d().setCurrentEditor(0, QModelIndex());
    emit const_cast<QxtItemDelegate*>(this)->editingFinished(index);
}
void QxtItemDelegate::setProgressTextFormat ( const QString &  format )

Definition at line 348 of file qxtitemdelegate.cpp.

{
    qxt_d().progressFormat = format;
}
void QxtItemDelegate::setProgressTextVisible ( bool  visible )

Definition at line 369 of file qxtitemdelegate.cpp.

{
    qxt_d().textVisible = visible;
}
QSize QxtItemDelegate::sizeHint ( const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const [virtual]

Definition at line 445 of file qxtitemdelegate.cpp.

References TOP_LEVEL_EXTENT.

{
    // something slightly bigger for top level indices
    QSize size = QItemDelegate::sizeHint(option, index);
    if (!index.parent().isValid())
        size += QSize(TOP_LEVEL_EXTENT, TOP_LEVEL_EXTENT);
    return  size;
}

Friends And Related Function Documentation

friend class QxtItemDelegatePrivate [friend]

Definition at line 38 of file qxtitemdelegate.h.


Property Documentation

Qxt::DecorationStyle QxtItemDelegate::decorationStyle [read, write]

This property holds the top level index decoration style.

Top level indices are decorated according to this property. The default value is Qxt::NoDecoration.

Note:
The property has effect only in case the delegate is installed on a QTreeView. The view must be the parent of the delegate.
Set QTreeView::rootIsDecorated to false to avoid multiple branch indicators.
See also:
Qxt::DecorationStyle, QTreeView::rootIsDecorated

Definition at line 38 of file qxtitemdelegate.h.

Qt::TextElideMode QxtItemDelegate::elideMode [read, write]

This property holds the text elide mode.

The text of a decorated top level index is elided according to this property. The default value is Qt::ElideMiddle.

Note:
The property has effect only for decorated top level indices.
See also:
decorationStyle, Qt::TextElideMode

Definition at line 40 of file qxtitemdelegate.h.

QString QxtItemDelegate::progressTextFormat [read, write]

This property holds the format of optional progress text.

The progress text is formatted according to this property. The default value is "%1%".

Note:
Progress bar is rendered for indices providing valid numerical data for ProgressValueRole.
%1 is replaced by the progress percent.
See also:
progressTextVisible, Role

Definition at line 41 of file qxtitemdelegate.h.

QxtItemDelegate::progressTextVisible [read, write]

This property holds whether progress text is visible.

The default value is true.

Note:
Progress bar is rendered for indices providing valid numerical data for ProgressValueRole.
See also:
progressTextFormat, QxtItemDelegate::Role

Definition at line 42 of file qxtitemdelegate.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines