Commit 5ae27f2c authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Remove uistatesaver

parent c9029dd4
Pipeline #33641 failed with stage
in 6 minutes and 27 seconds
......@@ -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
......
/*
SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "uistatesaver.h"
#include <KConfigGroup>
#include <QComboBox>
#include <QHeaderView>
#include <QSplitter>
#include <QTabWidget>
#include <QTreeView>
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<int> sizes = config.readEntry(splitter->objectName(), QList<int>());
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<T *>(w); \
if (obj) { \
Op::process(obj, config); \
continue; \
} \
}
template<typename Op, typename Config> static void processWidgets(QWidget *widget, Config config)
{
QList<QWidget *> widgets = widget->findChildren<QWidget *>();
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<Saver, KConfigGroup &>(widget, config);
}
void UiStateSaver::restoreState(QWidget *widget, const KConfigGroup &config)
{
processWidgets<Restorer, const KConfigGroup &>(widget, config);
}
/*
SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
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 <vkrause@kde.org>
* @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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment