REfining the Config behavior, trying to pr next

This commit is contained in:
samcake 2017-04-10 19:01:49 -07:00
parent 16e6f0900d
commit 4a47737d0b
6 changed files with 56 additions and 61 deletions

View file

@ -19,6 +19,8 @@ class ZoneRendererConfig : public render::Task::Config {
Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
public: public:
ZoneRendererConfig() : render::Task::Config(false) {}
int maxDrawn { -1 }; int maxDrawn { -1 };
signals: signals:

View file

@ -52,7 +52,7 @@ class DrawBounds {
public: public:
class Config : public render::JobConfig { class Config : public render::JobConfig {
public: public:
Config() : JobConfig(false) {} Config(bool enabled = false) : JobConfig(enabled) {}
}; };
using Inputs = render::ItemBounds; using Inputs = render::ItemBounds;

View file

@ -34,7 +34,7 @@ public:
} }
}; };
Engine::Engine() : Task("Engine", EngineTask::JobModel::factoryModel()), Engine::Engine() : Task("Engine", EngineTask::JobModel::create()),
_sceneContext(std::make_shared<SceneContext>()), _sceneContext(std::make_shared<SceneContext>()),
_renderContext(std::make_shared<RenderContext>()) _renderContext(std::make_shared<RenderContext>())
{ {

View file

@ -15,13 +15,42 @@
using namespace render; using namespace render;
void TaskConfig::connectChildConfig(QConfigPointer childConfig, const std::string& name) {
childConfig->setParent(this);
childConfig->setObjectName(name.c_str());
// Connect loaded->refresh
QObject::connect(childConfig.get(), SIGNAL(loaded()), this, SLOT(refresh()));
static const char* DIRTY_SIGNAL = "dirty()";
if (childConfig->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
// Connect dirty->refresh if defined
QObject::connect(childConfig.get(), SIGNAL(dirty()), this, SLOT(refresh()));
}
}
void TaskConfig::transferChildrenConfigs(QConfigPointer source) {
if (!source) {
return;
}
// Transfer children to the new configuration
auto children = source->children();
for (auto& child : children) {
child->setParent(this);
QObject::connect(child, SIGNAL(loaded()), this, SLOT(refresh()));
static const char* DIRTY_SIGNAL = "dirty()";
if (child->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
// Connect dirty->refresh if defined
QObject::connect(child, SIGNAL(dirty()), this, SLOT(refresh()));
}
}
}
void TaskConfig::refresh() { void TaskConfig::refresh() {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "refresh", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(this, "refresh", Qt::BlockingQueuedConnection);
return; return;
} }
// _task->configure(*this);
_task->applyConfiguration(); _task->applyConfiguration();
} }

View file

@ -431,22 +431,8 @@ public:
return findChild<typename T::Config*>(name); return findChild<typename T::Config*>(name);
} }
void connectSubJobConfig(QConfigPointer jobConfig, const std::string& name) { void connectChildConfig(QConfigPointer childConfig, const std::string& name);
// QConfigPointer config = _jobs.back().getConfiguration(); void transferChildrenConfigs(QConfigPointer source);
jobConfig->setParent(this);
jobConfig->setObjectName(name.c_str());
// Connect loaded->refresh
// QObject::connect(config.get(), SIGNAL(loaded()), getConfiguration().get(), SLOT(refresh()));
QObject::connect(jobConfig.get(), SIGNAL(loaded()), this, SLOT(refresh()));
static const char* DIRTY_SIGNAL = "dirty()";
// if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
if (jobConfig->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
// Connect dirty->refresh if defined
// QObject::connect(config.get(), SIGNAL(dirty()), getConfiguration().get(), SLOT(refresh()));
QObject::connect(jobConfig.get(), SIGNAL(dirty()), this, SLOT(refresh()));
}
}
public slots: public slots:
void refresh(); void refresh();
@ -525,8 +511,8 @@ public:
const Varying getOutput() const override { return _output; } const Varying getOutput() const override { return _output; }
template <class... A> template <class... A>
Model(const Varying& input, A&&... args) : Model(const Varying& input, QConfigPointer config, A&&... args) :
Concept(std::make_shared<C>()), Concept(config),
_data(Data(std::forward<A>(args)...)), _data(Data(std::forward<A>(args)...)),
_input(input), _input(input),
_output(Output()) { _output(Output()) {
@ -534,8 +520,8 @@ public:
} }
template <class... A> template <class... A>
static std::shared_ptr<Model> factoryModel(const Varying& input, A&&... args) { static std::shared_ptr<Model> create(const Varying& input, A&&... args) {
return std::make_shared<Model>(input, std::forward<A>(args)...); return std::make_shared<Model>(input, std::make_shared<C>(), std::forward<A>(args)...);
} }
@ -583,11 +569,6 @@ protected:
std::string _name = ""; std::string _name = "";
}; };
/*
template <class T, class... A> void taskBuild(T& data, typename T::JobModel* task, const Varying& input, Varying& output, A&&... args) {
data.build(*(task), input, output, std::forward<A>(args)...);
}*/
// A task is a specialized job to run a collection of other jobs // A task is a specialized job to run a collection of other jobs
// It is defined with JobModel = Task::Model<T> // It is defined with JobModel = Task::Model<T>
@ -614,20 +595,10 @@ public:
// Create a new job in the container's queue; returns the job's output // Create a new job in the container's queue; returns the job's output
template <class NT, class... NA> const Varying addJob(std::string name, const Varying& input, NA&&... args) { template <class NT, class... NA> const Varying addJob(std::string name, const Varying& input, NA&&... args) {
_jobs.emplace_back(name, (NT::JobModel::factoryModel(input, std::forward<NA>(args)...))); _jobs.emplace_back(name, (NT::JobModel::create(input, std::forward<NA>(args)...)));
/* QConfigPointer config = _jobs.back().getConfiguration();
config->setParent(getConfiguration().get());
config->setObjectName(name.c_str());
// Connect loaded->refresh // Conect the child config to this task's config
QObject::connect(config.get(), SIGNAL(loaded()), getConfiguration().get(), SLOT(refresh())); std::static_pointer_cast<TaskConfig>(getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name);
static const char* DIRTY_SIGNAL = "dirty()";
if (config->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
// Connect dirty->refresh if defined
QObject::connect(config.get(), SIGNAL(dirty()), getConfiguration().get(), SLOT(refresh()));
}*/
std::static_pointer_cast<TaskConfig>(getConfiguration())->connectSubJobConfig(_jobs.back().getConfiguration(), name);
return _jobs.back().getOutput(); return _jobs.back().getOutput();
} }
@ -645,13 +616,14 @@ public:
Data _data; Data _data;
TaskModel(const Varying& input) : TaskModel(const Varying& input, QConfigPointer config) :
TaskConcept(input, nullptr), TaskConcept(input, config),
_data(Data()) {} _data(Data()) {}
template <class... A> template <class... A>
static std::shared_ptr<TaskModel> factoryModel(const Varying& input, A&&... args) { static std::shared_ptr<TaskModel> create(const Varying& input, A&&... args) {
auto model = std::make_shared<TaskModel>(input); auto model = std::make_shared<TaskModel>(input, std::make_shared<C>());
// std::static_pointer_cast<C>(model->_config)->_task = model.get();
model->_data.build(*(model), model->_input, model->_output, std::forward<A>(args)...); model->_data.build(*(model), model->_input, model->_output, std::forward<A>(args)...);
@ -663,27 +635,19 @@ public:
} }
template <class... A> template <class... A>
static std::shared_ptr<TaskModel> factoryModel(A&&... args) { static std::shared_ptr<TaskModel> create(A&&... args) {
const auto input = Varying(Input()); const auto input = Varying(Input());
return factoryModel(input, std::forward<A>(args)...); return create(input, std::forward<A>(args)...);
} }
void createConfiguration() { void createConfiguration() {
// A brand new config
auto config = std::make_shared<C>(); auto config = std::make_shared<C>();
if (_config) { // Make sure we transfer the former children configs to the new config
// Transfer children to the new configuration config->transferChildrenConfigs(_config);
auto children = _config->children(); // swap
for (auto& child : children) {
child->setParent(config.get());
QObject::connect(child, SIGNAL(loaded()), config.get(), SLOT(refresh()));
static const char* DIRTY_SIGNAL = "dirty()";
if (child->metaObject()->indexOfSignal(DIRTY_SIGNAL) != -1) {
// Connect dirty->refresh if defined
QObject::connect(child, SIGNAL(dirty()), config.get(), SLOT(refresh()));
}
}
}
_config = config; _config = config;
// Capture this
std::static_pointer_cast<C>(_config)->_task = this; std::static_pointer_cast<C>(_config)->_task = this;
} }

View file

@ -192,7 +192,7 @@ Column {
CheckBox { CheckBox {
text: "Zones" text: "Zones"
checked: Render.getConfig("DrawZones")["enabled"] checked: Render.getConfig("DrawZones")["enabled"]
onCheckedChanged: { Render.getConfig("DrawZones")["enabled"] = checked } onCheckedChanged: { Render.getConfig("ZoneRenderer")["enabled"] = checked; Render.getConfig("DrawZones")["enabled"] = checked; }
} }
} }
} }