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:
Aaron Barany
2019-01-24 01:21:34 -08:00
parent d2e420bfe7
commit 307ea55027

View File

@@ -171,6 +171,12 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
m_configTextFilterModel->setFilterKeyColumn(-1); m_configTextFilterModel->setFilterKeyColumn(-1);
m_configTextFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); 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->setModel(m_configTextFilterModel);
m_configView->setMinimumHeight(300); m_configView->setMinimumHeight(300);
m_configView->setUniformRowHeights(true); m_configView->setUniformRowHeights(true);
@@ -307,9 +313,13 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
value = QString::fromLatin1("OFF"); value = QString::fromLatin1("OFF");
m_configModel->appendConfiguration(tr("<UNSET>"), value, type); m_configModel->appendConfiguration(tr("<UNSET>"), value, type);
QModelIndex idx; const Utils::TreeItem *item = m_configModel->findNonRootItem([&value, type](Utils::TreeItem *item) {
idx = m_configView->model()->index( ConfigModel::DataItem dataItem = ConfigModel::dataItemFromIndex(item->index());
m_configView->model()->rowCount(idx) - 1, 0); 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->setCurrentIndex(idx);
m_configView->edit(idx); m_configView->edit(idx);
}); });