Fix instances getting deselected after FTB instances are loaded (or whenever the model is reset)
This commit is contained in:
parent
fcb8612c10
commit
093143cfef
@ -289,24 +289,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
this, &MainWindow::notificationsChanged);
|
this, &MainWindow::notificationsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString currentInstanceId = MMC->settings()->get("SelectedInstance").toString();
|
setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString());
|
||||||
if (!currentInstanceId.isNull())
|
|
||||||
{
|
|
||||||
const QModelIndex index = MMC->instances()->getInstanceIndexById(currentInstanceId);
|
|
||||||
if (index.isValid())
|
|
||||||
{
|
|
||||||
const QModelIndex mappedIndex = proxymodel->mapFromSource(index);
|
|
||||||
view->setCurrentIndex(mappedIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
view->setCurrentIndex(proxymodel->index(0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
view->setCurrentIndex(proxymodel->index(0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
// removing this looks stupid
|
// removing this looks stupid
|
||||||
view->setFocus();
|
view->setFocus();
|
||||||
@ -788,6 +771,20 @@ void MainWindow::updateInstanceToolIcon(QString new_icon)
|
|||||||
ui->actionChangeInstIcon->setIcon(MMC->icons()->getIcon(m_currentInstIcon));
|
ui->actionChangeInstIcon->setIcon(MMC->icons()->getIcon(m_currentInstIcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setSelectedInstanceById(const QString &id)
|
||||||
|
{
|
||||||
|
QModelIndex selectionIndex = proxymodel->index(0, 0);
|
||||||
|
if (!id.isNull())
|
||||||
|
{
|
||||||
|
const QModelIndex index = MMC->instances()->getInstanceIndexById(id);
|
||||||
|
if (index.isValid())
|
||||||
|
{
|
||||||
|
selectionIndex = proxymodel->mapFromSource(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionChangeInstGroup_triggered()
|
void MainWindow::on_actionChangeInstGroup_triggered()
|
||||||
{
|
{
|
||||||
if (!m_selectedInstance)
|
if (!m_selectedInstance)
|
||||||
@ -1274,12 +1271,16 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &
|
|||||||
|
|
||||||
void MainWindow::selectionBad()
|
void MainWindow::selectionBad()
|
||||||
{
|
{
|
||||||
|
// start by reseting everything...
|
||||||
m_selectedInstance = nullptr;
|
m_selectedInstance = nullptr;
|
||||||
|
|
||||||
statusBar()->clearMessage();
|
statusBar()->clearMessage();
|
||||||
ui->instanceToolBar->setEnabled(false);
|
ui->instanceToolBar->setEnabled(false);
|
||||||
renameButton->setText(tr("Rename Instance"));
|
renameButton->setText(tr("Rename Instance"));
|
||||||
updateInstanceToolIcon("infinity");
|
updateInstanceToolIcon("infinity");
|
||||||
|
|
||||||
|
// ...and then see if we can enable the previously selected instance
|
||||||
|
setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionEditInstNotes_triggered()
|
void MainWindow::on_actionEditInstNotes_triggered()
|
||||||
|
@ -179,6 +179,8 @@ protected:
|
|||||||
void setCatBackground(bool enabled);
|
void setCatBackground(bool enabled);
|
||||||
void updateInstanceToolIcon(QString new_icon);
|
void updateInstanceToolIcon(QString new_icon);
|
||||||
|
|
||||||
|
void setSelectedInstanceById(const QString &id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
KCategoryDrawer *drawer;
|
KCategoryDrawer *drawer;
|
||||||
|
Loading…
Reference in New Issue
Block a user