Trying to fix the getCOnfig from QML...

This commit is contained in:
Sam Cake 2017-06-20 00:25:51 -07:00
parent ba9dbbb4d4
commit 5b6f6ab84f
3 changed files with 37 additions and 17 deletions

View file

@ -124,6 +124,11 @@ signals:
void dirtyEnabled(); void dirtyEnabled();
}; };
class TConfigProxy {
public:
using Config = JobConfig;
};
class TaskConfig : public JobConfig { class TaskConfig : public JobConfig {
Q_OBJECT Q_OBJECT
public: public:
@ -134,12 +139,29 @@ public:
TaskConfig() = default ; TaskConfig() = default ;
TaskConfig(bool enabled) : JobConfig(enabled) {} TaskConfig(bool enabled) : JobConfig(enabled) {}
// getter for qml integration, prefer the templated getter // getter for qml integration, prefer the templated getter
Q_INVOKABLE QObject* getConfig(const QString& name) { return QObject::findChild<JobConfig*>(name); } Q_INVOKABLE QObject* getConfig(const QString& name) { return getConfig<TConfigProxy>(name.toStdString()); }
// getter for cpp (strictly typed), prefer this getter // getter for cpp (strictly typed), prefer this getter
template <class T> typename T::Config* getConfig(std::string job = "") const { template <class T> typename T::Config* getConfig(std::string job = "") const {
QString name = job.empty() ? QString() : QString(job.c_str()); // an empty string is not a null string const TaskConfig* root = this;
return findChild<typename T::Config*>(name); QString path = (job.empty() ? QString() : QString(job.c_str())); // an empty string is not a null string
auto tokens = path.split('.', QString::SkipEmptyParts);
if (tokens.empty()) {
tokens.push_back(QString());
} else {
while (tokens.size() > 1) {
auto name = tokens.front();
tokens.pop_front();
root = QObject::findChild<TaskConfig*>(name);
if (!root) {
return nullptr;
}
}
}
return root->findChild<typename T::Config*>(tokens.front());
} }
void connectChildConfig(QConfigPointer childConfig, const std::string& name); void connectChildConfig(QConfigPointer childConfig, const std::string& name);

View file

@ -22,8 +22,7 @@ Item {
anchors.fill:parent anchors.fill:parent
property var mainViewTask: Render.getConfig("RenderMainView"); property var mainViewTask: Render.getConfig("RenderMainView");
property var config: mainViewTask.getConfig("Stats")
function evalEvenHeight() { function evalEvenHeight() {
// Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ? // Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ?
return (height - spacing * (children.length - 1)) / children.length return (height - spacing * (children.length - 1)) / children.length
@ -39,31 +38,31 @@ Item {
valueNumDigits: "4" valueNumDigits: "4"
plots: [ plots: [
{ {
object: mainViewTask.getConfig("OpaqueRangeTimer"), object: Render.getConfig("RenderMainView.OpaqueRangeTimer"),
prop: "gpuRunTime", prop: "gpuRunTime",
label: "Opaque", label: "Opaque",
color: "#FFFFFF" color: "#FFFFFF"
}, },
{ {
object: mainViewTask.getConfig("LinearDepth"), object: Render.getConfig("RenderMainView.LinearDepth"),
prop: "gpuRunTime", prop: "gpuRunTime",
label: "LinearDepth", label: "LinearDepth",
color: "#00FF00" color: "#00FF00"
},{ },{
object: mainViewTask.getConfig("SurfaceGeometry"), object: Render.getConfig("RenderMainView.SurfaceGeometry"),
prop: "gpuRunTime", prop: "gpuRunTime",
label: "SurfaceGeometry", label: "SurfaceGeometry",
color: "#00FFFF" color: "#00FFFF"
}, },
{ {
object: mainViewTask.getConfig("RenderDeferred"), object: Render.getConfig("RenderMainView.RenderDeferred"),
prop: "gpuRunTime", prop: "gpuRunTime",
label: "DeferredLighting", label: "DeferredLighting",
color: "#FF00FF" color: "#FF00FF"
} }
, ,
{ {
object: mainViewTask.getConfig("ToneAndPostRangeTimer"), object: Render.getConfig("RenderMainView.ToneAndPostRangeTimer"),
prop: "gpuRunTime", prop: "gpuRunTime",
label: "tone and post", label: "tone and post",
color: "#FF0000" color: "#FF0000"
@ -79,31 +78,31 @@ Item {
valueNumDigits: "3" valueNumDigits: "3"
plots: [ plots: [
{ {
object: mainViewTask.getConfig("OpaqueRangeTimer"), object: Render.getConfig("RenderMainView.OpaqueRangeTimer"),
prop: "batchRunTime", prop: "batchRunTime",
label: "Opaque", label: "Opaque",
color: "#FFFFFF" color: "#FFFFFF"
}, },
{ {
object: mainViewTask.getConfig("LinearDepth"), object: Render.getConfig("RenderMainView.LinearDepth"),
prop: "batchRunTime", prop: "batchRunTime",
label: "LinearDepth", label: "LinearDepth",
color: "#00FF00" color: "#00FF00"
},{ },{
object: mainViewTask.getConfig("SurfaceGeometry"), object: Render.getConfig("RenderMainView.SurfaceGeometry"),
prop: "batchRunTime", prop: "batchRunTime",
label: "SurfaceGeometry", label: "SurfaceGeometry",
color: "#00FFFF" color: "#00FFFF"
}, },
{ {
object: mainViewTask.getConfig("RenderDeferred"), object: Render.getConfig("RenderMainView.RenderDeferred"),
prop: "batchRunTime", prop: "batchRunTime",
label: "DeferredLighting", label: "DeferredLighting",
color: "#FF00FF" color: "#FF00FF"
} }
, ,
{ {
object: mainViewTask.getConfig("ToneAndPostRangeTimer"), object: Render.getConfig("RenderMainView.ToneAndPostRangeTimer"),
prop: "batchRunTime", prop: "batchRunTime",
label: "tone and post", label: "tone and post",
color: "#FF0000" color: "#FF0000"

View file

@ -22,8 +22,7 @@ Item {
spacing: 8 spacing: 8
anchors.fill:parent anchors.fill:parent
property var mainViewTask: Render.getConfig("RenderMainView"); property var config: Render.getConfig("Stats")
property var config: mainViewTask.getConfig("Stats")
function evalEvenHeight() { function evalEvenHeight() {
// Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ? // Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ?