void MainWindow::displayViewActions() { ui->actionBack->setEnabled(ui->webView->canGoBack()); ui->backButton->setEnabled(ui->webView->canGoBack()); ui->actionForward->setEnabled(ui->webView->canGoForward()); ui->forwardButton->setEnabled(ui->webView->canGoForward()); ui->menuView->clear(); ui->menuView->addAction(ui->actionBack); ui->menuView->addAction(ui->actionForward); ui->menuView->addSeparator(); m_backMenu->clear(); m_forwardMenu->clear(); QWebHistory *history = ui->webView->page()->history(); for (const QWebHistoryItem &item: history->backItems(10)) m_backMenu->addAction(addHistoryAction(history, item)); if (history->count() > 0) addHistoryAction(history, history->currentItem())->setEnabled(false); for (const QWebHistoryItem &item: history->forwardItems(10)) m_forwardMenu->addAction(addHistoryAction(history, item)); displayTabs(); }
QString DumpRenderTree::dumpBackForwardList(QWebPage* page) { QWebHistory* history = page->history(); QString result; result.append(QLatin1String("\n============== Back Forward List ==============\n")); // FORMAT: // " (file test):fast/loader/resources/click-fragment-link.html **nav target**" // "curr-> (file test):fast/loader/resources/click-fragment-link.html#testfragment **nav target**" int maxItems = history->maximumItemCount(); foreach (const QWebHistoryItem item, history->backItems(maxItems)) { if (!item.isValid()) continue; result.append(dumpHistoryItem(item, 8, false)); } QWebHistoryItem item = history->currentItem(); if (item.isValid()) result.append(dumpHistoryItem(item, 8, true)); foreach (const QWebHistoryItem item, history->forwardItems(maxItems)) { if (!item.isValid()) continue; result.append(dumpHistoryItem(item, 8, false)); } result.append(QLatin1String("===============================================\n")); return result; }
void QtWebKitHelpViewer::goToHistoryItem(bool forward) { QAction *action = qobject_cast<QAction *>(sender()); QTC_ASSERT(action, return); QWebHistory *history = m_webView->history(); QTC_ASSERT(history, return); bool ok = false; int index = action->data().toInt(&ok); QTC_ASSERT(ok, return); if (forward) history->goToItem(history->forwardItems(history->count()).at(index)); else history->goToItem(history->backItems(history->count()).at(index)); }