CMake: Fix startup warning

Accessing MimeDatabase for text/x-cmake before plugins are initialized

There is not much use for using QMimeType internally anyway, since they
are effectively only used as strings.

Amends ac2ca7244a

Change-Id: I4d7b1bb2f0ad4e857409e3ef287f5b9abe052193
Reviewed-by: Xavier BESSON <developer@xavi-b.fr>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Eike Ziller
2022-12-12 14:51:33 +01:00
parent bc7eed8c62
commit 92ab0c7f13
3 changed files with 14 additions and 24 deletions

View File

@@ -83,17 +83,17 @@ void CMakeFormatterSettings::setAutoFormatOnSave(bool autoFormatOnSave)
m_autoFormatOnSave = autoFormatOnSave;
}
QList<Utils::MimeType> CMakeFormatterSettings::autoFormatMime() const
QStringList CMakeFormatterSettings::autoFormatMime() const
{
return m_autoFormatMime;
}
QString CMakeFormatterSettings::autoFormatMimeAsString() const
{
return Utils::transform(m_autoFormatMime, &Utils::MimeType::name).join("; ");
return m_autoFormatMime.join("; ");
}
void CMakeFormatterSettings::setAutoFormatMime(const QList<Utils::MimeType> &autoFormatMime)
void CMakeFormatterSettings::setAutoFormatMime(const QStringList &autoFormatMime)
{
if (m_autoFormatMime == autoFormatMime)
return;
@@ -104,16 +104,7 @@ void CMakeFormatterSettings::setAutoFormatMime(const QList<Utils::MimeType> &aut
void CMakeFormatterSettings::setAutoFormatMime(const QString &mimeList)
{
const QStringList stringTypes = mimeList.split(';');
QList<Utils::MimeType> types;
types.reserve(stringTypes.count());
for (QString t : stringTypes) {
t = t.trimmed();
const Utils::MimeType mime = Utils::mimeTypeForName(t);
if (mime.isValid())
types << mime;
}
setAutoFormatMime(types);
setAutoFormatMime(mimeList.split(';'));
}
bool CMakeFormatterSettings::autoFormatOnlyCurrentProject() const
@@ -135,8 +126,8 @@ bool CMakeFormatterSettings::isApplicable(const Core::IDocument *document) const
return true;
const Utils::MimeType documentMimeType = Utils::mimeTypeForName(document->mimeType());
return Utils::anyOf(m_autoFormatMime, [&documentMimeType](const Utils::MimeType &mime) {
return documentMimeType.inherits(mime.name());
return Utils::anyOf(m_autoFormatMime, [&documentMimeType](const QString &mime) {
return documentMimeType.inherits(mime);
});
}

View File

@@ -4,12 +4,12 @@
#pragma once
#include <utils/mimeutils.h>
#include <QList>
#include <QObject>
#include <QVersionNumber>
namespace Core { class IDocument; }
namespace Utils { class FilePath; }
namespace CMakeProjectManager {
namespace Internal {
@@ -32,9 +32,9 @@ public:
bool autoFormatOnSave() const;
void setAutoFormatOnSave(bool autoFormatOnSave);
QList<Utils::MimeType> autoFormatMime() const;
QStringList autoFormatMime() const;
QString autoFormatMimeAsString() const;
void setAutoFormatMime(const QList<Utils::MimeType> &autoFormatMime);
void setAutoFormatMime(const QStringList &autoFormatMime);
void setAutoFormatMime(const QString &mimeList);
bool autoFormatOnlyCurrentProject() const;
@@ -51,7 +51,7 @@ private:
bool m_autoFormatOnSave = false;
bool m_autoFormatOnlyCurrentProject = true;
QString m_autoFormatTool;
QList<Utils::MimeType> m_autoFormatMime;
QStringList m_autoFormatMime;
};
} // namespace Internal

View File

@@ -43,8 +43,7 @@ using namespace Utils;
namespace CMakeProjectManager::Internal {
bool isAutoFormatApplicable(const Core::IDocument *document,
const QList<Utils::MimeType> &allowedMimeTypes)
bool isAutoFormatApplicable(const Core::IDocument *document, const QStringList &allowedMimeTypes)
{
if (!document)
return false;
@@ -53,8 +52,8 @@ bool isAutoFormatApplicable(const Core::IDocument *document,
return true;
const Utils::MimeType documentMimeType = Utils::mimeTypeForName(document->mimeType());
return Utils::anyOf(allowedMimeTypes, [&documentMimeType](const Utils::MimeType &mime) {
return documentMimeType.inherits(mime.name());
return Utils::anyOf(allowedMimeTypes, [&documentMimeType](const QString &mime) {
return documentMimeType.inherits(mime);
});
}