本文整理汇总了C++中QWebElement::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebElement::hasAttribute方法的具体用法?C++ QWebElement::hasAttribute怎么用?C++ QWebElement::hasAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebElement
的用法示例。
在下文中一共展示了QWebElement::hasAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showSpellCheckAction
static bool showSpellCheckAction(const QWebElement& element)
{
if (element.hasAttribute(QL1S("readonly")))
return false;
if (element.attribute(QL1S("spellcheck"), QL1S("true")).compare(QL1S("false"), Qt::CaseInsensitive) == 0)
return false;
if (element.hasAttribute(QL1S("type"))
&& element.attribute(QL1S("type")).compare(QL1S("text"), Qt::CaseInsensitive) != 0)
return false;
return true;
}
示例2: processTodo
void EnmlFormatter::processTodo(QWebElement &node) {
bool checked=false;
if (node.hasAttribute("checked"))
checked = true;
node.removeAttribute("style");
node.removeAttribute("type");
removeInvalidAttributes(node);
if (checked)
node.setAttribute("checked", "true");
node.setOuterXml(node.toOuterXml().replace("<input", "<en-todo").replace("</input", "</en-todo"));
}
示例3: addEngineFromForm
void SearchEnginesManager::addEngineFromForm(const QWebElement &element, WebView* view)
{
QWebElement formElement = element.parent();
while (!formElement.isNull()) {
if (formElement.tagName().toLower() == QLatin1String("form")) {
break;
}
formElement = formElement.parent();
}
if (formElement.isNull()) {
return;
}
const QString method = formElement.hasAttribute("method") ? formElement.attribute("method").toUpper() : "GET";
bool isPost = method == QLatin1String("POST");
QUrl actionUrl = QUrl::fromEncoded(formElement.attribute("action").toUtf8());
if (actionUrl.isRelative()) {
actionUrl = view->url().resolved(actionUrl);
}
QUrl parameterUrl = actionUrl;
if (isPost) {
parameterUrl = QUrl("http://foo.bar");
}
#if QT_VERSION >= 0x050000
QUrlQuery query(parameterUrl);
query.addQueryItem(element.attribute("name"), "%s");
QWebElementCollection allInputs = formElement.findAll("input");
foreach (QWebElement e, allInputs) {
if (element == e || !e.hasAttribute("name")) {
continue;
}
query.addQueryItem(e.attribute("name"), e.evaluateJavaScript("this.value").toString());
}
parameterUrl.setQuery(query);
#else
QList<QPair<QByteArray, QByteArray> > queryItems;
QPair<QByteArray, QByteArray> item;
item.first = element.attribute("name").toUtf8();
item.second = "%s";
queryItems.append(item);
QWebElementCollection allInputs = formElement.findAll("input");
foreach (QWebElement e, allInputs) {
if (element == e || !e.hasAttribute("name")) {
continue;
}
QPair<QByteArray, QByteArray> item;
item.first = QUrl::toPercentEncoding(e.attribute("name").toUtf8());
item.second = QUrl::toPercentEncoding(e.evaluateJavaScript("this.value").toByteArray());
queryItems.append(item);
}
parameterUrl.setEncodedQueryItems(parameterUrl.encodedQueryItems() + queryItems);
#endif
if (!isPost) {
actionUrl = parameterUrl;
}
SearchEngine engine;
engine.name = view->title();
engine.icon = view->icon();
engine.url = actionUrl.toEncoded();
if (isPost) {
QByteArray data = parameterUrl.toEncoded(QUrl::RemoveScheme);
engine.postData = data.contains('?') ? data.mid(data.lastIndexOf('?') + 1) : QByteArray();
}
EditSearchEngine dialog(SearchEnginesDialog::tr("Add Search Engine"), view);
dialog.setName(engine.name);
dialog.setIcon(engine.icon);
dialog.setUrl(engine.url);
dialog.setPostData(engine.postData);
if (dialog.exec() != QDialog::Accepted) {
return;
}
engine.name = dialog.name();
engine.icon = dialog.icon();
engine.url = dialog.url();
engine.shortcut = dialog.shortcut();
engine.postData = dialog.postData().toUtf8();
if (engine.name.isEmpty() || engine.url.isEmpty()) {
return;
//.........这里部分代码省略.........
示例4: showContextMenu
void QtWebKitWebWidget::showContextMenu(const QPoint &position)
{
if (position.isNull() && m_webView->selectedText().isEmpty())
{
return;
}
const QPoint hitPosition = (position.isNull() ? m_webView->mapFromGlobal(QCursor::pos()) : position);
MenuFlags flags = NoMenu;
m_hitResult = m_webView->page()->frameAt(hitPosition)->hitTestContent(hitPosition);
if (m_hitResult.element().tagName().toLower() == QLatin1String("textarea") || m_hitResult.element().tagName().toLower() == QLatin1String("select") || (m_hitResult.element().tagName().toLower() == QLatin1String("input") && (m_hitResult.element().attribute(QLatin1String("type")).isEmpty() || m_hitResult.element().attribute(QLatin1String("type")).toLower() == QLatin1String("text"))))
{
QWebElement parentElement = m_hitResult.element().parent();
while (!parentElement.isNull() && parentElement.tagName().toLower() != QLatin1String("form"))
{
parentElement = parentElement.parent();
}
if (!parentElement.isNull() && parentElement.hasAttribute(QLatin1String("action")) && !parentElement.findFirst(QLatin1String("input[name], select[name], textarea[name]")).isNull())
{
flags |= FormMenu;
}
}
if (m_hitResult.pixmap().isNull() && m_hitResult.isContentSelected() && !m_webView->selectedText().isEmpty())
{
updateSearchActions(m_searchEngine);
flags |= SelectionMenu;
}
if (m_hitResult.linkUrl().isValid())
{
flags |= LinkMenu;
}
if (!m_hitResult.pixmap().isNull())
{
flags |= ImageMenu;
const bool isImageOpened = getUrl().matches(m_hitResult.imageUrl(), (QUrl::NormalizePathSegments | QUrl::RemoveFragment | QUrl::StripTrailingSlash));
getAction(OpenImageInNewTabAction)->setEnabled(!isImageOpened);
getAction(InspectElementAction)->setEnabled(!isImageOpened);
}
if (m_hitResult.mediaUrl().isValid())
{
flags |= MediaMenu;
const bool isVideo = (m_hitResult.element().tagName().toLower() == QLatin1String("video"));
const bool isPaused = m_hitResult.element().evaluateJavaScript(QLatin1String("this.paused")).toBool();
const bool isMuted = m_hitResult.element().evaluateJavaScript(QLatin1String("this.muted")).toBool();
getAction(SaveMediaToDiskAction)->setText(isVideo ? tr("Save Video...") : tr("Save Audio..."));
getAction(CopyMediaUrlToClipboardAction)->setText(isVideo ? tr("Copy Video Link to Clipboard") : tr("Copy Audio Link to Clipboard"));
getAction(ToggleMediaControlsAction)->setText(tr("Show Controls"));
getAction(ToggleMediaLoopAction)->setText(tr("Looping"));
getAction(ToggleMediaPlayPauseAction)->setIcon(Utils::getIcon(isPaused ? QLatin1String("media-playback-start") : QLatin1String("media-playback-pause")));
getAction(ToggleMediaPlayPauseAction)->setText(isPaused ? tr("Play") : tr("Pause"));
getAction(ToggleMediaMuteAction)->setIcon(Utils::getIcon(isMuted ? QLatin1String("audio-volume-medium") : QLatin1String("audio-volume-muted")));
getAction(ToggleMediaMuteAction)->setText(isMuted ? tr("Unmute") : tr("Mute"));
}
if (m_hitResult.isContentEditable())
{
flags |= EditMenu;
getAction(ClearAllAction)->setEnabled(getAction(SelectAllAction)->isEnabled());
}
if (flags == NoMenu || flags == FormMenu)
{
flags |= StandardMenu;
if (m_hitResult.frame() != m_webView->page()->mainFrame())
{
flags |= FrameMenu;
}
}
WebWidget::showContextMenu(hitPosition, flags);
}
示例5: triggerAction
//.........这里部分代码省略.........
break;
case CopyFrameLinkToClipboardAction:
if (m_hitResult.frame())
{
QGuiApplication::clipboard()->setText((m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()).toString());
}
break;
case ReloadFrameAction:
if (m_hitResult.frame())
{
const QUrl url = (m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl());
m_hitResult.frame()->setUrl(QUrl());
m_hitResult.frame()->setUrl(url);
}
break;
case SearchAction:
search(getAction(SearchAction));
break;
case CreateSearchAction:
{
QWebElement parentElement = m_hitResult.element().parent();
while (!parentElement.isNull() && parentElement.tagName().toLower() != "form")
{
parentElement = parentElement.parent();
}
const QWebElementCollection inputs = parentElement.findAll(QLatin1String("input:not([disabled])[name], select:not([disabled])[name], textarea:not([disabled])[name]"));
if (!parentElement.isNull() && parentElement.hasAttribute(QLatin1String("action")) && inputs.count() > 0)
{
QUrlQuery parameters;
for (int i = 0; i < inputs.count(); ++i)
{
QString value;
if (inputs.at(i).tagName().toLower() == QLatin1String("textarea"))
{
value = inputs.at(i).toPlainText();
}
else if (inputs.at(i).tagName().toLower() == QLatin1String("select"))
{
const QWebElementCollection options = inputs.at(i).findAll(QLatin1String("option"));
for (int j = 0; j < options.count(); ++j)
{
if (options.at(j).hasAttribute(QLatin1String("selected")))
{
value = options.at(j).attribute(QLatin1String("value"), options.at(j).toPlainText());
break;
}
}
}
else
{
if ((inputs.at(i).attribute(QLatin1String("type")) == QLatin1String("checkbox") || inputs.at(i).attribute(QLatin1String("type")) == QLatin1String("radio")) && !inputs.at(i).hasAttribute(QLatin1String("checked")))
{
continue;
}