本文整理汇总了C++中BookmarkItem::url方法的典型用法代码示例。如果您正苦于以下问题:C++ BookmarkItem::url方法的具体用法?C++ BookmarkItem::url怎么用?C++ BookmarkItem::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookmarkItem
的用法示例。
在下文中一共展示了BookmarkItem::url方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
QVariant BookmarksModel::data(const QModelIndex &index, int role) const
{
BookmarkItem* itm = item(index);
if (!itm) {
return QVariant();
}
switch (role) {
case TypeRole:
return itm->type();
case UrlRole:
return itm->url();
case UrlStringRole:
return itm->urlString();
case TitleRole:
return itm->title();
case DescriptionRole:
return itm->description();
case KeywordRole:
return itm->keyword();
case VisitCountRole:
return -1;
case ExpandedRole:
return itm->isExpanded();
case SidebarExpandedRole:
return itm->isSidebarExpanded();
case Qt::ToolTipRole:
if (index.column() == 0 && itm->isUrl()) {
return QString("%1\n%2").arg(itm->title(), QString::fromUtf8(itm->url().toEncoded()));
}
case Qt::DisplayRole:
switch (index.column()) {
case 0:
return itm->title();
case 1:
return itm->url().toEncoded();
default:
return QVariant();
}
case Qt::DecorationRole:
if (index.column() == 0) {
return itm->icon();
}
return QVariant();
default:
return QVariant();
}
}
示例2: createLoadRequest
LoadRequest LocationCompleter::createLoadRequest(const QModelIndex &index)
{
LoadRequest request;
BookmarkItem *bookmark = nullptr;
if (index.data(LocationCompleterModel::HistoryRole).toBool()) {
request = index.data(LocationCompleterModel::UrlRole).toUrl();
} else if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
} else if (index.data(LocationCompleterModel::SearchSuggestionRole).toBool()) {
const QString text = index.data(LocationCompleterModel::TitleRole).toString();
request = mApp->searchEnginesManager()->searchResult(LocationBar::searchEngine(), text);
} else if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
const auto action = LocationBar::loadAction(m_originalText);
switch (action.type) {
case LocationBar::LoadAction::Url:
case LocationBar::LoadAction::Search:
request = action.loadRequest;
break;
case LocationBar::LoadAction::Bookmark:
bookmark = action.bookmark;
break;
default:
break;
}
}
if (bookmark) {
bookmark->updateVisitCount();
request = bookmark->url();
}
return request;
}
示例3: createLoadRequest
LoadRequest LocationBar::createLoadRequest() const
{
LoadRequest req;
// Check for Search Engine shortcut
int firstSpacePos = text().indexOf(QLatin1Char(' '));
if (firstSpacePos != -1) {
const QString shortcut = text().left(firstSpacePos);
const QString searchedString = text().mid(firstSpacePos).trimmed();
SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
if (!en.name.isEmpty()) {
req = mApp->searchEnginesManager()->searchResult(en, searchedString);
}
}
// Check for Bookmark keyword
QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(text());
if (!items.isEmpty()) {
BookmarkItem* item = items.first();
item->updateVisitCount();
req.setUrl(item->url());
}
if (req.isEmpty()) {
const QUrl guessedUrl = WebView::guessUrlFromString(text());
if (!guessedUrl.isEmpty())
req.setUrl(guessedUrl);
else
req.setUrl(QUrl::fromEncoded(text().toUtf8()));
}
return req;
}
示例4: startDrag
void BookmarksListBox::startDrag()
{
int currentItem = QListBox::currentItem();
if (currentItem != -1) {
BookmarkItem* bookmark = (BookmarkItem*)item(currentItem);
if (bookmark!=0){
KURL::List lst;
lst.append( bookmark->url() );
KURLDrag *drag = new KURLDrag(lst, this);
drag->drag();
}
}
}
示例5: createLoadRequest
LoadRequest LocationBar::createLoadRequest() const
{
LoadRequest req;
const QString &t = text().trimmed();
// Check for Search Engine shortcut
int firstSpacePos = t.indexOf(QLatin1Char(' '));
if (firstSpacePos != -1) {
const QString shortcut = t.left(firstSpacePos);
const QString searchedString = t.mid(firstSpacePos).trimmed();
SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
if (!en.name.isEmpty()) {
req = mApp->searchEnginesManager()->searchResult(en, searchedString);
}
}
// Check for Bookmark keyword
QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t);
if (!items.isEmpty()) {
BookmarkItem* item = items.at(0);
item->updateVisitCount();
req.setUrl(item->url());
}
if (req.isEmpty()) {
// One word needs special handling, because QUrl::fromUserInput
// would convert it to QUrl("http://WORD")
if (!t.contains(QL1C(' ')) && !t.contains(QL1C('.'))) {
req.setUrl(QUrl(t));
}
else {
const QUrl &guessed = QUrl::fromUserInput(t);
if (!guessed.isEmpty())
req.setUrl(guessed);
else
req.setUrl(QUrl::fromEncoded(t.toUtf8()));
}
}
return req;
}
示例6: loadAction
LocationBar::LoadAction LocationBar::loadAction(const QString &text)
{
LoadAction action;
const QString &t = text.trimmed();
if (t.isEmpty()) {
return action;
}
// Check for Search Engine shortcut
const int firstSpacePos = t.indexOf(QLatin1Char(' '));
if (qzSettings->searchFromAddressBar && firstSpacePos != -1) {
const QString shortcut = t.left(firstSpacePos);
const QString searchedString = t.mid(firstSpacePos).trimmed();
SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
if (en.isValid()) {
action.type = LoadAction::Search;
action.searchEngine = en;
action.loadRequest = mApp->searchEnginesManager()->searchResult(en, searchedString);
return action;
}
}
// Check for Bookmark keyword
const QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t);
if (!items.isEmpty()) {
BookmarkItem* item = items.at(0);
action.type = LoadAction::Bookmark;
action.bookmark = item;
action.loadRequest.setUrl(item->url());
return action;
}
if (!qzSettings->searchFromAddressBar) {
const QUrl &guessedUrl = QUrl::fromUserInput(t);
if (guessedUrl.isValid()) {
action.type = LoadAction::Url;
action.loadRequest = guessedUrl;
}
return action;
}
// Check for one word search
if (t != QL1S("localhost")
&& !QzTools::containsSpace(t)
&& !t.contains(QL1C('.'))
&& !t.contains(QL1C(':'))
&& !t.contains(QL1C('/'))
) {
action.type = LoadAction::Search;
action.searchEngine = searchEngine();
action.loadRequest = mApp->searchEnginesManager()->searchResult(searchEngine(), t);
return action;
}
// Otherwise load as url
const QUrl &guessedUrl = QUrl::fromUserInput(t);
if (guessedUrl.isValid()) {
// Always allow javascript: to be loaded
const bool forceLoad = guessedUrl.scheme() == QL1S("javascript");
// Only allow spaces in query
if (forceLoad || !QzTools::containsSpace(guessedUrl.toString(QUrl::RemoveQuery))) {
// Only allow whitelisted schemes
static const QSet<QString> whitelistedSchemes = {
QSL("http"), QSL("https"), QSL("ftp"), QSL("file"),
QSL("data"), QSL("about"), QSL("qupzilla")
};
if (forceLoad || whitelistedSchemes.contains(guessedUrl.scheme())) {
action.type = LoadAction::Url;
action.loadRequest = guessedUrl;
return action;
}
}
}
// Search when creating url failed
action.type = LoadAction::Search;
action.searchEngine = searchEngine();
action.loadRequest = mApp->searchEnginesManager()->searchResult(searchEngine(), t);
return action;
}