Esempio n. 1
0
void ImageListModel::fetchMore(const QModelIndex &)
{
    int remainder = m_imageInfoList.count() - m_imageInfoCount;
    int itemsToFetch = qMin(100, remainder);

    int beginIndex = m_imageInfoCount;
    int endIndex = beginIndex + itemsToFetch;
    if (endIndex >= m_imageInfoList.count())
        endIndex = m_imageInfoList.count() - 1;

    beginInsertRows(QModelIndex(), beginIndex, endIndex);
    m_imageInfoCount += itemsToFetch;
    endInsertRows();

    // start multithreaded image loading
    for (int i = beginIndex; i <= endIndex; i++) {
        const ImageInfo imageInfo = m_imageInfoList.at(i);
        if (imageInfo.exists()) {
            ImageLoader *imageLoader = new ImageLoader(imageInfo.imagePath(), i);
            imageLoader->setScaleSize(MainWindow::MAX_THUMBNAIL_SIZE, MainWindow::MAX_THUMBNAIL_SIZE);
            connect(imageLoader, SIGNAL(imageLoaded(QImage, int, int, int)), SLOT(thumbnailLoaded(QImage, int, int, int)));
            m_imageLoaderPool.start(imageLoader);
        }
    }

    emit changed();
    qDebug("ImageListModel::fetchMore(): from %d to %d", beginIndex, endIndex);
}