Commit 70e4c263 authored by WINTZ Julien's avatar WINTZ Julien

Implements #13.

parent cf9129a9
......@@ -47,20 +47,20 @@ int main(int argc, char **argv)
// ///////////////////////////////////////////////////////////////////
if (dtkCoreParameter *parameter = application->window()->menubar()->parameter(":Model parameters 1:prec:"))
qDebug() << 1 << "Oh yeah";
qDebug() << 1 << "Oh yeah" << parameter;
if (dtkCoreParameter *parameter = application->window()->menubar()->parameter(":Model parameters 1:Model parameters 1.1:prec:"))
qDebug() << 2 << "Oh yeah";
qDebug() << 2 << "Oh yeah" << parameter;
// ///////////////////////////////////////////////////////////////////
// Retrieve an arbitrary parameter widget
// ///////////////////////////////////////////////////////////////////
if (dtkWidgetsParameter *parameter = application->window()->menubar()->parameterWidget(":Model parameters 1:prec:"))
qDebug() << 3 << "Oh yeah";
qDebug() << 3 << "Oh yeah" << parameter;
if (dtkWidgetsParameter *parameter = application->window()->menubar()->parameterWidget(":Model parameters 1:Model parameters 1.1prec:"))
qDebug() << 4 << "Oh yeah";
if (dtkWidgetsParameter *parameter = application->window()->menubar()->parameterWidget(":Model parameters 1:Model parameters 1.1:prec:"))
qDebug() << 4 << "Oh yeah" << parameter;
// ///////////////////////////////////////////////////////////////////
......
......@@ -230,6 +230,11 @@ QVector<dtkWidgetsMenu *> dtkWidgetsMenu::menus(void) const
return d->menu_list;
}
QObject *dtkWidgetsMenu::object(const QString& id)
{
return d->object_hash[id];
}
int dtkWidgetsMenu::icon(void) const
{
return d->icon_id;
......
......@@ -76,6 +76,8 @@ public:
QVector<dtkWidgetsMenu *> menus(void) const;
QObject *object(const QString&);
public:
int icon(void) const;
......
......@@ -699,16 +699,58 @@ void dtkWidgetsMenuBar::removeMenu(const QString &title)
dtkCoreParameter *dtkWidgetsMenuBar::parameter(const QString& id)
{
Q_UNUSED(id);
QStringList path = id.split(":", QString::SkipEmptyParts);
return nullptr;
dtkWidgetsMenu *root = d->menu_hash[path.takeFirst()];
dtkWidgetsMenuItemParameter *parameter = nullptr;
std::function<void (dtkWidgetsMenu *)> sniff = [&] (dtkWidgetsMenu *menu) -> void {
if(path.isEmpty())
return;
QObject *object = menu->object(path.takeFirst());
if (dtkWidgetsMenu *m = qobject_cast<dtkWidgetsMenu *>(object))
sniff(m);
else
parameter = qobject_cast<dtkWidgetsMenuItemParameter *>(object);
};
sniff(root);
if (parameter)
return parameter->parameter();
else
return nullptr;
}
dtkWidgetsParameter *dtkWidgetsMenuBar::parameterWidget(const QString& id)
{
Q_UNUSED(id);
QStringList path = id.split(":", QString::SkipEmptyParts);
return nullptr;
dtkWidgetsMenu *root = d->menu_hash[path.takeFirst()];
dtkWidgetsMenuItemParameter *parameter = nullptr;
std::function<void (dtkWidgetsMenu *)> sniff = [&] (dtkWidgetsMenu *menu) -> void {
if(path.isEmpty())
return;
QObject *object = menu->object(path.takeFirst());
if (dtkWidgetsMenu *m = qobject_cast<dtkWidgetsMenu *>(object))
sniff(m);
else
parameter = qobject_cast<dtkWidgetsMenuItemParameter *>(object);
};
sniff(root);
if (parameter)
return parameter->widget();
else
return nullptr;
}
void dtkWidgetsMenuBar::setCurrentIndex(int index)
......
......@@ -77,6 +77,7 @@ int dtkWidgetsMenuItem::icon(void) const
class dtkWidgetsMenuItemParameterPrivate
{
public:
dtkCoreParameter *parameter;
dtkWidgetsParameter *widget = nullptr;
};
......@@ -87,10 +88,15 @@ public:
dtkWidgetsMenuItemParameter::dtkWidgetsMenuItemParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation) : dtkWidgetsMenuItem(0, title, 0)
{
d = new dtkWidgetsMenuItemParameterPrivate;
d->parameter = parameter;
d->widget = ::dtk::widgets::parameters::pluginFactory().create(parameter, representation);
}
dtkCoreParameter *dtkWidgetsMenuItemParameter::parameter(void)
{
return d->parameter;
}
dtkWidgetsParameter *dtkWidgetsMenuItemParameter::widget(void)
{
return d->widget;
......
......@@ -78,6 +78,7 @@ public:
bool isParameter(void) const override { return true; }
public:
dtkCoreParameter *parameter(void);
dtkWidgetsParameter *widget(void);
private:
......
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