本文整理汇总了C++中QMimeData::hasUrls方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::hasUrls方法的具体用法?C++ QMimeData::hasUrls怎么用?C++ QMimeData::hasUrls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::hasUrls方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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]));
}
示例3:
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;
}
示例4: 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;
}
示例5: testCut
void KIOPasteTest::testCut()
{
QMimeData *mimeData = new QMimeData;
QUrl localURL1(QStringLiteral("file:///tmp/Mat%C3%A9riel"));
QUrl localURL2(QStringLiteral("file:///tmp"));
QList<QUrl> localURLs; localURLs << localURL1 << localURL2;
KUrlMimeData::setUrls(QList<QUrl>(), localURLs, mimeData);
KIO::setClipboardDataCut(mimeData, true);
QVERIFY(mimeData->hasUrls());
const QList<QUrl> lst = KUrlMimeData::urlsFromMimeData(mimeData);
QCOMPARE(lst.count(), 2);
QCOMPARE(lst[0].url(), localURL1.url());
QCOMPARE(lst[1].url(), localURL2.url());
const bool isCut = KIO::isClipboardDataCut(mimeData);
QVERIFY(isCut);
delete mimeData;
}
示例6: testPopulate
void KIOPasteTest::testPopulate()
{
QMimeData *mimeData = new QMimeData;
// Those URLs don't have to exist.
QUrl mediaURL(QStringLiteral("media:/hda1/tmp/Mat%C3%A9riel"));
QUrl localURL(QStringLiteral("file:///tmp/Mat%C3%A9riel"));
QList<QUrl> kdeURLs; kdeURLs << mediaURL;
QList<QUrl> mostLocalURLs; mostLocalURLs << localURL;
KUrlMimeData::setUrls(kdeURLs, mostLocalURLs, mimeData);
QVERIFY(mimeData->hasUrls());
const QList<QUrl> lst = KUrlMimeData::urlsFromMimeData(mimeData);
QCOMPARE(lst.count(), 1);
QCOMPARE(lst[0].url(), mediaURL.url());
const bool isCut = KIO::isClipboardDataCut(mimeData);
QVERIFY(!isCut);
delete mimeData;
}
示例7: deleteElements
void UBFeaturesWidget::deleteElements( const QMimeData & mimeData )
{
if ( !mimeData.hasUrls() )
return;
QList<QUrl> urls = mimeData.urls();
foreach ( QUrl url, urls )
{
if ( controller->isTrash( url ) )
{
controller->deleteItem( url );
}
else
{
UBFeature elem = controller->moveItemToFolder( url, controller->getTrashElement() );
controller->removeFromFavorite( url );
featuresModel->addItem( elem );
featuresModel->deleteFavoriteItem( UBFeaturesController::fileNameFromUrl( url ) );
}
}
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
model->invalidate();
}
示例8: PasteData
void PasteData(const QMimeData& data)
{
if (data.hasUrls())
{
const QList<QUrl>& urls = data.urls();
QStringList files;
std::for_each(urls.begin(), urls.end(),
boost::bind(&QStringList::push_back, &files,
boost::bind(&QUrl::toLocalFile, _1)));
AddItems(files);
}
else if (data.hasFormat(ITEMS_MIMETYPE))
{
const QByteArray& encodedData = data.data(ITEMS_MIMETYPE);
QStringList items;
{
QDataStream stream(encodedData);
stream >> items;
}
//pasting is done immediately, so update UI right here
const Playlist::Scanner::Ptr scanner = Controller->GetScanner();
scanner->PasteItems(items);
}
else if (data.hasText())