Commit dfec256d authored by Tobias Hunger's avatar Tobias Hunger

CMake: Allow CMake configuration to be forced to string type

This allows editing values with misidentified types in Project Mode.

Change-Id: Ic74da2ca71cc9046cbbeb1202075976c9edd28b7
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 3d8ddb38
......@@ -140,6 +140,8 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
tree, [tree](const QModelIndex &idx) { tree->edit(idx); });
m_configView = tree;
m_configView->viewport()->installEventFilter(this);
m_configFilterModel->setSourceModel(m_configModel);
m_configFilterModel->setFilterKeyColumn(0);
m_configFilterModel->setFilterRole(ConfigModel::ItemIsAdvancedRole);
......@@ -339,6 +341,9 @@ void CMakeBuildSettingsWidget::updateFromKit()
static QModelIndex mapToSource(const QAbstractItemView *view, const QModelIndex &idx)
{
if (!idx.isValid())
return idx;
QAbstractItemModel *model = view->model();
QModelIndex result = idx;
while (QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel *>(model)) {
......@@ -356,5 +361,30 @@ void CMakeBuildSettingsWidget::updateSelection(const QModelIndex &current, const
m_editButton->setEnabled(currentModelIndex.flags().testFlag(Qt::ItemIsEditable));
}
bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event)
{
// handle context menu events:
if (target != m_configView->viewport() || event->type() != QEvent::ContextMenu)
return false;
auto e = static_cast<QContextMenuEvent *>(event);
const QModelIndex idx = mapToSource(m_configView, m_configView->indexAt(e->pos()));
if (!idx.isValid())
return false;
QMenu *menu = new QMenu(this);
connect(menu, &QMenu::triggered, menu, &QMenu::deleteLater);
QAction *forceToStringAction = new QAction(tr("Force to String"));
forceToStringAction->setEnabled(m_configModel->canForceToString(idx));
menu->addAction(forceToStringAction);
connect(forceToStringAction, &QAction::triggered, this, [this, idx]() { m_configModel->forceToString(idx); });
menu->move(e->globalPos());
menu->show();
return true;
}
} // namespace Internal
} // namespace CMakeProjectManager
......@@ -66,6 +66,8 @@ private:
void updateSelection(const QModelIndex &current, const QModelIndex &previous);
bool eventFilter(QObject *target, QEvent *event);
CMakeBuildConfiguration *m_buildConfiguration;
QTreeView *m_configView;
ConfigModel *m_configModel;
......
......@@ -134,6 +134,26 @@ bool ConfigModel::hasCMakeChanges() const
return Utils::contains(m_configuration, [](const InternalDataItem &i) { return i.isCMakeChanged; });
}
bool ConfigModel::canForceToString(const QModelIndex &idx) const
{
if (idx.model() != const_cast<ConfigModel *>(this) || idx.column() != 1)
return false;
Utils::TreeItem *item = itemForIndex(idx);
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
return cmti && (cmti->dataItem->type != DataItem::STRING);
}
void ConfigModel::forceToString(const QModelIndex &idx)
{
QTC_ASSERT(canForceToString(idx), return);
Utils::TreeItem *item = itemForIndex(idx);
auto cmti = dynamic_cast<Internal::ConfigModelTreeItem *>(item);
cmti->dataItem->type = DataItem::STRING;
const QModelIndex valueIdx = idx.sibling(1, idx.column());
emit dataChanged(valueIdx, valueIdx);
}
QList<ConfigModel::DataItem> ConfigModel::configurationChanges() const
{
const QList<InternalDataItem> tmp
......
......@@ -75,6 +75,9 @@ public:
bool hasChanges() const;
bool hasCMakeChanges() const;
bool canForceToString(const QModelIndex &idx) const;
void forceToString(const QModelIndex &idx);
QList<DataItem> configurationChanges() const;
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment