本文整理汇总了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);
}
示例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());
}
示例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);
}
示例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]));
}
示例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;
}
示例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;
}