CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
serializer_controller.cpp
Go to the documentation of this file.
1
9#include <spdlog/spdlog.h>
10
11namespace CaptureMoment::UI {
12
13namespace Serializer {
14
27SerializerController::SerializerController(std::unique_ptr<CaptureMoment::Core::Serializer::FileSerializerManager> file_serializer_manager, QObject* parent)
28 : QObject(parent), m_file_serializer_manager(std::move(file_serializer_manager)) {
29 if (!m_file_serializer_manager) {
30 spdlog::error("SerializerController: Constructor received a null FileSerializerManager.");
31 throw std::invalid_argument("SerializerController: FileSerializerManager cannot be null.");
32 }
33 spdlog::debug("SerializerController: Constructed with FileSerializerManager.");
34}
35
40 spdlog::debug("SerializerController: Destroyed.");
41}
42
52void SerializerController::saveOperations(const QString& image_path, const std::vector<CaptureMoment::Core::Operations::OperationDescriptor>& operations) {
53 if (!m_file_serializer_manager)
54 {
55 spdlog::error("SerializerController::saveOperations: FileSerializerManager is null.");
56 emit operationsSaveFailed("Internal error: Serialization manager not initialized.");
57 return;
58 }
59
60 if (image_path.isEmpty())
61 {
62 spdlog::error("SerializerController::saveOperations: Image path is empty.");
63 emit operationsSaveFailed("Image path is empty.");
64 return;
65 }
66
67 spdlog::debug("SerializerController::saveOperations: Attempting to save {} operations for image: {}", operations.size(), image_path.toStdString());
68
69 bool success = m_file_serializer_manager->saveToFile(image_path.toStdString(), operations);
70
71 if (success) {
72 spdlog::info("SerializerController::saveOperations: Successfully saved operations for image: {}", image_path.toStdString());
73 emit operationsSaved();
74 } else {
75 spdlog::error("SerializerController::saveOperations: Failed to save operations for image: {}", image_path.toStdString());
76 emit operationsSaveFailed("Failed to write operations to file.");
77 }
78}
79
89void SerializerController::loadOperations(const QString& image_path) {
90 if (!m_file_serializer_manager)
91 {
92 spdlog::error("SerializerController::loadOperations: FileSerializerManager is null.");
93 emit operationsLoadFailed("Internal error: Serialization manager not initialized.");
94 return;
95 }
96
97 if (image_path.isEmpty())
98 {
99 spdlog::error("SerializerController::loadOperations: Image path is empty.");
100 emit operationsLoadFailed("Image path is empty.");
101 return;
102 }
103
104 spdlog::debug("SerializerController::loadOperations: Attempting to load operations for image: {}", image_path.toStdString());
105 std::vector<CaptureMoment::Core::Operations::OperationDescriptor> loaded_ops = m_file_serializer_manager->loadFromFile(image_path.toStdString());
106
107 if (loaded_ops.empty())
108 {
109 spdlog::info("SerializerController::loadOperations: No operations loaded from file for image: {} (file might not exist or be empty)", image_path.toStdString());
111 return;
112 }
113
114 spdlog::info("SerializerController::loadOperations: Successfully loaded {} operations from file for image: {}", loaded_ops.size(), image_path.toStdString());
115 emit operationsLoaded(loaded_ops);
116}
117
118} // namespace Serializer
119
120} // namespace CaptureMoment::UI
std::vector< Operations::OperationDescriptor > loadFromFile(std::string_view source_image_path) const
Loads a list of operations from a file associated with the source image path.
bool saveToFile(std::string_view source_image_path, std::span< const Operations::OperationDescriptor > operations) const
Saves the provided list of operations to a file associated with the source image path.
void saveOperations(const QString &image_path, const std::vector< CaptureMoment::Core::Operations::OperationDescriptor > &operations)
Saves the provided list of operations to a file associated with the given image path.
SerializerController(std::unique_ptr< CaptureMoment::Core::Serializer::FileSerializerManager > file_serializer_manager, QObject *parent=nullptr)
Constructs a UISerializerManager.
void operationsSaved()
Signal emitted when operations are successfully saved to a file.
void operationsSaveFailed(const QString &error_msg)
Signal emitted when the operation to save operations fails.
void operationsLoadFailed(const QString &error_msg)
Signal emitted when the operation to load operations fails.
void operationsNotFoundOnLoad()
Signal emitted when no operations were found in the file during load.
void operationsLoaded(const std::vector< CaptureMoment::Core::Operations::OperationDescriptor > &operations)
Signal emitted when operations are successfully loaded from a file.
void loadOperations(const QString &image_path)
Loads a list of operations from a file associated with the given image path.
UI manager for handling file-based serialization and deserialization of image operations.
CaptureMoment — footer