Commit 867f871d authored by LE BRETON Come's avatar LE BRETON Come

Adds the first draft of menu bar generator from json.

parent 49560a68
......@@ -64,6 +64,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterIntSpinBox.h
dtkWidgetsParameterFactory
dtkWidgetsParameterFactory.h
dtkWidgetsParameterMenuBarGenerator
dtkWidgetsParameterMenuBarGenerator.h
dtkWidgetsSettings
dtkWidgetsSettings.h
dtkWidgetsStylesheetParser
......@@ -94,6 +96,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameter.cpp
dtkWidgetsParameterIntSpinBox.cpp
dtkWidgetsParameterFactory.cpp
dtkWidgetsParameterMenuBarGenerator.cpp
dtkWidgetsSettings.cpp
dtkWidgetsStylesheetParser.cpp
dtkWidgetsWidget.cpp)
......
#include "dtkWidgetsParameterMenuBarGenerator.h"
\ No newline at end of file
// Version: $Id:
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterMenuBarGenerator.h"
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
class dtkWidgetsParameterMenuBarGeneratorPrivate {
public:
void parseGroup(const QJsonObject&);
void parseParameter(const QJsonObject&);
public:
QHash<QString, dtkCoreAbstractParameter *> parameters;
QHash<QString, dtkWidgetsAbstractParameter *> widgets;
};
void dtkWidgetsParameterMenuBarGeneratorPrivate::parseParameter(const QJsonObject& parameter_object)
{
QString parameter_uid = parameter_object["uid"].toString();
bool advanced = parameter_object["advanced"].toBool();
dtkCoreAbstractParameter *parameter =
QString widget = parameter_object["widget"].toString();
// parameters.insert(
qDebug() << "p uid" << parameter_uid << ", advanced" << advanced << ", widget" << widget;
}
void dtkWidgetsParameterMenuBarGeneratorPrivate::parseGroup(const QJsonObject& group_object)
{
QString group_uid = group_object["uid"].toString();
QString icon = group_object["icon"].toString();
bool advanced = group_object["advanced"].toBool();
QJsonArray group_contents_array = group_object["contents"].toArray();
for (auto it = group_contents_array.begin(); it != group_contents_array.end(); ++it) {
if (it->isObject()) {
QJsonObject content_object = it->toObject();
if(content_object.contains("group")) {
QJsonObject group_object = content_object["group"].toObject();
parseGroup(group_object);
} else if (content_object.contains("parameter")) {
QJsonObject parameter_object = content_object["parameter"].toObject();
parseParameter(parameter_object);
}
}
}
}
dtkWidgetsParameterMenuBarGenerator::dtkWidgetsParameterMenuBarGenerator(void) : d(new dtkWidgetsParameterMenuBarGeneratorPrivate)
{
}
dtkWidgetsParameterMenuBarGenerator::dtkWidgetsParameterMenuBarGenerator(const QString& nature_file_path, const QString& definition_file_path)
{
QFile nature_file(nature_file_path);
if (nature_file.open(QFile::ReadOnly)) {
QJsonParseError nature_error;
QJsonDocument nature_document = QJsonDocument::fromJson(nature_file.readAll(), &nature_error);
if(nature_error.error != QJsonParseError::NoError) {
qWarning() << "Error :" << nature_error.errorString() << "parsing" << nature_file_path << "offset :" << nature_error.offset;
return;
}
QJsonObject main_object = nature_document.object();
QJsonValue main_contents = main_object["contents"];
if (main_contents.isArray()) {
QJsonArray main_contents_array = main_contents.toArray();
for(auto it = main_contents_array.begin(); it != main_contents_array.end(); ++it) {
if(it->isObject()) {
QJsonObject content_object = it->toObject();
if(content_object.contains("group")) {
QJsonObject group_object = content_object["group"].toObject();
d->parseGroup(group_object);
} else if (content_object.contains("parameter")) {
QJsonObject parameter_object = content_object["parameter"].toObject();
d->parseParameter(parameter_object);
}
}
}
} else {
qWarning() << "We have an issue.";
}
}
}
dtkWidgetsParameterMenuBarGenerator::~dtkWidgetsParameterMenuBarGenerator(void)
{
delete d;
}
//
// dtkWidgetsParameterMenuBarGenerator.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include <QtCore>
class DTKWIDGETS_EXPORT dtkWidgetsParameterMenuBarGenerator
{
public:
dtkWidgetsParameterMenuBarGenerator(void);
dtkWidgetsParameterMenuBarGenerator(const QString&, const QString&);
~dtkWidgetsParameterMenuBarGenerator(void);
protected:
class dtkWidgetsParameterMenuBarGeneratorPrivate *d;
};
//
// dtkWidgetsParameterMenuBarGenerator.h ends here
......@@ -26,10 +26,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(${PROJECT_NAME}_HEADERS
dtkWidgetsParametersTest.h
dtkWidgetsParameterMenuBarGeneratorTest.h
)
set(${PROJECT_NAME}_SOURCES
dtkWidgetsParametersTest.cpp
dtkWidgetsParameterMenuBarGeneratorTest.cpp
)
## ###################################################################
......@@ -65,6 +67,7 @@ target_link_libraries(${PROJECT_NAME} Qt5::Test)
## ###################################################################
add_test(dtkWidgetsParametersTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} dtkWidgetsParametersTest)
add_test(dtkWidgetsParameterMenuBarGeneratorTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} dtkWidgetsParameterMenuBarGeneratorTest)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterMenuBarGeneratorTest.h"
#include <dtkWidgetsTest>
#include <dtkWidgets/dtkWidgets>
#include <dtkWidgets/dtkWidgetsParameterMenuBarGenerator>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterMenuBarGeneratorTestCasePrivate
{
};
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterMenuBarGeneratorTestCase::dtkWidgetsParameterMenuBarGeneratorTestCase(void) : d(new dtkWidgetsParameterMenuBarGeneratorTestCasePrivate)
{
dtk::widgets::setVerboseLoading(true);
dtk::widgets::initialize("");
}
dtkWidgetsParameterMenuBarGeneratorTestCase::~dtkWidgetsParameterMenuBarGeneratorTestCase(void)
{
delete d;
}
void dtkWidgetsParameterMenuBarGeneratorTestCase::initTestCase(void)
{
}
void dtkWidgetsParameterMenuBarGeneratorTestCase::init(void)
{
}
void dtkWidgetsParameterMenuBarGeneratorTestCase::testBasic(void)
{
QString nature_file_path = QFINDTESTDATA("../resources/parameters_nature.json");
QString definition_file_path = QFINDTESTDATA("../resources/parameters_definition.json");
dtkWidgetsParameterMenuBarGenerator menu_bar_generator(nature_file_path, definition_file_path);
}
void dtkWidgetsParameterMenuBarGeneratorTestCase::cleanup(void)
{
}
void dtkWidgetsParameterMenuBarGeneratorTestCase::cleanupTestCase(void)
{
}
DTKWIDGETSTEST_MAIN(dtkWidgetsParameterMenuBarGeneratorTest, dtkWidgetsParameterMenuBarGeneratorTestCase)
//
// dtkWidgetsParameterMenuBarGeneratorTest.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsTest>
class dtkWidgetsParameterMenuBarGeneratorTestCase : public QObject
{
Q_OBJECT
public:
dtkWidgetsParameterMenuBarGeneratorTestCase(void);
~dtkWidgetsParameterMenuBarGeneratorTestCase(void);
private slots:
void initTestCase(void);
void init(void);
private slots:
void testBasic(void);
private slots:
void cleanupTestCase(void);
void cleanup(void);
private:
class dtkWidgetsParameterMenuBarGeneratorTestCasePrivate *d;
};
//
// dtkWidgetsParameterMenuBarGeneratorTest.h ends here
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