From 76bc9dd29b1fd70b7416064f84ef6d07e624582c Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Tue, 18 Jan 2022 13:36:04 +0100 Subject: [PATCH] Store header states for all extension views. Fixes #189. --- src/analogchanneldialog.cc | 1 + src/aprssystemdialog.cc | 1 + src/channellistview.cc | 4 ++-- src/contactlistview.cc | 4 ++-- src/digitalchanneldialog.cc | 2 ++ src/dmrcontactdialog.cc | 1 + src/dmriddialog.cc | 2 ++ src/dtmfcontactdialog.cc | 1 + src/extensionview.cc | 17 +++++++++++++ src/extensionview.hh | 2 ++ src/generalsettingsview.cc | 1 + src/gpssystemdialog.cc | 1 + src/positioningsystemlistview.cc | 4 ++-- src/radioidlistview.cc | 4 ++-- src/roamingzonedialog.cc | 1 + src/rxgrouplistdialog.cc | 1 + src/scanlistdialog.cc | 1 + src/settings.cc | 41 ++++++++------------------------ src/settings.hh | 13 ++-------- src/zonedialog.cc | 1 + 20 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/analogchanneldialog.cc b/src/analogchanneldialog.cc index 3ed7b5ce..28c5f532 100644 --- a/src/analogchanneldialog.cc +++ b/src/analogchanneldialog.cc @@ -117,6 +117,7 @@ AnalogChannelDialog::construct() { if (! settings.showCommercialFeatures()) tabWidget->tabBar()->hide(); + extensionView->setObjectName("AnalogChannelExtension"); extensionView->setObject(_myChannel); connect(powerDefault, SIGNAL(toggled(bool)), this, SLOT(onPowerDefaultToggled(bool))); diff --git a/src/aprssystemdialog.cc b/src/aprssystemdialog.cc index 0ac79a57..8672c666 100644 --- a/src/aprssystemdialog.cc +++ b/src/aprssystemdialog.cc @@ -157,6 +157,7 @@ APRSSystemDialog::construct() { ui->updatePeriod->setValue(_myAPRS->period()); ui->message->setText(_myAPRS->message()); + ui->extensionView->setObjectName("aprsSystemExtension"); ui->extensionView->setObject(_myAPRS); if (! settings.showCommercialFeatures()) ui->tabWidget->tabBar()->hide(); diff --git a/src/channellistview.cc b/src/channellistview.cc index 8deb66a2..f54957e0 100644 --- a/src/channellistview.cc +++ b/src/channellistview.cc @@ -159,11 +159,11 @@ ChannelListView::onEditChannel(unsigned row) { void ChannelListView::loadChannelListSectionState() { Settings settings; - ui->listView->header()->restoreState(settings.channelListHeaderState()); + ui->listView->header()->restoreState(settings.headerState("channelList")); } void ChannelListView::storeChannelListSectionState() { Settings settings; - settings.setChannelListHeaderState(ui->listView->header()->saveState()); + settings.setHeaderState("channelList", ui->listView->header()->saveState()); } diff --git a/src/contactlistview.cc b/src/contactlistview.cc index 8a18940a..b9a14f96 100644 --- a/src/contactlistview.cc +++ b/src/contactlistview.cc @@ -110,10 +110,10 @@ ContactListView::onEditContact(unsigned row) { void ContactListView::loadHeaderState() { Settings settings; - ui->listView->header()->restoreState(settings.contactListHeaderState()); + ui->listView->header()->restoreState(settings.headerState("contactList")); } void ContactListView::storeHeaderState() { Settings settings; - settings.setContactListHeaderState(ui->listView->header()->saveState()); + settings.setHeaderState("contactList", ui->listView->header()->saveState()); } diff --git a/src/digitalchanneldialog.cc b/src/digitalchanneldialog.cc index 167d7306..c10c8e1c 100644 --- a/src/digitalchanneldialog.cc +++ b/src/digitalchanneldialog.cc @@ -137,6 +137,8 @@ DigitalChannelDialog::construct() { voxDefault->setChecked(false); voxValue->setEnabled(true); voxValue->setValue(_channel->vox()); } + + extensionView->setObjectName("digitalChannelExtension"); extensionView->setObject(_myChannel); if (! settings.showCommercialFeatures()) diff --git a/src/dmrcontactdialog.cc b/src/dmrcontactdialog.cc index fec70d89..4d41cd5b 100644 --- a/src/dmrcontactdialog.cc +++ b/src/dmrcontactdialog.cc @@ -95,6 +95,7 @@ DMRContactDialog::construct() { ui->numberLineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+"))); ui->ringCheckBox->setChecked(_myContact->ring()); + ui->extensionView->setObjectName("dmrContactExtension"); ui->extensionView->setObject(_myContact); if (! settings.showCommercialFeatures()) ui->tabWidget->tabBar()->hide(); diff --git a/src/dmriddialog.cc b/src/dmriddialog.cc index 9630e4d9..73c4e415 100644 --- a/src/dmriddialog.cc +++ b/src/dmriddialog.cc @@ -29,6 +29,8 @@ DMRIDDialog::construct() { if (! settings.showCommercialFeatures()) ui->tabWidget->tabBar()->hide(); + + ui->extensionView->setObjectName("dmrRadioIdExtension"); ui->extensionView->setObject(_myID); } diff --git a/src/dtmfcontactdialog.cc b/src/dtmfcontactdialog.cc index c8db4c3e..090abac2 100644 --- a/src/dtmfcontactdialog.cc +++ b/src/dtmfcontactdialog.cc @@ -38,6 +38,7 @@ DTMFContactDialog::construct() { ui->numberLineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9a-dA-D\\*#]+"))); ui->ringCheckBox->setChecked(_myContact->ring()); + ui->extensionView->setObjectName("dtmfContactExtension"); ui->extensionView->setObject(_myContact); if (! settings.showCommercialFeatures()) ui->tabWidget->tabBar()->hide(); diff --git a/src/extensionview.cc b/src/extensionview.cc index 90a12795..a08d63d6 100644 --- a/src/extensionview.cc +++ b/src/extensionview.cc @@ -2,6 +2,7 @@ #include "ui_extensionview.h" #include "propertydelegate.hh" #include "extensionwrapper.hh" +#include "settings.hh" #include @@ -21,6 +22,10 @@ ExtensionView::ExtensionView(QWidget *parent) : this, SLOT(onSelectionChanged(QItemSelection,QItemSelection))); connect(ui->create, SIGNAL(clicked(bool)), this, SLOT(onCreateExtension())); connect(ui->remove, SIGNAL(clicked(bool)), this, SLOT(onDeleteExtension())); + connect(ui->view->header(), SIGNAL(sectionCountChanged(int,int)), + this, SLOT(loadSectionState())); + connect(ui->view->header(), SIGNAL(sectionResized(int,int,int)), + this, SLOT(storeSectionState())); } ExtensionView::~ExtensionView() @@ -95,3 +100,15 @@ ExtensionView::onDeleteExtension() { _model->deleteInstanceAt(item); ui->view->selectionModel()->clearSelection(); } + +void +ExtensionView::loadSectionState() { + Settings settings; + ui->view->header()->restoreState(settings.headerState(this->objectName())); +} + +void +ExtensionView::storeSectionState() { + Settings settings; + settings.setHeaderState(this->objectName(), ui->view->header()->saveState()); +} diff --git a/src/extensionview.hh b/src/extensionview.hh index cdaa2ee0..993de09c 100644 --- a/src/extensionview.hh +++ b/src/extensionview.hh @@ -27,6 +27,8 @@ protected slots: void onSelectionChanged(const QItemSelection ¤t, const QItemSelection &last); void onCreateExtension(); void onDeleteExtension(); + void loadSectionState(); + void storeSectionState(); private: Ui::ExtensionView *ui; diff --git a/src/generalsettingsview.cc b/src/generalsettingsview.cc index bc345417..890a3ca9 100644 --- a/src/generalsettingsview.cc +++ b/src/generalsettingsview.cc @@ -35,6 +35,7 @@ GeneralSettingsView::GeneralSettingsView(Config *config, QWidget *parent) ui->totValue->setValue(config->settings()->tot()); ui->voxValue->setValue(config->settings()->vox()); + ui->extensionView->setObjectName("radioSettingsExtension"); ui->extensionView->setObject(config->settings()); connect(_config, SIGNAL(modified(ConfigItem*)), this, SLOT(onConfigModified())); diff --git a/src/gpssystemdialog.cc b/src/gpssystemdialog.cc index 66f79eff..c2b5ca17 100644 --- a/src/gpssystemdialog.cc +++ b/src/gpssystemdialog.cc @@ -49,6 +49,7 @@ GPSSystemDialog::construct() { i++; } + extensionView->setObjectName("dmrAPRSSystemExtension"); extensionView->setObject(_myGPSSystem); if (! settings.showCommercialFeatures()) return tabWidget->tabBar()->hide(); diff --git a/src/positioningsystemlistview.cc b/src/positioningsystemlistview.cc index d7c3cab2..1897f455 100644 --- a/src/positioningsystemlistview.cc +++ b/src/positioningsystemlistview.cc @@ -124,11 +124,11 @@ PositioningSystemListView::onHideGPSNote() { void PositioningSystemListView::loadPositioningSectionState() { Settings settings; - ui->listView->header()->restoreState(settings.positioningHeaderState()); + ui->listView->header()->restoreState(settings.headerState("positioningList")); } void PositioningSystemListView::storePositioningSectionState() { Settings settings; - settings.setPositioningHeaderState(ui->listView->header()->saveState()); + settings.setHeaderState("positioningList", ui->listView->header()->saveState()); } diff --git a/src/radioidlistview.cc b/src/radioidlistview.cc index 8b761bc9..3a736c50 100644 --- a/src/radioidlistview.cc +++ b/src/radioidlistview.cc @@ -106,11 +106,11 @@ RadioIDListView::onDefaultIDSelected(int idx) { void RadioIDListView::loadHeaderState() { - ui->listView->header()->restoreState(Settings().radioIdListHeaderState()); + ui->listView->header()->restoreState(Settings().headerState("radioIDList")); } void RadioIDListView::storeHeaderState() { - Settings().setRadioIdListHeaderState(ui->listView->header()->saveState()); + Settings().setHeaderState("radioIDList", ui->listView->header()->saveState()); } diff --git a/src/roamingzonedialog.cc b/src/roamingzonedialog.cc index 7c349923..da6e2fc4 100644 --- a/src/roamingzonedialog.cc +++ b/src/roamingzonedialog.cc @@ -31,6 +31,7 @@ RoamingZoneDialog::construct() { zoneName->setText(_myZone->name()); channelListView->setModel(new ChannelRefListWrapper(_myZone->channels(), channelListView)); + extensionView->setObjectName("roamingZoneExtension"); extensionView->setObject(_myZone); if (! settings.showCommercialFeatures()) tabWidget->tabBar()->hide(); diff --git a/src/rxgrouplistdialog.cc b/src/rxgrouplistdialog.cc index d27585aa..29a43a70 100644 --- a/src/rxgrouplistdialog.cc +++ b/src/rxgrouplistdialog.cc @@ -56,6 +56,7 @@ RXGroupListDialog::construct() { groupListName->setText(_myGroupList->name()); contactListView->setModel(new GroupListWrapper(_myGroupList, contactListView)); + extensionView->setObjectName("groupListExtension"); extensionView->setObject(_myGroupList); if (! settings.showCommercialFeatures()) tabWidget->tabBar()->hide(); diff --git a/src/scanlistdialog.cc b/src/scanlistdialog.cc index 32980ebd..45fcb897 100644 --- a/src/scanlistdialog.cc +++ b/src/scanlistdialog.cc @@ -57,6 +57,7 @@ ScanListDialog::construct() { channelListView->setModel(new ChannelRefListWrapper(_myScanList->channels(), channelListView)); + extensionView->setObjectName("scanListExtension"); extensionView->setObject(_myScanList); if (! settings.showCommercialFeatures()) tabWidget->tabBar()->hide(); diff --git a/src/settings.cc b/src/settings.cc index 7792e4f2..72f9e89f 100644 --- a/src/settings.cc +++ b/src/settings.cc @@ -288,39 +288,18 @@ Settings::setMainWindowState(const QByteArray &state) { } QByteArray -Settings::radioIdListHeaderState() const { - return value("radioIdListHeaderState", QByteArray()).toByteArray(); +Settings::headerState(const QString &objName) const { + if (objName.isEmpty()) + return QByteArray(); + QString key = QString("headerState/%1").arg(objName); + return value(key, QByteArray()).toByteArray(); } void -Settings::setRadioIdListHeaderState(const QByteArray &state) { - setValue("radioIdListHeaderState", state); -} - -QByteArray -Settings::contactListHeaderState() const { - return value("contactListHeaderState", QByteArray()).toByteArray(); -} -void -Settings::setContactListHeaderState(const QByteArray &state) { - setValue("contactListHeaderState", state); -} - -QByteArray -Settings::channelListHeaderState() const { - return value("channelListHeaderState", QByteArray()).toByteArray(); -} -void -Settings::setChannelListHeaderState(const QByteArray &state) { - setValue("channelListHeaderState", state); -} - -QByteArray -Settings::positioningHeaderState() const { - return value("positioningHeaderState", QByteArray()).toByteArray(); -} -void -Settings::setPositioningHeaderState(const QByteArray &state) { - setValue("positioningHeaderState", state); +Settings::setHeaderState(const QString &objName, const QByteArray &state) { + if (objName.isEmpty()) + return; + QString key = QString("headerState/%1").arg(objName); + setValue(key, state); } bool diff --git a/src/settings.hh b/src/settings.hh index bc4e0f9b..e5945906 100644 --- a/src/settings.hh +++ b/src/settings.hh @@ -76,17 +76,8 @@ public: QByteArray mainWindowState() const; void setMainWindowState(const QByteArray &state); - QByteArray radioIdListHeaderState() const; - void setRadioIdListHeaderState(const QByteArray &state); - - QByteArray contactListHeaderState() const; - void setContactListHeaderState(const QByteArray &state); - - QByteArray channelListHeaderState() const; - void setChannelListHeaderState(const QByteArray &state); - - QByteArray positioningHeaderState() const; - void setPositioningHeaderState(const QByteArray &state); + QByteArray headerState(const QString &objName) const; + void setHeaderState(const QString &objName, const QByteArray &state); bool isUpdated() const; void markUpdated(); diff --git a/src/zonedialog.cc b/src/zonedialog.cc index eaf1a3cb..2542bdd5 100644 --- a/src/zonedialog.cc +++ b/src/zonedialog.cc @@ -40,6 +40,7 @@ ZoneDialog::construct() { listAView->setModel(new ChannelRefListWrapper(_myZone->A())); listBView->setModel(new ChannelRefListWrapper(_myZone->B())); + extensionView->setObjectName("zoneExtension"); extensionView->setObject(_myZone); if (! settings.showCommercialFeatures()) { tabWidget->tabBar()->hide();