void BookmarkFilterModel::setSourceModel(QAbstractItemModel *_sourceModel) { beginResetModel(); QAbstractProxyModel::setSourceModel(sourceModel); sourceModel = qobject_cast<BookmarkModel*> (_sourceModel); connect(sourceModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(changed(QModelIndex, QModelIndex))); connect(sourceModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(rowsInserted(QModelIndex, int, int))); connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int))); connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(rowsRemoved(QModelIndex, int, int))); connect(sourceModel, SIGNAL(layoutAboutToBeChanged()), this, SLOT(layoutAboutToBeChanged())); connect(sourceModel, SIGNAL(layoutChanged()), this, SLOT(layoutChanged())); connect(sourceModel, SIGNAL(modelAboutToBeReset()), this, SLOT(modelAboutToBeReset())); connect(sourceModel, SIGNAL(modelReset()), this, SLOT(modelReset())); if (sourceModel) setupCache(sourceModel->index(0, 0, QModelIndex())); endResetModel(); }
ProcessingElement::ProcessingElement(sc_module_name name, int peID, int maxOutstandingRequests, int cacheWordsTotal, CacheMode cacheMode, SpMVOCMSimulation *parentSim, QList<MemRequestTag> bypass) : sc_module(name) { m_parentSim = parentSim; m_peID = peID; m_maxOutstandingRequests = maxOutstandingRequests; m_streamBufferHeadPos = 0; m_maxAlive = 0; m_requestBypassEnable = bypass; setupCache(cacheMode, cacheWordsTotal); m_cyclesWithRequest = 0; m_cyclesWithResponse = 0; m_memLatencySamples = 0; m_memLatencySum = sc_time(0, SC_NS); m_cacheHits = m_cacheMisses = 0; m_peNZCount = 0; m_peRowCount = 0; // declare SystemC threads SC_THREAD(rowPtrAddrGen); SC_THREAD(matrixValueAddrGen); SC_THREAD(colIndAddrGen); SC_THREAD(progress); }
QImage NemoThumbnailProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { setupCache(); // needed for stupid things like gallery model, which pass us a url if (id.startsWith("file://")) { // qWarning() << Q_FUNC_INFO << "Removing file:// prefix, before: " << id; QString &nid = const_cast<QString &>(id); nid = nid.remove(0, 7); } TDEBUG() << Q_FUNC_INFO << "Requested image: " << id << " with size " << requestedSize; // sourceSize should indicate what size thumbnail you want. i.e. if you want a 120x120px thumbnail, // set sourceSize: Qt.size(120, 120). if (!requestedSize.isValid()) qFatal("You must request a sourceSize whenever you use nemoThumbnail"); if (size) *size = requestedSize; QByteArray hashData = cacheKey(id, requestedSize); QImage img = attemptCachedServe(id, hashData); if (!img.isNull()) { TDEBUG() << Q_FUNC_INFO << "Read " << id << " from cache"; return img; } return generateThumbnail(id, hashData, requestedSize); }
void BookmarkModel::setBookmarks(const QByteArray &bookmarks) { beginResetModel(); delete rootItem; folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); bookmarkIcon = QIcon(QLatin1String(":/trolltech/assistant/images/bookmark.png")); rootItem = new BookmarkItem(DataVector() << tr("Name") << tr("Address") << true); QStack<BookmarkItem*> parents; QDataStream stream(bookmarks); qint32 version; stream >> version; if (version < VERSION) { stream.device()->seek(0); BookmarkItem* toolbar = new BookmarkItem(DataVector() << tr("Toolbar Menu") << QLatin1String("Folder") << true); rootItem->addChild(toolbar); BookmarkItem* menu = new BookmarkItem(DataVector() << tr("Bookmarks Menu") << QLatin1String("Folder") << true); rootItem->addChild(menu); parents.push(menu); } else { parents.push(rootItem); } qint32 depth; bool expanded; QString name, url; while (!stream.atEnd()) { stream >> depth >> name >> url >> expanded; while ((parents.count() - 1) != depth) parents.pop(); BookmarkItem *item = new BookmarkItem(DataVector() << name << url << expanded); if (url == QLatin1String("Folder")) { parents.top()->addChild(item); parents.push(item); } else { parents.top()->addChild(item); } } cache.clear(); setupCache(index(0,0, QModelIndex().parent())); endResetModel(); }
void BookmarkModel::setBookmarks(const QByteArray &bookmarks) { beginResetModel(); delete rootItem; folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); bookmarkIcon = QIcon(QLatin1String(":/trolltech/assistant/images/bookmark.png")); rootItem = new BookmarkItem(DataVector() << tr("Name") << tr("Address") << true); BookmarkItem* item = new BookmarkItem(DataVector() << tr("Bookmarks Menu") << QLatin1String("Folder") << true); rootItem->addChild(item); QStack<BookmarkItem*> parents; parents.push(item); qint32 depth; bool expanded; QString name, url; QDataStream stream(bookmarks); while (!stream.atEnd()) { stream >> depth >> name >> url >> expanded; while ((parents.count() - 1) != depth) parents.pop(); item = new BookmarkItem(DataVector() << name << url << expanded); if (url == QLatin1String("Folder")) { parents.top()->addChild(item); parents.push(item); } else { parents.top()->addChild(item); } } cache.clear(); const QModelIndex &root = index(0,0, QModelIndex()); setupCache(root); cache.insert(static_cast<BookmarkItem*> (root.internalPointer()), root); endResetModel(); }
int main(int argc, char *argv[]) { int opt = 0; int setBitCount = 1, blockBitCount = 1, associativity = 1; while ((opt = getopt(argc, argv, "hvs:E:b:t:")) != -1) { switch(opt) { case 'h': printf( "Usage: %s [-hv] -s <num> -E <num> -b <num> -t <file>\n" "Options:\n" "-h Print this help message.\n" "-v Optional verbose flag.\n" "-s <num> Number of set index bits.\n" "-E <num> Number of lines per set.\n" "-b <num> Number of block offset bits.\n" "-t <file> Trace file.\n" "\n" "Examples:\n" "linux> %s -s 4 -E 1 -b 4 -t traces/yi.trace\n" "linux> %s -v -s 8 -E 2 -b 4 -t traces/yi.trace\n", argv[0], argv[0], argv[0]); break; case 'v': g_isVerbose = 1; break; case 's': setBitCount = atoi(optarg); break; case 'E': associativity = atoi(optarg); break; case 'b': blockBitCount = atoi(optarg); break; case 't': { FILE *traceFile = fopen(optarg, "r"); dup2(fileno(traceFile), fileno(stdin)); fclose(traceFile); } break; default: break; } } Cache* cache = setupCache(setBitCount, associativity, blockBitCount, &onCacheHit, &onCacheMiss, &onCacheEviction); { char buf[32] = ""; long long addr; int size; while (scanf("%s %llx,%d", buf, &addr, &size) == 3) { printf("%s %llx,%d", buf, addr, size); switch (buf[0]) { case 'I': break; case 'L': accessCache(cache, addr, size); break; case 'S': accessCache(cache, addr, size); break; case 'M': accessCache(cache, addr, size); accessCache(cache, addr, size); break; } puts(""); } } cleanupCache(cache); printSummary(g_hitCount, g_missCount, g_evictionCount); return 0; }
QImage FileThumbnailImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { setupCache(); // needed for stupid things like gallery model, which pass us a url if (id.startsWith("file://")) { qWarning() << Q_FUNC_INFO << "Removing file:// prefix, before: " << id; QString &nid = const_cast<QString &>(id); nid = nid.remove(0, 7); } qDebug() << Q_FUNC_INFO << "Requested image: " << id << " with size " << requestedSize; // sourceSize should indicate what size thumbnail you want. i.e. if you want a 120x120px thumbnail, // set sourceSize: Qt.size(120, 120). if (!requestedSize.isValid()) qFatal("You must request a sourceSize whenever you use nemoThumbnail"); if (size) *size = requestedSize; QByteArray hashData = cacheKey(id, requestedSize); QImage img = attemptCachedServe(hashData); if (!img.isNull()) { qDebug() << Q_FUNC_INFO << "Read " << id << " from cache"; return img; } // cache couldn't satisfy us. // step 1: read source image in QImageReader ir(id); img = ir.read(); // don't pollute the cache with false positives if (img.isNull()) return QImage(); if (img.size() == requestedSize) return img; // step 2: scale to target size if (img.height() == img.width()) { // in the case of a squared image, there's no need to crop img = img.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } else if (img.height() >= requestedSize.height() && img.width() >= requestedSize.width()) { // if the image is larger than the desired size (on both dimensions) // then crop, and scale down if (img.width() < img.height()) { int cropPosition = (img.height() - img.width()) / 2; img = img.copy(0, cropPosition, img.width(), img.width()); img = img.scaledToWidth(requestedSize.width(), Qt::SmoothTransformation); } else { int cropPosition = (img.width() - img.height()) / 2; img = img.copy(cropPosition, 0, img.height(), img.height()); img = img.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); } } else if ((img.width() <= requestedSize.width() && img.height() >= requestedSize.height()) || (img.width() >= requestedSize.width() && img.height() <= requestedSize.height())) { // if the image is smaller than the desired size on one dimension, scale it up, // then crop down to thumbnail size. if (img.width() <= requestedSize.width() && img.height() >= requestedSize.height()) { img = img.scaledToWidth(requestedSize.width(), Qt::SmoothTransformation); int cropPosition = (img.height() - img.width()) / 2; img = img.copy(0, cropPosition, img.width(), img.width()); } else { img = img.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); int cropPosition = (img.width() - img.height()) / 2; img = img.copy(cropPosition, 0, img.height(), img.height()); } } else { // if the image is smaller on both dimensions, scale it up, and use the requested // size to do the cropping if (img.width() < img.height()) { img = img.scaledToWidth(requestedSize.width(), Qt::SmoothTransformation); int cropPosition = (img.height() - requestedSize.height()) / 2; img = img.copy(0, cropPosition, img.width(), img.width()); } else { img = img.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); int cropPosition = (img.width() - requestedSize.width()) / 2; img = img.copy(cropPosition, 0, img.height(), img.height()); } } // step 3: write to cache for next time writeCacheFile(hashData, img); qDebug() << Q_FUNC_INFO << "Wrote " << id << " to cache"; return img; }