Commit 37d80eba authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Fix collision in the map since QVariant has no operator <

parent 41cd2663
......@@ -99,17 +99,16 @@ template <typename T> inline bool dtkComposerNodeObject<T>::implementationHasCha
template <typename T> inline QWidget *dtkComposerNodeObject<T>::editor(void)
{
if (!m_factory) {
if (!m_factory || !m_object) {
return nullptr;
}
QVariant v = dtkMetaType::variantFromValue(this->object());
QWidget *w = dtkCorePluginWidgetManager::instance().widget(v);
QWidget *w = dtkCorePluginWidgetManager::instance().widget(m_object);
if (!w) {
w = m_factory->createWidget(m_implementation);
if (w) {
dtkCorePluginWidgetManager::instance().add(v, w);
QVariant v = dtkMetaType::variantFromValue(m_object);
dtkCorePluginWidgetManager::instance().add(m_object, v, w);
}
}
return w;
......
......@@ -19,7 +19,8 @@
class dtkCorePluginWidgetManagerPrivate
{
public:
QMap<QVariant, QWidget *> widgets;
QHash<const void *, QWidget *> widgets;
QHash<const void *, QVariant> variants;
};
// ///////////////////////////////////////////////////////////////////
......@@ -33,21 +34,23 @@ dtkCorePluginWidgetManager& dtkCorePluginWidgetManager::instance(void)
return *s_instance;
}
void dtkCorePluginWidgetManager::add(const QVariant& v, QWidget *w)
void dtkCorePluginWidgetManager::add(const void *ptr, const QVariant& v, QWidget *w)
{
d->widgets.insert(v, w);
d->widgets.insert(ptr, w);
d->variants.insert(ptr, v);
emit added(v, w);
}
int dtkCorePluginWidgetManager::remove(const QVariant& v)
int dtkCorePluginWidgetManager::remove(const void *ptr)
{
return d->widgets.remove(v);
return d->widgets.remove(ptr);
return d->variants.remove(ptr);
}
int dtkCorePluginWidgetManager::remove(QWidget *w)
{
QList<QVariant> keys;
QList<const void *> keys;
for (auto it = d->widgets.begin(), end = d->widgets.end(); it != end; ++it) {
if (*it == w) {
......@@ -57,6 +60,7 @@ int dtkCorePluginWidgetManager::remove(QWidget *w)
for (auto&& k : keys) {
d->widgets.remove(k);
d->variants.remove(k);
}
return keys.size();
}
......@@ -66,9 +70,9 @@ void dtkCorePluginWidgetManager::clear(void)
d->widgets.clear();
}
QWidget *dtkCorePluginWidgetManager::widget(const QVariant& v) const
QWidget *dtkCorePluginWidgetManager::widget(const void *ptr) const
{
const QWidget *w = d->widgets.value(v, nullptr);
const QWidget *w = d->widgets.value(ptr, nullptr);
if (w) {
return const_cast<QWidget *>(w);
}
......@@ -81,8 +85,11 @@ QString dtkCorePluginWidgetManager::description(void) const
QString content("[ ");
int i = 0;
int e = d->widgets.count()-1;
for (auto it = d->widgets.cbegin(), end = d->widgets.cend(); it != end; ++it, ++i) {
content += it.key().typeName() + QStringLiteral(" : ") + reinterpret_cast<const QObject *>(it.value())->objectName();
auto it = d->widgets.cbegin();
auto end = d->widgets.cend();
auto vit = d->variants.cbegin();
for (;it != end; ++it, ++i, ++vit) {
content += vit.value().typeName() + QStringLiteral(" : ") + reinterpret_cast<const QObject *>(it.value())->objectName();
if (i < e) {
content += "\n";
} else {
......
......@@ -28,14 +28,14 @@ public:
static dtkCorePluginWidgetManager& instance(void);
public:
void add(const QVariant&, QWidget *);
void add(const void *, const QVariant&, QWidget *);
int remove(const QVariant&);
int remove(const void *);
int remove(QWidget *);
void clear(void);
QWidget *widget(const QVariant&) const;
QWidget *widget(const void *) const;
QString description(void) const;
......
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