forked from qt-creator/qt-creator
LSP: rename LanguageClientSettings -> BaseSettings
And move the static init function to a separate class. Change-Id: I7c924ce72ad74047e6bfdb04fa04a6132050a360 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -771,7 +771,7 @@ void StdIOClient::setWorkingDirectory(const QString &workingDirectory)
|
|||||||
m_process.setWorkingDirectory(workingDirectory);
|
m_process.setWorkingDirectory(workingDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StdIOClient::matches(const LanguageClientSettings *setting)
|
bool StdIOClient::matches(const BaseSettings *setting)
|
||||||
{
|
{
|
||||||
return setting->m_executable == m_executable && setting->m_arguments == m_executable;
|
return setting->m_executable == m_executable && setting->m_arguments == m_executable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public:
|
|||||||
Core::Id id() const { return m_id; }
|
Core::Id id() const { return m_id; }
|
||||||
|
|
||||||
virtual bool start() { return true; }
|
virtual bool start() { return true; }
|
||||||
virtual bool matches(const LanguageClientSettings * /*setting*/) { return false; }
|
virtual bool matches(const BaseSettings * /*setting*/) { return false; }
|
||||||
virtual bool reset();
|
virtual bool reset();
|
||||||
|
|
||||||
void log(const QString &message,
|
void log(const QString &message,
|
||||||
@@ -179,7 +179,7 @@ public:
|
|||||||
|
|
||||||
void setWorkingDirectory(const QString &workingDirectory);
|
void setWorkingDirectory(const QString &workingDirectory);
|
||||||
|
|
||||||
bool matches(const LanguageClientSettings *setting) override;
|
bool matches(const BaseSettings *setting) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sendData(const QByteArray &data) final;
|
void sendData(const QByteArray &data) final;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<LanguageClientSettings *> m_settings;
|
QList<BaseSettings *> m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LanguageClientSettingsPageWidget : public QWidget
|
class LanguageClientSettingsPageWidget : public QWidget
|
||||||
@@ -238,7 +238,7 @@ QVariant LanguageClientSettingsModel::data(const QModelIndex &index, int role) c
|
|||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
LanguageClientSettings *setting = m_settings[index.row()];
|
BaseSettings *setting = m_settings[index.row()];
|
||||||
QTC_ASSERT(setting, return false);
|
QTC_ASSERT(setting, return false);
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
@@ -286,7 +286,7 @@ bool LanguageClientSettingsModel::insertRows(int row, int count, const QModelInd
|
|||||||
return false;
|
return false;
|
||||||
beginInsertRows(parent, row, row + count - 1);
|
beginInsertRows(parent, row, row + count - 1);
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
m_settings.insert(row + i, new LanguageClientSettings());
|
m_settings.insert(row + i, new BaseSettings());
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -295,7 +295,7 @@ bool LanguageClientSettingsModel::setData(const QModelIndex &index, const QVaria
|
|||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return false;
|
return false;
|
||||||
LanguageClientSettings *setting = m_settings[index.row()];
|
BaseSettings *setting = m_settings[index.row()];
|
||||||
QTC_ASSERT(setting, return false);
|
QTC_ASSERT(setting, return false);
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
@@ -329,7 +329,7 @@ void LanguageClientSettingsModel::toSettings(QSettings *settings) const
|
|||||||
{
|
{
|
||||||
settings->beginGroup(settingsGroupKey);
|
settings->beginGroup(settingsGroupKey);
|
||||||
settings->setValue(clientsKey, Utils::transform(m_settings,
|
settings->setValue(clientsKey, Utils::transform(m_settings,
|
||||||
[](const LanguageClientSettings *setting){
|
[](const BaseSettings *setting){
|
||||||
return QVariant(setting->toMap());
|
return QVariant(setting->toMap());
|
||||||
}));
|
}));
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
@@ -341,7 +341,7 @@ void LanguageClientSettingsModel::fromSettings(QSettings *settings)
|
|||||||
auto variants = settings->value(clientsKey).toList();
|
auto variants = settings->value(clientsKey).toList();
|
||||||
m_settings.reserve(variants.size());
|
m_settings.reserve(variants.size());
|
||||||
m_settings = Utils::transform(variants, [](const QVariant& var){
|
m_settings = Utils::transform(variants, [](const QVariant& var){
|
||||||
return new LanguageClientSettings(LanguageClientSettings::fromMap(var.toMap()));
|
return new BaseSettings(BaseSettings::fromMap(var.toMap()));
|
||||||
});
|
});
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
@@ -350,11 +350,11 @@ void LanguageClientSettingsModel::applyChanges()
|
|||||||
{
|
{
|
||||||
const QVector<BaseClient *> interfaces(LanguageClientManager::clients());
|
const QVector<BaseClient *> interfaces(LanguageClientManager::clients());
|
||||||
QVector<BaseClient *> toShutdown;
|
QVector<BaseClient *> toShutdown;
|
||||||
QList<LanguageClientSettings *> toStart = m_settings;
|
QList<BaseSettings *> toStart = m_settings;
|
||||||
// check currently registered interfaces
|
// check currently registered interfaces
|
||||||
for (auto interface : interfaces) {
|
for (auto interface : interfaces) {
|
||||||
auto setting = Utils::findOr(m_settings, nullptr,
|
auto setting = Utils::findOr(m_settings, nullptr,
|
||||||
[interface](const LanguageClientSettings *setting){
|
[interface](const BaseSettings *setting){
|
||||||
return interface->matches(setting);
|
return interface->matches(setting);
|
||||||
});
|
});
|
||||||
if (setting && setting->isValid() && setting->m_enabled) {
|
if (setting && setting->isValid() && setting->m_enabled) {
|
||||||
@@ -377,12 +377,12 @@ void LanguageClientSettingsModel::applyChanges()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanguageClientSettings::isValid()
|
bool BaseSettings::isValid()
|
||||||
{
|
{
|
||||||
return !m_name.isEmpty() && !m_executable.isEmpty() && QFile::exists(m_executable);
|
return !m_name.isEmpty() && !m_executable.isEmpty() && QFile::exists(m_executable);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseClient *LanguageClientSettings::createClient()
|
BaseClient *BaseSettings::createClient()
|
||||||
{
|
{
|
||||||
auto client = new StdIOClient(m_executable, m_arguments);
|
auto client = new StdIOClient(m_executable, m_arguments);
|
||||||
client->setName(m_name);
|
client->setName(m_name);
|
||||||
@@ -391,7 +391,7 @@ BaseClient *LanguageClientSettings::createClient()
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap LanguageClientSettings::toMap() const
|
QVariantMap BaseSettings::toMap() const
|
||||||
{
|
{
|
||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
map.insert(nameKey, m_name);
|
map.insert(nameKey, m_name);
|
||||||
@@ -402,7 +402,7 @@ QVariantMap LanguageClientSettings::toMap() const
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageClientSettings LanguageClientSettings::fromMap(const QVariantMap &map)
|
BaseSettings BaseSettings::fromMap(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
return { map[nameKey].toString(),
|
return { map[nameKey].toString(),
|
||||||
map[enabledKey].toBool(),
|
map[enabledKey].toBool(),
|
||||||
|
|||||||
@@ -40,9 +40,15 @@ class BaseClient;
|
|||||||
class LanguageClientSettings
|
class LanguageClientSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LanguageClientSettings() = default;
|
static void init();
|
||||||
LanguageClientSettings(const QString &name, bool enabled, const QString &mimeTypeName,
|
};
|
||||||
const QString &executable, const QString &arguments)
|
|
||||||
|
class BaseSettings
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BaseSettings() = default;
|
||||||
|
BaseSettings(const QString &name, bool enabled, const QString &mimeTypeName,
|
||||||
|
const QString &executable, const QString &arguments)
|
||||||
: m_name(name)
|
: m_name(name)
|
||||||
, m_enabled(enabled)
|
, m_enabled(enabled)
|
||||||
, m_mimeType(mimeTypeName)
|
, m_mimeType(mimeTypeName)
|
||||||
@@ -60,8 +66,7 @@ public:
|
|||||||
BaseClient *createClient();
|
BaseClient *createClient();
|
||||||
|
|
||||||
QVariantMap toMap() const;
|
QVariantMap toMap() const;
|
||||||
static LanguageClientSettings fromMap(const QVariantMap &map);
|
static BaseSettings fromMap(const QVariantMap &map);
|
||||||
static void init();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user