diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2014-05-15 14:52:31 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2014-05-15 14:52:31 +0200 |
| commit | 2f6c50d2764138583dcf89d86b13440a23f217cf (patch) | |
| tree | 08cc78ff875c1501375f7a28401da3b3fd327d82 /qt_adapter.hpp | |
| parent | 6a1e6120c4efc46f1d192b0e5fabc06b780113cc (diff) | |
| download | generic-gui-2f6c50d2764138583dcf89d86b13440a23f217cf.tar.gz generic-gui-2f6c50d2764138583dcf89d86b13440a23f217cf.tar.bz2 generic-gui-2f6c50d2764138583dcf89d86b13440a23f217cf.zip | |
3 major changes.
Renamed fusion_model to FusionModel to follow the naming convention.
Added observers so models can be shared over views and update properly.
Constness in datastructure now makes the data uneditable.
Diffstat (limited to 'qt_adapter.hpp')
| -rw-r--r-- | qt_adapter.hpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/qt_adapter.hpp b/qt_adapter.hpp index dea660f..23a8c9f 100644 --- a/qt_adapter.hpp +++ b/qt_adapter.hpp @@ -47,7 +47,6 @@ struct AdapterType; template <typename T, typename Model> struct QtWidget : public T { - GuiItemDelegate delegate; std::shared_ptr<typename AdapterType<Model>::type> model; @@ -56,14 +55,34 @@ struct QtWidget : public T { , delegate() , model(std::make_shared<typename AdapterType<Model>::type>(model)) { + model->add_observer(this->model); T::setModel(this->model.get()); T::setItemDelegate(&delegate); T::setEditTriggers(QAbstractItemView::DoubleClicked); } }; +template <typename Model> +struct QtAdapterBase : public Model, public FusionModelObserver +{ + virtual void cell_changed(int row, int column) override + { + emit this->dataChanged(this->createIndex(row, column), this->createIndex(row, column)); + } + + virtual void append_row_begin() override + { + this->beginInsertRows(QModelIndex(), this->rowCount(QModelIndex()), this->rowCount(QModelIndex())); + } + + virtual void append_row_end() override + { + this->endInsertRows(); + } +}; + template <typename T> -struct QtAdapter<T, QAbstractTableModel> : public QAbstractTableModel +struct QtAdapter<T, QAbstractTableModel> : public QtAdapterBase<QAbstractTableModel> { typedef QTableView view; typedef QtWidget<view, T> widget; @@ -95,7 +114,9 @@ struct QtAdapter<T, QAbstractTableModel> : public QAbstractTableModel virtual Qt::ItemFlags flags(const QModelIndex &index) const { - return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; + bool constness = is_const<typename T::row_type>(index.column()); + + return QAbstractTableModel::flags(index) | (constness ? Qt::NoItemFlags : Qt::ItemIsEditable); } virtual QVariant data(QModelIndex const& index, int role) const override |
