#pragma once #include "fusion_model.hpp" #include "boost_any_to_qvariant.hpp" #include "meta_types.hpp" #include "gui_item_delegate.hpp" #include #include #include #include #include #include #include template struct QtModelType { typedef void type; }; template struct QtModelType> { typedef QAbstractTableModel type; }; template struct QtModelType> { typedef QAbstractTableModel type; }; template struct widget_type { // typedef void type; }; template struct widget_type> { typedef typename T::widget type; }; template struct widget_type&&> { typedef typename T::widget type; }; template struct widget_type&> { typedef typename T::widget type; }; template struct QtWidget : public T { GuiItemDelegate delegate; std::shared_ptr model; QtWidget(std::shared_ptr model, QWidget* parent = nullptr) : T(parent) , delegate() , model(model) { T::setModel(this->model.get()); T::setItemDelegate(&delegate); } }; template struct QtAdapter : public Q { typedef void view; QtAdapter(T) {} }; template struct QtAdapter : public QAbstractTableModel { typedef QTableView view; typedef QtWidget> widget; T model; QtAdapter(T model) : model(model) {} virtual int rowCount(QModelIndex const&) const override { return model.row_count(); } virtual int columnCount(QModelIndex const&) const override { return model.column_count(); } virtual QVariant data(QModelIndex const& index, int role) const override { if(role != Qt::DisplayRole) return QVariant(); return to_qvariant(model.get_cell(index.row(), index.column()), index.column()); } virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override { if(role != Qt::DisplayRole) { return QVariant(); } if(orientation == Qt::Horizontal && T::has_header_h) { return QVariant(QString::fromStdString(model.field_name(section))); } if(orientation == Qt::Vertical && T::has_header_v) { return QVariant(QString::fromStdString(model.key(section))); } return QVariant(); } }; template std::shared_ptr::type>> make_qt_adapter(T value) { typedef QtAdapter::type> type; return std::make_shared(value); }