本文整理汇总了C++中QMimeData::urls方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::urls方法的具体用法?C++ QMimeData::urls怎么用?C++ QMimeData::urls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::urls方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getUtf8Data
QByteArray getUtf8Data(const QMimeData &data, const QString &format)
{
if (format == mimeText || format == mimeHtml)
return dataToText( data.data(format), format ).toUtf8();
if (format == mimeUriList) {
QByteArray bytes;
foreach ( const QUrl &url, data.urls() ) {
if ( !bytes.isEmpty() )
bytes += '\n';
bytes += url.toString().toUtf8();
}
return bytes;
}
示例4: mimeData
QMimeData* PaletteModel::mimeData(const QModelIndexList& indexes) const
{
QMimeData* pUrlData = QDirModel::mimeData(indexes);
if (pUrlData == NULL)
{
return NULL;
}
QMimeData* pData = new QMimeData();
QList<QUrl> urls = pUrlData->urls();
if (!urls.empty())
{
pData->setData(dndMimeType, urls.front().toString().toAscii());
}
delete pUrlData;
return pData;
}
示例5: sipConvertFromNewType
static PyObject *meth_QMimeData_urls(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
QMimeData *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QMimeData, &sipCpp))
{
QList<QUrl> *sipRes;
Py_BEGIN_ALLOW_THREADS
sipRes = new QList<QUrl>(sipCpp->urls());
Py_END_ALLOW_THREADS
return sipConvertFromNewType(sipRes,sipType_QList_0100QUrl,NULL);
}
}
示例6:
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;
}
示例7: IsValidFile
bool cg_disasm_window::IsValidFile(const QMimeData& md, bool save)
{
for (auto url : md.urls())
{
for (QString suff : {"fpo", "vpo"})
{
if (QFileInfo(url.fileName()).suffix().toLower() == suff)
{
if (save)
{
m_path_last = url.toLocalFile();
xgui_settings->SetValue(GUI::fd_cg_disasm, m_path_last);
}
return true;
}
}
}
return false;
}
示例8: 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;
}
示例9: 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();
}
示例10: 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())
示例11: mouseMoveEvent
void PlayListView::mouseMoveEvent(QMouseEvent *event){
//
// if not left button - return
if (!(event->buttons() & Qt::LeftButton)) return;
// if no item selected, return (else it would crash)
if (currentItem() == NULL) return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
QString line;
line = currentItem()->text(0); // 0 == first Column of QTreeWidgetItem
list.append( QUrl(line) ); // only QUrl in list will be text of actual item
// mime stuff
mimeData->setUrls(list);
//mimeData->setData( line.toUtf8(), "text/uri-list" );
drag->setMimeData(mimeData);
RG_DEBUG << "Starting drag from PlayListView::mouseMoveEvent() with mime : " << mimeData->formats() << " - " << mimeData->urls()[0] << endl;
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}