Skip to content

Instantly share code, notes, and snippets.

@Riateche
Created August 16, 2012 11:29
Show Gist options
  • Save Riateche/3369481 to your computer and use it in GitHub Desktop.
Save Riateche/3369481 to your computer and use it in GitHub Desktop.
namespace hsp {
class File;
class Properties_widget;
template<class T>
class Properties_registry_entry {
public:
Properties_registry_entry() {}
T* get_instance(File* file) { return new T(file); }
private:
};
class Properties_module : public QObject, public Hearty {
Q_OBJECT
public:
explicit Properties_module(Heart *h);
template<class T>
void register_widget(QString name, QString title) {
if (registry.contains(name)) {
qWarning("Properties_module::register_widget: name already exists");
}
registry.insert(name, new Properties_registry_entry<T>());
titles_registry.insert(name, title);
}
inline const QMap<QString, QString>& get_list() { return titles_registry; }
Properties_widget* get_widget(QString name, File* file);
signals:
public slots:
private:
QMap<QString, Properties_registry_entry<Properties_widget>*> registry;
QMap<QString, QString> titles_registry;
//QList<Properties_tab*> widgets;
};
namespace hsp {
Properties_module::Properties_module(Heart* h) :
Hearty(h)
{
}
Properties_widget *Properties_module::get_widget(QString name, File *file) {
if (!registry.contains(name)) {
qWarning("Properties_module::get_tab: unregistered name");
}
return registry[name]->get_instance(file);
}
} // namespace hsp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment