Commit 6ac6be5d authored by kh1's avatar kh1
Browse files

Rewrite of the whole help modul initialization.

We now do as much as possible lazy initialisation, e.g only start the
full text search indexer if we really access the search widget. Also
moved the QFutur progress into the search widget. Changed all ctors to
be called without an argument, since we share the help engines from
help manager all over the place. Make use of the fact that we only need
to call setupData on the gui engine if we access the help mode, otherwise
all data is fetched thru the core engine whichs setupData is really fast.
parent c3326eb6
......@@ -55,7 +55,7 @@
#include <QtGui/QPrintPreviewDialog>
#include <QtGui/QPageSetupDialog>
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpEngineCore>
#include <coreplugin/coreconstants.h>
......@@ -75,7 +75,7 @@ namespace {
Help::Internal::CentralWidget *staticCentralWidget = 0;
}
CentralWidget::CentralWidget(QHelpEngine *engine, QWidget *parent)
CentralWidget::CentralWidget(QWidget *parent)
: QWidget(parent)
, findBar(0)
, tabWidget(0)
......
......@@ -46,7 +46,6 @@ class QCheckBox;
class QLineEdit;
class QToolButton;
class QTabWidget;
class QHelpEngine;
class QFocusEvent;
QT_END_NAMESPACE
......@@ -61,7 +60,7 @@ class CentralWidget : public QWidget
Q_OBJECT
public:
CentralWidget(QHelpEngine *engine, QWidget *parent = 0);
CentralWidget(QWidget *parent = 0);
~CentralWidget();
bool hasSelection() const;
......
......@@ -125,8 +125,14 @@ void DocSettingsPage::removeDocumentation()
void DocSettingsPage::apply()
{
emit dialogAccepted();
emit documentationChanged();
HelpManager* manager = &HelpManager::instance();
manager->unregisterDocumentation(m_filesToUnregister.keys());
manager->registerDocumentation(m_filesToRegister.values());
if (manager->guiEngineNeedsUpdate()) {
// emit this signal to the help plugin, since we don't want
// to force gui help engine setup if we are not in help mode
emit documentationChanged();
}
m_filesToRegister.clear();
m_filesToUnregister.clear();
......@@ -137,16 +143,6 @@ bool DocSettingsPage::matches(const QString &s) const
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
QStringList DocSettingsPage::docsToRegister() const
{
return m_filesToRegister.values();
}
QStringList DocSettingsPage::docsToUnregister() const
{
return m_filesToUnregister.keys();
}
bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
{
if (object != m_ui.docsListWidget)
......
......@@ -54,11 +54,7 @@ public:
void finish() {}
virtual bool matches(const QString &s) const;
QStringList docsToRegister() const;
QStringList docsToUnregister() const;
signals:
void dialogAccepted();
void documentationChanged();
private slots:
......
......@@ -178,12 +178,6 @@ void FilterSettingsPage::removeFilter()
}
void FilterSettingsPage::apply()
{
// This is handled via HelpPlugin::checkForHelpChanges, which is connected
// to DocSettingsPage::apply.
}
bool FilterSettingsPage::applyChanges()
{
bool changed = m_filterMap.count() != m_filterMapBackup.count();
if (!changed) {
......@@ -216,10 +210,11 @@ bool FilterSettingsPage::applyChanges()
FilterMap::const_iterator it;
for (it = m_filterMap.constBegin(); it != m_filterMap.constEnd(); ++it)
engine->addCustomFilter(it.key(), it.value());
return true;
}
return false;
// emit this signal to the help plugin, since we don't want
// to force gui help engine setup if we are not in help mode
emit filtersChanged();
}
}
bool FilterSettingsPage::matches(const QString &s) const
......
......@@ -54,7 +54,8 @@ public:
void finish() {}
virtual bool matches(const QString &s) const;
bool applyChanges();
signals:
void filtersChanged();
private slots:
void updateAttributes(QListWidgetItem *item);
......
......@@ -52,8 +52,7 @@
using namespace Help::Internal;
GeneralSettingsPage::GeneralSettingsPage(BookmarkManager *bookmarkManager)
: m_bookmarkManager(bookmarkManager)
GeneralSettingsPage::GeneralSettingsPage()
{
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
......@@ -134,11 +133,6 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
}
void GeneralSettingsPage::apply()
{
emit dialogAccepted();
}
bool GeneralSettingsPage::applyChanges()
{
QFont newFont;
const QString &family = m_ui.familyComboBox->currentFont().family();
......@@ -168,7 +162,6 @@ bool GeneralSettingsPage::applyChanges()
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
engine->setCustomValue(QLatin1String("font"), newFont);
bool needsUpdate = newFont != m_font;
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
......@@ -182,17 +175,14 @@ bool GeneralSettingsPage::applyChanges()
if (homePage.isEmpty())
homePage = QLatin1String("about:blank");
engine->setCustomValue(QLatin1String("HomePage"), homePage);
needsUpdate |= homePage != m_homePage;
const int startOption = m_ui.helpStartComboBox->currentIndex();
engine->setCustomValue(QLatin1String("StartOption"), startOption);
needsUpdate |= startOption != m_startOption;
const int helpOption = m_ui.contextHelpComboBox->currentIndex();
engine->setCustomValue(QLatin1String("ContextHelpOption"), helpOption);
needsUpdate |= helpOption != m_helpOption;
return needsUpdate;
// no need to call setup on the gui engine since we use only core engine
}
void GeneralSettingsPage::setCurrentPage()
......@@ -226,8 +216,8 @@ void GeneralSettingsPage::importBookmarks()
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
XbelReader reader(m_bookmarkManager->treeBookmarkModel(),
m_bookmarkManager->listBookmarkModel());
const BookmarkManager &manager = HelpManager::bookmarkManager();
XbelReader reader(manager.treeBookmarkModel(), manager.listBookmarkModel());
if (reader.readFromFile(&file))
return;
}
......@@ -249,7 +239,7 @@ void GeneralSettingsPage::exportBookmarks()
QFile file(fileName);
if (file.open(QIODevice::WriteOnly)) {
XbelWriter writer(m_bookmarkManager->treeBookmarkModel());
XbelWriter writer(HelpManager::bookmarkManager().treeBookmarkModel());
writer.writeToFile(&file);
}
}
......
......@@ -33,8 +33,6 @@
#include "ui_generalsettingspage.h"
#include <coreplugin/dialogs/ioptionspage.h>
class BookmarkManager;
namespace Help {
namespace Internal {
......@@ -45,7 +43,7 @@ class GeneralSettingsPage : public Core::IOptionsPage
Q_OBJECT
public:
GeneralSettingsPage(BookmarkManager *bookmarkManager);
GeneralSettingsPage();
QString id() const;
virtual QString displayName() const;
......@@ -57,11 +55,8 @@ public:
void finish() {}
virtual bool matches(const QString &s) const;
bool applyChanges();
signals:
void fontChanged();
void dialogAccepted();
private slots:
void setCurrentPage();
......@@ -86,8 +81,6 @@ private:
QString m_searchKeywords;
Ui::GeneralSettingsPage m_ui;
BookmarkManager *m_bookmarkManager;
};
} // Internal
......
......@@ -188,3 +188,12 @@ QHelpEngineCore& HelpManager::helpEngineCore()
}
return *m_coreEngine;
}
BookmarkManager& HelpManager::bookmarkManager()
{
if (!m_bookmarkManager) {
m_bookmarkManager = new BookmarkManager;
m_bookmarkManager->setupBookmarkModels();
}
return *m_bookmarkManager;
}
This diff is collapsed.
......@@ -30,29 +30,22 @@
#define HELPPLUGIN_H
#include <extensionsystem/iplugin.h>
#include <QtCore/QFutureInterface>
#include <QtCore/QFutureWatcher>
#include <QtCore/QMap>
#include <QtCore/QStringList>
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QHelpEngine;
class QToolBar;
class QUrl;
QT_END_NAMESPACE
class IndexWindow;
class ContentWindow;
class BookmarkManager;
class BookmarkWidget;
class HelpViewer;
namespace Core {
class ICore;
class IMode;
class MiniSplitter;
class SideBar;
class SideBarItem;
} // Core
......@@ -80,16 +73,7 @@ public:
void extensionsInitialized();
void shutdown();
// Necessary to get the unfiltered list in the help index filter
void setIndexFilter(const QString &filter);
QString indexFilter() const;
QHelpEngine* helpEngine() const;
void setFilesToRegister(const QStringList &files);
public slots:
void slotRegisterDocumentation();
void handleHelpRequest(const QString &url);
private slots:
......@@ -98,55 +82,41 @@ private slots:
void activateIndex();
void activateContents();
void activateSearch();
void checkForHelpChanges();
void checkForGeneralChanges();
void updateFilterComboBox();
void filterDocumentation(const QString &customFilter);
void addBookmark();
void addNewBookmark(const QString &title, const QString &url);
void rightPaneBackward();
void rightPaneForward();
void switchToHelpMode();
void switchToHelpMode(const QUrl &source);
void switchToHelpMode(const QMap<QString, QUrl> &urls, const QString &keyword);
void slotHideRightPane();
void copyFromSideBar();
void updateSideBarSource();
void updateSideBarSource(const QUrl &newUrl);
void fontChanged();
void setupHelpEngineIfNeeded();
void rebuildViewerComboBox();
void removeViewerFromComboBox(int index);
void updateViewerComboBoxIndex(int index);
void indexingStarted();
void indexingFinished();
private:
void setupUi();
void resetFilter();
bool verifiyDocumentation();
bool registerDocumentation();
bool unregisterDocumentation(const QStringList &nameSpaces);
private:
QToolBar *createToolBar();
void createRightPaneContextViewer();
void activateHelpMode();
QToolBar *createToolBar();
void connectCentralWidget();
HelpViewer* viewerForContextMode();
void createRightPaneContextViewer();
private:
HelpMode *m_mode;
Core::ICore *m_core;
QHelpEngine *m_helpEngine;
ContentWindow *m_contentWidget;
IndexWindow *m_indexWidget;
BookmarkWidget *m_bookmarkWidget;
BookmarkManager *m_bookmarkManager;
SearchWidget *m_searchWidget;
QWidget *m_mainWidget;
CentralWidget *m_centralWidget;
HelpViewer *m_helpViewerForSideBar;
HelpMode *m_mode;
Core::SideBarItem *m_contentItem;
Core::SideBarItem *m_indexItem;
......@@ -155,20 +125,15 @@ private:
DocSettingsPage *m_docSettingsPage;
FilterSettingsPage *m_filterSettingsPage;
GeneralSettingsPage *generalSettingsPage;
GeneralSettingsPage *m_generalSettingsPage;
QComboBox *m_documentsCombo;
QComboBox *m_filterComboBox;
Core::SideBar *m_sideBar;
HelpManager *helpManager;
QStringList filesToRegister;
QFutureWatcher<void> m_watcher;
QFutureInterface<void> *m_progress;
bool isInitialised;
bool firstModeChange;
bool m_firstModeChange;
HelpManager *m_helpManager;
Core::MiniSplitter *m_splitter;
};
} // namespace Internal
......
......@@ -28,6 +28,10 @@
**************************************************************************/
#include "searchwidget.h"
#include "helpmanager.h"
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <QtCore/QMap>
#include <QtCore/QString>
......@@ -40,39 +44,18 @@
#include <QtGui/QApplication>
#include <QtGui/QTextBrowser>
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpSearchEngine>
#include <QtHelp/QHelpSearchQueryWidget>
#include <QtHelp/QHelpSearchResultWidget>
using namespace Help::Internal;
SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent)
: QWidget(parent)
, zoomCount(0)
, searchEngine(engine)
SearchWidget::SearchWidget()
: zoomCount(0)
, m_progress(0)
, searchEngine(0)
{
QVBoxLayout *vLayout = new QVBoxLayout(this);
vLayout->setMargin(4);
resultWidget = searchEngine->resultWidget();
QHelpSearchQueryWidget *queryWidget = searchEngine->queryWidget();
vLayout->addWidget(queryWidget);
vLayout->addWidget(resultWidget);
setFocusProxy(queryWidget);
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this,
SIGNAL(requestShowLink(QUrl)));
connect(searchEngine, SIGNAL(searchingStarted()), this,
SLOT(searchingStarted()));
connect(searchEngine, SIGNAL(searchingFinished(int)), this,
SLOT(searchingFinished(int)));
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
browser->viewport()->installEventFilter(this);
}
SearchWidget::~SearchWidget()
......@@ -109,6 +92,43 @@ void SearchWidget::resetZoom()
}
}
void SearchWidget::showEvent(QShowEvent *event)
{
if (!event->spontaneous() && !searchEngine) {
QVBoxLayout *vLayout = new QVBoxLayout(this);
vLayout->setMargin(4);
searchEngine = (&HelpManager::helpEngine())->searchEngine();
resultWidget = searchEngine->resultWidget();
QHelpSearchQueryWidget *queryWidget = searchEngine->queryWidget();
vLayout->addWidget(queryWidget);
vLayout->addWidget(resultWidget);
setFocusProxy(queryWidget);
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
connect(resultWidget, SIGNAL(requestShowLink(QUrl)), this,
SIGNAL(requestShowLink(QUrl)));
connect(searchEngine, SIGNAL(searchingStarted()), this,
SLOT(searchingStarted()));
connect(searchEngine, SIGNAL(searchingFinished(int)), this,
SLOT(searchingFinished(int)));
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
browser->viewport()->installEventFilter(this);
connect(searchEngine, SIGNAL(indexingStarted()), this,
SLOT(indexingStarted()));
connect(searchEngine, SIGNAL(indexingFinished()), this,
SLOT(indexingFinished()));
QMetaObject::invokeMethod(&HelpManager::helpEngine(), "setupFinished",
Qt::QueuedConnection);
}
}
void SearchWidget::search() const
{
QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query();
......@@ -126,6 +146,28 @@ void SearchWidget::searchingFinished(int hits)
qApp->restoreOverrideCursor();
}
void SearchWidget::indexingStarted()
{
Q_ASSERT(!m_progress);
m_progress = new QFutureInterface<void>();
Core::ICore::instance()->progressManager() ->addTask(m_progress->future(),
tr("Indexing"), QLatin1String("Help.Indexer"));
m_progress->setProgressRange(0, 2);
m_progress->setProgressValueAndText(1, tr("Indexing Documentation..."));
m_progress->reportStarted();
m_watcher.setFuture(m_progress->future());
connect(&m_watcher, SIGNAL(canceled()), searchEngine, SLOT(cancelIndexing()));
}
void SearchWidget::indexingFinished()
{
m_progress->reportFinished();
delete m_progress;
m_progress = NULL;
}
bool SearchWidget::eventFilter(QObject* o, QEvent *e)
{
QTextBrowser* browser = qFindChild<QTextBrowser*>(resultWidget);
......
......@@ -30,18 +30,15 @@
#ifndef SEARCHWIDGET_H
#define SEARCHWIDGET_H
#include <QtCore/QUrl>
#include <QtCore/QPoint>
#include <QtCore/QFutureInterface>
#include <QtCore/QFutureWatcher>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QMouseEvent;
class QHelpSearchEngine;
class QHelpSearchResultWidget;
QT_END_NAMESPACE
QT_FORWARD_DECLARE_CLASS(QHelpSearchEngine)
QT_FORWARD_DECLARE_CLASS(QHelpSearchResultWidget)
QT_FORWARD_DECLARE_CLASS(QMouseEvent)
QT_FORWARD_DECLARE_CLASS(QUrl)
namespace Help {
namespace Internal {
......@@ -51,7 +48,7 @@ class SearchWidget : public QWidget
Q_OBJECT
public:
SearchWidget(QHelpSearchEngine *engine, QWidget *parent = 0);
SearchWidget();
~SearchWidget();
void zoomIn();
......@@ -63,11 +60,18 @@ signals:
void requestShowLinkInNewTab(const QUrl &url);
void escapePressed();
protected:
void showEvent(QShowEvent *event);
private slots:
void search() const;
void searchingStarted();
void searchingFinished(int hits);
void indexingStarted();
void indexingFinished();
private:
bool eventFilter(QObject* o, QEvent *e);
void keyPressEvent(QKeyEvent *keyEvent);
......@@ -75,6 +79,10 @@ private:
private:
int zoomCount;
QFutureWatcher<void> m_watcher;
QFutureInterface<void> *m_progress;
QHelpSearchEngine *searchEngine;
QHelpSearchResultWidget *resultWidget;
};
......
......@@ -605,11 +605,11 @@ Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const
// #pragma mark -- BookmarkManager
BookmarkManager::BookmarkManager(QHelpEngineCore* _helpEngine) :
m_folderIcon(QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon)),
m_bookmarkIcon(QLatin1String(":/help/images/bookmark.png")),
treeModel(new BookmarkModel(0, 1, this)),
listModel(new BookmarkModel(0, 1, this))
BookmarkManager::BookmarkManager()
: m_folderIcon(QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon))
, m_bookmarkIcon(QLatin1String(":/help/images/bookmark.png"))
, treeModel(new BookmarkModel(0, 1, this))
, listModel(new BookmarkModel(0, 1, this))
{
connect(treeModel, SIGNAL(itemChanged(QStandardItem*)), this,
SLOT(itemChanged(QStandardItem*)));
......
......@@ -51,7 +51,6 @@ class QLineEdit;
class QTreeView;
class QToolButton;
class QStandardItem;
class QHelpEngineCore;
class QAbstractItemModel;
class QSortFilterProxyModel;
......@@ -158,7 +157,7 @@ class BookmarkManager : public QObject
Q_OBJECT
public:
BookmarkManager(QHelpEngineCore *helpEngine);
BookmarkManager();
~BookmarkManager();
BookmarkModel *treeBookmarkModel() const;
......
......@@ -39,7 +39,7 @@
#include <QtHelp/QHelpEngine>
#include <QtHelp/QHelpContentWidget>
ContentWindow::ContentWindow(QHelpEngine *helpEngine)
ContentWindow::ContentWindow()
: m_contentWidget(0)
, m_expandDepth(-2)
{
......