CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_model_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5#include <QQmlContext>
6#include <type_traits>
7
10
11#include <spdlog/spdlog.h>
12
13namespace CaptureMoment::UI {
14
15namespace Models::Manager {
16
26class OperationModelManager {
27public:
32 explicit OperationModelManager();
33
39
40 // Disable copy and assignment
43
49 [[nodiscard]] bool createBasicAdjustmentModels();
50
57 template<typename... TModels>
58 [[nodiscard]] bool createModels();
59
66 [[nodiscard]] bool registerModelsToQml(QQmlContext* context);
67
74 [[nodiscard]] const std::vector<std::shared_ptr<Models::Operations::OperationProvider>>& getModels() const { return m_operation_models; }
75
83 [[nodiscard]] const std::vector<std::shared_ptr<UI::Models::Operations::BaseAdjustmentModel>>& getBaseAdjustmentModels() const { return m_base_adjustment_models; }
84
85private:
90 std::vector<std::shared_ptr<Models::Operations::OperationProvider>> m_operation_models;
91
98 std::vector<std::shared_ptr<UI::Models::Operations::BaseAdjustmentModel>> m_base_adjustment_models;
99
106 template<typename T>
107 [[nodiscard]] bool createAndAddModel() {
108 static_assert(std::is_base_of_v<UI::Models::Operations::OperationProvider, T>, "T must derive from OperationProvider");
109
110 auto model = std::make_shared<T>();
111 if (!model) {
112 spdlog::error("OperationModelManager::createAndAddModel: Failed to create model of type {}", typeid(T).name());
113 return false;
114 }
115 spdlog::debug("OperationModelManager::createAndAddModel: Created model of type {}", typeid(T).name());
116
117 QString qmlName = model->name().toLower() + "Control";
118 spdlog::debug("OperationModelManager::createAndAddModel: Generated QML name '{}'", qmlName.toStdString());
119
120 m_operation_models.push_back(model);
121
122 // If it's a BaseAdjustmentModel, add it to the specific list using dynamic_pointer_cast
123 if constexpr (std::is_base_of_v<UI::Models::Operations::BaseAdjustmentModel, T>) {
124 auto adjustment_model_ptr = std::dynamic_pointer_cast<UI::Models::Operations::BaseAdjustmentModel>(model);
125 if (adjustment_model_ptr) {
126 m_base_adjustment_models.push_back(adjustment_model_ptr);
127 } else {
128 // This should ideally not happen if the static_assert holds, but good for safety
129 spdlog::warn("OperationModelManager::createAndAddModel: Failed dynamic_pointer_cast for type {}", typeid(T).name());
130 }
131 }
132
133 return true;
134 }
135};
136
137} // namespace Models::Manager
138
139} // namespace CaptureMoment::UI
Generic Qt base class for single-value adjustment operations (e.g., Brightness, Contrast,...
Manages the creation, storage, and QML registration of operation model instances.
const std::vector< std::shared_ptr< Models::Operations::OperationProvider > > & getModels() const
Gets a const reference to the vector of created operation model instances. Provides access to the int...
bool registerModelsToQml(QQmlContext *context)
Registers the created operation models to the QML context. Makes the models available under their gen...
bool createModels()
Creates instances of specified operation model types. This is a variadic template method allowing for...
bool createBasicAdjustmentModels()
Creates instances of basic adjustment operation models. This method typically creates models like Bri...
OperationModelManager()
Constructs an OperationModelManager. Initializes the manager without requiring external dependencies ...
~OperationModelManager()=default
Destructor. Cleans up the owned operation model instances.
const std::vector< std::shared_ptr< UI::Models::Operations::BaseAdjustmentModel > > & getBaseAdjustmentModels() const
Gets a const reference to the vector of created BaseAdjustmentModel instances. Provides access to the...
OperationModelManager(const OperationModelManager &)=delete
OperationModelManager & operator=(const OperationModelManager &)=delete
Generic Qt base class for operation models with QObject infrastructure.
CaptureMoment — footer