forked from qt-creator/qt-creator
Utils: Use free functions in OsSpecificAspects
Generates a bit less code in debug mode and is easier to read IMNSHO. Change-Id: Ib9c0b9a0c058327facff16600a7014207167b050 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -325,13 +325,13 @@ void Environment::prependOrSet(const QString&key, const QString &value, const QS
|
||||
void Environment::appendOrSetPath(const QString &value)
|
||||
{
|
||||
appendOrSet("PATH", QDir::toNativeSeparators(value),
|
||||
QString(OsSpecificAspects(m_osType).pathListSeparator()));
|
||||
QString(OsSpecificAspects::pathListSeparator(m_osType)));
|
||||
}
|
||||
|
||||
void Environment::prependOrSetPath(const QString &value)
|
||||
{
|
||||
prependOrSet("PATH", QDir::toNativeSeparators(value),
|
||||
QString(OsSpecificAspects(m_osType).pathListSeparator()));
|
||||
QString(OsSpecificAspects::pathListSeparator(m_osType)));
|
||||
}
|
||||
|
||||
void Environment::prependOrSetLibrarySearchPath(const QString &value)
|
||||
@@ -496,7 +496,7 @@ FileName Environment::searchInPath(const QString &executable,
|
||||
FileNameList Environment::path() const
|
||||
{
|
||||
const QStringList pathComponents = value("PATH")
|
||||
.split(OsSpecificAspects(m_osType).pathListSeparator(), QString::SkipEmptyParts);
|
||||
.split(OsSpecificAspects::pathListSeparator(m_osType), QString::SkipEmptyParts);
|
||||
return Utils::transform(pathComponents, &FileName::fromUserInput);
|
||||
}
|
||||
|
||||
|
@@ -75,7 +75,7 @@ public:
|
||||
|
||||
static QString withExecutableSuffix(const QString &executable)
|
||||
{
|
||||
return hostOsAspects().withExecutableSuffix(executable);
|
||||
return OsSpecificAspects::withExecutableSuffix(hostOs(), executable);
|
||||
}
|
||||
|
||||
static void setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity);
|
||||
@@ -85,24 +85,22 @@ public:
|
||||
{
|
||||
return m_useOverrideFileNameCaseSensitivity
|
||||
? m_overrideFileNameCaseSensitivity
|
||||
: hostOsAspects().fileNameCaseSensitivity();
|
||||
: OsSpecificAspects::fileNameCaseSensitivity(hostOs());
|
||||
}
|
||||
|
||||
static QChar pathListSeparator()
|
||||
{
|
||||
return hostOsAspects().pathListSeparator();
|
||||
return OsSpecificAspects::pathListSeparator(hostOs());
|
||||
}
|
||||
|
||||
static Qt::KeyboardModifier controlModifier()
|
||||
{
|
||||
return hostOsAspects().controlModifier();
|
||||
return OsSpecificAspects::controlModifier(hostOs());
|
||||
}
|
||||
|
||||
static bool canCreateOpenGLContext(QString *errorMessage);
|
||||
|
||||
private:
|
||||
static OsSpecificAspects hostOsAspects() { return OsSpecificAspects(hostOs()); }
|
||||
|
||||
static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity;
|
||||
static bool m_useOverrideFileNameCaseSensitivity;
|
||||
};
|
||||
|
@@ -38,44 +38,43 @@ namespace Utils {
|
||||
// Add more as needed.
|
||||
enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOther };
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT OsSpecificAspects
|
||||
namespace OsSpecificAspects {
|
||||
|
||||
QTCREATOR_UTILS_EXPORT inline QString withExecutableSuffix(OsType osType, const QString &executable)
|
||||
{
|
||||
public:
|
||||
OsSpecificAspects(OsType osType) : m_osType(osType) { }
|
||||
QString finalName = executable;
|
||||
if (osType == OsTypeWindows)
|
||||
finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
|
||||
return finalName;
|
||||
}
|
||||
|
||||
QString withExecutableSuffix(const QString &executable) const {
|
||||
QString finalName = executable;
|
||||
if (m_osType == OsTypeWindows)
|
||||
finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
|
||||
return finalName;
|
||||
}
|
||||
QTCREATOR_UTILS_EXPORT inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType)
|
||||
{
|
||||
return osType == OsTypeWindows || osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive;
|
||||
}
|
||||
|
||||
Qt::CaseSensitivity fileNameCaseSensitivity() const {
|
||||
return m_osType == OsTypeWindows || m_osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive;
|
||||
}
|
||||
QTCREATOR_UTILS_EXPORT inline QChar pathListSeparator(OsType osType)
|
||||
{
|
||||
return QLatin1Char(osType == OsTypeWindows ? ';' : ':');
|
||||
}
|
||||
|
||||
QChar pathListSeparator() const {
|
||||
return QLatin1Char(m_osType == OsTypeWindows ? ';' : ':');
|
||||
}
|
||||
QTCREATOR_UTILS_EXPORT inline Qt::KeyboardModifier controlModifier(OsType osType)
|
||||
{
|
||||
return osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier;
|
||||
}
|
||||
|
||||
Qt::KeyboardModifier controlModifier() const {
|
||||
return m_osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier;
|
||||
}
|
||||
|
||||
QString pathWithNativeSeparators(const QString &pathName) const {
|
||||
if (m_osType == OsTypeWindows) {
|
||||
const int pos = pathName.indexOf('/');
|
||||
if (pos >= 0) {
|
||||
QString n = pathName;
|
||||
std::replace(std::begin(n) + pos, std::end(n), '/', '\\');
|
||||
return n;
|
||||
}
|
||||
QTCREATOR_UTILS_EXPORT inline QString pathWithNativeSeparators(OsType osType, const QString &pathName)
|
||||
{
|
||||
if (osType == OsTypeWindows) {
|
||||
const int pos = pathName.indexOf('/');
|
||||
if (pos >= 0) {
|
||||
QString n = pathName;
|
||||
std::replace(std::begin(n) + pos, std::end(n), '/', '\\');
|
||||
return n;
|
||||
}
|
||||
return pathName;
|
||||
}
|
||||
return pathName;
|
||||
}
|
||||
|
||||
private:
|
||||
const OsType m_osType;
|
||||
};
|
||||
|
||||
} // namespace OsSpecificAspects
|
||||
} // namespace Utils
|
||||
|
@@ -978,7 +978,7 @@ void EditorManagerPrivate::saveSettings()
|
||||
qsettings->setValue(bigTextFileSizeLimitKey, d->m_bigFileSizeLimitInMB);
|
||||
|
||||
Qt::CaseSensitivity defaultSensitivity
|
||||
= OsSpecificAspects(HostOsInfo::hostOs()).fileNameCaseSensitivity();
|
||||
= OsSpecificAspects::fileNameCaseSensitivity(HostOsInfo::hostOs());
|
||||
Qt::CaseSensitivity sensitivity = HostOsInfo::fileNameCaseSensitivity();
|
||||
if (defaultSensitivity == sensitivity)
|
||||
qsettings->remove(fileSystemCaseSensitivityKey);
|
||||
@@ -997,7 +997,7 @@ void EditorManagerPrivate::readSettings()
|
||||
|
||||
if (qs->contains(fileSystemCaseSensitivityKey)) {
|
||||
Qt::CaseSensitivity defaultSensitivity
|
||||
= OsSpecificAspects(HostOsInfo::hostOs()).fileNameCaseSensitivity();
|
||||
= OsSpecificAspects::fileNameCaseSensitivity(HostOsInfo::hostOs());
|
||||
bool ok = false;
|
||||
Qt::CaseSensitivity sensitivity = defaultSensitivity;
|
||||
int sensitivitySetting = qs->value(fileSystemCaseSensitivityKey).toInt(&ok);
|
||||
|
@@ -121,7 +121,7 @@ QWidget *SystemSettings::widget()
|
||||
|
||||
if (HostOsInfo::isMacHost()) {
|
||||
Qt::CaseSensitivity defaultSensitivity
|
||||
= OsSpecificAspects(HostOsInfo::hostOs()).fileNameCaseSensitivity();
|
||||
= OsSpecificAspects::fileNameCaseSensitivity(HostOsInfo::hostOs());
|
||||
if (defaultSensitivity == Qt::CaseSensitive) {
|
||||
m_page->fileSystemCaseSensitivityChooser->addItem(tr("Case Sensitive (Default)"),
|
||||
Qt::CaseSensitive);
|
||||
@@ -173,7 +173,7 @@ void SystemSettings::apply()
|
||||
|
||||
if (HostOsInfo::isMacHost()) {
|
||||
Qt::CaseSensitivity defaultSensitivity
|
||||
= OsSpecificAspects(HostOsInfo::hostOs()).fileNameCaseSensitivity();
|
||||
= OsSpecificAspects::fileNameCaseSensitivity(HostOsInfo::hostOs());
|
||||
Qt::CaseSensitivity selectedSensitivity = Qt::CaseSensitivity(
|
||||
m_page->fileSystemCaseSensitivityChooser->currentData().toInt());
|
||||
if (defaultSensitivity == selectedSensitivity)
|
||||
|
@@ -462,7 +462,7 @@ ExecutableAspect::ExecutableAspect(RunConfiguration *rc)
|
||||
void ExecutableAspect::setExecutablePathStyle(OsType osType)
|
||||
{
|
||||
m_executable.setDisplayFilter([osType](const QString &pathName) {
|
||||
return OsSpecificAspects(osType).pathWithNativeSeparators(pathName);
|
||||
return OsSpecificAspects::pathWithNativeSeparators(osType, pathName);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user