forked from qt-creator/qt-creator
Add variable expansion in tooltip
Enabled expansion of variables in CMake configuration tooltip. Note, I honestly tried to create a unit-test for this, but it all ended up futile: even ignoring the fact that `ConfigModelTreeItem` uses private `InternalDataItem` type, CMakeProjectManager does not expose some of the symbols required for the unit test to be implemented. At this point I do not think it is worth it to try any further. Change-Id: I78cd52c2470225e00477ada424cb43d7da75a14c Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -508,10 +508,11 @@ void ConfigModel::generateTree()
|
|||||||
auto root = new Utils::TreeItem;
|
auto root = new Utils::TreeItem;
|
||||||
for (InternalDataItem &di : m_configuration) {
|
for (InternalDataItem &di : m_configuration) {
|
||||||
auto it = initialHash.find(di.key);
|
auto it = initialHash.find(di.key);
|
||||||
|
Utils::MacroExpander *expander = macroExpander();
|
||||||
if (it != initialHash.end())
|
if (it != initialHash.end())
|
||||||
di.initialValue = it->expandedValue(macroExpander());
|
di.initialValue = it->expandedValue(expander);
|
||||||
|
|
||||||
root->appendChild(new Internal::ConfigModelTreeItem(&di));
|
root->appendChild(new Internal::ConfigModelTreeItem(&di, expander));
|
||||||
}
|
}
|
||||||
setRootItem(root);
|
setRootItem(root);
|
||||||
}
|
}
|
||||||
@@ -673,11 +674,17 @@ QString ConfigModelTreeItem::toolTip() const
|
|||||||
tooltip << dataItem->description;
|
tooltip << dataItem->description;
|
||||||
|
|
||||||
const QString pattern = "<dt style=\"font-weight:bold\">%1</dt><dd>%2</dd>";
|
const QString pattern = "<dt style=\"font-weight:bold\">%1</dt><dd>%2</dd>";
|
||||||
|
const QString value = dataItem->currentValue();
|
||||||
if (dataItem->isInitial) {
|
if (dataItem->isInitial) {
|
||||||
if (!dataItem->kitValue.isEmpty())
|
if (!dataItem->kitValue.isEmpty())
|
||||||
tooltip << pattern.arg(Tr::tr("Kit:")).arg(dataItem->kitValue);
|
tooltip << pattern.arg(Tr::tr("Kit:")).arg(dataItem->kitValue);
|
||||||
|
|
||||||
tooltip << pattern.arg(Tr::tr("Initial Configuration:")).arg(dataItem->currentValue());
|
tooltip << pattern.arg(Tr::tr("Initial Configuration:")).arg(value);
|
||||||
|
|
||||||
|
const QString expandedValue = dataItem->expandedValue(m_macroExpander);
|
||||||
|
const bool showExpanded = expandedValue != value;
|
||||||
|
if (showExpanded)
|
||||||
|
tooltip << pattern.arg(Tr::tr("Expands to:")).arg(expandedValue);
|
||||||
} else {
|
} else {
|
||||||
if (!dataItem->initialValue.isEmpty()) {
|
if (!dataItem->initialValue.isEmpty()) {
|
||||||
tooltip << pattern.arg(Tr::tr("Initial Configuration:"))
|
tooltip << pattern.arg(Tr::tr("Initial Configuration:"))
|
||||||
@@ -685,7 +692,7 @@ QString ConfigModelTreeItem::toolTip() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dataItem->inCMakeCache) {
|
if (dataItem->inCMakeCache) {
|
||||||
tooltip << pattern.arg(Tr::tr("Current Configuration:")).arg(dataItem->currentValue());
|
tooltip << pattern.arg(Tr::tr("Current Configuration:")).arg(value);
|
||||||
} else {
|
} else {
|
||||||
tooltip << pattern.arg(Tr::tr("Not in CMakeCache.txt")).arg(QString());
|
tooltip << pattern.arg(Tr::tr("Not in CMakeCache.txt")).arg(QString());
|
||||||
}
|
}
|
||||||
|
@@ -123,7 +123,10 @@ private:
|
|||||||
class ConfigModelTreeItem : public Utils::TreeItem
|
class ConfigModelTreeItem : public Utils::TreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConfigModelTreeItem(ConfigModel::InternalDataItem *di = nullptr) : dataItem(di) {}
|
ConfigModelTreeItem(ConfigModel::InternalDataItem *di, Utils::MacroExpander *macroExpander)
|
||||||
|
: dataItem(di)
|
||||||
|
, m_macroExpander(macroExpander)
|
||||||
|
{}
|
||||||
~ConfigModelTreeItem() override;
|
~ConfigModelTreeItem() override;
|
||||||
|
|
||||||
QVariant data(int column, int role) const final;
|
QVariant data(int column, int role) const final;
|
||||||
@@ -134,6 +137,9 @@ public:
|
|||||||
QString currentValue() const;
|
QString currentValue() const;
|
||||||
|
|
||||||
ConfigModel::InternalDataItem *dataItem;
|
ConfigModel::InternalDataItem *dataItem;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Utils::MacroExpander *m_macroExpander = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // CMakeProjectManager::Internal
|
} // CMakeProjectManager::Internal
|
||||||
|
Reference in New Issue
Block a user