Integrate JobConfig with JSON/qml

This commit is contained in:
Zach Pomerantz 2016-02-08 12:29:56 -08:00
parent e61636e8a7
commit 5f395654f0

View file

@ -74,7 +74,7 @@ public:
Q_INVOKABLE QString toJSON() { return QJsonDocument(toJsonValue(*this).toObject()).toJson(QJsonDocument::Compact); }
public slots:
void load(const QJsonValue& json) { qObjectFromJsonValue(json, *this); }
Q_INVOKABLE void fromJSON(const QJsonValue& json) { qObjectFromJsonValue(json, *this); }
};
class TaskConfig : public JobConfig {
@ -85,6 +85,9 @@ public:
void init(Task* task) { _task = task; }
// getter for qml integration, prefer the templated getter
Q_INVOKABLE QObject* getConfig(const QString& name) { return QObject::findChild<JobConfig*>(name); }
// 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);