12#include <QtCore/QDebug>
27const char *
const kGroup =
"ui";
28const char *
const kNamesKey =
"workspaceNames";
29const char *
const kCurrentKey =
"currentWorkspace";
31const char *
const kWorkspaceGroup =
"workspace";
32const char *
const kDockStateKey =
"dockState";
33const char *
const kPageKey =
"currentPage";
37QxWorkspaceManagerPrivate::QxWorkspaceManagerPrivate() =
default;
43 return m_shell ? m_shell->settings() :
Q_NULLPTR;
46QStringList QxWorkspaceManagerPrivate::names()
const
53 settings->beginGroup(QString::fromLatin1(kGroup));
54 const QStringList list = settings->stringListValue(QString::fromLatin1(kNamesKey));
59void QxWorkspaceManagerPrivate::setNames(
const QStringList &list)
66 settings->beginGroup(QString::fromLatin1(kGroup));
69 settings->remove(QString::fromLatin1(kNamesKey));
71 settings->setValue(QString::fromLatin1(kNamesKey), list);
76QString QxWorkspaceManagerPrivate::normalize(
const QString &
name)
78 return name.trimmed();
81QString QxWorkspaceManagerPrivate::current()
const
88 settings->beginGroup(QString::fromLatin1(kGroup));
89 const QString
name = settings->stringValue(QString::fromLatin1(kCurrentKey));
94void QxWorkspaceManagerPrivate::setCurrent(
const QString &
name)
108 settings->beginGroup(QString::fromLatin1(kGroup));
109 if (
name.isEmpty()) {
110 settings->remove(QString::fromLatin1(kCurrentKey));
112 settings->setValue(QString::fromLatin1(kCurrentKey),
name);
114 settings->endGroup();
117 Q_EMIT q->currentWorkspaceChanged(
name);
120QxWorkspaceManager::QxWorkspaceManager(
QxAppShell *shell, QObject *parent)
124 d_ptr->setPublic(
this);
142 return d->settings();
148 return d->names().count();
173 qWarning(
"QxWorkspaceManager: there is no shell to save a layout of");
179 qWarning(
"QxWorkspaceManager: a workspace needs a name");
185 QStringList list = d->names();
186 if (!list.contains(key)) {
194 settings->
setValue(QString::fromLatin1(kDockStateKey), d->m_shell->dockWindow()->saveState());
195 settings->
setValue(QString::fromLatin1(kPageKey), d->m_shell->currentPageId());
211 qWarning(
"QxWorkspaceManager: there is no shell to apply a layout to");
216 if (!d->names().contains(key)) {
217 qWarning(
"QxWorkspaceManager: there is no workspace called \"%s\"", qPrintable(key));
225 const QByteArray dockState =
settings->
value(QString::fromLatin1(kDockStateKey)).toByteArray();
231 if (dockState.isEmpty()) {
232 qWarning(
"QxWorkspaceManager: the workspace \"%s\" has no layout stored", qPrintable(key));
235 if (!d->m_shell->dockWindow()->restoreState(dockState)) {
239 qWarning(
"QxWorkspaceManager: the layout of \"%s\" does not fit this shell", qPrintable(key));
243 d->m_shell->setCurrentPage(pageId);
254 QStringList list = d->names();
255 if (!list.removeOne(key)) {
271 if (d->current() == key) {
272 d->setCurrent(QString());
284 if (oldKey.isEmpty() || newKey.isEmpty()) {
285 qWarning(
"QxWorkspaceManager: a workspace needs a name");
289 QStringList list = d->names();
290 const int index = list.indexOf(oldKey);
294 if (oldKey == newKey) {
297 if (list.contains(newKey)) {
298 qWarning(
"QxWorkspaceManager: \"%s\" is already taken", qPrintable(newKey));
308 const QVariant dockState =
settings->
value(QString::fromLatin1(kDockStateKey));
322 list.replace(index, newKey);
328 if (d->current() == oldKey) {
329 d->setCurrent(newKey);
343 const QStringList list = d->names();
344 if (list.isEmpty()) {
352 for (
const QString &
name : list) {
359 d->setNames(QStringList());
360 d->setCurrent(QString());
365 for (
const QString &
name : list) {
The window skeleton of a ribbon application.
The state behind QxWorkspaceManager: the shell it belongs to and the paths the workspaces are written...
static QString normalize(const QString &name)
The name as it is stored and looked up: without surrounding space.
The named layouts of one shell.
QxCore::QxSettings * settings() const
The settings object the workspaces are stored in - the one the shell uses, so there is a single confi...
void workspaceRemoved(const QString &name)
A workspace was forgotten - also emitted once per name by clearWorkspaces().
int count() const
How many workspaces are stored.
bool applyWorkspace(const QString &name)
Brings back the layout stored under name: the dock state is restored and the page that was in front c...
void workspaceSaved(const QString &name)
A workspace was stored, first time or overwriting.
~QxWorkspaceManager() override
QStringList workspaceNames() const
Their names, in the order they were saved - the order a menu wants.
QString currentWorkspace() const
The workspace applied or saved last, empty when there is none.
bool contains(const QString &name) const
Whether a workspace called name is stored.
void clearWorkspaces()
Forgets every workspace.
QxAppShell * shell() const
The shell whose layout this manages; null only for a default-built one.
bool removeWorkspace(const QString &name)
Forgets the workspace called name.
bool saveWorkspace(const QString &name)
Stores the dock layout and the visible page under name, which becomes the current workspace.
void workspaceApplied(const QString &name)
A workspace was brought back on screen.
bool renameWorkspace(const QString &from, const QString &to)
Moves everything stored under from to to, keeping its place in the order.
Thin wrapper around QSettings that keeps call sites free of the usual boilerplate: typed accessors wi...
QSettings * settings() const
The underlying QSettings instance, never null.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
QString stringValue(const QString &key, const QString &defaultValue=QString()) const
void beginGroup(const QString &prefix)
void remove(const QString &key)
void setValue(const QString &key, const QVariant &value)
#define QX_APP_END_NAMESPACE
#define Q_NULLPTR
Copyleft (C) 2025 maminjie canpool@163.com SPDX-License-Identifier: MulanPSL-2.0
#define QX_APP_BEGIN_NAMESPACE
#define QX_FINI_PRIVATE()
#define QX_CORE_USE_NAMESPACE
#define QX_CORE_PREPEND_NAMESPACE(name)
#define QX_DOCK_USE_NAMESPACE
QtMessageHandler previous