当前位置: 首页>>代码示例>>C++>>正文


C++ QCache类代码示例

本文整理汇总了C++中QCache的典型用法代码示例。如果您正苦于以下问题:C++ QCache类的具体用法?C++ QCache怎么用?C++ QCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: get_file_icon

QIcon get_file_icon(const QString& content_type) {
  static QCache<QString, QIcon> cache;
  cache.setMaxCost(100);
  if (cache.contains(content_type)) return QIcon(*(cache.object(content_type)));
  QByteArray ba = content_type.toLocal8Bit();
  GIcon* gicon = g_content_type_get_icon(ba.constData());
  if (G_IS_THEMED_ICON(gicon)) {
    const gchar * const * names = g_themed_icon_get_names(reinterpret_cast<GThemedIcon*>(gicon));
    if (names != 0) {
      int i = 0;
      while(names[i] != 0) {
        QString name = QString::fromLocal8Bit(names[i]);
        QIcon r = QIcon::fromTheme(name);
        if (r.isNull()) {
          qDebug() << "get_file_icon: no icon from theme for name: " << name;
        } else {
          cache.insert(content_type, new QIcon(r));
          g_object_unref(gicon);
          return r;
        }
        i++;
      }
    } else {
      qDebug() << "get_file_icon: empty or invalid result of g_themed_icon_get_names";
    }
  } else {
    qDebug() << "get_file_icon: gicon is not themed icon";
  }
  qDebug() << "get_file_icon: returning null icon";
  g_object_unref(gicon);
  return QIcon();
}
开发者ID:Disasm,项目名称:ridual,代码行数:32,代码来源:utils.cpp

示例2: operator_bracket_bracket

void tst_QCache::operator_bracket_bracket()
{
    QCache<int, int> cache;
    cache.insert(1, new int(2));
    QVERIFY(cache[0] == 0);
    QVERIFY(cache[1] != 0);
    QCOMPARE(*cache[1], 2);

    cache.insert(1, new int(4));
    QVERIFY(cache[1] != 0);
    QCOMPARE(*cache[1], 4);

    // check that operator[] doesn't remove the item
    QVERIFY(cache[1] != 0);
    QCOMPARE(*cache[1], 4);

    cache.remove(1);
    QVERIFY(cache[1] == 0);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:19,代码来源:tst_qcache.cpp

示例3: QString

QString DateStringBuilder::getShortDate(const KDateTime &dateTime)
{
    if (!dateTime.isValid() || dateTime.isNull()) {
        return QString();
    }
    QDate currentDate = QDateTime().currentDateTime().date();
    if (currentDate.weekNumber() == dateTime.date().weekNumber() || currentDate.addDays(1) == dateTime.date()) { //this week or tomorrow (i.e. on sunday)
        return getDayName(dateTime);
    }
    if (currentDate.year() == dateTime.date().year()) { //this year
        //Micro optimization because this function showed up as hotspot
        static QCache<uint, QString> cache;
        uint hash = dateTime.date().month() ^ dateTime.date().day();
        if (!cache.contains(hash)) {
            cache.insert(hash, new QString(dateTime.toString("%d.%m")));
        }
        return *cache[hash];
    }
    return dateTime.toString("%d.%m.%Y");
}
开发者ID:sandsmark,项目名称:zanshin,代码行数:20,代码来源:datestringbuilder.cpp

示例4: axioms_on_key_type

void tst_QCache::axioms_on_key_type()
{
    QCache<KeyType, ValueType> foo;
    foo.setMaxCost(1);
    foo.clear();
    foo.insert(KeyType(123), new ValueType(123));
    foo.object(KeyType(123));
    foo.contains(KeyType(456));
    foo[KeyType(456)];
    foo.remove(KeyType(456));
    foo.remove(KeyType(123));
    foo.take(KeyType(789));
// If this fails, contact the maintaner
    QVERIFY(sizeof(QHash<int, int>) == sizeof(void *));
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:15,代码来源:tst_qcache.cpp

示例5: remove

void tst_QCache::remove()
{
    QCache<QString, Foo> cache;
    cache.remove(QString());
    cache.remove("alpha");
    QVERIFY(cache.isEmpty());

    cache.insert("alpha", new Foo, 10);
    QCOMPARE(cache.size(), 1);

    cache.insert("beta", new Foo, 20);
    QCOMPARE(cache.size(), 2);

    for (int i = 0; i < 10; ++i) {
        cache.remove("alpha");
        QCOMPARE(cache.size(), 1);
        QCOMPARE(cache.totalCost(), 20);
    }

    cache.setMaxCost(1);
    QCOMPARE(cache.size(), 0);
    cache.remove("beta");
    QCOMPARE(cache.size(), 0);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:24,代码来源:tst_qcache.cpp

示例6: contains

void tst_QCache::contains()
{
    QCache<int, int> cache;
    QVERIFY(!cache.contains(0));
    QVERIFY(!cache.contains(1));

    cache.insert(1, new int(1), 1);
    QVERIFY(!cache.contains(0));
    QVERIFY(cache.contains(1));

    cache.remove(0);
    cache.remove(1);
    QVERIFY(!cache.contains(0));
    QVERIFY(!cache.contains(1));

    cache.insert(1, new int(1), 1);
    QVERIFY(!cache.contains(0));
    QVERIFY(cache.contains(1));

    cache.clear();
    QVERIFY(!cache.contains(0));
    QVERIFY(!cache.contains(1));
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:23,代码来源:tst_qcache.cpp

示例7: insert

void tst_QCache::insert()
{
    QCache<QString, Foo> cache;

    Foo *f1 = new Foo;
    cache.insert("one", f1, 1);
    QVERIFY(cache.contains("one"));

    Foo *f2 = new Foo;
    cache.insert("two", f2, 2);
    QVERIFY(cache.contains("two"));
    QCOMPARE(cache.size(), 2);

    Foo *f3 = new Foo;
    cache.insert("two", f3, 2);
    QVERIFY(cache.contains("two"));
    QCOMPARE(cache.size(), 2);

    QVERIFY(cache["two"] == f3);
    QCOMPARE(Foo::count, 2);

    /*
        If the new item is too big, any item with the same name in
        the cache must still be removed, otherwise the application
        might get bad results.
    */
    Foo *f4 = new Foo;
    cache.insert("two", f4, 10000);
    QVERIFY(!cache.contains("two"));
    QCOMPARE(cache.size(), 1);
    QCOMPARE(Foo::count, 1);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:32,代码来源:tst_qcache.cpp

示例8: totalCost

void tst_QCache::totalCost()
{
    QCache<QString, int> cache;
    QCOMPARE(cache.totalCost(), 0);

    cache.insert("one", new int(1), 0);
    QCOMPARE(cache.totalCost(), 0);

    cache.insert("two", new int(2), 1);
    QCOMPARE(cache.totalCost(), 1);

    cache.insert("three", new int(3), 2);
    QCOMPARE(cache.totalCost(), 3);

    cache.insert("four", new int(4), 10000);
    QCOMPARE(cache.totalCost(), 3);
    QVERIFY(!cache.contains("four"));

    cache.insert("five", new int(5), -5);
    QCOMPARE(cache.totalCost(), -2);

    cache.insert("six", new int(6), 101);
    QCOMPARE(cache.totalCost(), -2);

    cache.insert("seven", new int(7), 100);
    QCOMPARE(cache.totalCost(), 98);
    QCOMPARE(cache.size(), 5);

    cache.insert("eight", new int(8), 2);
    QCOMPARE(cache.totalCost(), 100);
    QCOMPARE(cache.size(), 6);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:32,代码来源:tst_qcache.cpp

示例9: setMaxCost

void tst_QCache::setMaxCost()
{
    QCache<int, Foo> cache;
    cache.setMaxCost(2);
    cache.insert(1, new Foo);
    cache.insert(2, new Foo);
    QCOMPARE(cache.totalCost(), 2);
    QCOMPARE(Foo::count, 2);

    cache.insert(3, new Foo);
    QCOMPARE(cache.totalCost(), 2);
    QCOMPARE(Foo::count, 2);

    cache.setMaxCost(3);
    QCOMPARE(cache.totalCost(), 2);
    QCOMPARE(Foo::count, 2);

    cache.setMaxCost(2);
    QCOMPARE(cache.totalCost(), 2);
    QCOMPARE(Foo::count, 2);

    cache.setMaxCost(1);
    QCOMPARE(cache.totalCost(), 1);
    QCOMPARE(Foo::count, 1);

    cache.setMaxCost(0);
    QCOMPARE(cache.totalCost(), 0);
    QCOMPARE(Foo::count, 0);

    cache.setMaxCost(-1);
    QCOMPARE(cache.totalCost(), 0);
    QCOMPARE(Foo::count, 0);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:33,代码来源:tst_qcache.cpp

示例10: take

void tst_QCache::take()
{
    QCache<QString, Foo> cache;
    QCOMPARE(cache.take(QString()), (Foo*)0);
    QCOMPARE(cache.take("alpha"), (Foo*)0);
    QVERIFY(cache.isEmpty());

    Foo *f1 = new Foo;
    cache.insert("alpha", f1, 10);
    QCOMPARE(cache.size(), 1);
    QVERIFY(cache["alpha"] == f1);

    cache.insert("beta", new Foo, 20);
    QCOMPARE(cache.size(), 2);

    QCOMPARE(cache.take("alpha"), f1);
    QCOMPARE(cache.size(), 1);
    QCOMPARE(cache.totalCost(), 20);
    QCOMPARE(Foo::count, 2);
    delete f1;
    QCOMPARE(Foo::count, 1);

    QCOMPARE(cache.take("alpha"), (Foo*)0);
    QCOMPARE(Foo::count, 1);
    QCOMPARE(cache.size(), 1);
    QCOMPARE(cache.totalCost(), 20);

    cache.setMaxCost(1);
    QCOMPARE(cache.size(), 0);
    QCOMPARE(cache.take("beta"), (Foo*)0);
    QCOMPARE(cache.size(), 0);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:32,代码来源:tst_qcache.cpp

示例11: markIsDefaultFolderCover

void FileSystemItem::markIsDefaultFolderCover(bool isDefault)
{
    g_isDefaultFolderCover.insert(coverCacheKey(), new bool(isDefault));
    m_useDefaultFolderCover = isDefault;
    // Re-create render here to refresh "m_useDefaultFolderCover"
    createRenderer();
}
开发者ID:shanshuiren,项目名称:Silica,代码行数:7,代码来源:FileSystemItem.cpp

示例12: timerEvent

void QGLBlurTextureCache::timerEvent(QTimerEvent *)
{
    killTimer(timerId);
    timerId = 0;

    cache.clear();
}
开发者ID:Suneal,项目名称:qt,代码行数:7,代码来源:qglpixmapfilter.cpp

示例13: quit

void Audio::quit(){
    if(System){
        SoundCache.clear();
        FMOD_System_Release(System);

        System = NULL;
    }
}
开发者ID:William8915,项目名称:QSanguosha,代码行数:8,代码来源:audio.cpp

示例14: coverThumbnailLoadFailed

void FileSystemItem::coverThumbnailLoadFailed()
{
    QImage *coverImage = new QImage(":/res/image.png");
    g_coverCache.insert(coverCacheKey(), coverImage);
    setThumbnail(new QImage(*coverImage));
    m_coverImage->deleteLater();
    m_coverImage = 0;
}
开发者ID:shanshuiren,项目名称:Silica,代码行数:8,代码来源:FileSystemItem.cpp

示例15: sCode

	QPixmap * getPixmapForCountryCode( const QString & countryCode )
	{
		if( countryCode.isEmpty() )
			return NULL;

		QString sCode( countryCode.toLower() );
		QPixmap * pm = NULL;
		pm = pPixmapCache->object(sCode);
		if( !pm )
		{
			QString sFlag( KStandardDirs::locate("locale", sFlagTemplate.arg(sCode)) );
			if( !sFlag.isEmpty() )
			{
				pm = new QPixmap(sFlag);
				pPixmapCache->insert( sCode, pm );
			}
		}
		return pm;
	}
开发者ID:pkt,项目名称:plasma-widget-yawp-0.4.1-el,代码行数:19,代码来源:countrymap.cpp


注:本文中的QCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。