CMakePM: Add "Appy Kit/Initial Configuration Value" context menu entry

Now the "Initial Configuration" and "Current Configuration" displays
in red the mismatches between kit / initial value and respectively
initial and current configuration values.

By having a "Apply Kit / Initial Configuration Value" context menu
entry the user can resolve the mismatches if needed.

Change-Id: I2e272821c3ba396cd8a6b7c81e1437cb3fd4bbad
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2022-01-28 18:16:23 +01:00
parent dc825e11bd
commit 9c8f46a173
3 changed files with 66 additions and 0 deletions

View File

@@ -895,6 +895,30 @@ bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
if ((action = createForceAction(ConfigModel::DataItem::STRING, idx)))
menu->addAction(action);
menu->addSeparator();
auto applyKitOrInitialValue = new QAction(isInitialConfiguration()
? tr("Apply Kit Value")
: tr("Apply Initial Configuration Value"),
this);
menu->addAction(applyKitOrInitialValue);
connect(applyKitOrInitialValue, &QAction::triggered, this, [this] {
const QModelIndexList selectedIndexes = m_configView->selectionModel()->selectedIndexes();
const QModelIndexList validIndexes = Utils::filtered(selectedIndexes, [](const QModelIndex &index) {
return index.isValid() && index.flags().testFlag(Qt::ItemIsSelectable);
});
for (const QModelIndex &index : validIndexes) {
if (isInitialConfiguration())
m_configModel->applyKitValue(mapToSource(m_configView, index));
else
m_configModel->applyInitialValue(mapToSource(m_configView, index));
}
});
menu->addSeparator();
auto copy = new QAction(tr("Copy"), this);
menu->addAction(copy);
connect(copy, &QAction::triggered, this, [this] {

View File

@@ -180,6 +180,42 @@ void ConfigModel::toggleUnsetFlag(const QModelIndex &idx)
emit dataChanged(keyIdx, valueIdx);
}
void ConfigModel::applyKitValue(const QModelIndex &idx)
{
applyKitOrInitialValue(idx, KitOrInitial::Kit);
}
void ConfigModel::applyInitialValue(const QModelIndex &idx)
{
applyKitOrInitialValue(idx, KitOrInitial::Initial);
}
void ConfigModel::applyKitOrInitialValue(const QModelIndex &idx, KitOrInitial ki)
{
Utils::TreeItem *item = itemForIndex(idx);
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
QTC_ASSERT(cmti, return );
auto dataItem = cmti->dataItem;
const QString &kitOrInitialValue = ki == KitOrInitial::Kit ? dataItem->kitValue
: dataItem->initialValue;
// Allow a different value when the user didn't change anything (don't mark the same value as new)
// But allow the same value (going back) when the user did a change
const bool canSetValue = (dataItem->value != kitOrInitialValue && !dataItem->isUserChanged)
|| dataItem->isUserChanged;
if (!kitOrInitialValue.isEmpty() && canSetValue) {
dataItem->newValue = kitOrInitialValue;
dataItem->isUserChanged = dataItem->value != kitOrInitialValue;
const QModelIndex valueIdx = idx.sibling(idx.row(), 1);
const QModelIndex keyIdx = idx.sibling(idx.row(), 0);
emit dataChanged(keyIdx, valueIdx);
}
}
ConfigModel::DataItem ConfigModel::dataItemFromIndex(const QModelIndex &idx)
{
const QAbstractItemModel *m = idx.model();

View File

@@ -158,6 +158,9 @@ public:
void toggleUnsetFlag(const QModelIndex &idx);
void applyKitValue(const QModelIndex &idx);
void applyInitialValue(const QModelIndex &idx);
static DataItem dataItemFromIndex(const QModelIndex &idx);
QList<DataItem> configurationForCMake() const;
@@ -166,6 +169,9 @@ public:
void setMacroExpander(Utils::MacroExpander *newExpander);
private:
enum class KitOrInitial { Kit, Initial };
void applyKitOrInitialValue(const QModelIndex &idx, KitOrInitial ki);
class InternalDataItem : public DataItem
{
public: