Use custom signals to record previous name

Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
Yihe Li
2025-03-27 17:13:38 +08:00
parent 11a0dbf810
commit a2e44c0ef7
8 changed files with 18 additions and 44 deletions

View File

@ -289,14 +289,15 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
view->setSelectionMode(QAbstractItemView::SingleSelection);
// FIXME: leaks ListViewDelegate
view->setItemDelegate(new ListViewDelegate(this));
auto delegate = new ListViewDelegate(this);
view->setItemDelegate(delegate);
view->setFrameShape(QFrame::NoFrame);
// do not show ugly blue border on the mac
view->setAttribute(Qt::WA_MacShowFocusRect, false);
connect(view->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, [this] {
if (auto newRoot = askToUpdateInstanceDirName(m_selectedInstance, this); !newRoot.isEmpty()) {
connect(delegate, &ListViewDelegate::textChanged, this, [this](QString before, QString after) {
if (auto newRoot = askToUpdateInstanceDirName(m_selectedInstance, before, after, this); !newRoot.isEmpty()) {
refreshInstances();
setSelectedInstanceByRoot(newRoot);
setSelectedInstanceById(QFileInfo(newRoot).fileName());
}
});
@ -1138,18 +1139,6 @@ void MainWindow::setSelectedInstanceById(const QString& id)
}
}
void MainWindow::setSelectedInstanceByRoot(const QString& instanceRoot)
{
if (instanceRoot.isNull())
return;
const QModelIndex index = APPLICATION->instances()->getInstanceIndexByRoot(instanceRoot);
if (index.isValid()) {
QModelIndex selectionIndex = proxymodel->mapFromSource(index);
view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
updateStatusCenter();
}
}
void MainWindow::on_actionChangeInstGroup_triggered()
{
if (!m_selectedInstance)