Commit 4607b607 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

fix clean and remove methods; remove unused files

parent afb70cfb
......@@ -13,6 +13,7 @@
// Code:
#include "dtkCorePluginWidgetManager.h"
#include <dtkLog>
// ///////////////////////////////////////////////////////////////////
......@@ -44,8 +45,12 @@ void dtkCorePluginWidgetManager::add(const void *ptr, const QVariant& v, QWidget
int dtkCorePluginWidgetManager::remove(const void *ptr)
{
return d->widgets.remove(ptr);
return d->variants.remove(ptr);
int n_w = d->widgets.remove(ptr);
int n_v = d->variants.remove(ptr);
if (n_v != n_w) {
dtkWarn() << Q_FUNC_INFO << "Not the same number of variants and objects removed from tables !" << n_w << n_v;
}
return n_v;
}
int dtkCorePluginWidgetManager::remove(QWidget *w)
......@@ -68,6 +73,7 @@ int dtkCorePluginWidgetManager::remove(QWidget *w)
void dtkCorePluginWidgetManager::clear(void)
{
d->widgets.clear();
d->variants.clear();
}
QWidget *dtkCorePluginWidgetManager::widget(const void *ptr) const
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <dtkWidgetsExport.h>
class QWidget;
// ///////////////////////////////////////////////////////////////////
// Widget Definition
// ///////////////////////////////////////////////////////////////////
#define DTK_DECLARE_WIDGET_CLASS(type, Export) \
class Export type##Widget : public QWidget \
{ \
public: \
type##Widget(QWidget *parent) : QWidget(parent) { \
\
} \
\
public: \
virtual void setProcess(type *process) = 0; \
};
// ///////////////////////////////////////////////////////////////////
// Trait definition
// ///////////////////////////////////////////////////////////////////
template <typename T> class dtkWidgetTrait {};
#define DTK_DECLARE_WIDGET_TRAIT(type) \
template <> class dtkWidgetTrait<type> \
{ \
public: \
typedef type##Widget WidgetType; \
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetFactory
// ///////////////////////////////////////////////////////////////////
template <typename T> class dtkWidgetFactory : public QObject
{
public:
dtkWidgetFactory(void);
~dtkWidgetFactory(void);
public:
typedef typename dtkWidgetTrait<T>::WidgetType *(*creator) ();
public:
void record(const QString& key, creator widget);
public:
typename dtkWidgetTrait<T>::WidgetType *get(const QString& key, T *process);
public:
QStringList keys(void) const;
private:
QHash<QString, creator> m_widgets;
QHash<T *, typename dtkWidgetTrait<T>::WidgetType *> m_instanciated;
};
#include "dtkWidgetFactory.tpp"
#define DTK_ASSOCIATE_WIDGET(type, Export) \
DTK_DECLARE_WIDGET_CLASS(type, Export);\
DTK_DECLARE_WIDGET_TRAIT(type);
//
// dtkWidgetFactory.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <dtkLog>
#include "dtkWidgetFactory.h"
template <typename T> dtkWidgetFactory<T>::dtkWidgetFactory(void)
{
}
template <typename T> dtkWidgetFactory<T>::~dtkWidgetFactory(void)
{
}
// /////////////////////////////////////////////////////////////////
// Type creator registration
// /////////////////////////////////////////////////////////////////
template <typename T> void dtkWidgetFactory<T>::record(const QString& key, creator widget)
{
if (this->m_widgets.contains(key)) {
dtkTrace() << Q_FUNC_INFO << "Factory already contains key" << key << ". Nothing is done";
return;
}
this->m_widgets.insert(key, widget);
}
// /////////////////////////////////////////////////////////////////
// Type creator invokation
// /////////////////////////////////////////////////////////////////
template <typename T> typename dtkWidgetTrait<T>::WidgetType *dtkWidgetFactory<T>::get(const QString& key, T *process)
{
if (!this->m_widgets.contains(key))
return NULL;
if (!m_instanciated.contains(process)) {
this->m_instanciated.insert(process, this->m_widgets.value(key)());
}
return this->m_instanciated.value(process);
}
// /////////////////////////////////////////////////////////////////
// Type creator inspection
// /////////////////////////////////////////////////////////////////
template <typename T> QStringList dtkWidgetFactory<T>::keys(void) const
{
return this->m_widgets.keys();
}
//
// dtkWidgetFactory_t.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