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();
};
class TConfigProxy {
public:
using Config = JobConfig;
};
class TaskConfig : public JobConfig {
Q_OBJECT
public:
@ -134,12 +139,29 @@ public:
TaskConfig() = default ;
TaskConfig(bool enabled) : JobConfig(enabled) {}
// 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
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
return findChild<typename T::Config*>(name);
const TaskConfig* root = this;
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);

View file

@ -22,8 +22,7 @@ Item {
anchors.fill:parent
property var mainViewTask: Render.getConfig("RenderMainView");
property var config: mainViewTask.getConfig("Stats")
function evalEvenHeight() {
// 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
@ -39,31 +38,31 @@ Item {
valueNumDigits: "4"
plots: [
{
object: mainViewTask.getConfig("OpaqueRangeTimer"),
object: Render.getConfig("RenderMainView.OpaqueRangeTimer"),
prop: "gpuRunTime",
label: "Opaque",
color: "#FFFFFF"
},
{
object: mainViewTask.getConfig("LinearDepth"),
object: Render.getConfig("RenderMainView.LinearDepth"),
prop: "gpuRunTime",
label: "LinearDepth",
color: "#00FF00"
},{
object: mainViewTask.getConfig("SurfaceGeometry"),
object: Render.getConfig("RenderMainView.SurfaceGeometry"),
prop: "gpuRunTime",
label: "SurfaceGeometry",
color: "#00FFFF"
},
{
object: mainViewTask.getConfig("RenderDeferred"),
object: Render.getConfig("RenderMainView.RenderDeferred"),
prop: "gpuRunTime",
label: "DeferredLighting",
color: "#FF00FF"
}
,
{
object: mainViewTask.getConfig("ToneAndPostRangeTimer"),
object: Render.getConfig("RenderMainView.ToneAndPostRangeTimer"),
prop: "gpuRunTime",
label: "tone and post",
color: "#FF0000"
@ -79,31 +78,31 @@ Item {
valueNumDigits: "3"
plots: [
{
object: mainViewTask.getConfig("OpaqueRangeTimer"),
object: Render.getConfig("RenderMainView.OpaqueRangeTimer"),
prop: "batchRunTime",
label: "Opaque",
color: "#FFFFFF"
},
{
object: mainViewTask.getConfig("LinearDepth"),
object: Render.getConfig("RenderMainView.LinearDepth"),
prop: "batchRunTime",
label: "LinearDepth",
color: "#00FF00"
},{
object: mainViewTask.getConfig("SurfaceGeometry"),
object: Render.getConfig("RenderMainView.SurfaceGeometry"),
prop: "batchRunTime",
label: "SurfaceGeometry",
color: "#00FFFF"
},
{
object: mainViewTask.getConfig("RenderDeferred"),
object: Render.getConfig("RenderMainView.RenderDeferred"),
prop: "batchRunTime",
label: "DeferredLighting",
color: "#FF00FF"
}
,
{
object: mainViewTask.getConfig("ToneAndPostRangeTimer"),
object: Render.getConfig("RenderMainView.ToneAndPostRangeTimer"),
prop: "batchRunTime",
label: "tone and post",
color: "#FF0000"

View file

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