-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App: save/restore application UI state
Relates to GitHub #277
- Loading branch information
1 parent
3b4d7e6
commit 0ce65c3
Showing
18 changed files
with
228 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "app_ui_state.h" | ||
|
||
#include "../qtcommon/qtcore_utils.h" | ||
#include <QtCore/QDataStream> | ||
#include <QtCore/QIODevice> | ||
|
||
namespace Mayo { | ||
|
||
template<> const char PropertyAppUiState::TypeName[] = "Mayo::PropertyAppUiState"; | ||
|
||
QByteArray AppUiState::toBlob(const AppUiState& state) | ||
{ | ||
QByteArray blob; | ||
QDataStream stream(&blob, QIODevice::WriteOnly); | ||
stream << QtCoreUtils::QByteArray_frowRawData(std::string_view{PropertyAppUiState::TypeName}); | ||
constexpr uint32_t version = 1; | ||
stream << version; | ||
stream << state.mainWindowGeometry; | ||
stream << state.pageDocuments_isLeftSideBarVisible; | ||
return blob; | ||
|
||
} | ||
|
||
AppUiState AppUiState::fromBlob(const QByteArray& blob, bool* ok) | ||
{ | ||
auto fnSetOk = [=](bool v) { | ||
if (ok) | ||
*ok = v; | ||
}; | ||
|
||
fnSetOk(false); | ||
AppUiState state; | ||
QDataStream stream(blob); | ||
QByteArray identifier; | ||
stream >> identifier; | ||
if (identifier == PropertyAppUiState::TypeName) { | ||
uint32_t version = 0; | ||
stream >> version; | ||
if (version == 1) { | ||
stream >> state.mainWindowGeometry; | ||
stream >> state.pageDocuments_isLeftSideBarVisible; | ||
fnSetOk(true); | ||
} | ||
} | ||
|
||
return state; | ||
} | ||
|
||
} // namespace Mayo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/**************************************************************************** | ||
** Copyright (c) 2024, Fougue Ltd. <https://www.fougue.pro> | ||
** All rights reserved. | ||
** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "../base/property_builtins.h" | ||
#include <QtCore/QByteArray> | ||
|
||
namespace Mayo { | ||
|
||
// Stores the UI state of the main application widgets | ||
struct AppUiState { | ||
QByteArray mainWindowGeometry; // Provided by QWidget::saveGeometry() | ||
bool pageDocuments_isLeftSideBarVisible = true; | ||
|
||
// Serialization functions | ||
static QByteArray toBlob(const AppUiState& state); | ||
static AppUiState fromBlob(const QByteArray& blob, bool* ok = nullptr); | ||
}; | ||
using PropertyAppUiState = GenericProperty<AppUiState>; | ||
|
||
} // namespace Mayo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.