Esempio n. 1
0
QVariant
JobStatusModel::data( const QModelIndex& index, int role ) const
{
    if ( !hasIndex( index.row(), index.column(), index.parent() ) )
        return QVariant();

    JobStatusItem* item = m_items[ index.row() ];

    switch ( role )
    {
    case Qt::DecorationRole:
        return item->icon();
    case Qt::ToolTipRole:
    case Qt::DisplayRole:
    {
        if ( m_collapseCount.contains( item->type() ) )
            return m_collapseCount[ item->type() ].last()->mainText();
        else
            return item->mainText();
    }
    case RightColumnRole:
    {
        if ( m_collapseCount.contains( item->type() ) )
            return m_collapseCount[ item->type() ].count();
        else
            return item->rightColumnText();
    }
    case AllowMultiLineRole:
        return item->allowMultiLine();
    }

    return QVariant();
}
Esempio n. 2
0
void
JobStatusModel::itemUpdated()
{
    JobStatusItem* item = qobject_cast< JobStatusItem* >( sender() );
    Q_ASSERT( item );

    if ( m_collapseCount.contains( item->type() ) )
        item = m_collapseCount[ item->type() ].first();

    const QModelIndex idx = index( m_items.indexOf( item ), 0, QModelIndex() );
    emit dataChanged( idx, idx );
    return;
}
Esempio n. 3
0
void
JobStatusView::refreshDelegates()
{
    int count = m_model->rowCount();
    for ( int i = 0; i < count; i++ )
    {
        QModelIndex index = m_model->index( i, 0 );
        QVariant itemVar = index.data( JobStatusModel::JobDataRole );
        if ( !itemVar.canConvert< JobStatusItem* >() || !itemVar.value< JobStatusItem* >() )
        {
            tLog() << Q_FUNC_INFO << "unable to fetch JobStatusItem* at row" << i;
            continue;
        }
        JobStatusItem* item = itemVar.value< JobStatusItem* >();
        if ( item->hasCustomDelegate() )
            m_view->setItemDelegateForRow( i, item->customDelegate() );
        else
            m_view->setItemDelegateForRow( i, m_view->itemDelegate() );
    }

    checkCount();
}
Esempio n. 4
0
void
JobStatusModel::itemFinished()
{
    JobStatusItem* item = qobject_cast< JobStatusItem* >( sender() );
    Q_ASSERT( item );

//     tDebug() << "Got item finished:" << item->type() << item->mainText() << item;
    if ( !m_items.contains( item ) && !m_collapseCount.contains( item->type() ) )
        return;

//     foreach( JobStatusItem* item, m_items )
//     {
//         qDebug() << "ITEM #:" << item;
//     }
//     foreach( const QString& str, m_collapseCount.keys() )
//     {
//         tDebug() << "\t" << str;
//         foreach( JobStatusItem* chain, m_collapseCount[ str ] )
//             qDebug() << "\t\t" << chain;
//     }
    if ( m_collapseCount.contains( item->type() ) )
    {
        const int indexOf = m_items.indexOf( m_collapseCount[ item->type() ].first() );
//         tDebug() << "index in main list of collapsed irst item:" << indexOf;
        if ( m_collapseCount[ item->type() ].first() == item &&
             m_items.contains( m_collapseCount[ item->type() ].first() ) && m_collapseCount[ item->type() ].size() > 1 )
        {
            // the placeholder we use that links m_items and m_collapsecount is done, so choose another one
            m_items.replace( m_items.indexOf( m_collapseCount[ item->type() ].first() ), m_collapseCount[ item->type() ][ 1 ] );
//             qDebug() << "Replaced" << m_collapseCount[ item->type() ].first() << "with:" << m_collapseCount[ item->type() ][ 1 ] << m_items;
        }
        m_collapseCount[ item->type() ].removeAll( item );
//         tDebug() << "New collapse count list:" << m_collapseCount[ item->type() ];
        if ( m_collapseCount[ item->type() ].isEmpty() )
            m_collapseCount.remove( item->type() );
        else
        {
            // One less to count, but item is still there
            const QModelIndex idx = index( indexOf, 0, QModelIndex() );
            emit dataChanged( idx, idx );
            return;
        }
    }

    // Remove row completely
    const int idx = m_items.indexOf( item );
//     tDebug() << "Got index of item:" << idx;
    Q_ASSERT( idx >= 0 );

    beginRemoveRows( QModelIndex(), idx, idx );
    m_items.removeAll( item );
    endRemoveRows();

    item->deleteLater();
}