Share code between "central" and other help viewers.

This removes a lot of duplication of actions and interaction.
It's also a preparation step into making the external help
window behave more like the full-fledged help mode.

Change-Id: I318d831f229b0a75bb8702a5f163c96cce6a668c
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-09-25 16:29:56 +02:00
parent 85ac965116
commit a56432b3b1
11 changed files with 391 additions and 649 deletions

View File

@@ -35,6 +35,7 @@
#include <app/app_version.h>
#include <coreplugin/helpmanager.h>
#include <utils/qtcassert.h>
#include <QMutexLocker>
@@ -50,6 +51,10 @@ QHelpEngine* LocalHelpManager::m_guiEngine = 0;
QMutex LocalHelpManager::m_bkmarkMutex;
BookmarkManager* LocalHelpManager::m_bookmarkManager = 0;
QStandardItemModel *LocalHelpManager::m_filterModel = 0;
QString LocalHelpManager::m_currentFilter = QString();
int LocalHelpManager::m_currentFilterIndex = -1;
LocalHelpManager::LocalHelpManager(QObject *parent)
: QObject(parent)
, m_guiNeedsSetup(true)
@@ -57,6 +62,7 @@ LocalHelpManager::LocalHelpManager(QObject *parent)
{
m_instance = this;
qRegisterMetaType<Help::Internal::LocalHelpManager::HelpData>("Help::Internal::LocalHelpManager::HelpData");
m_filterModel = new QStandardItemModel(this);
}
LocalHelpManager::~LocalHelpManager()
@@ -227,3 +233,47 @@ LocalHelpManager::HelpData LocalHelpManager::helpData(const QUrl &url)
}
return data;
}
QAbstractItemModel *LocalHelpManager::filterModel()
{
return m_filterModel;
}
void LocalHelpManager::setFilterIndex(int index)
{
if (index == m_currentFilterIndex)
return;
m_currentFilterIndex = index;
QStandardItem *item = m_filterModel->item(index);
if (!item) {
helpEngine().setCurrentFilter(QString());
return;
}
helpEngine().setCurrentFilter(item->text());
emit m_instance->filterIndexChanged(m_currentFilterIndex);
}
void LocalHelpManager::updateFilterModel()
{
const QHelpEngine &engine = helpEngine();
if (m_currentFilter.isEmpty())
m_currentFilter = engine.currentFilter();
m_filterModel->clear();
m_currentFilterIndex = -1;
int count = 0;
const QStringList &filters = engine.customFilters();
foreach (const QString &filterString, filters) {
m_filterModel->appendRow(new QStandardItem(filterString));
if (filterString == m_currentFilter)
m_currentFilterIndex = count;
count++;
}
if (filters.size() < 1)
return;
if (m_currentFilterIndex < 0) {
m_currentFilterIndex = 0;
m_currentFilter = filters.at(0);
}
emit m_instance->filterIndexChanged(m_currentFilterIndex);
}