Exemplo n.º 1
0
QVariantMap ClipboardBrowser::copyIndexes(const QModelIndexList &indexes, bool serializeItems) const
{
    QByteArray bytes;
    QDataStream stream(&bytes, QIODevice::WriteOnly);
    QByteArray text;
    QByteArray uriList;
    QVariantMap data;

    for ( int i = 0; i < indexes.size(); ++i ) {
        const QModelIndex ind = indexes.at(i);
        if ( isIndexHidden(ind) )
            continue;

        const QVariantMap copiedItemData =
                m_itemLoader ? m_itemLoader->copyItem(m, itemData(ind)) : itemData(ind);

        if (serializeItems)
            stream << copiedItemData;

        if (indexes.size() == 1) {
            data = copiedItemData;
        } else {
            appendTextData(copiedItemData, mimeText, &text);
            appendTextData(copiedItemData, mimeUriList, &uriList);
        }
    }

    if (serializeItems)
        data.insert(mimeItems, bytes);

    if (indexes.size() > 1) {
        if ( !text.isNull() )
            data.insert(mimeText, text);
        if ( !uriList.isNull() )
            data.insert(mimeUriList, uriList);
    }

    return data;
}
Exemplo n.º 2
0
 inline bool tst_isIndexHidden(const QModelIndex &index) const
     { return isIndexHidden(index); }
Exemplo n.º 3
0
 bool IsIndexHidden(const QModelIndex&index) const
     { return isIndexHidden(index); }
Exemplo n.º 4
0
void ClipboardBrowser::preload(int minY, int maxY)
{
    ClipboardBrowser::Lock lock(this);

    QModelIndex ind;
    int i = 0;
    int y = spacing();
    const int s = 2 * spacing();
    int offset = verticalOffset();

    // Find first index to preload.
    forever {
        ind = index(i);
        if ( !ind.isValid() )
            return;

        if ( !isIndexHidden(ind) ) {
            const int h = d.sizeHint(ind).height();
            y += h; // bottom of item
            if (y >= offset)
                break;
            y += s; // top of next item
        }

        d.setRowVisible(i, false);

        ++i;
    }

    // Absolute to relative.
    y -= offset;

    bool update = false;

    // Preload items backwards.
    forever {
        const int lastIndex = i;
        for ( ind = index(--i); ind.isValid() && isIndexHidden(ind); ind = index(--i) ) {}

        if ( !ind.isValid() ) {
            i = lastIndex;
            ind = index(i);
            break;
        }

        const QRect oldRect(visualRect(ind));

        // Fetch item.
        d.cache(ind);
        const int h = d.sizeHint(ind).height();

        // Re-layout rows afterwards if size has changed.
        const int dy = h - oldRect.height();
        if (dy != 0) {
            maxY += dy;
            update = true;
        }

        // Done?
        y -= h; // top of item
        if (y + h < minY)
            break;
        y -= s; // bottom of previous item
    }

    y = visualRect(ind).y();
    bool lastToPreload = false;

    // Render visible items, re-layout rows and correct scroll offset.
    forever {
        if (m_lastFiltered != -1 && m_lastFiltered < i)
            break;

        const QRect oldRect(update ? QRect() : visualRect(ind));

        // Fetch item.
        d.cache(ind);
        const int h = d.sizeHint(ind).height();

        // Re-layout rows afterwards if row position or size has changed.
        if (!update)
            update = (y != oldRect.y() || h != oldRect.height());

        // Correct widget position.
        d.updateRowPosition(i, y);

        d.setRowVisible(i, true);

        // Next.
        ind = index(++i);

        // Done?
        y += h + s; // top of item
        if (y > maxY) {
            if (lastToPreload)
                break;
            lastToPreload = true; // One more item to preload.
        }

        // Skip hidden.
        for ( ; ind.isValid() && isIndexHidden(ind); ind = index(++i) ) {}

        if ( !ind.isValid() )
            break;
    }

    // Hide the rest.
    for ( ; i < m.rowCount(); ++i )
        d.setRowVisible(i, false);

    if (update)
        scheduleDelayedItemsLayout();
}