forked from qt-creator/qt-creator
Some more refactoring, reuse existing code.
Reuse the core help engine in the settings pages. Do not setup the gui help engine at all since any getter will do so. Split update documentation into smaller pieces for better performance. Reviewed-by: ck
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "docsettingspage.h"
|
#include "docsettingspage.h"
|
||||||
#include "helpconstants.h"
|
#include "helpconstants.h"
|
||||||
|
#include "helpmanager.h"
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
@@ -36,13 +37,11 @@
|
|||||||
#include <QtGui/QKeyEvent>
|
#include <QtGui/QKeyEvent>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
#include <QtHelp/QHelpEngine>
|
#include <QtHelp/QHelpEngineCore>
|
||||||
|
|
||||||
using namespace Help::Internal;
|
using namespace Help::Internal;
|
||||||
|
|
||||||
DocSettingsPage::DocSettingsPage(QHelpEngine *helpEngine)
|
DocSettingsPage::DocSettingsPage()
|
||||||
: m_helpEngine(helpEngine),
|
|
||||||
m_registeredDocs(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,46 +67,55 @@ QString DocSettingsPage::displayCategory() const
|
|||||||
|
|
||||||
QWidget *DocSettingsPage::createPage(QWidget *parent)
|
QWidget *DocSettingsPage::createPage(QWidget *parent)
|
||||||
{
|
{
|
||||||
QWidget *w = new QWidget(parent);
|
QWidget *widget = new QWidget(parent);
|
||||||
m_ui.setupUi(w);
|
m_ui.setupUi(widget);
|
||||||
|
|
||||||
connect(m_ui.addButton, SIGNAL(clicked()),
|
connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(addDocumentation()));
|
||||||
this, SLOT(addDocumentation()));
|
connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeDocumentation()));
|
||||||
connect(m_ui.removeButton, SIGNAL(clicked()),
|
|
||||||
this, SLOT(removeDocumentation()));
|
|
||||||
|
|
||||||
m_ui.docsListWidget->installEventFilter(this);
|
m_ui.docsListWidget->installEventFilter(this);
|
||||||
m_ui.docsListWidget->addItems(m_helpEngine->registeredDocumentations());
|
|
||||||
m_registeredDocs = false;
|
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
|
||||||
m_removeDocs.clear();
|
const QStringList &nameSpaces = engine->registeredDocumentations();
|
||||||
|
foreach (const QString &nameSpace, nameSpaces)
|
||||||
|
addItem(nameSpace, engine->documentationFileName(nameSpace));
|
||||||
|
|
||||||
|
m_filesToRegister.clear();
|
||||||
|
m_filesToUnregister.clear();
|
||||||
|
|
||||||
if (m_searchKeywords.isEmpty())
|
if (m_searchKeywords.isEmpty())
|
||||||
m_searchKeywords = m_ui.groupBox->title();
|
m_searchKeywords = m_ui.groupBox->title();
|
||||||
return w;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocSettingsPage::addDocumentation()
|
void DocSettingsPage::addDocumentation()
|
||||||
{
|
{
|
||||||
QStringList files = QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(),
|
const QStringList &files =
|
||||||
tr("Add Documentation"),
|
QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(),
|
||||||
QString(), tr("Qt Help Files (*.qch)"));
|
tr("Add Documentation"), m_recentDialogPath, tr("Qt Help Files (*.qch)"));
|
||||||
|
|
||||||
if (files.isEmpty())
|
if (files.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
m_recentDialogPath = QFileInfo(files.first()).canonicalPath();
|
||||||
|
|
||||||
|
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
|
||||||
|
const QStringList &nameSpaces = engine.registeredDocumentations();
|
||||||
|
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
QString nsName = QHelpEngineCore::namespaceName(file);
|
const QString &nameSpace = engine.namespaceName(file);
|
||||||
if (nsName.isEmpty()) {
|
if (nameSpace.isEmpty())
|
||||||
QMessageBox::warning(m_ui.addButton->parentWidget(),
|
|
||||||
tr("Add Documentation"),
|
|
||||||
tr("The file %1 is not a valid Qt Help file!")
|
|
||||||
.arg(file));
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (m_filesToUnregister.value(nameSpace) != QDir::cleanPath(file)) {
|
||||||
|
if (!m_filesToRegister.contains(nameSpace) && !nameSpaces.contains(nameSpace)) {
|
||||||
|
addItem(nameSpace, file);
|
||||||
|
m_filesToRegister.insert(nameSpace, QDir::cleanPath(file));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addItem(nameSpace, file);
|
||||||
|
m_filesToUnregister.remove(nameSpace);
|
||||||
}
|
}
|
||||||
m_helpEngine->registerDocumentation(file);
|
|
||||||
m_ui.docsListWidget->addItem(nsName);
|
|
||||||
}
|
}
|
||||||
m_registeredDocs = true;
|
|
||||||
emit documentationAdded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocSettingsPage::removeDocumentation()
|
void DocSettingsPage::removeDocumentation()
|
||||||
@@ -118,6 +126,10 @@ void DocSettingsPage::removeDocumentation()
|
|||||||
void DocSettingsPage::apply()
|
void DocSettingsPage::apply()
|
||||||
{
|
{
|
||||||
emit dialogAccepted();
|
emit dialogAccepted();
|
||||||
|
emit documentationChanged();
|
||||||
|
|
||||||
|
m_filesToRegister.clear();
|
||||||
|
m_filesToUnregister.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocSettingsPage::matches(const QString &s) const
|
bool DocSettingsPage::matches(const QString &s) const
|
||||||
@@ -125,25 +137,14 @@ bool DocSettingsPage::matches(const QString &s) const
|
|||||||
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocSettingsPage::applyChanges()
|
QStringList DocSettingsPage::docsToRegister() const
|
||||||
{
|
{
|
||||||
QStringList::const_iterator it = m_removeDocs.constBegin();
|
return m_filesToRegister.values();
|
||||||
while (it != m_removeDocs.constEnd()) {
|
}
|
||||||
if (!m_helpEngine->unregisterDocumentation((*it))) {
|
|
||||||
QMessageBox::warning(m_ui.addButton->parentWidget(),
|
|
||||||
tr("Documentation"),
|
|
||||||
tr("Cannot unregister documentation file %1!")
|
|
||||||
.arg((*it)));
|
|
||||||
}
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success = m_registeredDocs || m_removeDocs.count();
|
QStringList DocSettingsPage::docsToUnregister() const
|
||||||
|
{
|
||||||
m_removeDocs.clear();
|
return m_filesToUnregister.keys();
|
||||||
m_registeredDocs = false;
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
|
bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
|
||||||
@@ -170,8 +171,18 @@ void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> items)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
|
||||||
foreach (QListWidgetItem* item, items) {
|
foreach (QListWidgetItem* item, items) {
|
||||||
m_removeDocs.append(item->text());
|
const QString &nameSpace = item->text();
|
||||||
|
const QString &docPath = engine->documentationFileName(nameSpace);
|
||||||
|
|
||||||
|
if (m_filesToRegister.value(nameSpace) != docPath) {
|
||||||
|
if (!m_filesToUnregister.contains(nameSpace))
|
||||||
|
m_filesToUnregister.insert(nameSpace, docPath);
|
||||||
|
} else {
|
||||||
|
m_filesToRegister.remove(nameSpace);
|
||||||
|
}
|
||||||
|
|
||||||
row = m_ui.docsListWidget->row(item);
|
row = m_ui.docsListWidget->row(item);
|
||||||
delete m_ui.docsListWidget->takeItem(row);
|
delete m_ui.docsListWidget->takeItem(row);
|
||||||
}
|
}
|
||||||
@@ -179,3 +190,10 @@ void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> items)
|
|||||||
m_ui.docsListWidget->setCurrentRow(qMax(row - 1, 0),
|
m_ui.docsListWidget->setCurrentRow(qMax(row - 1, 0),
|
||||||
QItemSelectionModel::ClearAndSelect);
|
QItemSelectionModel::ClearAndSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DocSettingsPage::addItem(const QString &nameSpace, const QString &fileName)
|
||||||
|
{
|
||||||
|
QListWidgetItem* item = new QListWidgetItem(nameSpace);
|
||||||
|
item->setToolTip(fileName);
|
||||||
|
m_ui.docsListWidget->addItem(item);
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,22 +31,18 @@
|
|||||||
#define DOCSETTINGSPAGE_H
|
#define DOCSETTINGSPAGE_H
|
||||||
|
|
||||||
#include "ui_docsettingspage.h"
|
#include "ui_docsettingspage.h"
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QtGui/QWidget>
|
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QHelpEngine)
|
|
||||||
|
|
||||||
namespace Help {
|
namespace Help {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class DocSettingsPage : public Core::IOptionsPage
|
class DocSettingsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
typedef QHash<QString, QString> FilesToNameSpaceHash;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DocSettingsPage(QHelpEngine *helpEngine);
|
DocSettingsPage();
|
||||||
|
|
||||||
QString id() const;
|
QString id() const;
|
||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
@@ -55,14 +51,15 @@ public:
|
|||||||
|
|
||||||
QWidget *createPage(QWidget *parent);
|
QWidget *createPage(QWidget *parent);
|
||||||
void apply();
|
void apply();
|
||||||
void finish() { }
|
void finish() {}
|
||||||
virtual bool matches(const QString &s) const;
|
virtual bool matches(const QString &s) const;
|
||||||
|
|
||||||
bool applyChanges();
|
QStringList docsToRegister() const;
|
||||||
|
QStringList docsToUnregister() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void documentationAdded();
|
|
||||||
void dialogAccepted();
|
void dialogAccepted();
|
||||||
|
void documentationChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addDocumentation();
|
void addDocumentation();
|
||||||
@@ -71,13 +68,16 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
bool eventFilter(QObject *object, QEvent *event);
|
bool eventFilter(QObject *object, QEvent *event);
|
||||||
void removeDocumentation(const QList<QListWidgetItem*> items);
|
void removeDocumentation(const QList<QListWidgetItem*> items);
|
||||||
|
void addItem(const QString &nameSpace, const QString &fileName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHelpEngine *m_helpEngine;
|
|
||||||
bool m_registeredDocs;
|
|
||||||
QStringList m_removeDocs;
|
|
||||||
Ui::DocSettingsPage m_ui;
|
Ui::DocSettingsPage m_ui;
|
||||||
|
|
||||||
QString m_searchKeywords;
|
QString m_searchKeywords;
|
||||||
|
QString m_recentDialogPath;
|
||||||
|
|
||||||
|
FilesToNameSpaceHash m_filesToRegister;
|
||||||
|
FilesToNameSpaceHash m_filesToUnregister;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Help
|
} // namespace Help
|
||||||
|
|||||||
@@ -28,19 +28,21 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "filtersettingspage.h"
|
#include "filtersettingspage.h"
|
||||||
#include "helpconstants.h"
|
|
||||||
#include "filternamedialog.h"
|
#include "filternamedialog.h"
|
||||||
|
#include "helpconstants.h"
|
||||||
|
#include "helpmanager.h"
|
||||||
|
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
|
|
||||||
#include <QtHelp/QHelpEngine>
|
#include <QtHelp/QHelpEngineCore>
|
||||||
|
|
||||||
using namespace Help::Internal;
|
using namespace Help::Internal;
|
||||||
|
|
||||||
FilterSettingsPage::FilterSettingsPage(QHelpEngine *helpEngine) :
|
FilterSettingsPage::FilterSettingsPage()
|
||||||
m_helpEngine(helpEngine)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,11 +68,14 @@ QString FilterSettingsPage::displayCategory() const
|
|||||||
|
|
||||||
QWidget *FilterSettingsPage::createPage(QWidget *parent)
|
QWidget *FilterSettingsPage::createPage(QWidget *parent)
|
||||||
{
|
{
|
||||||
m_currentPage = new QWidget(parent);
|
QWidget *widget = new QWidget(parent);
|
||||||
m_ui.setupUi(m_currentPage);
|
m_ui.setupUi(widget);
|
||||||
|
|
||||||
m_ui.attributeWidget->header()->hide();
|
m_ui.attributeWidget->header()->hide();
|
||||||
m_ui.attributeWidget->setRootIsDecorated(false);
|
m_ui.attributeWidget->setRootIsDecorated(false);
|
||||||
|
|
||||||
|
updateFilterPage(); // does call setupData on the engine
|
||||||
|
|
||||||
connect(m_ui.attributeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
|
connect(m_ui.attributeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
|
||||||
this, SLOT(updateFilterMap()));
|
this, SLOT(updateFilterMap()));
|
||||||
connect(m_ui.filterWidget,
|
connect(m_ui.filterWidget,
|
||||||
@@ -79,37 +84,33 @@ QWidget *FilterSettingsPage::createPage(QWidget *parent)
|
|||||||
connect(m_ui.filterAddButton, SIGNAL(clicked()), this, SLOT(addFilter()));
|
connect(m_ui.filterAddButton, SIGNAL(clicked()), this, SLOT(addFilter()));
|
||||||
connect(m_ui.filterRemoveButton, SIGNAL(clicked()), this,
|
connect(m_ui.filterRemoveButton, SIGNAL(clicked()), this,
|
||||||
SLOT(removeFilter()));
|
SLOT(removeFilter()));
|
||||||
updateFilterPage();
|
|
||||||
|
|
||||||
if (m_searchKeywords.isEmpty())
|
if (m_searchKeywords.isEmpty()) {
|
||||||
m_searchKeywords = m_ui.filterGroupBox->title() + QLatin1Char(' ') + m_ui.attributesGroupBox->title();
|
m_searchKeywords = m_ui.filterGroupBox->title() + QLatin1Char(' ')
|
||||||
|
+ m_ui.attributesGroupBox->title();
|
||||||
return m_currentPage;
|
}
|
||||||
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterSettingsPage::updateFilterPage()
|
void FilterSettingsPage::updateFilterPage()
|
||||||
{
|
{
|
||||||
if (!m_helpEngine)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_ui.filterWidget->clear();
|
m_ui.filterWidget->clear();
|
||||||
m_ui.attributeWidget->clear();
|
m_ui.attributeWidget->clear();
|
||||||
|
|
||||||
QHelpEngineCore help(m_helpEngine->collectionFile(), 0);
|
|
||||||
help.setupData();
|
|
||||||
m_filterMapBackup.clear();
|
m_filterMapBackup.clear();
|
||||||
const QStringList filters = help.customFilters();
|
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
|
||||||
|
const QStringList &filters = engine.customFilters();
|
||||||
foreach (const QString &filter, filters) {
|
foreach (const QString &filter, filters) {
|
||||||
const QStringList atts = help.filterAttributes(filter);
|
const QStringList &attributes = engine.filterAttributes(filter);
|
||||||
m_filterMapBackup.insert(filter, atts);
|
m_filterMapBackup.insert(filter, attributes);
|
||||||
if (!m_filterMap.contains(filter))
|
if (!m_filterMap.contains(filter))
|
||||||
m_filterMap.insert(filter, atts);
|
m_filterMap.insert(filter, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui.filterWidget->addItems(m_filterMap.keys());
|
m_ui.filterWidget->addItems(m_filterMap.keys());
|
||||||
|
|
||||||
foreach (const QString &a, help.filterAttributes())
|
const QStringList &attributes = engine.filterAttributes();
|
||||||
new QTreeWidgetItem(m_ui.attributeWidget, QStringList(a));
|
foreach (const QString &attribute, attributes)
|
||||||
|
new QTreeWidgetItem(m_ui.attributeWidget, QStringList(attribute));
|
||||||
|
|
||||||
if (m_filterMap.keys().count())
|
if (m_filterMap.keys().count())
|
||||||
m_ui.filterWidget->setCurrentRow(0);
|
m_ui.filterWidget->setCurrentRow(0);
|
||||||
@@ -120,9 +121,9 @@ void FilterSettingsPage::updateAttributes(QListWidgetItem *item)
|
|||||||
QStringList checkedList;
|
QStringList checkedList;
|
||||||
if (item)
|
if (item)
|
||||||
checkedList = m_filterMap.value(item->text());
|
checkedList = m_filterMap.value(item->text());
|
||||||
QTreeWidgetItem *itm;
|
|
||||||
for (int i=0; i<m_ui.attributeWidget->topLevelItemCount(); ++i) {
|
for (int i = 0; i < m_ui.attributeWidget->topLevelItemCount(); ++i) {
|
||||||
itm = m_ui.attributeWidget->topLevelItem(i);
|
QTreeWidgetItem *itm = m_ui.attributeWidget->topLevelItem(i);
|
||||||
if (checkedList.contains(itm->text(0)))
|
if (checkedList.contains(itm->text(0)))
|
||||||
itm->setCheckState(0, Qt::Checked);
|
itm->setCheckState(0, Qt::Checked);
|
||||||
else
|
else
|
||||||
@@ -134,14 +135,14 @@ void FilterSettingsPage::updateFilterMap()
|
|||||||
{
|
{
|
||||||
if (!m_ui.filterWidget->currentItem())
|
if (!m_ui.filterWidget->currentItem())
|
||||||
return;
|
return;
|
||||||
QString filter = m_ui.filterWidget->currentItem()->text();
|
|
||||||
|
const QString &filter = m_ui.filterWidget->currentItem()->text();
|
||||||
if (!m_filterMap.contains(filter))
|
if (!m_filterMap.contains(filter))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QStringList newAtts;
|
QStringList newAtts;
|
||||||
QTreeWidgetItem *itm = 0;
|
for (int i = 0; i < m_ui.attributeWidget->topLevelItemCount(); ++i) {
|
||||||
for (int i=0; i<m_ui.attributeWidget->topLevelItemCount(); ++i) {
|
QTreeWidgetItem *itm = m_ui.attributeWidget->topLevelItem(i);
|
||||||
itm = m_ui.attributeWidget->topLevelItem(i);
|
|
||||||
if (itm->checkState(0) == Qt::Checked)
|
if (itm->checkState(0) == Qt::Checked)
|
||||||
newAtts.append(itm->text(0));
|
newAtts.append(itm->text(0));
|
||||||
}
|
}
|
||||||
@@ -150,25 +151,25 @@ void FilterSettingsPage::updateFilterMap()
|
|||||||
|
|
||||||
void FilterSettingsPage::addFilter()
|
void FilterSettingsPage::addFilter()
|
||||||
{
|
{
|
||||||
FilterNameDialog dia(m_currentPage);
|
FilterNameDialog dia(m_ui.filterWidget);
|
||||||
if (dia.exec() == QDialog::Rejected)
|
if (dia.exec() == QDialog::Rejected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString filterName = dia.filterName();
|
const QString &filterName = dia.filterName();
|
||||||
if (!m_filterMap.contains(filterName)) {
|
if (!m_filterMap.contains(filterName)) {
|
||||||
m_filterMap.insert(filterName, QStringList());
|
m_filterMap.insert(filterName, QStringList());
|
||||||
m_ui.filterWidget->addItem(filterName);
|
m_ui.filterWidget->addItem(filterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QListWidgetItem*> lst = m_ui.filterWidget
|
const QList<QListWidgetItem*> &lst = m_ui.filterWidget->findItems(filterName,
|
||||||
->findItems(filterName, Qt::MatchCaseSensitive);
|
Qt::MatchCaseSensitive);
|
||||||
m_ui.filterWidget->setCurrentItem(lst.first());
|
m_ui.filterWidget->setCurrentItem(lst.first());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterSettingsPage::removeFilter()
|
void FilterSettingsPage::removeFilter()
|
||||||
{
|
{
|
||||||
QListWidgetItem *item = m_ui.filterWidget
|
QListWidgetItem *item =
|
||||||
->takeItem(m_ui.filterWidget->currentRow());
|
m_ui.filterWidget->takeItem(m_ui.filterWidget->currentRow());
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -187,43 +188,40 @@ void FilterSettingsPage::apply()
|
|||||||
|
|
||||||
bool FilterSettingsPage::applyChanges()
|
bool FilterSettingsPage::applyChanges()
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = m_filterMap.count() != m_filterMapBackup.count();
|
||||||
if (m_filterMap.count() != m_filterMapBackup.count()) {
|
if (!changed) {
|
||||||
changed = true;
|
FilterMap::const_iterator it = m_filterMapBackup.constBegin();
|
||||||
} else {
|
for (; it != m_filterMapBackup.constEnd() && !changed; ++it) {
|
||||||
QMapIterator<QString, QStringList> it(m_filterMapBackup);
|
if (m_filterMap.contains(it.key())) {
|
||||||
while (it.hasNext() && !changed) {
|
const QStringList &a = it.value();
|
||||||
it.next();
|
const QStringList &b = m_filterMap.value(it.key());
|
||||||
if (!m_filterMap.contains(it.key())) {
|
if (a.count() == b.count()) {
|
||||||
changed = true;
|
QStringList::const_iterator i = a.constBegin();
|
||||||
} else {
|
for (; i != a.constEnd() && !changed; ++i) {
|
||||||
QStringList a = it.value();
|
if (b.contains(*i))
|
||||||
QStringList b = m_filterMap.value(it.key());
|
continue;
|
||||||
if (a.count() != b.count()) {
|
changed = true;
|
||||||
changed = true;
|
|
||||||
} else {
|
|
||||||
QStringList::const_iterator i(a.constBegin());
|
|
||||||
while (i != a.constEnd()) {
|
|
||||||
if (!b.contains(*i)) {
|
|
||||||
changed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
|
||||||
foreach (const QString &filter, m_removedFilters)
|
foreach (const QString &filter, m_removedFilters)
|
||||||
m_helpEngine->removeCustomFilter(filter);
|
engine->removeCustomFilter(filter);
|
||||||
QMapIterator<QString, QStringList> it(m_filterMap);
|
|
||||||
while (it.hasNext()) {
|
FilterMap::const_iterator it;
|
||||||
it.next();
|
for (it = m_filterMap.constBegin(); it != m_filterMap.constEnd(); ++it)
|
||||||
m_helpEngine->addCustomFilter(it.key(), it.value());
|
engine->addCustomFilter(it.key(), it.value());
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,5 +229,3 @@ bool FilterSettingsPage::matches(const QString &s) const
|
|||||||
{
|
{
|
||||||
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,12 +30,8 @@
|
|||||||
#ifndef FILTERSETTINGSPAGE_H
|
#ifndef FILTERSETTINGSPAGE_H
|
||||||
#define FILTERSETTINGSPAGE_H
|
#define FILTERSETTINGSPAGE_H
|
||||||
|
|
||||||
#include <QtGui/QWidget>
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
|
||||||
|
|
||||||
#include "ui_filtersettingspage.h"
|
#include "ui_filtersettingspage.h"
|
||||||
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
QT_FORWARD_DECLARE_CLASS(QHelpEngine)
|
|
||||||
|
|
||||||
namespace Help {
|
namespace Help {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -43,9 +39,10 @@ namespace Internal {
|
|||||||
class FilterSettingsPage : public Core::IOptionsPage
|
class FilterSettingsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
typedef QMap<QString, QStringList> FilterMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FilterSettingsPage(QHelpEngine *helpEngine);
|
FilterSettingsPage();
|
||||||
|
|
||||||
QString id() const;
|
QString id() const;
|
||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
@@ -54,7 +51,7 @@ public:
|
|||||||
|
|
||||||
QWidget *createPage(QWidget *parent);
|
QWidget *createPage(QWidget *parent);
|
||||||
void apply();
|
void apply();
|
||||||
void finish() { }
|
void finish() {}
|
||||||
virtual bool matches(const QString &s) const;
|
virtual bool matches(const QString &s) const;
|
||||||
|
|
||||||
bool applyChanges();
|
bool applyChanges();
|
||||||
@@ -67,13 +64,13 @@ private slots:
|
|||||||
void removeFilter();
|
void removeFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHelpEngine *m_helpEngine;
|
|
||||||
Ui::FilterSettingsPage m_ui;
|
Ui::FilterSettingsPage m_ui;
|
||||||
QMap<QString, QStringList> m_filterMapBackup;
|
|
||||||
QMap<QString, QStringList> m_filterMap;
|
FilterMap m_filterMap;
|
||||||
QStringList m_removedFilters;
|
FilterMap m_filterMapBackup;
|
||||||
QWidget *m_currentPage;
|
|
||||||
QString m_searchKeywords;
|
QString m_searchKeywords;
|
||||||
|
QStringList m_removedFilters;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Help
|
} // namespace Help
|
||||||
|
|||||||
@@ -146,28 +146,20 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
//webSettings->setFontSize(QWebSettings::DefaultFontSize, applicationFont.pointSize());
|
//webSettings->setFontSize(QWebSettings::DefaultFontSize, applicationFont.pointSize());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FIXME shouldn't the help engine create the directory if it doesn't exist?
|
addAutoReleasedObject(helpManager = new HelpManager(this));
|
||||||
const QFileInfo &fi(m_core->settings()->fileName());
|
addAutoReleasedObject(m_docSettingsPage = new DocSettingsPage());
|
||||||
const QDir directory(fi.absolutePath() + QLatin1String("/qtcreator"));
|
addAutoReleasedObject(m_filterSettingsPage = new FilterSettingsPage());
|
||||||
if (!directory.exists())
|
|
||||||
directory.mkpath(directory.absolutePath());
|
|
||||||
m_helpEngine = new QHelpEngine(directory.absolutePath() +
|
|
||||||
QLatin1String("/helpcollection.qhc"), this);
|
|
||||||
m_helpEngine->setAutoSaveFilter(false);
|
|
||||||
|
|
||||||
helpManager = new HelpManager(this);
|
connect(m_docSettingsPage, SIGNAL(documentationChanged()),
|
||||||
addAutoReleasedObject(helpManager);
|
|
||||||
|
|
||||||
m_filterSettingsPage = new FilterSettingsPage(m_helpEngine);
|
|
||||||
addAutoReleasedObject(m_filterSettingsPage);
|
|
||||||
|
|
||||||
m_docSettingsPage = new DocSettingsPage(m_helpEngine);
|
|
||||||
addAutoReleasedObject(m_docSettingsPage);
|
|
||||||
|
|
||||||
connect(m_docSettingsPage, SIGNAL(documentationAdded()),
|
|
||||||
m_filterSettingsPage, SLOT(updateFilterPage()));
|
m_filterSettingsPage, SLOT(updateFilterPage()));
|
||||||
connect(m_docSettingsPage, SIGNAL(dialogAccepted()), this,
|
connect(m_docSettingsPage, SIGNAL(dialogAccepted()), this,
|
||||||
SLOT(checkForHelpChanges()));
|
SLOT(checkForHelpChanges()));
|
||||||
|
connect(helpManager, SIGNAL(registerDocumentation()), this,
|
||||||
|
SLOT(slotRegisterDocumentation()));
|
||||||
|
|
||||||
|
// force a block here to avoid the expensive indexing restart signal, etc...
|
||||||
|
m_helpEngine = new QHelpEngine("", this);
|
||||||
|
m_helpEngine->blockSignals(true);
|
||||||
|
|
||||||
m_contentWidget = new ContentWindow(m_helpEngine);
|
m_contentWidget = new ContentWindow(m_helpEngine);
|
||||||
m_contentWidget->setWindowTitle(tr("Contents"));
|
m_contentWidget->setWindowTitle(tr("Contents"));
|
||||||
@@ -414,10 +406,12 @@ void HelpPlugin::setFilesToRegister(const QStringList &files)
|
|||||||
filesToRegister += files;
|
filesToRegister += files;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpPlugin::pluginUpdateDocumentation()
|
void HelpPlugin::slotRegisterDocumentation()
|
||||||
{
|
{
|
||||||
if (isInitialised)
|
if (isInitialised) {
|
||||||
updateDocumentation();
|
if (registerDocumentation())
|
||||||
|
m_helpEngine->setupData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpPlugin::resetFilter()
|
void HelpPlugin::resetFilter()
|
||||||
@@ -441,24 +435,24 @@ void HelpPlugin::resetFilter()
|
|||||||
m_helpEngine->setCurrentFilter(filterName);
|
m_helpEngine->setCurrentFilter(filterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HelpPlugin::updateDocumentation()
|
bool HelpPlugin::verifiyDocumentation()
|
||||||
{
|
{
|
||||||
bool needsSetup = false;
|
QStringList nameSpacesToUnregister;
|
||||||
const QStringList ®isteredDocs = m_helpEngine->registeredDocumentations();
|
const QStringList ®isteredDocs = m_helpEngine->registeredDocumentations();
|
||||||
foreach (const QString &nameSpace, registeredDocs) {
|
foreach (const QString &nameSpace, registeredDocs) {
|
||||||
const QString &file = m_helpEngine->documentationFileName(nameSpace);
|
const QString &file = m_helpEngine->documentationFileName(nameSpace);
|
||||||
if (QFileInfo(file).exists())
|
if (!QFileInfo(file).exists())
|
||||||
continue;
|
nameSpacesToUnregister.append(nameSpace);
|
||||||
|
|
||||||
if (!m_helpEngine->unregisterDocumentation(nameSpace)) {
|
|
||||||
qWarning() << "Error unregistering namespace '"
|
|
||||||
<< nameSpace << "' from file '" << file << "': "
|
|
||||||
<< m_helpEngine->error();
|
|
||||||
} else {
|
|
||||||
needsSetup = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nameSpacesToUnregister.isEmpty())
|
||||||
|
return unregisterDocumentation(nameSpacesToUnregister);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HelpPlugin::registerDocumentation()
|
||||||
|
{
|
||||||
|
bool needsSetup = false;
|
||||||
foreach (const QString &file, filesToRegister) {
|
foreach (const QString &file, filesToRegister) {
|
||||||
const QString &nameSpace = m_helpEngine->namespaceName(file);
|
const QString &nameSpace = m_helpEngine->namespaceName(file);
|
||||||
if (nameSpace.isEmpty())
|
if (nameSpace.isEmpty())
|
||||||
@@ -467,14 +461,27 @@ bool HelpPlugin::updateDocumentation()
|
|||||||
if (m_helpEngine->registerDocumentation(file)) {
|
if (m_helpEngine->registerDocumentation(file)) {
|
||||||
needsSetup = true;
|
needsSetup = true;
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "error registering" << file << m_helpEngine->error();
|
qWarning() << "Error registering namespace '" << nameSpace
|
||||||
|
<< "' from file '" << file << "':" << m_helpEngine->error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filesToRegister.clear();
|
filesToRegister.clear();
|
||||||
|
return needsSetup;
|
||||||
|
}
|
||||||
|
|
||||||
if (needsSetup)
|
bool HelpPlugin::unregisterDocumentation(const QStringList &nameSpaces)
|
||||||
m_helpEngine->setupData();
|
{
|
||||||
|
bool needsSetup = false;
|
||||||
|
foreach (const QString &nameSpace, nameSpaces) {
|
||||||
|
const QString &file = m_helpEngine->documentationFileName(nameSpace);
|
||||||
|
if (m_helpEngine->unregisterDocumentation(nameSpace)) {
|
||||||
|
needsSetup = true;
|
||||||
|
} else {
|
||||||
|
qWarning() << "Error unregistering namespace '" << nameSpace
|
||||||
|
<< "' from file '" << file << "': " << m_helpEngine->error();
|
||||||
|
}
|
||||||
|
}
|
||||||
return needsSetup;
|
return needsSetup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,13 +614,8 @@ void HelpPlugin::extensionsInitialized()
|
|||||||
{
|
{
|
||||||
m_sideBar->readSettings(m_core->settings(), QLatin1String("HelpSideBar"));
|
m_sideBar->readSettings(m_core->settings(), QLatin1String("HelpSideBar"));
|
||||||
|
|
||||||
// force a block here to avoid the expensive indexing restart signal, etc...
|
m_helpEngine->setCollectionFile(HelpManager::collectionFilePath());
|
||||||
bool blocked = m_helpEngine->blockSignals(true);
|
m_helpEngine->setAutoSaveFilter(false);
|
||||||
if (!m_helpEngine->setupData()) {
|
|
||||||
m_helpEngine->blockSignals(blocked);
|
|
||||||
qWarning() << "Could not initialize help engine: " << m_helpEngine->error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &docInternal = QString::fromLatin1("com.nokia.qtcreator.%1%2%3")
|
const QString &docInternal = QString::fromLatin1("com.nokia.qtcreator.%1%2%3")
|
||||||
.arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR).arg(IDE_VERSION_RELEASE);
|
.arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR).arg(IDE_VERSION_RELEASE);
|
||||||
@@ -638,21 +640,6 @@ void HelpPlugin::extensionsInitialized()
|
|||||||
m_helpEngine->removeCustomFilter(filter);
|
m_helpEngine->removeCustomFilter(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_helpEngine->blockSignals(blocked);
|
|
||||||
|
|
||||||
connect(m_helpEngine, SIGNAL(setupFinished()), this,
|
|
||||||
SLOT(updateFilterComboBox()));
|
|
||||||
|
|
||||||
// explicit disconnect the full text search indexer, we connect and start
|
|
||||||
// it later once we really need it, e.g. the full text search is opened...
|
|
||||||
disconnect(m_helpEngine, SIGNAL(setupFinished()), m_helpEngine->searchEngine(),
|
|
||||||
SLOT(indexDocumentation()));
|
|
||||||
connect(m_helpEngine->searchEngine(), SIGNAL(indexingStarted()), this,
|
|
||||||
SLOT(indexingStarted()));
|
|
||||||
connect(m_helpEngine->searchEngine(), SIGNAL(indexingFinished()), this,
|
|
||||||
SLOT(indexingFinished()));
|
|
||||||
|
|
||||||
// Explicitly register qml.qch if located in creator directory. This is only
|
// Explicitly register qml.qch if located in creator directory. This is only
|
||||||
// needed for the creator-qml package, were we want to ship the documentation
|
// needed for the creator-qml package, were we want to ship the documentation
|
||||||
// without a qt development version.
|
// without a qt development version.
|
||||||
@@ -674,11 +661,9 @@ void HelpPlugin::extensionsInitialized()
|
|||||||
filesToRegister += addedDocs.split(QLatin1Char(';'));
|
filesToRegister += addedDocs.split(QLatin1Char(';'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!updateDocumentation()) {
|
verifiyDocumentation();
|
||||||
// if no documentation has been added, we need to force a setup data,
|
registerDocumentation();
|
||||||
// otherwise it has already been run in updateDocumentation
|
m_bookmarkManager->setupBookmarkModels();
|
||||||
m_helpEngine->setupData();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(QT_NO_WEBKIT)
|
#if !defined(QT_NO_WEBKIT)
|
||||||
QWebSettings* webSettings = QWebSettings::globalSettings();
|
QWebSettings* webSettings = QWebSettings::globalSettings();
|
||||||
@@ -704,10 +689,20 @@ void HelpPlugin::extensionsInitialized()
|
|||||||
connect(m_centralWidget, SIGNAL(viewerAboutToBeRemoved(int)), this,
|
connect(m_centralWidget, SIGNAL(viewerAboutToBeRemoved(int)), this,
|
||||||
SLOT(removeViewerFromComboBox(int)));
|
SLOT(removeViewerFromComboBox(int)));
|
||||||
|
|
||||||
connect(helpManager, SIGNAL(registerDocumentation()), this,
|
// explicit disconnect the full text search indexer, we connect and start
|
||||||
SLOT(pluginUpdateDocumentation()));
|
// it later once we really need it, e.g. the full text search is opened...
|
||||||
|
disconnect(m_helpEngine, SIGNAL(setupFinished()), m_helpEngine->searchEngine(),
|
||||||
|
SLOT(indexDocumentation()));
|
||||||
|
|
||||||
isInitialised = true;
|
connect(m_helpEngine, SIGNAL(setupFinished()), this,
|
||||||
|
SLOT(updateFilterComboBox()));
|
||||||
|
connect(m_helpEngine->searchEngine(), SIGNAL(indexingStarted()), this,
|
||||||
|
SLOT(indexingStarted()));
|
||||||
|
connect(m_helpEngine->searchEngine(), SIGNAL(indexingFinished()), this,
|
||||||
|
SLOT(indexingFinished()));
|
||||||
|
|
||||||
|
isInitialised = true; // helper for slotRegisterDocumentation()
|
||||||
|
m_helpEngine->blockSignals(false); // blocked in initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpPlugin::shutdown()
|
void HelpPlugin::shutdown()
|
||||||
@@ -736,10 +731,13 @@ void HelpPlugin::modeChanged(Core::IMode *mode)
|
|||||||
qApp->setOverrideCursor(Qt::WaitCursor);
|
qApp->setOverrideCursor(Qt::WaitCursor);
|
||||||
|
|
||||||
resetFilter();
|
resetFilter();
|
||||||
m_centralWidget->setLastShownPages();
|
m_helpEngine->setupData();
|
||||||
connect(m_helpEngine, SIGNAL(setupFinished()), m_helpEngine->searchEngine(),
|
connect(m_helpEngine, SIGNAL(setupFinished()), m_helpEngine->searchEngine(),
|
||||||
SLOT(indexDocumentation()));
|
SLOT(indexDocumentation()));
|
||||||
QMetaObject::invokeMethod(m_helpEngine, "setupFinished", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(m_helpEngine, "setupFinished", Qt::QueuedConnection);
|
||||||
|
|
||||||
|
m_centralWidget->setLastShownPages();
|
||||||
|
|
||||||
qApp->restoreOverrideCursor();
|
qApp->restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -979,8 +977,9 @@ void HelpPlugin::updateFilterComboBox()
|
|||||||
|
|
||||||
void HelpPlugin::checkForHelpChanges()
|
void HelpPlugin::checkForHelpChanges()
|
||||||
{
|
{
|
||||||
bool changed = m_docSettingsPage->applyChanges();
|
bool changed = unregisterDocumentation(m_docSettingsPage->docsToUnregister());
|
||||||
changed |= m_filterSettingsPage->applyChanges();
|
filesToRegister += m_docSettingsPage->docsToRegister();
|
||||||
|
changed |= registerDocumentation();
|
||||||
if (changed)
|
if (changed)
|
||||||
m_helpEngine->setupData();
|
m_helpEngine->setupData();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public:
|
|||||||
void setFilesToRegister(const QStringList &files);
|
void setFilesToRegister(const QStringList &files);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void pluginUpdateDocumentation();
|
void slotRegisterDocumentation();
|
||||||
void handleHelpRequest(const QString &url);
|
void handleHelpRequest(const QString &url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -134,7 +134,9 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void resetFilter();
|
void resetFilter();
|
||||||
bool updateDocumentation();
|
bool verifiyDocumentation();
|
||||||
|
bool registerDocumentation();
|
||||||
|
bool unregisterDocumentation(const QStringList &nameSpaces);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QToolBar *createToolBar();
|
QToolBar *createToolBar();
|
||||||
|
|||||||
Reference in New Issue
Block a user