feat: save instance view state

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-01 19:21:05 +02:00
parent d9b265d7ac
commit 319b816d79
No known key found for this signature in database
GPG Key ID: C10411294912A422
4 changed files with 17 additions and 2 deletions

View File

@ -617,6 +617,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_settings->registerSetting("MainWindowState", "");
m_settings->registerSetting("MainWindowGeometry", "");
m_settings->registerSetting("InstanceViewTableHeaderState", "");
m_settings->registerSetting("ConsoleWindowState", "");
m_settings->registerSetting("ConsoleWindowGeometry", "");

View File

@ -1910,6 +1910,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
// Save the window state and geometry.
APPLICATION->settings()->set("MainWindowState", saveState().toBase64());
APPLICATION->settings()->set("MainWindowGeometry", saveGeometry().toBase64());
view->storeState();
event->accept();
emit isClosing();
}

View File

@ -22,8 +22,8 @@
* or later.
*/
#include "Application.h"
#include "InstanceView.h"
#include <qabstractitemmodel.h>
#include "InstanceList.h"
#include "ui/instanceview/InstanceProxyModel.h"
@ -39,6 +39,10 @@ InstanceView::InstanceView(QWidget *parent, InstanceList *instances) : QStackedW
setCurrentWidget(m_table);
}
void InstanceView::storeState() {
APPLICATION->settings()->set("InstanceViewTableHeaderState", m_table->horizontalHeader()->saveState().toBase64());
}
void InstanceView::prepareModel() {
m_proxy = new InstanceProxyModel(this);
m_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
@ -68,6 +72,8 @@ void InstanceView::createTable() {
m_table->verticalHeader()->hide();
QHeaderView *header = m_table->horizontalHeader();
header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray()));
header->setSectionsMovable(true);
header->setSectionResizeMode(InstanceList::Icon, QHeaderView::Fixed);
header->setSectionResizeMode(InstanceList::Name, QHeaderView::Stretch);
@ -77,6 +83,9 @@ void InstanceView::createTable() {
m_table->setColumnWidth(InstanceList::Icon, m_rowHeight + 3 + 3); // padding left and right
m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom
if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState"))
m_table->sortByColumn(InstanceList::LastPlayed, Qt::AscendingOrder);
connect(m_table, &QTableView::doubleClicked, this, &InstanceView::activateInstance);
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstanceView::currentRowChanged);
connect(m_table->selectionModel(), &QItemSelectionModel::currentColumnChanged, this, &InstanceView::selectNameColumn);

View File

@ -27,7 +27,7 @@ class InstanceProxyModel;
class InstanceList;
class InstanceView : public QStackedWidget {
Q_OBJECT
Q_OBJECT
public:
explicit InstanceView(QWidget *parent = nullptr, InstanceList* instances = nullptr);
@ -38,6 +38,9 @@ public:
InstancePtr currentInstance();
// save state of current view
void storeState();
signals:
void instanceActivated(InstancePtr inst);
void currentInstanceChanged(InstancePtr current, InstancePtr previous);