forked from qt-creator/qt-creator
Locator: Cleanup and modernize Locator and filters
* Omit QLatin1{Char|String}
* Use member initialization
* Use range-based-for
(and fixed the cases with non-const Qt container)
* Sort includes to common style
Change-Id: Ibc33a732bb153862efd6d5febfac758229cb61d4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
André Hartmann
parent
ccc0bebcf4
commit
b2aa1b9845
@@ -27,13 +27,13 @@
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpicons.h"
|
||||
#include "topicchooser.h"
|
||||
|
||||
#include <topicchooser.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/asconst.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QIcon>
|
||||
@@ -48,12 +48,11 @@ using namespace Help;
|
||||
using namespace Help::Internal;
|
||||
|
||||
HelpIndexFilter::HelpIndexFilter()
|
||||
: m_needsUpdate(true)
|
||||
{
|
||||
setId("HelpIndexFilter");
|
||||
setDisplayName(tr("Help Index"));
|
||||
setIncludedByDefault(false);
|
||||
setShortcutString(QString(QLatin1Char('?')));
|
||||
setShortcutString("?");
|
||||
|
||||
m_icon = Utils::Icons::BOOKMARK.icon();
|
||||
connect(HelpManager::instance(), &HelpManager::setupFinished,
|
||||
@@ -87,7 +86,7 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi
|
||||
|| !entry.contains(m_searchTermCache)) {
|
||||
int limit = entry.size() < 2 ? 200 : INT_MAX;
|
||||
QSet<QString> results;
|
||||
foreach (const QString &filePath, m_helpDatabases) {
|
||||
for (const QString &filePath : Utils::asConst(m_helpDatabases)) {
|
||||
if (future.isCanceled())
|
||||
return QList<LocatorFilterEntry>();
|
||||
QSet<QString> result;
|
||||
@@ -112,7 +111,7 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi
|
||||
keywords.reserve(m_keywordCache.size());
|
||||
unsortedKeywords.reserve(m_keywordCache.size());
|
||||
QSet<QString> allresults;
|
||||
foreach (const QString &keyword, m_keywordCache) {
|
||||
for (const QString &keyword : Utils::asConst(m_keywordCache)) {
|
||||
if (future.isCanceled())
|
||||
return QList<LocatorFilterEntry>();
|
||||
if (keyword.startsWith(entry, cs)) {
|
||||
@@ -127,7 +126,7 @@ QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFi
|
||||
keywords << unsortedKeywords;
|
||||
m_keywordCache = allresults;
|
||||
m_searchTermCache = entry;
|
||||
foreach (const QString &keyword, keywords) {
|
||||
for (const QString &keyword : Utils::asConst(keywords)) {
|
||||
const int index = keyword.indexOf(entry, 0, cs);
|
||||
LocatorFilterEntry filterEntry(this, keyword, QVariant(), m_icon);
|
||||
filterEntry.highlightInfo = {index, entry.length()};
|
||||
|
||||
@@ -60,7 +60,7 @@ private:
|
||||
QStringList m_helpDatabases;
|
||||
QSet<QString> m_keywordCache;
|
||||
QString m_searchTermCache;
|
||||
bool m_needsUpdate;
|
||||
bool m_needsUpdate = true;
|
||||
QMutex m_mutex;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <QUrl>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
namespace Internal {
|
||||
|
||||
RemoteFilterOptions::RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
@@ -43,7 +43,9 @@ RemoteFilterOptions::RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *pare
|
||||
m_ui.includeByDefault->setToolTip(Core::ILocatorFilter::msgIncludeByDefaultToolTip());
|
||||
m_ui.shortcutEdit->setText(m_filter->shortcutString());
|
||||
m_ui.includeByDefault->setChecked(m_filter->isIncludedByDefault());
|
||||
foreach (const QString &url, m_filter->remoteUrls()) {
|
||||
|
||||
const QStringList remoteUrls = m_filter->remoteUrls();
|
||||
for (const QString &url : remoteUrls) {
|
||||
QListWidgetItem *item = new QListWidgetItem(url);
|
||||
m_ui.listWidget->addItem(item);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
@@ -132,7 +134,8 @@ RemoteHelpFilter::~RemoteHelpFilter()
|
||||
QList<Core::LocatorFilterEntry> RemoteHelpFilter::matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
|
||||
{
|
||||
QList<Core::LocatorFilterEntry> entries;
|
||||
foreach (const QString &url, remoteUrls()) {
|
||||
const QStringList urls = remoteUrls();
|
||||
for (const QString &url : urls) {
|
||||
if (future.isCanceled())
|
||||
break;
|
||||
const QString name = url.arg(entry);
|
||||
@@ -164,7 +167,7 @@ QByteArray RemoteHelpFilter::saveState() const
|
||||
{
|
||||
QByteArray value;
|
||||
QDataStream out(&value, QIODevice::WriteOnly);
|
||||
out << m_remoteUrls.join(QLatin1Char('^'));
|
||||
out << m_remoteUrls.join('^');
|
||||
out << shortcutString();
|
||||
out << isIncludedByDefault();
|
||||
return value;
|
||||
@@ -176,7 +179,7 @@ void RemoteHelpFilter::restoreState(const QByteArray &state)
|
||||
|
||||
QString value;
|
||||
in >> value;
|
||||
m_remoteUrls = value.split(QLatin1Char('^'), QString::SkipEmptyParts);
|
||||
m_remoteUrls = value.split('^', QString::SkipEmptyParts);
|
||||
|
||||
QString shortcut;
|
||||
in >> shortcut;
|
||||
@@ -209,5 +212,5 @@ QStringList RemoteHelpFilter::remoteUrls() const
|
||||
return m_remoteUrls;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <QMutex>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
namespace Internal {
|
||||
|
||||
class RemoteHelpFilter : public Core::ILocatorFilter
|
||||
{
|
||||
@@ -69,7 +69,7 @@ class RemoteFilterOptions : public QDialog
|
||||
friend class RemoteHelpFilter;
|
||||
|
||||
public:
|
||||
explicit RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent = 0);
|
||||
explicit RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void addNewItem();
|
||||
@@ -78,9 +78,9 @@ private:
|
||||
void moveItemDown();
|
||||
void updateActionButtons();
|
||||
|
||||
RemoteHelpFilter *m_filter;
|
||||
RemoteHelpFilter *m_filter = nullptr;
|
||||
Ui::RemoteFilterOptions m_ui;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
|
||||
Reference in New Issue
Block a user