From 22abbc1d41836027a963e7326e9c8cae0c0dd079 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 4 Nov 2021 11:34:00 +0800 Subject: [PATCH] Store Qt6 table header states under a different key --- src/base/preferences.cpp | 72 +++++++++++++++++++++++++++++++++ src/gui/addnewtorrentdialog.cpp | 10 +++-- src/gui/addnewtorrentdialog.h | 4 +- src/gui/cookiesdialog.cpp | 21 +++++----- src/gui/cookiesdialog.h | 5 +++ src/gui/previewselectdialog.cpp | 4 ++ 6 files changed, 101 insertions(+), 15 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 296241191..7bbf961f4 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1265,12 +1265,20 @@ void Preferences::setMainGeometry(const QByteArray &geometry) QByteArray Preferences::getMainVSplitterState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/MainWindow/VSplitterState").toByteArray(); +#else return value("MainWindow/qt5/vsplitterState").toByteArray(); +#endif } void Preferences::setMainVSplitterState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/MainWindow/VSplitterState", state); +#else setValue("MainWindow/qt5/vsplitterState", state); +#endif } QString Preferences::getMainLastDir() const @@ -1285,12 +1293,20 @@ void Preferences::setMainLastDir(const QString &path) QByteArray Preferences::getPeerListState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/TorrentProperties/PeerListState").toByteArray(); +#else return value("TorrentProperties/Peers/qt5/PeerListState").toByteArray(); +#endif } void Preferences::setPeerListState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/TorrentProperties/PeerListState", state); +#else setValue("TorrentProperties/Peers/qt5/PeerListState", state); +#endif } QString Preferences::getPropSplitterSizes() const @@ -1305,12 +1321,20 @@ void Preferences::setPropSplitterSizes(const QString &sizes) QByteArray Preferences::getPropFileListState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/TorrentProperties/FilesListState").toByteArray(); +#else return value("TorrentProperties/qt5/FilesListState").toByteArray(); +#endif } void Preferences::setPropFileListState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/TorrentProperties/FilesListState", state); +#else setValue("TorrentProperties/qt5/FilesListState", state); +#endif } int Preferences::getPropCurTab() const @@ -1335,12 +1359,20 @@ void Preferences::setPropVisible(const bool visible) QByteArray Preferences::getPropTrackerListState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/TorrentProperties/TrackerListState").toByteArray(); +#else return value("TorrentProperties/Trackers/qt5/TrackerListState").toByteArray(); +#endif } void Preferences::setPropTrackerListState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/TorrentProperties/TrackerListState", state); +#else setValue("TorrentProperties/Trackers/qt5/TrackerListState", state); +#endif } QSize Preferences::getRssGeometrySize() const @@ -1355,12 +1387,20 @@ void Preferences::setRssGeometrySize(const QSize &geometry) QByteArray Preferences::getRssHSplitterSizes() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/RSSFeedDownloader/HSplitterSizes").toByteArray(); +#else return value("RssFeedDownloader/qt5/hsplitterSizes").toByteArray(); +#endif } void Preferences::setRssHSplitterSizes(const QByteArray &sizes) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/RSSFeedDownloader/HSplitterSizes", sizes); +#else setValue("RssFeedDownloader/qt5/hsplitterSizes", sizes); +#endif } QStringList Preferences::getRssOpenFolders() const @@ -1375,32 +1415,56 @@ void Preferences::setRssOpenFolders(const QStringList &folders) QByteArray Preferences::getRssSideSplitterState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/RSSWidget/SideSplitterState").toByteArray(); +#else return value("GUI/RSSWidget/qt5/splitter_h").toByteArray(); +#endif } void Preferences::setRssSideSplitterState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/RSSWidget/SideSplitterState", state); +#else setValue("GUI/RSSWidget/qt5/splitter_h", state); +#endif } QByteArray Preferences::getRssMainSplitterState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/RSSWidget/MainSplitterState").toByteArray(); +#else return value("GUI/RSSWidget/qt5/splitterMain").toByteArray(); +#endif } void Preferences::setRssMainSplitterState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/RSSWidget/MainSplitterState", state); +#else setValue("GUI/RSSWidget/qt5/splitterMain", state); +#endif } QByteArray Preferences::getSearchTabHeaderState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/SearchTab/HeaderState").toByteArray(); +#else return value("SearchTab/qt5/HeaderState").toByteArray(); +#endif } void Preferences::setSearchTabHeaderState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/SearchTab/HeaderState", state); +#else setValue("SearchTab/qt5/HeaderState", state); +#endif } bool Preferences::getRegexAsFilteringPatternForSearchJob() const @@ -1495,12 +1559,20 @@ void Preferences::setTransSelFilter(const int index) QByteArray Preferences::getTransHeaderState() const { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return value("GUI/Qt6/TransferList/HeaderState").toByteArray(); +#else return value("TransferList/qt5/HeaderState").toByteArray(); +#endif } void Preferences::setTransHeaderState(const QByteArray &state) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + setValue("GUI/Qt6/TransferList/HeaderState", state); +#else setValue("TransferList/qt5/HeaderState", state); +#endif } bool Preferences::getRegexAsFilteringPatternForTransferList() const diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 1027a3ae4..eae0153be 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -82,10 +82,14 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP , m_ui(new Ui::AddNewTorrentDialog) , m_torrentParams(inParams) , m_storeDialogSize(SETTINGS_KEY("DialogSize")) - , m_storeSplitterState(SETTINGS_KEY("SplitterState")) , m_storeDefaultCategory(SETTINGS_KEY("DefaultCategory")) , m_storeRememberLastSavePath(SETTINGS_KEY("RememberLastSavePath")) , m_storeTreeHeaderState(SETTINGS_KEY("TreeHeaderState")) +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + , m_storeSplitterState("GUI/Qt6/" SETTINGS_KEY("SplitterState")) +#else + , m_storeSplitterState(SETTINGS_KEY("SplitterState")) +#endif { // TODO: set dialog file properties using m_torrentParams.filePriorities m_ui->setupUi(this); @@ -715,8 +719,8 @@ void AddNewTorrentDialog::setupTreeview() // List files in torrent m_contentModel->model()->setupModelData(m_torrentInfo); - if (!m_storeTreeHeaderState.get().isEmpty()) - m_ui->contentTreeView->header()->restoreState(m_storeTreeHeaderState); + if (const QByteArray state = m_storeTreeHeaderState; !state.isEmpty()) + m_ui->contentTreeView->header()->restoreState(state); // Hide useless columns after loading the header state m_ui->contentTreeView->hideColumn(PROGRESS); diff --git a/src/gui/addnewtorrentdialog.h b/src/gui/addnewtorrentdialog.h index b36241c36..0fb98dacd 100644 --- a/src/gui/addnewtorrentdialog.h +++ b/src/gui/addnewtorrentdialog.h @@ -118,8 +118,8 @@ private: BitTorrent::AddTorrentParams m_torrentParams; SettingValue m_storeDialogSize; - SettingValue m_storeSplitterState; SettingValue m_storeDefaultCategory; SettingValue m_storeRememberLastSavePath; - CachedSettingValue m_storeTreeHeaderState; + SettingValue m_storeTreeHeaderState; + SettingValue m_storeSplitterState; }; diff --git a/src/gui/cookiesdialog.cpp b/src/gui/cookiesdialog.cpp index d1281131e..a65958db1 100644 --- a/src/gui/cookiesdialog.cpp +++ b/src/gui/cookiesdialog.cpp @@ -32,20 +32,23 @@ #include "base/global.h" #include "base/net/downloadmanager.h" -#include "base/settingsstorage.h" #include "cookiesmodel.h" #include "ui_cookiesdialog.h" #include "uithememanager.h" #include "utils.h" -#define SETTINGS_KEY(name) QStringLiteral("CookiesDialog/" name) -const QString KEY_SIZE = SETTINGS_KEY("Size"); -const QString KEY_COOKIESVIEWSTATE = SETTINGS_KEY("CookiesViewState"); +#define SETTINGS_KEY(name) "CookiesDialog/" name CookiesDialog::CookiesDialog(QWidget *parent) : QDialog(parent) , m_ui(new Ui::CookiesDialog) , m_cookiesModel(new CookiesModel(Net::DownloadManager::instance()->allCookies(), this)) + , m_storeDialogSize(SETTINGS_KEY("Size")) +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + , m_storeViewState("GUI/Qt6/" SETTINGS_KEY("ViewState")) +#else + , m_storeViewState(SETTINGS_KEY("CookiesViewState")) +#endif { m_ui->setupUi(this); @@ -61,16 +64,14 @@ CookiesDialog::CookiesDialog(QWidget *parent) m_cookiesModel->index(0, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - Utils::Gui::resize(this, SettingsStorage::instance()->loadValue(KEY_SIZE)); - m_ui->treeView->header()->restoreState( - SettingsStorage::instance()->loadValue(KEY_COOKIESVIEWSTATE)); + Utils::Gui::resize(this, m_storeDialogSize); + m_ui->treeView->header()->restoreState(m_storeViewState); } CookiesDialog::~CookiesDialog() { - SettingsStorage::instance()->storeValue(KEY_SIZE, size()); - SettingsStorage::instance()->storeValue( - KEY_COOKIESVIEWSTATE, m_ui->treeView->header()->saveState()); + m_storeDialogSize = size(); + m_storeViewState = m_ui->treeView->header()->saveState(); delete m_ui; } diff --git a/src/gui/cookiesdialog.h b/src/gui/cookiesdialog.h index 7a8e0c9fa..9bb181880 100644 --- a/src/gui/cookiesdialog.h +++ b/src/gui/cookiesdialog.h @@ -30,6 +30,8 @@ #include +#include "base/settingvalue.h" + class CookiesModel; namespace Ui @@ -55,4 +57,7 @@ private slots: private: Ui::CookiesDialog *m_ui; CookiesModel *m_cookiesModel; + + SettingValue m_storeDialogSize; + SettingValue m_storeViewState; }; diff --git a/src/gui/previewselectdialog.cpp b/src/gui/previewselectdialog.cpp index 6c8f9ab4f..a2b64137f 100644 --- a/src/gui/previewselectdialog.cpp +++ b/src/gui/previewselectdialog.cpp @@ -52,7 +52,11 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr , m_ui(new Ui::PreviewSelectDialog) , m_torrent(torrent) , m_storeDialogSize(SETTINGS_KEY("Size")) +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + , m_storeTreeHeaderState("GUI/Qt6/" SETTINGS_KEY("HeaderState")) +#else , m_storeTreeHeaderState(SETTINGS_KEY("HeaderState")) +#endif { m_ui->setupUi(this);