forked from qt-creator/qt-creator
CMake: Fix scrolling when editing configuration
Find the index for the new item from the model rather than attempting to find the item by the row count, which would often return the incorrect index. It also scrolls to the item so it's in view once it starts editing. Listen for layout change to scroll to the selected index. This ensures that when you name an item after adding it, it will scroll to the new location to edit the value afterward. Change-Id: Iaa338148a40b921398cfe95da977371a91965a58 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -171,6 +171,12 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
|
||||
m_configTextFilterModel->setFilterKeyColumn(-1);
|
||||
m_configTextFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
connect(m_configTextFilterModel, &QAbstractItemModel::layoutChanged, this, [this]() {
|
||||
QModelIndex selectedIdx = m_configView->currentIndex();
|
||||
if (selectedIdx.isValid())
|
||||
m_configView->scrollTo(selectedIdx);
|
||||
});
|
||||
|
||||
m_configView->setModel(m_configTextFilterModel);
|
||||
m_configView->setMinimumHeight(300);
|
||||
m_configView->setUniformRowHeights(true);
|
||||
@@ -307,9 +313,13 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
|
||||
value = QString::fromLatin1("OFF");
|
||||
|
||||
m_configModel->appendConfiguration(tr("<UNSET>"), value, type);
|
||||
QModelIndex idx;
|
||||
idx = m_configView->model()->index(
|
||||
m_configView->model()->rowCount(idx) - 1, 0);
|
||||
const Utils::TreeItem *item = m_configModel->findNonRootItem([&value, type](Utils::TreeItem *item) {
|
||||
ConfigModel::DataItem dataItem = ConfigModel::dataItemFromIndex(item->index());
|
||||
return dataItem.key == tr("<UNSET>") && dataItem.type == type && dataItem.value == value;
|
||||
});
|
||||
QModelIndex idx = m_configModel->indexForItem(item);
|
||||
idx = m_configTextFilterModel->mapFromSource(m_configFilterModel->mapFromSource(idx));
|
||||
m_configView->scrollTo(idx);
|
||||
m_configView->setCurrentIndex(idx);
|
||||
m_configView->edit(idx);
|
||||
});
|
||||
|
Reference in New Issue
Block a user