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


C++ QMimeData::hasText方法代码示例

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


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

示例1: setText

void tst_QMimeData::setText() const
{
    QMimeData mimeData;

    // verify initial state
    QCOMPARE(mimeData.text(), QLatin1String(""));
    QVERIFY(mimeData.hasText() == false);

    // set, verify
    mimeData.setText("pirates");
    QVERIFY(mimeData.hasText());
    QCOMPARE(mimeData.text(), QLatin1String("pirates"));
    QCOMPARE(mimeData.text().toLatin1(), mimeData.data("text/plain"));

    // reset, verify
    mimeData.setText("ninjas");
    QVERIFY(mimeData.hasText());
    QCOMPARE(mimeData.text(), QLatin1String("ninjas"));
    QCOMPARE(mimeData.text().toLatin1(), mimeData.data("text/plain"));

    // clear, verify
    mimeData.clear();
    QCOMPARE(mimeData.text(), QLatin1String(""));
    QVERIFY(mimeData.hasText() == false);
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:25,代码来源:tst_qmimedata.cpp

示例2: clear

void tst_QMimeData::clear() const
{
    QMimeData mimeData;

    // set, clear, verify empty
    mimeData.setData("text/plain", "pirates");
    QVERIFY(mimeData.hasText());
    mimeData.clear();
    QVERIFY(mimeData.hasText() == false);

    // repopulate, verify not empty
    mimeData.setData("text/plain", "pirates");
    QVERIFY(mimeData.hasText());
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:14,代码来源:tst_qmimedata.cpp

示例3: setUrls

void tst_QMimeData::setUrls() const
{
    QMimeData mimeData;
    QList<QUrl> shortUrlList;
    QList<QUrl> longUrlList;

    // set up
    shortUrlList += QUrl("http://qt-project.org");
    longUrlList = shortUrlList;
    longUrlList += QUrl("http://www.google.com");

    // verify initial state
    QCOMPARE(mimeData.hasUrls(), false);

    // set a few, verify
    mimeData.setUrls(shortUrlList);
    QCOMPARE(mimeData.urls(), shortUrlList);
    QCOMPARE(mimeData.text(), QString("http://qt-project.org"));

    // change them, verify
    mimeData.setUrls(longUrlList);
    QCOMPARE(mimeData.urls(), longUrlList);
    QCOMPARE(mimeData.text(), QString("http://qt-project.org\nhttp://www.google.com\n"));

    // clear, verify
    mimeData.clear();
    QCOMPARE(mimeData.hasUrls(), false);
    QCOMPARE(mimeData.hasText(), false);
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:29,代码来源:tst_qmimedata.cpp

示例4: testMostLocalUrlList

void KUrlMimeTest::testMostLocalUrlList()
{
    QMimeData* mimeData = new QMimeData;
    KUrl::List urls;
    urls.append(KUrl("desktop:/foo"));
    urls.append(KUrl("desktop:/bar"));
    KUrl::List localUrls;
    localUrls.append(KUrl("file:/home/dfaure/Desktop/foo"));
    localUrls.append(KUrl("file:/home/dfaure/Desktop/bar"));

    urls.populateMimeData(localUrls, mimeData);

    QVERIFY(KUrl::List::canDecode(mimeData));
    QVERIFY(mimeData->hasUrls());
    QVERIFY(mimeData->hasText());
    QVERIFY(mimeData->hasFormat("text/plain"));

    // KUrl decodes the real "kde" urls by default
    KUrl::List decodedURLs = KUrl::List::fromMimeData(mimeData);
    QVERIFY(!decodedURLs.isEmpty());
    QCOMPARE(decodedURLs.toStringList().join(" "), urls.toStringList().join(" ") );

    // KUrl can also be told to decode the "most local" urls
    decodedURLs = KUrl::List::fromMimeData(mimeData, 0, KUrl::List::PreferLocalUrls);
    QVERIFY(!decodedURLs.isEmpty());
    QCOMPARE(decodedURLs.toStringList().join(" "), localUrls.toStringList().join(" ") );

    // QMimeData decodes the "most local" urls
    const QList<QUrl> qurls = mimeData->urls();
    QCOMPARE(qurls.count(), localUrls.count());
    for (int i = 0; i < qurls.count(); ++i )
        QCOMPARE(qurls[i], static_cast<QUrl>(localUrls[i]));

}
开发者ID:fluxer,项目名称:kdelibs,代码行数:34,代码来源:kurlmimetest.cpp

示例5:

QDebug operator<<(QDebug d, const QMimeData &m)
{
    QDebug nospace = d.nospace();
    const QStringList formats = m.formats();
    nospace << "QMimeData: " << formats.join(QStringLiteral(", ")) << '\n'
            << "  Text=" << m.hasText() << " HTML=" << m.hasHtml()
            << " Color=" << m.hasColor() << " Image=" << m.hasImage()
            << " URLs=" << m.hasUrls() << '\n';
    if (m.hasText())
        nospace << "  Text: '" << m.text() << "'\n";
    if (m.hasHtml())
        nospace << "  HTML: '" << m.html() << "'\n";
    if (m.hasColor())
        nospace << "  Color: " << qvariant_cast<QColor>(m.colorData()) << '\n';
    if (m.hasImage())
        nospace << "  Image: " << qvariant_cast<QImage>(m.imageData()).size() << '\n';
    if (m.hasUrls())
        nospace << "  URLs: " << m.urls() << '\n';
    return d;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:20,代码来源:qwindowsclipboard.cpp

示例6: testURLList

void KUrlMimeTest::testURLList()
{
    QMimeData* mimeData = new QMimeData;
    QVERIFY( !KUrl::List::canDecode( mimeData ) );
    QVERIFY(!mimeData->hasUrls());

    KUrl::List urls;
    urls.append( KUrl( "http://www.kde.org" ) );
    urls.append( KUrl( "http://wstephenson:[email protected]/path" ) );
    urls.append( KUrl( "file:///home/dfaure/konqtests/Mat%C3%A9riel" ) );
    QMap<QString, QString> metaData;
    metaData["key"] = "value";
    metaData["key2"] = "value2";

    urls.populateMimeData( mimeData, metaData );

    QVERIFY(KUrl::List::canDecode( mimeData ));
    QVERIFY(mimeData->hasUrls());
    QVERIFY(mimeData->hasText());

    QMap<QString, QString> decodedMetaData;
    KUrl::List decodedURLs = KUrl::List::fromMimeData( mimeData, &decodedMetaData );
    QVERIFY( !decodedURLs.isEmpty() );
    KUrl::List expectedUrls = urls;
    expectedUrls[1] = KUrl("http://[email protected]/path"); // password removed
    QCOMPARE( expectedUrls.toStringList().join(" "), decodedURLs.toStringList().join(" ") );

    const QList<QUrl> qurls = mimeData->urls();
    QCOMPARE(qurls.count(), urls.count());
    for (int i = 0; i < qurls.count(); ++i )
        QCOMPARE(qurls[i], static_cast<QUrl>(decodedURLs[i]));

    QVERIFY( !decodedMetaData.isEmpty() );
    QCOMPARE( decodedMetaData["key"], QString( "value" ) );
    QCOMPARE( decodedMetaData["key2"], QString( "value2" ) );

    delete mimeData;
}
开发者ID:fluxer,项目名称:kdelibs,代码行数:38,代码来源:kurlmimetest.cpp


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