Commit 1a1bc880 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Merge branch 'feature/fix-menubar-accessor' into 'develop'

Fix parameter/parameterWidget accessors for dtkWidgetsMenuBar

See merge request !74
parents b2276496 dc2b9308
Pipeline #210238 passed with stage
in 0 seconds
......@@ -20,6 +20,7 @@
#include <dtkThemes>
#include <dtkWidgets>
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
......@@ -159,12 +160,20 @@ void setup(dtkApplication *application)
params["checkbox_ro_toggle"]->connect( [=] (QVariant v) {
bool visible = v.value<dtk::d_bool>();
dtkWidgetsParameter *widget_slider = application->window()->menubar()->parameterWidget(":Read-only parameters:slider_double_ro_and_rw:");
dtkWidgetsParameter *widget_filebrowser = application->window()->menubar()->parameterWidget(":Read-only parameters:file_browse_ro:");
if(visible) {
//params["slider_double_ro_and_rw"]->setReadOnly(false);
widget_slider->setReadOnly(false);
widget_filebrowser->setReadOnly(false);
params["slider_double_ro_and_rw"]->setLabel("Slider READWRITE");
params["checkbox_ro_toggle"]->setDocumentation("Next widget is READWRITE");
} else {
//params["slider_double_ro_and_rw"]->setReadOnly(true);
widget_slider->setReadOnly(true);
widget_filebrowser->setReadOnly(true);
params["slider_double_ro_and_rw"]->setLabel("Slider READONLY");
params["checkbox_ro_toggle"]->setDocumentation("Next widget is READONLY");
}
......
......@@ -145,7 +145,7 @@
"type": "dtk::d_bool"
},
"file_browse_ro": {
"label": "Open a file (Read Only)",
"label": "Open a file (toggle RO/RW)",
"doc": "Open a VTK file.",
"path": ".",
"filters": [
......@@ -186,7 +186,7 @@
"decimals": 2
},
"checkbox_ro_toggle":{
"label": "toggle RO/RW of next parameter",
"label": "toggle RO/RW of Slider and Open a file",
"doc": "It's a checkbox",
"value": true,
"type": "dtk::d_bool"
......@@ -194,7 +194,7 @@
"slider_double_ro_and_rw": {
"type": "dtk::d_real",
"doc": "It's a slider of double, which is READONLY or not",
"label": "Slider double (Read Write)",
"label": "Slider double (toggle RO/RW)",
"min": -10.0,
"value": 3.0,
"max": 10.0,
......
......@@ -17,6 +17,7 @@
#include "dtkWidgetsMenuItem.h"
#include "dtkLog"
#include "dtkCoreParameter"
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsMenuPrivate
......@@ -26,6 +27,7 @@ class dtkWidgetsMenuPrivate
{
public:
QHash<QString, QObject *> object_hash;
QHash<QString, QObject *> object_hash_uid;
QVector<QObject *> object_list;
QVector<dtkWidgetsMenu *> menu_list;
......@@ -61,6 +63,7 @@ dtkWidgetsMenu *dtkWidgetsMenu::addMenu(dtkWidgetsMenu *menu)
}
if ( !d->object_hash.contains(menu->title()) ) {
d->object_hash.insert(menu->title(), menu);
d->object_hash_uid.insert(menu->title(), menu);
d->object_list << menu;
d->menu_list << menu;
return menu;
......@@ -109,6 +112,7 @@ dtkWidgetsMenu *dtkWidgetsMenu::insertMenu(int pos, dtkWidgetsMenu *menu)
menu->setParent(this);
d->object_hash.insert(menu->title(), menu);
d->object_hash_uid.insert(menu->title(), menu);
d->menu_list.insert(menu_pos, menu);
d->object_list.insert(pos, menu);
return menu;
......@@ -130,6 +134,7 @@ dtkWidgetsMenu *dtkWidgetsMenu::insertMenu(int pos, int icon_id, const QString &
void dtkWidgetsMenu::clear(void)
{
d->object_hash.clear();
d->object_hash_uid.clear();
d->object_list.clear();
d->menu_list.clear();
}
......@@ -142,6 +147,12 @@ dtkWidgetsMenuItem *dtkWidgetsMenu::addItem(dtkWidgetsMenuItem *item)
}
if (!d->object_hash.contains(item->title())) {
d->object_hash.insert(item->title(), item);
if (item->isParameter()) {
dtkWidgetsMenuItemParameter *item_param = static_cast<dtkWidgetsMenuItemParameter *>(item);
d->object_hash_uid.insert(item_param->parameter()->uid(), item);
} else {
d->object_hash_uid.insert(item->title(), item);
}
d->object_list << item;
return item;
}
......@@ -171,6 +182,12 @@ dtkWidgetsMenuItem *dtkWidgetsMenu::insertItem(int pos, dtkWidgetsMenuItem *item
}
if ( !d->object_hash.contains(item->title()) ) {
d->object_hash.insert(item->title(), item);
if (item->isParameter()) {
dtkWidgetsMenuItemParameter *item_param = static_cast<dtkWidgetsMenuItemParameter *>(item);
d->object_hash_uid.insert(item_param->parameter()->uid(), item);
} else {
d->object_hash_uid.insert(item->title(), item);
}
d->object_list.insert(pos, item);
return item;
}
......@@ -202,6 +219,7 @@ dtkWidgetsMenuItem *dtkWidgetsMenu::addSeparator(void)
separator->setSeparator(true);
d->object_hash.insert(title, separator);
d->object_hash_uid.insert(title, separator);
d->object_list << separator;
return separator;
......@@ -229,15 +247,24 @@ void dtkWidgetsMenu::removeItem(dtkWidgetsMenuItem *item)
{
if (!(item && d->object_hash.contains(item->title())))
return;
d->object_hash.remove(item->title());
QString title;
if (item->isParameter())
title = (static_cast<dtkWidgetsMenuItemParameter *>(item))->parameter()->uid();
else
title = item->title();
if(d->object_hash_uid.contains(title))
d->object_hash_uid.remove(title);
d->object_list.removeAll(item);
}
void dtkWidgetsMenu::removeMenu(dtkWidgetsMenu *menu)
{
if (menu && d->object_hash.contains(menu->title())) {
if (menu && d->object_hash.contains(menu->title()) && d->object_hash_uid.contains(menu->title())) {
d->object_hash.remove(menu->title());
d->object_hash_uid.remove(menu->title());
d->object_list.removeAll(menu);
d->menu_list.removeAll(menu);
}
......@@ -245,10 +272,12 @@ void dtkWidgetsMenu::removeMenu(dtkWidgetsMenu *menu)
void dtkWidgetsMenu::renameMenu(dtkWidgetsMenu *menu, const QString& title)
{
if (menu && d->object_hash.contains(menu->title())) {
if (menu && d->object_hash.contains(menu->title()) && d->object_hash_uid.contains(menu->title())) {
d->object_hash.remove(menu->title());
d->object_hash_uid.remove(menu->title());
menu->d->title = title;
d->object_hash.insert(menu->title(), menu);
d->object_hash_uid.insert(menu->title(), menu);
}
}
......@@ -278,6 +307,14 @@ QObject *dtkWidgetsMenu::object(const QString& id)
return d->object_hash[id];
}
QObject *dtkWidgetsMenu::objectFromUid(const QString& id)
{
if(!d->object_hash_uid.contains(id))
return nullptr;
return d->object_hash_uid[id];
}
QVector<QObject *> dtkWidgetsMenu::objects(void) const
{
return d->object_list;
......
......@@ -84,6 +84,8 @@ public:
QObject *object(const QString&);
QObject *objectFromUid(const QString&);
QVector<QObject *> objects(void) const;
public:
......
......@@ -25,6 +25,8 @@
#include <dtkThemes/dtkThemesEngine>
#include <dtkCoreParameter>
// ///////////////////////////////////////////////////////////////////
namespace dtkWidgetsMenuBarHelper {
......@@ -947,12 +949,15 @@ dtkCoreParameter *dtkWidgetsMenuBar::parameter(const QString& id)
if(path.isEmpty())
return;
QObject *object = menu->object(path.takeFirst());
const QString &pathfirst = path.takeFirst();
QObject *object = menu->object(pathfirst);
if (dtkWidgetsMenu *m = qobject_cast<dtkWidgetsMenu *>(object))
sniff(m);
else
else {
object = menu->objectFromUid(pathfirst);
parameter = qobject_cast<dtkWidgetsMenuItemParameter *>(object);
}
};
if(root)
......@@ -979,12 +984,15 @@ dtkWidgetsParameter *dtkWidgetsMenuBar::parameterWidget(const QString& id)
if(path.isEmpty())
return;
QObject *object = menu->object(path.takeFirst());
const QString &pathfirst = path.takeFirst();
QObject *object = menu->object(pathfirst);
if (dtkWidgetsMenu *m = qobject_cast<dtkWidgetsMenu *>(object))
sniff(m);
else
else {
object = menu->objectFromUid(pathfirst);
parameter = qobject_cast<dtkWidgetsMenuItemParameter *>(object);
}
};
if(root)
......
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