コード例 #1
0
QDebug operator<<( QDebug d, const CollectionStatistics& s )
{
    return d << "CollectionStatistics:" << endl
            << "   count:" << s.count() << endl
            << "   unread count:" << s.unreadCount() << endl
            << "   size:" << s.size();
}
コード例 #2
0
ファイル: entitytreemodel.cpp プロジェクト: crevetor/kcalcore
QVariant EntityTreeModel::data( const QModelIndex & index, int role ) const
{
  Q_D( const EntityTreeModel );
  if ( role == SessionRole ) {
    return QVariant::fromValue( qobject_cast<QObject *>( d->m_session ) );
  }

  // Ugly, but at least the API is clean.
  const HeaderGroup headerGroup = static_cast<HeaderGroup>( ( role / static_cast<int>( TerminalUserRole ) ) );

  role %= TerminalUserRole;
  if ( !index.isValid() ) {
    if ( ColumnCountRole != role ) {
      return QVariant();
    }

    return entityColumnCount( headerGroup );
  }

  if ( ColumnCountRole == role ) {
    return entityColumnCount( headerGroup );
  }

  const Node *node = reinterpret_cast<Node *>( index.internalPointer() );

  if ( ParentCollectionRole == role &&
       d->m_collectionFetchStrategy != FetchNoCollections ) {
    const Collection parentCollection = d->m_collections.value( node->parent );
    Q_ASSERT( parentCollection.isValid() );

    return QVariant::fromValue( parentCollection );
  }

  if ( Node::Collection == node->type ) {

    const Collection collection = d->m_collections.value( node->id );

    if ( !collection.isValid() ) {
      return QVariant();
    }

    switch ( role ) {
      case MimeTypeRole:
        return collection.mimeType();
        break;
      case RemoteIdRole:
        return collection.remoteId();
        break;
      case CollectionIdRole:
        return collection.id();
        break;
      case ItemIdRole:
        // QVariant().toInt() is 0, not -1, so we have to handle the ItemIdRole
        // and CollectionIdRole (below) specially
        return -1;
        break;
      case CollectionRole:
        return QVariant::fromValue( collection );
        break;
      case EntityUrlRole:
        return collection.url().url();
        break;
      case UnreadCountRole:
      {
        CollectionStatistics statistics = collection.statistics();
        return statistics.unreadCount();
      }
      case FetchStateRole:
      {
        return d->m_pendingCollectionRetrieveJobs.contains( collection.id() ) ? FetchingState : IdleState;
      }
      case CollectionSyncProgressRole:
      {
        return d->m_collectionSyncProgress.value( collection.id() );
      }
      case IsPopulatedRole:
      {
        return d->m_populatedCols.contains( collection.id() );
      }
      case Qt::BackgroundRole:
      {
        if ( collection.hasAttribute<EntityDisplayAttribute>() ) {
          EntityDisplayAttribute *eda = collection.attribute<EntityDisplayAttribute>();
          QColor color = eda->backgroundColor();
          if ( color.isValid() ) {
            return color;
          }
        }
        // fall through.
      }
      default:
        return entityData( collection, index.column(), role );
        break;
    }

  } else if ( Node::Item == node->type ) {
    const Item item = d->m_items.value( node->id );
    if ( !item.isValid() ) {
      return QVariant();
    }

    switch ( role ) {
      case ParentCollectionRole:
        return QVariant::fromValue( item.parentCollection() );
      case MimeTypeRole:
        return item.mimeType();
        break;
      case RemoteIdRole:
        return item.remoteId();
        break;
      case ItemRole:
        return QVariant::fromValue( item );
        break;
      case ItemIdRole:
        return item.id();
        break;
      case CollectionIdRole:
        return -1;
        break;
      case LoadedPartsRole:
        return QVariant::fromValue( item.loadedPayloadParts() );
        break;
      case AvailablePartsRole:
        return QVariant::fromValue( item.availablePayloadParts() );
        break;
      case EntityUrlRole:
        return item.url( Akonadi::Item::UrlWithMimeType ).url();
        break;
      case Qt::BackgroundRole:
      {
        if ( item.hasAttribute<EntityDisplayAttribute>() ) {
          EntityDisplayAttribute *eda = item.attribute<EntityDisplayAttribute>();
          const QColor color = eda->backgroundColor();
          if ( color.isValid() ) {
            return color;
          }
        }
        // fall through.
      }
      default:
        return entityData( item, index.column(), role );
        break;
    }
  }

  return QVariant();
}