Commit 233086de authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

use dtkCoreParameterReader in menuBarGenerator

parent 4128b5ca
......@@ -20,6 +20,7 @@
#include "dtkWidgetsMenuBar.h"
#include <dtkCore/dtkCoreParameter>
#include <dtkCore/dtkCoreParameterReader>
#include <dtkFonts/dtkFontAwesome>
......@@ -35,7 +36,6 @@ public:
public:
QJsonArray menu;
QJsonObject definition;
public:
QHash<QString, dtkCoreParameter *> parameters;
......@@ -46,21 +46,10 @@ public:
void dtkWidgetsParameterMenuBarGeneratorPrivate::parseParameter(dtkWidgetsMenu *menu, const QJsonObject& parameter_object)
{
QString widget_string = parameter_object["widget"].toString();
QString type_string = parameter_object["type"].toString();
QVariantHash map;
map.insert("type", type_string);
dtkCoreParameter *parameter = dtkCoreParameter::create(map);
if (!parameter)
return;
QString parameter_uid = parameter_object["uid"].toString();
parameter->setValue(this->definition[parameter_uid].toObject().toVariantHash());
dtkCoreParameter *parameter = this->parameters[parameter_uid];
menu->addParameter(parameter->label(), parameter, widget_string);
parameters[parameter_uid] = parameter;
}
template<class T>
......@@ -100,8 +89,17 @@ void dtkWidgetsParameterMenuBarGeneratorPrivate::parseGroup(T* menu, const QJson
dtkWidgetsParameterMenuBarGenerator::dtkWidgetsParameterMenuBarGenerator(const QString& menu_file_path, const QString& definition_file_path) : d(new dtkWidgetsParameterMenuBarGeneratorPrivate)
{
QFile menu_file(menu_file_path);
QFile definition_file(definition_file_path);
if (menu_file.open(QFile::ReadOnly) && definition_file.open(QFile::ReadOnly)) {
dtkCoreParameterReader param_reader;
param_reader.setJsonFile(definition_file_path);
if (!param_reader.read()) {
qWarning() << Q_FUNC_INFO << "The file" << definition_file_path << "could not be read.";
return;
}
d->parameters = param_reader.parameters();
if (menu_file.open(QFile::ReadOnly)) {
QJsonParseError menu_error;
QJsonDocument menu_document = QJsonDocument::fromJson(menu_file.readAll(), &menu_error);
if(menu_error.error != QJsonParseError::NoError) {
......@@ -115,24 +113,9 @@ dtkWidgetsParameterMenuBarGenerator::dtkWidgetsParameterMenuBarGenerator(const Q
return;
}
QJsonParseError definition_error;
QJsonDocument definition_document = QJsonDocument::fromJson(definition_file.readAll(), &definition_error);
if(definition_error.error != QJsonParseError::NoError) {
qWarning() << Q_FUNC_INFO << "Error :" << definition_error.errorString() << "parsing" << definition_file_path << "offset :" << definition_error.offset << ".";
return;
}
QJsonObject definition_object = definition_document.object();
if(!definition_object.contains("contents")) {
qWarning() << Q_FUNC_INFO << "The menu parameters file should contain a first json object with key 'contents'. The file cannot be processed any further.";
return;
}
QJsonValue menu_contents = menu_object["contents"];
QJsonValue definition_contents = definition_object["contents"];
if (menu_contents.isArray() && definition_contents.isObject()) {
if (menu_contents.isArray()) {
d->menu = menu_contents.toArray();
d->definition = definition_contents.toObject();
} else {
qWarning() << Q_FUNC_INFO << "The first object with key 'contents' must be an array.";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment