forked from qt-creator/qt-creator
Utils: Rename NameValueItem to EnvironmentItem (1/2)
Only used in Environments nowadays. Change-Id: I64a645ebebd5cb57c50d5d8f72a5e4dba40e122f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -50,7 +50,7 @@ Environment::Environment(const NameValueDictionary &dict)
|
||||
m_changeItems.append(dict);
|
||||
}
|
||||
|
||||
NameValueItems Environment::diff(const Environment &other, bool checkAppendPrepend) const
|
||||
EnvironmentItems Environment::diff(const Environment &other, bool checkAppendPrepend) const
|
||||
{
|
||||
const NameValueDictionary &dict = resolved();
|
||||
const NameValueDictionary &otherDict = other.resolved();
|
||||
@@ -393,7 +393,7 @@ void Environment::unset(const QString &key)
|
||||
addItem(Item{std::in_place_index_t<UnsetValue>(), key});
|
||||
}
|
||||
|
||||
void Environment::modify(const NameValueItems &items)
|
||||
void Environment::modify(const EnvironmentItems &items)
|
||||
{
|
||||
addItem(Item{std::in_place_index_t<Modify>(), items});
|
||||
}
|
||||
@@ -485,7 +485,7 @@ const NameValueDictionary &Environment::resolved() const
|
||||
break;
|
||||
}
|
||||
case Modify: {
|
||||
NameValueItems items = std::get<Modify>(item);
|
||||
EnvironmentItems items = std::get<Modify>(item);
|
||||
m_dict.modify(items);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
void set(const QString &key, const QString &value, bool enabled = true);
|
||||
void setFallback(const QString &key, const QString &value);
|
||||
void unset(const QString &key);
|
||||
void modify(const NameValueItems &items);
|
||||
void modify(const EnvironmentItems &items);
|
||||
|
||||
bool hasChanges() const;
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
QStringList expandVariables(const QStringList &input) const;
|
||||
|
||||
NameValueDictionary toDictionary() const; // FIXME: avoid
|
||||
NameValueItems diff(const Environment &other, bool checkAppendPrepend = false) const; // FIXME: avoid
|
||||
EnvironmentItems diff(const Environment &other, bool checkAppendPrepend = false) const; // FIXME: avoid
|
||||
|
||||
struct Entry { QString key; QString value; bool enabled; };
|
||||
using FindResult = std::optional<Entry>;
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
QString, // UnsetValue (key)
|
||||
std::tuple<QString, QString, PathSeparator>, // PrependOrSet (key, value, separator)
|
||||
std::tuple<QString, QString, PathSeparator>, // AppendOrSet (key, value, separator)
|
||||
NameValueItems, // Modify
|
||||
EnvironmentItems, // Modify
|
||||
std::monostate, // SetupEnglishOutput
|
||||
FilePath // SetupSudoAskPass (file path of qtc-askpass or ssh-askpass)
|
||||
>;
|
||||
|
||||
@@ -7,16 +7,10 @@
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class NameValueDictionary;
|
||||
class NameValueItem;
|
||||
using NameValueItems = QList<NameValueItem>;
|
||||
|
||||
class Environment;
|
||||
using EnvironmentItem = NameValueItem;
|
||||
using EnvironmentItems = NameValueItems;
|
||||
class EnvironmentItem;
|
||||
using EnvironmentItems = QList<EnvironmentItem>;
|
||||
|
||||
class PreprocessorMacroDictionary;
|
||||
using PreprocessorMacroItem = NameValueItem;
|
||||
using PreprocessorMacroItems = NameValueItems;
|
||||
class NameValueDictionary;
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -30,8 +30,8 @@ public:
|
||||
m_resultNameValueDictionary.modify(m_items);
|
||||
// Add removed variables again and mark them as "<UNSET>" so
|
||||
// that the user can actually see those removals:
|
||||
for (const NameValueItem &item : std::as_const(m_items)) {
|
||||
if (item.operation == NameValueItem::Unset)
|
||||
for (const EnvironmentItem &item : std::as_const(m_items)) {
|
||||
if (item.operation == EnvironmentItem::Unset)
|
||||
m_resultNameValueDictionary.set(item.name, Tr::tr("<UNSET>"));
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
NameValueDictionary m_baseNameValueDictionary;
|
||||
NameValueDictionary m_resultNameValueDictionary;
|
||||
NameValueItems m_items;
|
||||
EnvironmentItems m_items;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -145,7 +145,7 @@ QVariant EnvironmentModel::data(const QModelIndex &index, int role) const
|
||||
// Do not return "<UNSET>" when editing a previously unset variable:
|
||||
if (role == Qt::EditRole) {
|
||||
int pos = d->findInChanges(indexToVariable(index));
|
||||
if (pos != -1 && d->m_items.at(pos).operation == NameValueItem::Unset)
|
||||
if (pos != -1 && d->m_items.at(pos).operation == EnvironmentItem::Unset)
|
||||
return QString();
|
||||
}
|
||||
QString value = d->m_resultNameValueDictionary.value(resultIterator);
|
||||
@@ -225,7 +225,7 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
if (d->m_resultNameValueDictionary.hasKey(newName) || newName.isEmpty())
|
||||
return false;
|
||||
|
||||
NameValueItem newVariable(newName, oldValue);
|
||||
EnvironmentItem newVariable(newName, oldValue);
|
||||
|
||||
if (changesPos != -1)
|
||||
resetVariable(oldName); // restore the original base variable again
|
||||
@@ -249,12 +249,12 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
} else {
|
||||
// ... and changed it again
|
||||
d->m_items[changesPos].value = stringValue;
|
||||
if (d->m_items[changesPos].operation == NameValueItem::Unset)
|
||||
d->m_items[changesPos].operation = NameValueItem::SetEnabled;
|
||||
if (d->m_items[changesPos].operation == EnvironmentItem::Unset)
|
||||
d->m_items[changesPos].operation = EnvironmentItem::SetEnabled;
|
||||
}
|
||||
} else {
|
||||
// Add a new change item:
|
||||
d->m_items.append(NameValueItem(oldName, stringValue));
|
||||
d->m_items.append(EnvironmentItem(oldName, stringValue));
|
||||
}
|
||||
d->updateResultNameValueDictionary();
|
||||
emit dataChanged(index, index);
|
||||
@@ -266,10 +266,10 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
|
||||
QModelIndex EnvironmentModel::addVariable()
|
||||
{
|
||||
return addVariable(NameValueItem("NEWVAR", "VALUE"));
|
||||
return addVariable(EnvironmentItem("NEWVAR", "VALUE"));
|
||||
}
|
||||
|
||||
QModelIndex EnvironmentModel::addVariable(const NameValueItem &item)
|
||||
QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
|
||||
{
|
||||
// Return existing index if the name is already in the result set:
|
||||
int pos = d->findInResult(item.name);
|
||||
@@ -283,7 +283,7 @@ QModelIndex EnvironmentModel::addVariable(const NameValueItem &item)
|
||||
Q_ASSERT(changePos >= 0);
|
||||
// Do not insert a line here as we listed the variable as <UNSET> before!
|
||||
Q_ASSERT(d->m_items.at(changePos).name == item.name);
|
||||
Q_ASSERT(d->m_items.at(changePos).operation == NameValueItem::Unset);
|
||||
Q_ASSERT(d->m_items.at(changePos).operation == EnvironmentItem::Unset);
|
||||
Q_ASSERT(d->m_items.at(changePos).value.isEmpty());
|
||||
d->m_items[changePos] = item;
|
||||
emit dataChanged(index(insertPos, 0, QModelIndex()), index(insertPos, 1, QModelIndex()));
|
||||
@@ -336,14 +336,14 @@ void EnvironmentModel::unsetVariable(const QString &name)
|
||||
// look in d->m_items for the variable
|
||||
int pos = d->findInChanges(name);
|
||||
if (pos != -1) {
|
||||
d->m_items[pos].operation = NameValueItem::Unset;
|
||||
d->m_items[pos].operation = EnvironmentItem::Unset;
|
||||
d->m_items[pos].value.clear();
|
||||
d->updateResultNameValueDictionary();
|
||||
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
|
||||
emit userChangesChanged();
|
||||
return;
|
||||
}
|
||||
d->m_items.append(NameValueItem(name, QString(), NameValueItem::Unset));
|
||||
d->m_items.append(EnvironmentItem(name, QString(), EnvironmentItem::Unset));
|
||||
d->updateResultNameValueDictionary();
|
||||
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
|
||||
emit userChangesChanged();
|
||||
@@ -355,7 +355,7 @@ void EnvironmentModel::toggleVariable(const QModelIndex &idx)
|
||||
const auto newIt = d->m_resultNameValueDictionary.constFind(name);
|
||||
QTC_ASSERT(newIt != d->m_resultNameValueDictionary.constEnd(), return);
|
||||
const auto op = d->m_resultNameValueDictionary.isEnabled(newIt)
|
||||
? NameValueItem::SetDisabled : NameValueItem::SetEnabled;
|
||||
? EnvironmentItem::SetDisabled : EnvironmentItem::SetEnabled;
|
||||
const int changesPos = d->findInChanges(name);
|
||||
if (changesPos != -1) {
|
||||
const auto oldIt = d->m_baseNameValueDictionary.constFind(name);
|
||||
@@ -376,7 +376,7 @@ void EnvironmentModel::toggleVariable(const QModelIndex &idx)
|
||||
bool EnvironmentModel::isUnset(const QString &name)
|
||||
{
|
||||
const int pos = d->findInChanges(name);
|
||||
return pos == -1 ? false : d->m_items.at(pos).operation == NameValueItem::Unset;
|
||||
return pos == -1 ? false : d->m_items.at(pos).operation == EnvironmentItem::Unset;
|
||||
}
|
||||
|
||||
bool EnvironmentModel::isEnabled(const QString &name) const
|
||||
@@ -389,14 +389,14 @@ bool EnvironmentModel::canReset(const QString &name)
|
||||
return d->m_baseNameValueDictionary.hasKey(name);
|
||||
}
|
||||
|
||||
NameValueItems EnvironmentModel::userChanges() const
|
||||
EnvironmentItems EnvironmentModel::userChanges() const
|
||||
{
|
||||
return d->m_items;
|
||||
}
|
||||
|
||||
void EnvironmentModel::setUserChanges(const NameValueItems &items)
|
||||
void EnvironmentModel::setUserChanges(const EnvironmentItems &items)
|
||||
{
|
||||
NameValueItems filtered = Utils::filtered(items, [](const NameValueItem &i) {
|
||||
EnvironmentItems filtered = Utils::filtered(items, [](const EnvironmentItem &i) {
|
||||
return i.name != "export " && !i.name.contains('=');
|
||||
});
|
||||
// We assume nobody is reordering the items here.
|
||||
@@ -404,7 +404,7 @@ void EnvironmentModel::setUserChanges(const NameValueItems &items)
|
||||
return;
|
||||
beginResetModel();
|
||||
d->m_items = filtered;
|
||||
for (NameValueItem &item : d->m_items) {
|
||||
for (EnvironmentItem &item : d->m_items) {
|
||||
QString &name = item.name;
|
||||
name = name.trimmed();
|
||||
if (name.startsWith("export "))
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
void setBaseEnvironment(const Environment &env);
|
||||
|
||||
QModelIndex addVariable();
|
||||
QModelIndex addVariable(const NameValueItem &item);
|
||||
QModelIndex addVariable(const EnvironmentItem &item);
|
||||
void resetVariable(const QString &name);
|
||||
void unsetVariable(const QString &name);
|
||||
void toggleVariable(const QModelIndex &index);
|
||||
@@ -46,8 +46,8 @@ public:
|
||||
QString indexToVariable(const QModelIndex &index) const;
|
||||
QModelIndex variableToIndex(const QString &name) const;
|
||||
bool changes(const QString &key) const;
|
||||
NameValueItems userChanges() const;
|
||||
void setUserChanges(const NameValueItems &items);
|
||||
EnvironmentItems userChanges() const;
|
||||
void setUserChanges(const EnvironmentItems &items);
|
||||
bool currentEntryIsPathList(const QModelIndex ¤t) const;
|
||||
|
||||
signals:
|
||||
|
||||
@@ -97,34 +97,34 @@ int NameValueDictionary::size() const
|
||||
return m_values.size();
|
||||
}
|
||||
|
||||
void NameValueDictionary::modify(const NameValueItems &items)
|
||||
void NameValueDictionary::modify(const EnvironmentItems &items)
|
||||
{
|
||||
NameValueDictionary resultKeyValueDictionary = *this;
|
||||
for (const NameValueItem &item : items)
|
||||
for (const EnvironmentItem &item : items)
|
||||
item.apply(&resultKeyValueDictionary);
|
||||
*this = resultKeyValueDictionary;
|
||||
}
|
||||
|
||||
NameValueItems NameValueDictionary::diff(const NameValueDictionary &other, bool checkAppendPrepend) const
|
||||
EnvironmentItems NameValueDictionary::diff(const NameValueDictionary &other, bool checkAppendPrepend) const
|
||||
{
|
||||
NameValueMap::const_iterator thisIt = constBegin();
|
||||
NameValueMap::const_iterator otherIt = other.constBegin();
|
||||
|
||||
NameValueItems result;
|
||||
EnvironmentItems result;
|
||||
while (thisIt != constEnd() || otherIt != other.constEnd()) {
|
||||
if (thisIt == constEnd()) {
|
||||
result.append({other.key(otherIt), other.value(otherIt),
|
||||
otherIt.value().second ? NameValueItem::SetEnabled : NameValueItem::SetDisabled});
|
||||
otherIt.value().second ? EnvironmentItem::SetEnabled : EnvironmentItem::SetDisabled});
|
||||
++otherIt;
|
||||
} else if (otherIt == other.constEnd()) {
|
||||
result.append(NameValueItem(key(thisIt), QString(), NameValueItem::Unset));
|
||||
result.append(EnvironmentItem(key(thisIt), QString(), EnvironmentItem::Unset));
|
||||
++thisIt;
|
||||
} else if (thisIt.key() < otherIt.key()) {
|
||||
result.append(NameValueItem(key(thisIt), QString(), NameValueItem::Unset));
|
||||
result.append(EnvironmentItem(key(thisIt), QString(), EnvironmentItem::Unset));
|
||||
++thisIt;
|
||||
} else if (thisIt.key() > otherIt.key()) {
|
||||
result.append({other.key(otherIt), otherIt.value().first,
|
||||
otherIt.value().second ? NameValueItem::SetEnabled : NameValueItem::SetDisabled});
|
||||
otherIt.value().second ? EnvironmentItem::SetEnabled : EnvironmentItem::SetDisabled});
|
||||
++otherIt;
|
||||
} else {
|
||||
const QString &oldValue = thisIt.value().first;
|
||||
@@ -137,16 +137,16 @@ NameValueItems NameValueDictionary::diff(const NameValueDictionary &other, bool
|
||||
QString appended = newValue.right(newValue.size() - oldValue.size());
|
||||
if (appended.startsWith(OsSpecificAspects::pathListSeparator(osType())))
|
||||
appended.remove(0, 1);
|
||||
result.append(NameValueItem(other.key(otherIt), appended, NameValueItem::Append));
|
||||
result.append(EnvironmentItem(other.key(otherIt), appended, EnvironmentItem::Append));
|
||||
} else if (checkAppendPrepend && newValue.endsWith(oldValue)
|
||||
&& oldEnabled == newEnabled) {
|
||||
QString prepended = newValue.left(newValue.size() - oldValue.size());
|
||||
if (prepended.endsWith(OsSpecificAspects::pathListSeparator(osType())))
|
||||
prepended.chop(1);
|
||||
result.append(NameValueItem(other.key(otherIt), prepended, NameValueItem::Prepend));
|
||||
result.append(EnvironmentItem(other.key(otherIt), prepended, EnvironmentItem::Prepend));
|
||||
} else {
|
||||
result.append({other.key(otherIt), newValue, newEnabled
|
||||
? NameValueItem::SetEnabled : NameValueItem::SetDisabled});
|
||||
? EnvironmentItem::SetEnabled : EnvironmentItem::SetDisabled});
|
||||
}
|
||||
}
|
||||
++otherIt;
|
||||
|
||||
@@ -48,9 +48,9 @@ public:
|
||||
QString value(const QString &key) const;
|
||||
void set(const QString &key, const QString &value, bool enabled = true);
|
||||
void unset(const QString &key);
|
||||
void modify(const NameValueItems &items);
|
||||
void modify(const EnvironmentItems &items);
|
||||
/// Return the KeyValueDictionary changes necessary to modify this into the other environment.
|
||||
NameValueItems diff(const NameValueDictionary &other, bool checkAppendPrepend = false) const;
|
||||
EnvironmentItems diff(const NameValueDictionary &other, bool checkAppendPrepend = false) const;
|
||||
bool hasKey(const QString &key) const;
|
||||
OsType osType() const;
|
||||
Qt::CaseSensitivity nameCaseSensitivity() const;
|
||||
|
||||
@@ -10,34 +10,34 @@
|
||||
|
||||
namespace Utils {
|
||||
|
||||
void NameValueItem::sort(NameValueItems *list)
|
||||
void EnvironmentItem::sort(EnvironmentItems *list)
|
||||
{
|
||||
Utils::sort(*list, &NameValueItem::name);
|
||||
Utils::sort(*list, &EnvironmentItem::name);
|
||||
}
|
||||
|
||||
NameValueItems NameValueItem::fromStringList(const QStringList &list)
|
||||
EnvironmentItems EnvironmentItem::fromStringList(const QStringList &list)
|
||||
{
|
||||
NameValueItems result;
|
||||
EnvironmentItems result;
|
||||
for (const QString &string : list) {
|
||||
int pos = string.indexOf("+=");
|
||||
if (pos != -1) {
|
||||
result.append({string.left(pos), string.mid(pos + 2), NameValueItem::Append});
|
||||
result.append({string.left(pos), string.mid(pos + 2), EnvironmentItem::Append});
|
||||
continue;
|
||||
}
|
||||
pos = string.indexOf("=+");
|
||||
if (pos != -1) {
|
||||
result.append({string.left(pos), string.mid(pos + 2), NameValueItem::Prepend});
|
||||
result.append({string.left(pos), string.mid(pos + 2), EnvironmentItem::Prepend});
|
||||
continue;
|
||||
}
|
||||
pos = string.indexOf('=', 1);
|
||||
if (pos == -1) {
|
||||
result.append(NameValueItem(string, QString(), NameValueItem::Unset));
|
||||
result.append(EnvironmentItem(string, QString(), EnvironmentItem::Unset));
|
||||
continue;
|
||||
}
|
||||
const int hashPos = string.indexOf('#');
|
||||
if (hashPos != -1 && hashPos < pos) {
|
||||
result.append({string.mid(hashPos + 1, pos - hashPos - 1), string.mid(pos + 1),
|
||||
NameValueItem::SetDisabled});
|
||||
EnvironmentItem::SetDisabled});
|
||||
} else {
|
||||
result.append({string.left(pos), string.mid(pos + 1)});
|
||||
}
|
||||
@@ -45,49 +45,49 @@ NameValueItems NameValueItem::fromStringList(const QStringList &list)
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList NameValueItem::toStringList(const NameValueItems &list)
|
||||
QStringList EnvironmentItem::toStringList(const EnvironmentItems &list)
|
||||
{
|
||||
return Utils::transform<QStringList>(list, [](const NameValueItem &item) {
|
||||
return Utils::transform<QStringList>(list, [](const EnvironmentItem &item) {
|
||||
switch (item.operation) {
|
||||
case NameValueItem::Unset:
|
||||
case EnvironmentItem::Unset:
|
||||
return item.name;
|
||||
case NameValueItem::Append:
|
||||
case EnvironmentItem::Append:
|
||||
return QString(item.name + "+=" + item.value);
|
||||
case NameValueItem::Prepend:
|
||||
case EnvironmentItem::Prepend:
|
||||
return QString(item.name + "=+" + item.value);
|
||||
case NameValueItem::SetDisabled:
|
||||
case EnvironmentItem::SetDisabled:
|
||||
return QString('#' + item.name + '=' + item.value);
|
||||
case NameValueItem::SetEnabled:
|
||||
case EnvironmentItem::SetEnabled:
|
||||
return QString(item.name + '=' + item.value);
|
||||
}
|
||||
return QString();
|
||||
});
|
||||
}
|
||||
|
||||
NameValueItems NameValueItem::itemsFromVariantList(const QVariantList &list)
|
||||
EnvironmentItems EnvironmentItem::itemsFromVariantList(const QVariantList &list)
|
||||
{
|
||||
return Utils::transform<NameValueItems>(list, [](const QVariant &item) {
|
||||
return Utils::transform<EnvironmentItems>(list, [](const QVariant &item) {
|
||||
return itemFromVariantList(item.toList());
|
||||
});
|
||||
}
|
||||
|
||||
QVariantList NameValueItem::toVariantList(const NameValueItems &list)
|
||||
QVariantList EnvironmentItem::toVariantList(const EnvironmentItems &list)
|
||||
{
|
||||
return Utils::transform<QVariantList>(list, [](const NameValueItem &item) {
|
||||
return Utils::transform<QVariantList>(list, [](const EnvironmentItem &item) {
|
||||
return QVariant(toVariantList(item));
|
||||
});
|
||||
}
|
||||
|
||||
NameValueItem NameValueItem::itemFromVariantList(const QVariantList &list)
|
||||
EnvironmentItem EnvironmentItem::itemFromVariantList(const QVariantList &list)
|
||||
{
|
||||
QTC_ASSERT(list.size() == 3, return NameValueItem("", ""));
|
||||
QTC_ASSERT(list.size() == 3, return EnvironmentItem("", ""));
|
||||
QString key = list.value(0).toString();
|
||||
Operation operation = Operation(list.value(1).toInt());
|
||||
QString value = list.value(2).toString();
|
||||
return NameValueItem(key, value, operation);
|
||||
return EnvironmentItem(key, value, operation);
|
||||
}
|
||||
|
||||
QVariantList NameValueItem::toVariantList(const NameValueItem &item)
|
||||
QVariantList EnvironmentItem::toVariantList(const EnvironmentItem &item)
|
||||
{
|
||||
return QVariantList() << item.name << item.operation << item.value;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ static QString expand(const NameValueDictionary *dictionary, QString value)
|
||||
return value;
|
||||
}
|
||||
|
||||
void NameValueItem::apply(NameValueDictionary *dictionary, Operation op) const
|
||||
void EnvironmentItem::apply(NameValueDictionary *dictionary, Operation op) const
|
||||
{
|
||||
switch (op) {
|
||||
case SetEnabled:
|
||||
@@ -173,26 +173,26 @@ void NameValueItem::apply(NameValueDictionary *dictionary, Operation op) const
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const NameValueItem &i)
|
||||
QDebug operator<<(QDebug debug, const EnvironmentItem &i)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.noquote();
|
||||
debug.nospace();
|
||||
debug << "KeyValueItem(";
|
||||
switch (i.operation) {
|
||||
case NameValueItem::SetEnabled:
|
||||
case EnvironmentItem::SetEnabled:
|
||||
debug << "set \"" << i.name << "\" to \"" << i.value << '"';
|
||||
break;
|
||||
case NameValueItem::SetDisabled:
|
||||
case EnvironmentItem::SetDisabled:
|
||||
debug << "set \"" << i.name << "\" to \"" << i.value << '"' << "[disabled]";
|
||||
break;
|
||||
case NameValueItem::Unset:
|
||||
case EnvironmentItem::Unset:
|
||||
debug << "unset \"" << i.name << '"';
|
||||
break;
|
||||
case NameValueItem::Prepend:
|
||||
case EnvironmentItem::Prepend:
|
||||
debug << "prepend to \"" << i.name << "\":\"" << i.value << '"';
|
||||
break;
|
||||
case NameValueItem::Append:
|
||||
case EnvironmentItem::Append:
|
||||
debug << "append to \"" << i.name << "\":\"" << i.value << '"';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT NameValueItem
|
||||
class QTCREATOR_UTILS_EXPORT EnvironmentItem
|
||||
{
|
||||
public:
|
||||
enum Operation : char { SetEnabled, Unset, Prepend, Append, SetDisabled };
|
||||
NameValueItem() = default;
|
||||
NameValueItem(const QString &key, const QString &value, Operation operation = SetEnabled)
|
||||
EnvironmentItem() = default;
|
||||
EnvironmentItem(const QString &key, const QString &value, Operation operation = SetEnabled)
|
||||
: name(key)
|
||||
, value(value)
|
||||
, operation(operation)
|
||||
@@ -26,25 +26,25 @@ public:
|
||||
|
||||
void apply(NameValueDictionary *dictionary) const { apply(dictionary, operation); }
|
||||
|
||||
static void sort(NameValueItems *list);
|
||||
static NameValueItems fromStringList(const QStringList &list);
|
||||
static QStringList toStringList(const NameValueItems &list);
|
||||
static NameValueItems itemsFromVariantList(const QVariantList &list);
|
||||
static QVariantList toVariantList(const NameValueItems &list);
|
||||
static NameValueItem itemFromVariantList(const QVariantList &list);
|
||||
static QVariantList toVariantList(const NameValueItem &item);
|
||||
static void sort(EnvironmentItems *list);
|
||||
static EnvironmentItems fromStringList(const QStringList &list);
|
||||
static QStringList toStringList(const EnvironmentItems &list);
|
||||
static EnvironmentItems itemsFromVariantList(const QVariantList &list);
|
||||
static QVariantList toVariantList(const EnvironmentItems &list);
|
||||
static EnvironmentItem itemFromVariantList(const QVariantList &list);
|
||||
static QVariantList toVariantList(const EnvironmentItem &item);
|
||||
|
||||
friend bool operator==(const NameValueItem &first, const NameValueItem &second)
|
||||
friend bool operator==(const EnvironmentItem &first, const EnvironmentItem &second)
|
||||
{
|
||||
return first.operation == second.operation && first.name == second.name
|
||||
&& first.value == second.value;
|
||||
}
|
||||
friend bool operator!=(const NameValueItem &first, const NameValueItem &second)
|
||||
friend bool operator!=(const EnvironmentItem &first, const EnvironmentItem &second)
|
||||
{
|
||||
return !(first == second);
|
||||
}
|
||||
|
||||
friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const NameValueItem &i);
|
||||
friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const EnvironmentItem &i);
|
||||
|
||||
public:
|
||||
QString name;
|
||||
|
||||
@@ -70,7 +70,7 @@ NameValueItemsWidget::NameValueItemsWidget(QWidget *parent)
|
||||
layout->addWidget(new QLabel(helpText, this));
|
||||
|
||||
const auto checkForItemChange = [this] {
|
||||
const NameValueItems newItems = environmentItems();
|
||||
const EnvironmentItems newItems = environmentItems();
|
||||
if (newItems != m_originalItems) {
|
||||
m_originalItems = newItems;
|
||||
emit userChangedItems(newItems);
|
||||
@@ -190,8 +190,8 @@ void NameValuesDialog::setPlaceholderText(const QString &text)
|
||||
m_editor->setPlaceholderText(text);
|
||||
}
|
||||
|
||||
std::optional<NameValueItems> NameValuesDialog::getNameValueItems(QWidget *parent,
|
||||
const NameValueItems &initial,
|
||||
std::optional<EnvironmentItems> NameValuesDialog::getNameValueItems(QWidget *parent,
|
||||
const EnvironmentItems &initial,
|
||||
const QString &placeholderText,
|
||||
Polisher polisher,
|
||||
const QString &windowTitle)
|
||||
|
||||
@@ -34,20 +34,20 @@ signals:
|
||||
|
||||
private:
|
||||
Internal::TextEditHelper *m_editor;
|
||||
NameValueItems m_originalItems;
|
||||
EnvironmentItems m_originalItems;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT NameValuesDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
void setNameValueItems(const NameValueItems &items);
|
||||
NameValueItems nameValueItems() const;
|
||||
void setNameValueItems(const EnvironmentItems &items);
|
||||
EnvironmentItems nameValueItems() const;
|
||||
|
||||
void setPlaceholderText(const QString &text);
|
||||
|
||||
using Polisher = std::function<void(QWidget *)>;
|
||||
static std::optional<NameValueItems> getNameValueItems(QWidget *parent = nullptr,
|
||||
const NameValueItems &initial = {},
|
||||
static std::optional<EnvironmentItems> getNameValueItems(QWidget *parent = nullptr,
|
||||
const EnvironmentItems &initial = {},
|
||||
const QString &placeholderText = {},
|
||||
Polisher polish = {},
|
||||
const QString &windowTitle = {});
|
||||
|
||||
@@ -4093,7 +4093,7 @@ void GdbEngine::setEnvironmentVariables()
|
||||
|
||||
Environment baseEnv = runParameters().debugger.environment;
|
||||
Environment runEnv = runParameters().inferior.environment;
|
||||
const NameValueItems items = baseEnv.diff(runEnv);
|
||||
const EnvironmentItems items = baseEnv.diff(runEnv);
|
||||
for (const EnvironmentItem &item : items) {
|
||||
// imitate the weird windows gdb behavior of setting the case of the path environment
|
||||
// variable name to an all uppercase PATH
|
||||
|
||||
@@ -32,19 +32,19 @@ Utils::Id McuDependenciesKitAspect::id()
|
||||
return "PE.Profile.McuCMakeDependencies";
|
||||
}
|
||||
|
||||
Utils::NameValueItems McuDependenciesKitAspect::dependencies(const Kit *kit)
|
||||
Utils::EnvironmentItems McuDependenciesKitAspect::dependencies(const Kit *kit)
|
||||
{
|
||||
if (kit)
|
||||
return Utils::NameValueItem::fromStringList(
|
||||
return Utils::EnvironmentItem::fromStringList(
|
||||
kit->value(McuDependenciesKitAspect::id()).toStringList());
|
||||
return Utils::NameValueItems();
|
||||
return Utils::EnvironmentItems();
|
||||
}
|
||||
|
||||
void McuDependenciesKitAspect::setDependencies(Kit *k, const Utils::NameValueItems &dependencies)
|
||||
void McuDependenciesKitAspect::setDependencies(Kit *k, const Utils::EnvironmentItems &dependencies)
|
||||
{
|
||||
if (k)
|
||||
k->setValue(McuDependenciesKitAspect::id(),
|
||||
Utils::NameValueItem::toStringList(dependencies));
|
||||
Utils::EnvironmentItem::toStringList(dependencies));
|
||||
}
|
||||
|
||||
Utils::NameValuePairs McuDependenciesKitAspect::configuration(const Kit *kit)
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
if (!variant.isNull() && !variant.canConvert(QVariant::List)) {
|
||||
qWarning("Kit \"%s\" has a wrong mcu dependencies value set.",
|
||||
qPrintable(kit->displayName()));
|
||||
McuDependenciesKitAspect::setDependencies(kit, Utils::NameValueItems());
|
||||
McuDependenciesKitAspect::setDependencies(kit, Utils::EnvironmentItems());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ class McuDependenciesKitAspect final
|
||||
{
|
||||
public:
|
||||
static Utils::Id id();
|
||||
static Utils::NameValueItems dependencies(const ProjectExplorer::Kit *kit);
|
||||
static void setDependencies(ProjectExplorer::Kit *kit, const Utils::NameValueItems &dependencies);
|
||||
static Utils::EnvironmentItems dependencies(const ProjectExplorer::Kit *kit);
|
||||
static void setDependencies(ProjectExplorer::Kit *kit, const Utils::EnvironmentItems &dependencies);
|
||||
static Utils::NameValuePairs configuration(const ProjectExplorer::Kit *kit);
|
||||
};
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
const McuTarget *mcuTarget,
|
||||
const McuPackagePtr &qtForMCUsSdkPackage)
|
||||
{
|
||||
NameValueItems dependencies;
|
||||
EnvironmentItems dependencies;
|
||||
|
||||
auto processPackage = [&dependencies](const McuPackagePtr &package) {
|
||||
const auto cmakeVariableName = package->cmakeVariableName();
|
||||
|
||||
@@ -481,25 +481,25 @@ void EnvironmentWidget::unsetEnvironmentButtonClicked()
|
||||
d->m_editor.setEnvironmentItems(d->m_model->userChanges());
|
||||
}
|
||||
|
||||
void EnvironmentWidget::amendPathList(Utils::NameValueItem::Operation op)
|
||||
void EnvironmentWidget::amendPathList(Utils::EnvironmentItem::Operation op)
|
||||
{
|
||||
const QString varName = d->m_model->indexToVariable(d->m_environmentView->currentIndex());
|
||||
const FilePath dir = FileUtils::getExistingDirectory(this, Tr::tr("Choose Directory"));
|
||||
if (dir.isEmpty())
|
||||
return;
|
||||
Utils::NameValueItems changes = d->m_model->userChanges();
|
||||
Utils::EnvironmentItems changes = d->m_model->userChanges();
|
||||
changes.append({varName, dir.toUserOutput(), op});
|
||||
setUserChanges(changes);
|
||||
}
|
||||
|
||||
void EnvironmentWidget::appendPathButtonClicked()
|
||||
{
|
||||
amendPathList(Utils::NameValueItem::Append);
|
||||
amendPathList(Utils::EnvironmentItem::Append);
|
||||
}
|
||||
|
||||
void EnvironmentWidget::prependPathButtonClicked()
|
||||
{
|
||||
amendPathList(Utils::NameValueItem::Prepend);
|
||||
amendPathList(Utils::EnvironmentItem::Prepend);
|
||||
}
|
||||
|
||||
void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex ¤t)
|
||||
|
||||
@@ -57,7 +57,7 @@ private:
|
||||
void linkActivated(const QString &link);
|
||||
|
||||
using PathListModifier = std::function<QString(const QString &oldList, const QString &newDir)>;
|
||||
void amendPathList(Utils::NameValueItem::Operation op);
|
||||
void amendPathList(Utils::EnvironmentItem::Operation op);
|
||||
|
||||
class Private;
|
||||
const std::unique_ptr<Private> d;
|
||||
|
||||
@@ -1063,13 +1063,13 @@ void Project::setNamedSettings(const Key &name, const QVariant &value)
|
||||
|
||||
void Project::setAdditionalEnvironment(const EnvironmentItems &envItems)
|
||||
{
|
||||
setNamedSettings(PROJECT_ENV_KEY, NameValueItem::toStringList(envItems));
|
||||
setNamedSettings(PROJECT_ENV_KEY, EnvironmentItem::toStringList(envItems));
|
||||
emit environmentChanged();
|
||||
}
|
||||
|
||||
EnvironmentItems Project::additionalEnvironment() const
|
||||
{
|
||||
return NameValueItem::fromStringList(namedSettings(PROJECT_ENV_KEY).toStringList());
|
||||
return EnvironmentItem::fromStringList(namedSettings(PROJECT_ENV_KEY).toStringList());
|
||||
}
|
||||
|
||||
bool Project::needsConfiguration() const
|
||||
|
||||
@@ -286,7 +286,7 @@ const QString projectEnvironmentVariable(const QString &key)
|
||||
|
||||
if (auto buildSystem = getBuildSystem()) {
|
||||
auto envItems = buildSystem->environment();
|
||||
auto confEnv = std::find_if(envItems.begin(), envItems.end(), [key](NameValueItem &item) {
|
||||
auto confEnv = std::find_if(envItems.begin(), envItems.end(), [key](EnvironmentItem &item) {
|
||||
return item.name == key;
|
||||
});
|
||||
if (confEnv != envItems.end())
|
||||
|
||||
@@ -262,11 +262,11 @@ void tst_Environment::expansion()
|
||||
void tst_Environment::incrementalChanges()
|
||||
{
|
||||
const Environment origEnv({{"VAR1", "VALUE1"}, {"VAR2", "VALUE2"}, {"PATH", "/usr/bin"}});
|
||||
const NameValueItems changes({
|
||||
{"VAR1", QString(), NameValueItem::Unset},
|
||||
{"VAR2", "VALUE2", NameValueItem::SetDisabled},
|
||||
{"PATH", "/usr/local/bin", NameValueItem::Append},
|
||||
{"PATH", "/tmp", NameValueItem::Prepend}});
|
||||
const EnvironmentItems changes({
|
||||
{"VAR1", QString(), EnvironmentItem::Unset},
|
||||
{"VAR2", "VALUE2", EnvironmentItem::SetDisabled},
|
||||
{"PATH", "/usr/local/bin", EnvironmentItem::Append},
|
||||
{"PATH", "/tmp", EnvironmentItem::Prepend}});
|
||||
|
||||
// Check values after change application.
|
||||
Environment newEnv = origEnv;
|
||||
@@ -281,8 +281,8 @@ void tst_Environment::incrementalChanges()
|
||||
QString("/tmp").append(sep).append("/usr/bin").append(sep).append("/usr/local/bin"));
|
||||
|
||||
// Check apply/diff round-trips.
|
||||
const NameValueItems diff = origEnv.diff(newEnv);
|
||||
const NameValueItems reverseDiff = newEnv.diff(origEnv);
|
||||
const EnvironmentItems diff = origEnv.diff(newEnv);
|
||||
const EnvironmentItems reverseDiff = newEnv.diff(origEnv);
|
||||
Environment newEnv2 = origEnv;
|
||||
newEnv2.modify(diff);
|
||||
QCOMPARE(newEnv, newEnv2);
|
||||
@@ -290,12 +290,12 @@ void tst_Environment::incrementalChanges()
|
||||
QCOMPARE(newEnv2, origEnv);
|
||||
|
||||
// Check conversion round-trips.
|
||||
QCOMPARE(NameValueItem::fromStringList(NameValueItem::toStringList(changes)), changes);
|
||||
QCOMPARE(NameValueItem::fromStringList(NameValueItem::toStringList(diff)), diff);
|
||||
QCOMPARE(NameValueItem::fromStringList(NameValueItem::toStringList(reverseDiff)), reverseDiff);
|
||||
QCOMPARE(NameValueItem::itemsFromVariantList(NameValueItem::toVariantList(changes)), changes);
|
||||
QCOMPARE(NameValueItem::itemsFromVariantList(NameValueItem::toVariantList(diff)), diff);
|
||||
QCOMPARE(NameValueItem::itemsFromVariantList(NameValueItem::toVariantList(reverseDiff)),
|
||||
QCOMPARE(EnvironmentItem::fromStringList(EnvironmentItem::toStringList(changes)), changes);
|
||||
QCOMPARE(EnvironmentItem::fromStringList(EnvironmentItem::toStringList(diff)), diff);
|
||||
QCOMPARE(EnvironmentItem::fromStringList(EnvironmentItem::toStringList(reverseDiff)), reverseDiff);
|
||||
QCOMPARE(EnvironmentItem::itemsFromVariantList(EnvironmentItem::toVariantList(changes)), changes);
|
||||
QCOMPARE(EnvironmentItem::itemsFromVariantList(EnvironmentItem::toVariantList(diff)), diff);
|
||||
QCOMPARE(EnvironmentItem::itemsFromVariantList(EnvironmentItem::toVariantList(reverseDiff)),
|
||||
reverseDiff);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user