Aggregation/Utils/ExtensionSystem: Make member functions const/static

readability-make-member-function-const finds lots of member functions
that could be made const. This change just picks getter functions that
really should be const.

readability-convert-member-functions-to-static finds non-static member
functions which do not access this. This change turns most of them
into static ones, but leaves some non static to keep the class API
consistent.

readability-static-accessed-through-instance fixes the places where
the originally non-static, now static functions were called through
instance.

Change-Id: I8cf16c01f7988a7c9d073b5f8ede6a9706b94fb0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2020-11-21 01:04:56 +01:00
parent 5951b26f1a
commit 81f3452e1c
21 changed files with 83 additions and 86 deletions

View File

@@ -413,7 +413,7 @@ static QString filled(const QString &s, int min)
return s + QString(qMax(0, min - s.size()), ' ');
}
QString PluginManager::systemInformation() const
QString PluginManager::systemInformation()
{
QString result;
CommandLine qtDiag(HostOsInfo::withExecutableSuffix(
@@ -864,7 +864,7 @@ void PluginManagerPrivate::nextDelayedInitialize()
profilingSummary();
emit q->initializationDone();
#ifdef WITH_TESTS
if (q->testRunRequested())
if (PluginManager::testRunRequested())
startTests();
#endif
} else {

View File

@@ -126,10 +126,10 @@ public:
static bool isInitializationDone();
void remoteArguments(const QString &serializedArguments, QObject *socket);
void shutdown();
static void remoteArguments(const QString &serializedArguments, QObject *socket);
static void shutdown();
QString systemInformation() const;
static QString systemInformation();
signals:
void objectAdded(QObject *obj);

View File

@@ -115,8 +115,6 @@ public:
: m_spec(spec), m_view(view)
{}
int columnCount() const { return 4; }
QVariant data(int column, int role) const override
{
switch (column) {
@@ -226,8 +224,6 @@ public:
appendChild(new PluginItem(spec, view));
}
int columnCount() const { return 4; }
QVariant data(int column, int role) const override
{
if (column == NameColumn) {

View File

@@ -321,7 +321,7 @@ void ChangeSet::convertToReplace(const EditOp &op, QList<EditOp> *replaceList)
}
}
bool ChangeSet::hadErrors()
bool ChangeSet::hadErrors() const
{
return m_error;
}

View File

@@ -92,7 +92,7 @@ public:
bool copy(int start, int end, int to);
bool insert(int pos, const QString &text);
bool hadErrors();
bool hadErrors() const;
void apply(QString *s);
void apply(QTextCursor *textCursor);

View File

@@ -92,12 +92,12 @@ QStringList DropSupport::mimeTypesForFilePaths()
return QStringList("text/uri-list");
}
bool DropSupport::isFileDrop(QDropEvent *event) const
bool DropSupport::isFileDrop(QDropEvent *event)
{
return Utils::isFileDrop(event->mimeData());
}
bool DropSupport::isValueDrop(QDropEvent *event) const
bool DropSupport::isValueDrop(QDropEvent *event)
{
if (const auto internalData = qobject_cast<const DropMimeData *>(event->mimeData())) {
return !internalData->values().isEmpty();

View File

@@ -62,8 +62,8 @@ signals:
void valuesDropped(const QList<QVariant> &values, const QPoint &dropPos);
public:
bool isFileDrop(QDropEvent *event) const;
bool isValueDrop(QDropEvent *event) const;
static bool isFileDrop(QDropEvent *event);
static bool isValueDrop(QDropEvent *event);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;

View File

@@ -158,7 +158,7 @@ void Environment::setupEnglishOutput(QStringList *environment)
}
FilePath Environment::searchInDirectory(const QStringList &execs, const FilePath &directory,
QSet<FilePath> &alreadyChecked) const
QSet<FilePath> &alreadyChecked)
{
const int checkedCount = alreadyChecked.count();
alreadyChecked.insert(directory);

View File

@@ -85,8 +85,8 @@ public:
static void setSystemEnvironment(const Environment &environment); // don't use at all!!!
private:
FilePath searchInDirectory(const QStringList &execs, const FilePath &directory,
QSet<FilePath> &alreadyChecked) const;
static FilePath searchInDirectory(const QStringList &execs, const FilePath &directory,
QSet<FilePath> &alreadyChecked);
};
class QTCREATOR_UTILS_EXPORT EnvironmentProvider

View File

@@ -82,7 +82,7 @@ public:
return this == globalMacroExpander()->d ? false : globalMacroExpander()->d->resolveMacro(name, ret, seen);
}
QString value(const QByteArray &variable, bool *found)
QString value(const QByteArray &variable, bool *found) const
{
MacroExpander::StringFunction sf = m_map.value(variable);
if (sf) {

View File

@@ -104,14 +104,14 @@ protected:
static QString rightTrimmed(const QString &in);
Utils::FilePath absoluteFilePath(const Utils::FilePath &filePath);
static QString createLinkTarget(const FilePath &filePath, int line, int column);
void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
int lineNo, int pos, int len);
void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
int lineNo, const QRegularExpressionMatch &match,
int capIndex);
void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
int lineNo, const QRegularExpressionMatch &match,
const QString &capName);
static void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
int lineNo, int pos, int len);
static void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
int lineNo, const QRegularExpressionMatch &match,
int capIndex);
static void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
int lineNo, const QRegularExpressionMatch &match,
const QString &capName);
signals:
void newSearchDir(const Utils::FilePath &dir);

View File

@@ -176,7 +176,7 @@ SettingsAccessor::writeFile(const FilePath &path, const QVariantMap &data) const
SettingsAccessor::ProceedInfo
SettingsAccessor::reportIssues(const SettingsAccessor::Issue &issue, const FilePath &path,
QWidget *parent) const
QWidget *parent)
{
if (!path.exists())
return Continue;
@@ -697,7 +697,7 @@ MergingSettingsAccessor::mergeSettings(const SettingsAccessor::RestoreData &main
/*!
* Returns true for housekeeping related keys.
*/
bool MergingSettingsAccessor::isHouseKeepingKey(const QString &key) const
bool MergingSettingsAccessor::isHouseKeepingKey(const QString &key)
{
return key == VERSION_KEY || key == ORIGINAL_VERSION_KEY || key == SETTINGS_ID_KEY;
}

View File

@@ -131,7 +131,7 @@ public:
protected:
// Report errors:
QVariantMap restoreSettings(const FilePath &settingsPath, QWidget *parent) const;
ProceedInfo reportIssues(const Issue &issue, const FilePath &path, QWidget *parent) const;
static ProceedInfo reportIssues(const Issue &issue, const FilePath &path, QWidget *parent);
virtual QVariantMap preprocessReadSettings(const QVariantMap &data) const;
virtual QVariantMap prepareToWriteSettings(const QVariantMap &data) const;
@@ -294,7 +294,7 @@ protected:
virtual SettingsMergeResult merge(const SettingsMergeData &global,
const SettingsMergeData &local) const = 0;
bool isHouseKeepingKey(const QString &key) const;
static bool isHouseKeepingKey(const QString &key);
virtual QVariantMap postprocessMerge(const QVariantMap &main, const QVariantMap &secondary,
const QVariantMap &result) const;

View File

@@ -119,7 +119,7 @@ public:
void updatePositionAndShow(bool);
void updateFilter(const QString &filterText);
QWidget *currentWidget();
QWidget *currentWidget() const;
int buttonMargin() const;
void updateButtonGeometry();
@@ -563,7 +563,7 @@ void VariableChooserPrivate::updateFilter(const QString &filterText)
/*!
* \internal
*/
QWidget *VariableChooserPrivate::currentWidget()
QWidget *VariableChooserPrivate::currentWidget() const
{
if (m_lineEdit)
return m_lineEdit;

View File

@@ -566,7 +566,7 @@ class WizardProgressPrivate
public:
WizardProgressPrivate() = default;
bool isNextItem(WizardProgressItem *item, WizardProgressItem *nextItem) const;
static bool isNextItem(WizardProgressItem *item, WizardProgressItem *nextItem);
// if multiple paths are possible the empty list is returned
QList<WizardProgressItem *> singlePathBetween(WizardProgressItem *fromItem, WizardProgressItem *toItem) const;
void updateReachableItems();
@@ -597,7 +597,7 @@ public:
WizardProgressItem *m_nextShownItem;
};
bool WizardProgressPrivate::isNextItem(WizardProgressItem *item, WizardProgressItem *nextItem) const
bool WizardProgressPrivate::isNextItem(WizardProgressItem *item, WizardProgressItem *nextItem)
{
QHash<WizardProgressItem *, bool> visitedItems;
QList<WizardProgressItem *> workingItems = item->nextItems();
@@ -767,7 +767,7 @@ void WizardProgress::removePage(int pageId)
item->d_ptr->m_pages.removeOne(pageId);
}
QList<int> WizardProgress::pages(WizardProgressItem *item) const
QList<int> WizardProgress::pages(WizardProgressItem *item)
{
return item->pages();
}
@@ -931,7 +931,7 @@ void WizardProgressItem::setNextItems(const QList<WizardProgressItem *> &items)
// check if we create cycle
for (int i = 0; i < items.count(); i++) {
WizardProgressItem *nextItem = items.at(i);
if (nextItem == this || d->m_wizardProgress->d_ptr->isNextItem(nextItem, this)) {
if (nextItem == this || WizardProgressPrivate::isNextItem(nextItem, this)) {
qWarning("WizardProgress::setNextItems: Setting one of the next items would create a cycle");
return;
}

View File

@@ -102,7 +102,7 @@ public:
void removePage(int pageId);
QList<int> pages(WizardProgressItem *item) const;
static QList<int> pages(WizardProgressItem *item);
WizardProgressItem *item(int pageId) const;
WizardProgressItem *currentItem() const;

View File

@@ -142,7 +142,7 @@ EditorView::EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent) :
// item view
if (!qobject_cast<EditorToolBar*>(event->source()))
event->setDropAction(Qt::CopyAction);
if (event->type() == QDropEvent::DragEnter && !dropSupport->isFileDrop(event))
if (event->type() == QDropEvent::DragEnter && !DropSupport::isFileDrop(event))
return false; // do not accept drops without files
return event->source() != m_toolBar; // do not accept drops on ourselves
});

View File

@@ -790,7 +790,7 @@ void ICore::addPreCloseListener(const std::function<bool ()> &listener)
*/
QString ICore::systemInformation()
{
QString result = PluginManager::instance()->systemInformation() + '\n';
QString result = PluginManager::systemInformation() + '\n';
result += versionString() + '\n';
result += buildCompatibilityString() + '\n';
#ifdef IDE_REVISION

View File

@@ -49,8 +49,9 @@ EditorDiagramView::EditorDiagramView(QWidget *parent)
{
auto droputils = new Utils::DropSupport(
this,
[](QDropEvent *event, Utils::DropSupport *dropSupport)
-> bool { return dropSupport->isFileDrop(event) || dropSupport->isValueDrop(event); });
[](QDropEvent *event, Utils::DropSupport *)
-> bool { return Utils::DropSupport::isFileDrop(event)
|| Utils::DropSupport::isValueDrop(event); });
connect(droputils, &Utils::DropSupport::filesDropped,
this, &EditorDiagramView::dropFiles);
connect(droputils, &Utils::DropSupport::valuesDropped,

View File

@@ -77,8 +77,8 @@ static QString pluginFolder(const QLatin1String &folder)
void tst_PluginManager::init()
{
m_pm = new PluginManager;
m_pm->setSettings(new QSettings);
m_pm->setPluginIID(QLatin1String("plugin"));
PluginManager::setSettings(new QSettings);
PluginManager::setPluginIID(QLatin1String("plugin"));
m_objectAdded = new QSignalSpy(m_pm, SIGNAL(objectAdded(QObject*)));
m_aboutToRemoveObject = new QSignalSpy(m_pm, SIGNAL(aboutToRemoveObject(QObject*)));
m_pluginsChanged = new QSignalSpy(m_pm, SIGNAL(pluginsChanged()));
@@ -86,7 +86,7 @@ void tst_PluginManager::init()
void tst_PluginManager::cleanup()
{
m_pm->shutdown();
PluginManager::shutdown();
delete m_pm;
delete m_objectAdded;
delete m_aboutToRemoveObject;
@@ -97,35 +97,35 @@ void tst_PluginManager::addRemoveObjects()
{
QObject *object1 = new QObject;
QObject *object2 = new QObject;
QCOMPARE(m_pm->allObjects().size(), 0);
m_pm->addObject(object1);
QCOMPARE(PluginManager::allObjects().size(), 0);
PluginManager::addObject(object1);
QCOMPARE(m_objectAdded->count(), 1);
QCOMPARE(m_objectAdded->at(0).first().value<QObject *>(), object1);
QCOMPARE(m_aboutToRemoveObject->count(), 0);
QVERIFY(m_pm->allObjects().contains(object1));
QVERIFY(!m_pm->allObjects().contains(object2));
QCOMPARE(m_pm->allObjects().size(), 1);
m_pm->addObject(object2);
QVERIFY(PluginManager::allObjects().contains(object1));
QVERIFY(!PluginManager::allObjects().contains(object2));
QCOMPARE(PluginManager::allObjects().size(), 1);
PluginManager::addObject(object2);
QCOMPARE(m_objectAdded->count(), 2);
QCOMPARE(m_objectAdded->at(1).first().value<QObject *>(), object2);
QCOMPARE(m_aboutToRemoveObject->count(), 0);
QVERIFY(m_pm->allObjects().contains(object1));
QVERIFY(m_pm->allObjects().contains(object2));
QCOMPARE(m_pm->allObjects().size(), 2);
m_pm->removeObject(object1);
QVERIFY(PluginManager::allObjects().contains(object1));
QVERIFY(PluginManager::allObjects().contains(object2));
QCOMPARE(PluginManager::allObjects().size(), 2);
PluginManager::removeObject(object1);
QCOMPARE(m_objectAdded->count(), 2);
QCOMPARE(m_aboutToRemoveObject->count(), 1);
QCOMPARE(m_aboutToRemoveObject->at(0).first().value<QObject *>(), object1);
QVERIFY(!m_pm->allObjects().contains(object1));
QVERIFY(m_pm->allObjects().contains(object2));
QCOMPARE(m_pm->allObjects().size(), 1);
m_pm->removeObject(object2);
QVERIFY(!PluginManager::allObjects().contains(object1));
QVERIFY(PluginManager::allObjects().contains(object2));
QCOMPARE(PluginManager::allObjects().size(), 1);
PluginManager::removeObject(object2);
QCOMPARE(m_objectAdded->count(), 2);
QCOMPARE(m_aboutToRemoveObject->count(), 2);
QCOMPARE(m_aboutToRemoveObject->at(1).first().value<QObject *>(), object2);
QVERIFY(!m_pm->allObjects().contains(object1));
QVERIFY(!m_pm->allObjects().contains(object2));
QCOMPARE(m_pm->allObjects().size(), 0);
QVERIFY(!PluginManager::allObjects().contains(object1));
QVERIFY(!PluginManager::allObjects().contains(object2));
QCOMPARE(PluginManager::allObjects().size(), 0);
delete object1;
delete object2;
}
@@ -137,22 +137,22 @@ void tst_PluginManager::getObject()
MyClass2 *object2b = new MyClass2;
const QString objectName = QLatin1String("OBJECTNAME");
object2b->setObjectName(objectName);
m_pm->addObject(object2);
QCOMPARE(m_pm->getObject<MyClass11>(), static_cast<MyClass11 *>(0));
QCOMPARE(m_pm->getObject<MyClass1>(), static_cast<MyClass1 *>(0));
QCOMPARE(m_pm->getObject<MyClass2>(), object2);
m_pm->addObject(object11);
QCOMPARE(m_pm->getObject<MyClass11>(), object11);
QCOMPARE(m_pm->getObject<MyClass1>(), qobject_cast<MyClass1 *>(object11));
QCOMPARE(m_pm->getObject<MyClass2>(), object2);
QCOMPARE(m_pm->getObjectByName(objectName), static_cast<QObject *>(0));
m_pm->addObject(object2b);
QCOMPARE(m_pm->getObjectByName(objectName), object2b);
QCOMPARE(m_pm->getObject<MyClass2>(
[&objectName](MyClass2 *obj) { return obj->objectName() == objectName;}), object2b);
m_pm->removeObject(object2);
m_pm->removeObject(object11);
m_pm->removeObject(object2b);
PluginManager::addObject(object2);
QCOMPARE(PluginManager::getObject<MyClass11>(), static_cast<MyClass11 *>(0));
QCOMPARE(PluginManager::getObject<MyClass1>(), static_cast<MyClass1 *>(0));
QCOMPARE(PluginManager::getObject<MyClass2>(), object2);
PluginManager::addObject(object11);
QCOMPARE(PluginManager::getObject<MyClass11>(), object11);
QCOMPARE(PluginManager::getObject<MyClass1>(), qobject_cast<MyClass1 *>(object11));
QCOMPARE(PluginManager::getObject<MyClass2>(), object2);
QCOMPARE(PluginManager::getObjectByName(objectName), static_cast<QObject *>(0));
PluginManager::addObject(object2b);
QCOMPARE(PluginManager::getObjectByName(objectName), object2b);
QCOMPARE(PluginManager::getObject<MyClass2>(
[&objectName](MyClass2 *obj) { return obj->objectName() == objectName;}), object2b);
PluginManager::removeObject(object2);
PluginManager::removeObject(object11);
PluginManager::removeObject(object2b);
delete object2;
delete object11;
delete object2b;
@@ -160,9 +160,9 @@ void tst_PluginManager::getObject()
void tst_PluginManager::circularPlugins()
{
m_pm->setPluginPaths(QStringList() << pluginFolder(QLatin1String("circularplugins")));
m_pm->loadPlugins();
QVector<PluginSpec *> plugins = m_pm->plugins();
PluginManager::setPluginPaths(QStringList() << pluginFolder(QLatin1String("circularplugins")));
PluginManager::loadPlugins();
QVector<PluginSpec *> plugins = PluginManager::plugins();
QCOMPARE(plugins.count(), 3);
foreach (PluginSpec *spec, plugins) {
if (spec->name() == "plugin1") {
@@ -182,11 +182,11 @@ void tst_PluginManager::circularPlugins()
void tst_PluginManager::correctPlugins1()
{
m_pm->setPluginPaths(QStringList() << pluginFolder(QLatin1String("correctplugins1")));
m_pm->loadPlugins();
PluginManager::setPluginPaths(QStringList() << pluginFolder(QLatin1String("correctplugins1")));
PluginManager::loadPlugins();
bool specError = false;
bool runError = false;
foreach (PluginSpec *spec, m_pm->plugins()) {
foreach (PluginSpec *spec, PluginManager::plugins()) {
if (spec->hasError()) {
qDebug() << spec->filePath();
qDebug() << spec->errorString();
@@ -199,7 +199,7 @@ void tst_PluginManager::correctPlugins1()
bool plugin1running = false;
bool plugin2running = false;
bool plugin3running = false;
foreach (QObject *obj, m_pm->allObjects()) {
foreach (QObject *obj, PluginManager::allObjects()) {
if (obj->objectName() == "MyPlugin1_running")
plugin1running = true;
else if (obj->objectName() == "MyPlugin2_running")

View File

@@ -96,7 +96,7 @@ void tst_PluginSpec::init()
void tst_PluginSpec::initTestCase()
{
pm = new PluginManager;
pm->setPluginIID(QLatin1String("plugin"));
PluginManager::setPluginIID(QLatin1String("plugin"));
}
void tst_PluginSpec::cleanupTestCase()