summaryrefslogtreecommitdiff
path: root/qt_adapter.hpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2014-05-30 22:15:28 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2014-05-30 22:15:28 +0200
commita1737ecbd0aaea0aa8ce34557663cf0b4cdb8910 (patch)
treed8a9cbc97462889f8b8d72bbcb23f13d3c7bd663 /qt_adapter.hpp
parent79af684323abfa10abfc31003ab47fd89a03d625 (diff)
downloadgeneric-gui-a1737ecbd0aaea0aa8ce34557663cf0b4cdb8910.tar.gz
generic-gui-a1737ecbd0aaea0aa8ce34557663cf0b4cdb8910.tar.bz2
generic-gui-a1737ecbd0aaea0aa8ce34557663cf0b4cdb8910.zip
Unified and simplified the widget creation api.
Diffstat (limited to 'qt_adapter.hpp')
-rw-r--r--qt_adapter.hpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/qt_adapter.hpp b/qt_adapter.hpp
index 9a5c383..405f4f9 100644
--- a/qt_adapter.hpp
+++ b/qt_adapter.hpp
@@ -4,6 +4,7 @@
#include "boost_any_qvariant_convert.hpp"
#include "meta_types.hpp"
#include "gui_item_delegate.hpp"
+#include "form.hpp"
#include <QAbstractTableModel>
#include <QTableView>
@@ -16,6 +17,12 @@
#include <vector>
#include <map>
+namespace Gui
+{
+ struct Table{};
+ struct Form{};
+}
+
template <typename T>
struct QtModelType
{
@@ -215,9 +222,33 @@ struct WidgetType {
typedef typename AdapterType<Model>::type::widget type;
};
-template <typename Model>
-std::shared_ptr<typename WidgetType<Model>::type> make_qt_widget(std::shared_ptr<Model> x)
+//Generate a default Table-based widget.
+template <typename GuiType, typename Model, typename... Args>
+typename std::enable_if<std::is_same<Gui::Table, GuiType>::value, std::shared_ptr<typename WidgetType<Model>::type>>::type
+make_qt_widget(std::shared_ptr<Model> model, Args... args)
{
- auto widget_ptr = std::make_shared<typename WidgetType<Model>::type>(x);
+ auto widget_ptr = std::make_shared<typename WidgetType<Model>::type>(model, args...);
return widget_ptr;
}
+
+//Generate a default Form based widget.
+template <typename GuiType, typename Model, typename... Args>
+typename std::enable_if<std::is_same<Gui::Form, GuiType>::value, std::shared_ptr<Form<Model>>>::type
+make_qt_widget(std::shared_ptr<Model> model, Args... args)
+{
+ auto widget_ptr = std::make_shared<Form<Model>>(model, args...);
+ return widget_ptr;
+}
+
+//Generate a custom widget thats is neither a default Form or Table, for total specialisation of the function.
+template <typename GuiType, typename Model, typename... Args>
+typename std::enable_if<
+ !std::is_same<Gui::Form, GuiType>::value &&
+ !std::is_same<Gui::Table, GuiType>::value, std::shared_ptr<GuiType>
+>::type
+make_qt_widget(std::shared_ptr<Model> model, Args... args)
+{
+ auto widget_ptr = std::make_shared<GuiType>(model, args...);
+ return widget_ptr;
+}
+