CMakePM: Settings list UI changes

The CMake parameters QTreeView has now:
- alternating row colors
- row selection

Both key and value get the same font and foreground stylings.
- bold when the key is new or the value has been changed by user
- italic when the key has been inherited from kit or initial config
- red when there are differences between the inherited value and
  the current value

Change-Id: If09bb2c3e25f59938c5f56e6dd0d6817dfe442cc
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2022-02-01 11:08:14 +01:00
parent a3ca2f4c31
commit 0020ef7e30
3 changed files with 60 additions and 52 deletions

View File

@@ -252,7 +252,8 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
m_configView->sortByColumn(0, Qt::AscendingOrder);
auto stretcher = new HeaderViewStretcher(m_configView->header(), 0);
m_configView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_configView->setSelectionBehavior(QAbstractItemView::SelectItems);
m_configView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_configView->setAlternatingRowColors(true);
m_configView->setFrameShape(QFrame::NoFrame);
m_configView->setItemDelegate(new ConfigModelItemDelegate(m_buildConfiguration->project()->projectDirectory(),
m_configView));

View File

@@ -64,6 +64,18 @@ QVariant ConfigModel::data(const QModelIndex &idx, int role) const
return Utils::TreeModel<>::data(idx, role);
}
bool ConfigModel::setData(const QModelIndex &idx, const QVariant &data, int role)
{
Utils::TreeItem *item = itemForIndex(idx);
bool res = item ? item->setData(idx.column(), data, role) : false;
if (res) {
const QModelIndex keyIdx = idx.sibling(idx.row(), 0);
const QModelIndex valueIdx = idx.sibling(idx.row(), 1);
emit dataChanged(keyIdx, valueIdx);
}
return res;
}
ConfigModel::~ConfigModel() = default;
void ConfigModel::appendConfiguration(const QString &key,
@@ -439,59 +451,53 @@ QVariant ConfigModelTreeItem::data(int column, int role) const
return dataItem->isInitial ? "1" : "0";
}
switch (column) {
case 0:
switch (role) {
case Qt::DisplayRole:
return dataItem->key.isEmpty() ? QCoreApplication::translate("CMakeProjectManager::ConfigModel", "<UNSET>") : dataItem->key;
case Qt::EditRole:
return dataItem->key;
case Qt::ToolTipRole:
return toolTip();
case Qt::FontRole: {
QFont font;
font.setBold(dataItem->isUserNew);
font.setStrikeOut((!dataItem->inCMakeCache && !dataItem->isUserNew) || dataItem->isUnset);
return font;
}
default:
return QVariant();
}
case 1: {
const QString value = currentValue();
const auto boolValue = CMakeConfigItem::toBool(value);
const bool isTrue = boolValue.has_value() && boolValue.value();
auto fontRole = [this]() -> QFont {
QFont font;
font.setBold((dataItem->isUserChanged || dataItem->isUserNew) && !dataItem->isUnset);
font.setStrikeOut((!dataItem->inCMakeCache && !dataItem->isUserNew) || dataItem->isUnset);
font.setItalic((dataItem->isInitial && !dataItem->kitValue.isEmpty())
|| (!dataItem->isInitial && !dataItem->initialValue.isEmpty()));
return font;
};
switch (role) {
case Qt::CheckStateRole:
return (dataItem->type == ConfigModel::DataItem::BOOLEAN)
? QVariant(isTrue ? Qt::Checked : Qt::Unchecked) : QVariant();
case Qt::DisplayRole:
return value;
case Qt::EditRole:
return (dataItem->type == ConfigModel::DataItem::BOOLEAN) ? QVariant(isTrue) : QVariant(value);
case Qt::FontRole: {
QFont font;
font.setBold((dataItem->isUserChanged || dataItem->isUserNew) && !dataItem->isUnset);
font.setStrikeOut((!dataItem->inCMakeCache && !dataItem->isUserNew) || dataItem->isUnset);
return font;
}
case Qt::ForegroundRole: {
bool mismatch = false;
if (dataItem->isInitial)
mismatch = !dataItem->kitValue.isEmpty() && dataItem->kitValue != value;
else
mismatch = !dataItem->initialValue.isEmpty() && dataItem->initialValue != value;
return Utils::creatorTheme()->color(mismatch ? Utils::Theme::TextColorHighlight
: Utils::Theme::TextColorNormal);
}
case Qt::ToolTipRole: {
return toolTip();
}
default:
auto foregroundRole = [this](const QString &value) -> QColor {
bool mismatch = false;
if (dataItem->isInitial)
mismatch = !dataItem->kitValue.isEmpty() && dataItem->kitValue != value;
else
mismatch = !dataItem->initialValue.isEmpty() && dataItem->initialValue != value;
return Utils::creatorTheme()->color(mismatch ? Utils::Theme::TextColorHighlight
: Utils::Theme::TextColorNormal);
};
const QString value = currentValue();
const auto boolValue = CMakeConfigItem::toBool(value);
const bool isTrue = boolValue.has_value() && boolValue.value();
switch (role) {
case Qt::CheckStateRole:
if (column == 0)
return QVariant();
}
}
return (dataItem->type == ConfigModel::DataItem::BOOLEAN)
? QVariant(isTrue ? Qt::Checked : Qt::Unchecked)
: QVariant();
case Qt::DisplayRole:
if (column == 0)
return dataItem->key.isEmpty()
? QCoreApplication::translate("CMakeProjectManager::ConfigModel", "<UNSET>")
: dataItem->key;
return value;
case Qt::EditRole:
if (column == 0)
return dataItem->key;
return (dataItem->type == ConfigModel::DataItem::BOOLEAN) ? QVariant(isTrue)
: QVariant(value);
case Qt::FontRole:
return fontRole();
case Qt::ForegroundRole:
return foregroundRole(value);
case Qt::ToolTipRole:
return toolTip();
default:
return QVariant();
}

View File

@@ -133,6 +133,7 @@ public:
~ConfigModel() override;
QVariant data(const QModelIndex &idx, int role) const final;
bool setData(const QModelIndex &idx, const QVariant &data, int role) final;
void appendConfiguration(const QString &key,
const QString &value = QString(),