CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_state_manager.cpp
Go to the documentation of this file.
1
10#include <spdlog/spdlog.h>
11#include <algorithm>
12
14
16{
17 spdlog::debug("OperationStateManager: Constructed.");
18}
19
21{
22 std::lock_guard lock(m_mutex);
23 spdlog::debug("OperationStateManager::addOrUpdateOperation: Adding/updating operation '{}'.", descriptor.name);
24
25 // Find if an operation of the same type already exists
26 auto it = std::find_if(m_active_operations.begin(), m_active_operations.end(),
27 [&descriptor](const auto& op) { return op.type == descriptor.type; });
28
29 if (it != m_active_operations.end()) {
30 // Update existing operation
31 *it = descriptor;
32 spdlog::debug("OperationStateManager::addOrUpdateOperation: Updated operation '{}'.", descriptor.name);
33 } else {
34 // Add new operation
35 m_active_operations.push_back(descriptor);
36 spdlog::debug("OperationStateManager::addOrUpdateOperation: Added new operation '{}'.", descriptor.name);
37 }
38}
39
41{
42 std::lock_guard lock(m_mutex);
43 spdlog::debug("OperationStateManager::removeOperation: Removing operation type '{}'.", static_cast<int>(type));
44
45 // Remove operation of the specified type
46 m_active_operations.erase(
47 std::remove_if(m_active_operations.begin(), m_active_operations.end(),
48 [type](const auto& op) { return op.type == type; }),
49 m_active_operations.end()
50 );
51
52 spdlog::debug("OperationStateManager::removeOperation: Operation type '{}' removed (if it existed).", static_cast<int>(type));
53 // Note: applyCurrentOperationsToEngine() is no longer called here.
54 // That responsibility belongs to ImageControllerBase.
55}
56
58{
59 std::lock_guard lock(m_mutex);
60 spdlog::debug("OperationStateManager::clearAllOperations: Clearing all operations.");
61
62 m_active_operations.clear();
63 spdlog::debug("OperationStateManager::clearAllOperations: All operations cleared.");
64}
65
66std::vector<Core::Operations::OperationDescriptor> OperationStateManager::getActiveOperations() const
67{
68 std::lock_guard lock(m_mutex);
69 // Return a copy of the vector, safe for concurrent access by the caller
70 return m_active_operations;
71}
72
73} // namespace CaptureMoment::UI::Managers
void clearAllOperations()
Clears all active operations, resetting the state to the original image.
void addOrUpdateOperation(const Core::Operations::OperationDescriptor &descriptor)
Adds or updates an operation in the active state.
OperationStateManager()
Constructs an OperationStateManager.
std::vector< Core::Operations::OperationDescriptor > getActiveOperations() const
Gets the current list of active operation descriptors.
void removeOperation(Core::Operations::OperationType type)
Removes an operation of a specific type from the active state.
Manages the state of active image operations.
OperationType
Identifies the type of an image processing operation.
Descriptor of an operation with its parameters and unique identifier.
A universal container for operation settings with unique identifier.
std::string name
Human-readable name for display purposes. May include parameter values, e.g., "Brightness (100%)".
CaptureMoment — footer