diff --git a/src/libkdepim/CMakeLists.txt b/src/libkdepim/CMakeLists.txt index 6a78b05158bb9f6d176de80a1cdfd6531cd3081c..9f5eaff42e8394ff07df226a2da59e384a386700 100644 --- a/src/libkdepim/CMakeLists.txt +++ b/src/libkdepim/CMakeLists.txt @@ -28,7 +28,6 @@ set(kdepim_widgets_LIB_SRCS ) set(kdepim_misc_LIB_SRCS - misc/uistatesaver.cpp misc/lineeditcatchreturnkey.cpp ) @@ -96,7 +95,6 @@ ecm_generate_headers(libkdepim_Camelcasewidgets_HEADERS ecm_generate_headers(libkdepim_Camelcasemisc_HEADERS HEADER_NAMES - UiStateSaver LineEditCatchReturnKey REQUIRED_HEADERS libkdepim_misc_HEADERS PREFIX Libkdepim diff --git a/src/libkdepim/misc/uistatesaver.cpp b/src/libkdepim/misc/uistatesaver.cpp deleted file mode 100644 index fd76c42181d6b2b43270522306bff8f65e3b6278..0000000000000000000000000000000000000000 --- a/src/libkdepim/misc/uistatesaver.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Volker Krause - - SPDX-License-Identifier: LGPL-2.0-or-later -*/ - -#include "uistatesaver.h" - -#include - -#include -#include -#include -#include -#include - -using namespace KPIM; - -struct Saver { - static void process(QSplitter *splitter, KConfigGroup &config) - { - if (splitter->sizes().count(0) == splitter->sizes().count()) { - return; - } - config.writeEntry(splitter->objectName(), splitter->sizes()); - } - - static void process(QTabWidget *tab, KConfigGroup &config) - { - config.writeEntry(tab->objectName(), tab->currentIndex()); - } - - static void process(QTreeView *tv, KConfigGroup &config) - { - config.writeEntry(tv->objectName(), tv->header()->saveState()); - } - - static void process(QComboBox *cb, KConfigGroup &config) - { - config.writeEntry(cb->objectName(), cb->currentIndex()); - } -}; - -struct Restorer { - static void process(QSplitter *splitter, const KConfigGroup &config) - { - const QList sizes = config.readEntry(splitter->objectName(), QList()); - if (!sizes.isEmpty() && splitter->count() == sizes.count() && sizes.count() != sizes.count(0)) { - splitter->setSizes(sizes); - } - } - - static void process(QTabWidget *tab, const KConfigGroup &config) - { - const int index = config.readEntry(tab->objectName(), -1); - if (index >= 0 && index < tab->count()) { - tab->setCurrentIndex(index); - } - } - - static void process(QTreeView *tv, const KConfigGroup &config) - { - const QByteArray state = config.readEntry(tv->objectName(), QByteArray()); - if (!state.isEmpty()) { - tv->header()->restoreState(state); - } - } - - static void process(QComboBox *cb, const KConfigGroup &config) - { - const int index = config.readEntry(cb->objectName(), -1); - if (index >= 0 && index < cb->count()) { - cb->setCurrentIndex(index); - } - } -}; - -#define PROCESS_TYPE(T) \ - { \ - T *obj = qobject_cast(w); \ - if (obj) { \ - Op::process(obj, config); \ - continue; \ - } \ - } - -template static void processWidgets(QWidget *widget, Config config) -{ - QList widgets = widget->findChildren(); - widgets << widget; - for (QWidget *w : qAsConst(widgets)) { - if (w->objectName().isEmpty()) { - continue; - } - PROCESS_TYPE(QSplitter); - PROCESS_TYPE(QTabWidget); - PROCESS_TYPE(QTreeView); - PROCESS_TYPE(QComboBox); - } -} - -#undef PROCESS_TYPE - -void UiStateSaver::saveState(QWidget *widget, KConfigGroup &config) -{ - processWidgets(widget, config); -} - -void UiStateSaver::restoreState(QWidget *widget, const KConfigGroup &config) -{ - processWidgets(widget, config); -} diff --git a/src/libkdepim/misc/uistatesaver.h b/src/libkdepim/misc/uistatesaver.h deleted file mode 100644 index 9f3ee5ae52f9e24b5f27faca5674ad325f5d78b0..0000000000000000000000000000000000000000 --- a/src/libkdepim/misc/uistatesaver.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Volker Krause - - SPDX-License-Identifier: LGPL-2.0-or-later -*/ - -#ifndef UISTATESAVER_H -#define UISTATESAVER_H - -#include "kdepim_export.h" - -class QWidget; -class KConfigGroup; - -namespace KPIM { -/** - * @short Methods to save and restore the UI state of an application. - * - * This namespace provides methods that automatically save and restore - * the state of various UI elements to/from a configuration group. - * - * The following widgets are supported so far: - * - QSplitter - * - QTabWidget - * - QTreeView - * - QComboBox - * - * @note The widgets need to have set an objectName, otherwise they are ignored - * on processing. - * - * @author Volker Krause - * @since 4.5 - */ -namespace UiStateSaver { -/** - * Saves the state of @p widget and all its sub-widgets to @p config. - * @param widget The top-level widget which state should be saved. - * @param config The config group the settings should be written to. - */ -KDEPIM_EXPORT void saveState(QWidget *widget, KConfigGroup &config); - -/** - * Restores the UI state of @p widget and all its sub-widgets from @p config. - * @param widget The top-level widget which state should be restored. - * @param config The config gorup the settings should be read from. - */ -KDEPIM_EXPORT void restoreState(QWidget *widget, const KConfigGroup &config); -} -} - -#endif