Commit 8868a7c5 authored by CABEL Tristan's avatar CABEL Tristan

Merge branch 'release/2.11.0'

parents 28265261 cf519c60
# ChangeLog
## version 2.11.0 - 2019-05-21
- menubar generator use dtk-core parameter reader
- add python converter for parameters new json file formats
- fix menubar size
## version 2.10.0 - 2019-05-17
- cmake refactoring
- fix interaction
......
......@@ -23,7 +23,7 @@ project(dtkWidgets)
## ###################################################################
set(${PROJECT_NAME}_VERSION_MAJOR 2)
set(${PROJECT_NAME}_VERSION_MINOR 10)
set(${PROJECT_NAME}_VERSION_MINOR 11)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH})
......@@ -162,13 +162,9 @@ mark_as_advanced(Qt5Core_DIR)
mark_as_advanced(Qt5Gui_DIR)
mark_as_advanced(Qt5OpenGL_DIR)
mark_as_advanced(Qt5Test_DIR)
mark_as_advanced(Qt5Xml_DIR)
mark_as_advanced(Qt5Widgets_DIR)
mark_as_advanced(dtkCore_DIR)
mark_as_advanced(dtkFonts_DIR)
mark_as_advanced(dtkLog_DIR)
mark_as_advanced(dtkThemes_DIR)
mark_as_advanced(CMAKE_AR)
mark_as_advanced(CMAKE_BUILD_TYPE)
mark_as_advanced(CMAKE_OSX_ARCHITECTURES)
......
......@@ -12,8 +12,6 @@
##
### Code:
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/examples)
add_subdirectory(dtkWidgetsLayout)
add_subdirectory(dtkWidgetsMenu)
add_subdirectory(dtkWidgetsOverlayPaneItems)
......
......@@ -17,7 +17,7 @@ channels:
- dtk
dependencies:
- qt >=5.9.0
- dtk-core >=2.4.0
- dtk-core >=2.5.0
- dtk-fonts >=2.1.0
- dtk-log
- dtk-themes
......
......@@ -38,14 +38,14 @@ requirements:
- {{ cdt('libxxf86vm') }} # [linux]
host:
- qt >=5.9.0
- dtk-core >=2.4.0
- dtk-core >=2.5.0
- dtk-fonts >=2.1.0
- dtk-log
- dtk-themes
run:
- qt >=5.9.0
- dtk-core >=2.4.0
- dtk-core >=2.5.0
- dtk-fonts >=2.1.0
- dtk-log
- dtk-themes
......
......@@ -234,7 +234,7 @@ dtkWidgetsMenuItemParameterFacade::dtkWidgetsMenuItemParameterFacade(dtkWidgetsM
QFormLayout *layout = new QFormLayout(this);
layout->addRow(source->title(), source->widget());
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
}
dtkWidgetsMenuItemParameterFacade::~dtkWidgetsMenuItemParameterFacade(void)
......
......@@ -214,6 +214,7 @@ void dtkWidgetsMenuBarButton::touch(bool selected)
}
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
dtkThemesEngine::instance()->polish(this);
}
......
......@@ -20,6 +20,7 @@
#include "dtkWidgetsMenuBar.h"
#include <dtkCore/dtkCoreParameter>
#include <dtkCore/dtkCoreParameterReader>
#include <dtkFonts/dtkFontAwesome>
......@@ -34,11 +35,10 @@ public:
void parseParameter(dtkWidgetsMenu *, const QJsonObject&);
public:
QJsonArray nature;
QJsonObject definition;
QJsonArray menu;
public:
QHash<QString, dtkCoreParameter *> parameters;
dtkCoreParameters 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>
......@@ -97,47 +86,41 @@ void dtkWidgetsParameterMenuBarGeneratorPrivate::parseGroup(T* menu, const QJson
// dtkWidgetsParameterMenuBarGenerator implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterMenuBarGenerator::dtkWidgetsParameterMenuBarGenerator(const QString& nature_file_path, const QString& definition_file_path) : d(new dtkWidgetsParameterMenuBarGeneratorPrivate)
dtkWidgetsParameterMenuBarGenerator::dtkWidgetsParameterMenuBarGenerator(const QString& menu_file_path, const QString& definition_file_path) : d(new dtkWidgetsParameterMenuBarGeneratorPrivate)
{
QFile nature_file(nature_file_path);
QFile definition_file(definition_file_path);
if (nature_file.open(QFile::ReadOnly) && definition_file.open(QFile::ReadOnly)) {
QJsonParseError nature_error;
QJsonDocument nature_document = QJsonDocument::fromJson(nature_file.readAll(), &nature_error);
if(nature_error.error != QJsonParseError::NoError) {
qWarning() << Q_FUNC_INFO << "Error :" << nature_error.errorString() << "parsing" << nature_file_path << "offset :" << nature_error.offset << ".";
return;
}
QFile menu_file(menu_file_path);
QJsonObject nature_object = nature_document.object();
if(!nature_object.contains("contents")) {
qWarning() << Q_FUNC_INFO << "The nature parameters file should contain a first json object with key 'contents'. The file cannot be processed any further.";
return;
}
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();
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 << ".";
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) {
qWarning() << Q_FUNC_INFO << "Error :" << menu_error.errorString() << "parsing" << menu_file_path << "offset :" << menu_error.offset << ".";
return;
}
QJsonObject definition_object = definition_document.object();
if(!definition_object.contains("contents")) {
qWarning() << Q_FUNC_INFO << "The nature parameters file should contain a first json object with key 'contents'. The file cannot be processed any further.";
QJsonObject menu_object = menu_document.object();
if(!menu_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 nature_contents = nature_object["contents"];
QJsonValue definition_contents = definition_object["contents"];
if (nature_contents.isArray() && definition_contents.isObject()) {
d->nature = nature_contents.toArray();
d->definition = definition_contents.toObject();
QJsonValue menu_contents = menu_object["contents"];
if (menu_contents.isArray()) {
d->menu = menu_contents.toArray();
} else {
qWarning() << Q_FUNC_INFO << "The first object with key 'contents' must be an array.";
}
} else {
qWarning() << Q_FUNC_INFO << "The file" << nature_file_path << "could not be opened.";
qWarning() << Q_FUNC_INFO << "The file" << menu_file_path << "could not be opened.";
}
}
......@@ -148,7 +131,7 @@ dtkWidgetsParameterMenuBarGenerator::~dtkWidgetsParameterMenuBarGenerator(void)
void dtkWidgetsParameterMenuBarGenerator::populate(dtkWidgetsMenuBar *menubar)
{
for(auto it = d->nature.begin(); it != d->nature.end(); ++it) {
for(auto it = d->menu.begin(); it != d->menu.end(); ++it) {
if(it->isObject()) {
QJsonObject content_object = it->toObject();
if(content_object.contains("group")) {
......@@ -163,7 +146,7 @@ void dtkWidgetsParameterMenuBarGenerator::populate(dtkWidgetsMenuBar *menubar)
}
}
QHash<QString, dtkCoreParameter *> dtkWidgetsParameterMenuBarGenerator::parameters(void) const
dtkCoreParameters dtkWidgetsParameterMenuBarGenerator::parameters(void) const
{
return d->parameters;
}
......
......@@ -16,11 +16,12 @@
#include <dtkWidgetsExport>
#include <dtkCore/dtkCoreParameters>
#include <QtCore>
class dtkWidgetsMenuBar;
class dtkCoreParameter;
class dtkWidgetsParameter;
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterMenuBarGenerator declaration
......@@ -29,14 +30,14 @@ class dtkWidgetsParameter;
class DTKWIDGETS_EXPORT dtkWidgetsParameterMenuBarGenerator
{
public:
dtkWidgetsParameterMenuBarGenerator(const QString&, const QString&);
dtkWidgetsParameterMenuBarGenerator(const QString& menu_file, const QString& definition_file);
~dtkWidgetsParameterMenuBarGenerator(void);
public:
void populate(dtkWidgetsMenuBar *menubar);
public:
QHash<QString, dtkCoreParameter *> parameters(void) const;
dtkCoreParameters parameters(void) const;
protected:
class dtkWidgetsParameterMenuBarGeneratorPrivate *d;
......
......@@ -58,6 +58,7 @@ add_executable(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} dtkWidgets)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkThemes)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Test)
......
......@@ -17,8 +17,9 @@
#include <dtkWidgetsTest>
#include <dtkWidgets/dtkWidgets>
#include <dtkThemes>
#include <dtkWidgets/dtkWidgets>
#include <dtkWidgets/dtkWidgetsParameterMenuBarGenerator>
// ///////////////////////////////////////////////////////////////////
......@@ -36,20 +37,11 @@ class dtkWidgetsParameterMenuBarGeneratorTestCasePrivate
dtkWidgetsParameterMenuBarGeneratorTestCase::dtkWidgetsParameterMenuBarGeneratorTestCase(void) : d(new dtkWidgetsParameterMenuBarGeneratorTestCasePrivate)
{
qRegisterMetaTypeStreamOperators<dtk::d_bool>("dtk::d_bool");
qRegisterMetaTypeStreamOperators<dtk::d_real>("dtk::d_real");
qRegisterMetaTypeStreamOperators<dtk::d_int>("dtk::d_int");
qRegisterMetaTypeStreamOperators<dtk::d_string>("dtk::d_string");
qRegisterMetaType<dtk::d_real *>();
qRegisterMetaType<dtk::d_bool *>();
qRegisterMetaType<dtk::d_int *>();
qRegisterMetaType<dtk::d_string *>();
dtk::core::registerParameters();
dtk::widgets::setVerboseLoading(true);
dtk::widgets::initialize("");
dtkThemesEngine::instance()->apply();
}
dtkWidgetsParameterMenuBarGeneratorTestCase::~dtkWidgetsParameterMenuBarGeneratorTestCase(void)
......@@ -69,11 +61,19 @@ 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");
QString nature_file_path = QFINDTESTDATA("../resources/new_menu.json");
QString definition_file_path = QFINDTESTDATA("../resources/new_definition.json");
dtkWidgetsParameterMenuBarGenerator menu_bar_generator(nature_file_path, definition_file_path);
dtkCoreParameters params = menu_bar_generator.parameters();
QCOMPARE(params.count() , 78);
dtkWidgetsMenuBar bar;
menu_bar_generator.populate(&bar);
auto menus = bar.menus();
QCOMPARE(menus.count() , 4);
}
void dtkWidgetsParameterMenuBarGeneratorTestCase::cleanup(void)
......
#!/usr/bin/env python3
import json
import argparse
def parse_group(json_o, type_map):
for c in json_o["contents"]:
if 'group' in c:
parse_group(c['group'], type_map)
else:
uid = c['parameter']['uid']
newtype = c['parameter']['type']
del c['parameter']['type']
type_map[uid] = newtype
parser = argparse.ArgumentParser(description='Process Convert dtk parameters file to new format (type in def).')
parser.add_argument('def_file', help='definition file')
parser.add_argument('menu_file', help='menu file')
args = parser.parse_args()
def_data = open(args.def_file)
menu_data = open(args.menu_file)
def_json = json.load(def_data)
menu_json = json.load(menu_data)
type_map = {}
for c in menu_json["contents"]:
parse_group(c['group'], type_map)
for uid in def_json["contents"].keys():
if uid in type_map:
def_json["contents"][uid]['type'] = type_map[uid]
else:
print(uid, "not used !")
with open('new_menu.json', 'w') as outfile:
print("write new_menu.json")
json.dump(menu_json, outfile, indent = 4,)
with open('new_definition.json', 'w') as outfile:
print("write new_definition.json")
json.dump(def_json, outfile, indent = 4,)
This diff is collapsed.
This diff is collapsed.
{
"contents": [
{"uid" : "hyp", "label": "hyp", "doc": "documentation", "default_value": 2, "bound_min": 0, "bound_max": 5},
{"uid" : "dif", "label": "dif", "doc": "documentation", "default_value": false},
{"uid" : "res", "label": "res", "doc": "documentation", "default_value": false},
{"uid" : "prec", "label": "prec", "doc": "documentation", "default_value": false},
{"uid" : "inf", "label": "inf", "doc": "documentation", "default_value": false},
{"uid" : "wind", "label": "wind", "doc": "documentation", "default_value": false},
]
}
{
"contents": [
{ "group": {"uid" : "Model parameters", "icon": "fa::cogs", "advanced": false,
"contents": [
{"parameter": {"uid": "hyp", "type": "dtk::d_int", "widget": "dtkWidgetsParameterIntSpinBox", "advanced": false}},
{"parameter": {"uid": "dif", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "res", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "prec", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "inf", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "wind", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}}
]
} }
]
}
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