CMake: Only enable edit button for CMake configuration when useful

Only enable the button when items are actually editable.

Change-Id: I54fd5430772a6db61c85b59d5c655d3bd4ebf8d7
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2017-09-13 12:23:21 +02:00
parent d1799b9aa1
commit 8e5528212f
2 changed files with 24 additions and 0 deletions

View File

@@ -197,6 +197,9 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
mainLayout->addLayout(buttonLayout, row, 2);
connect(m_configView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &CMakeBuildSettingsWidget::updateSelection);
++row;
m_reconfigureButton = new QPushButton(tr("Apply Configuration Changes"));
m_reconfigureButton->setEnabled(false);
@@ -331,5 +334,24 @@ void CMakeBuildSettingsWidget::updateFromKit()
m_configModel->setKitConfiguration(configHash);
}
static QModelIndex mapToSource(const QAbstractItemView *view, const QModelIndex &idx)
{
QAbstractItemModel *model = view->model();
QModelIndex result = idx;
while (QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel *>(model)) {
result = proxy->mapToSource(result);
model = proxy->sourceModel();
}
return result;
}
void CMakeBuildSettingsWidget::updateSelection(const QModelIndex &current, const QModelIndex &previous)
{
Q_UNUSED(previous);
const QModelIndex currentModelIndex = mapToSource(m_configView, current);
if (currentModelIndex.isValid())
m_editButton->setEnabled(currentModelIndex.flags().testFlag(Qt::ItemIsEditable));
}
} // namespace Internal
} // namespace CMakeProjectManager

View File

@@ -64,6 +64,8 @@ private:
void updateAdvancedCheckBox();
void updateFromKit();
void updateSelection(const QModelIndex &current, const QModelIndex &previous);
CMakeBuildConfiguration *m_buildConfiguration;
QTreeView *m_configView;
ConfigModel *m_configModel;