Skip to content

Template-based tree and table model creation for Qt MVC in a modern c++11 functional style (More easy than direct using QAbstractItemModel, QAbstractTableModel and QAbstractTreeModel)

License

Notifications You must be signed in to change notification settings

narizhny/qt-mvc-templates

Repository files navigation

Qt MVC templates

Library for farst creating trees and tables

Adding to project

Just add "include(path_to_lib/Model.pri)" in your project file

Tree

#include "TreeModelCustomItem.h"
auto *i = new TreeModelCustomItem<Type>(Type(...));

//member function getter
i->addGetter(0, Qt::DisplayRole, &Type::fun);

//functor's getter
i->addGetter(0, Qt::ToolTipRole, [](const Type &t) -> QString {return t.getTip();});

//member function setter
i->addSetter(0, Qt::EditRole, &Type::setText);

//functor's setter
i->addSetter(0, Qt::EditRole, [](Type &t, const QString &value) {t.setText(value);});
i->addCheckingSetter(0, Qt::EditRole, [](Type &t, const QString &value) -> bool {return t.setText(value);});

auto *m = new TreeModel();
m->getRootItem()->appendChild(i);

You can add or remove items without calling beginInsertRows, beginRemoveRows etc. You should set column count in root item.

TreeModelCustomItem

Template-based item, to get column/role value by lambda/member pointer

TreeModelStandardItem

Item to set values in column/role implicitly.

Table

#include "TableModel.h"
...
QStringList sl;
sl << "One" << "Two" << "Three";
auto *tableModel = new TableModel<QStringList>();
tableModel->setValues(sl);
tableModel->addGetter(0, Qt::DisplayRole, [](const QString &value){return value;});
tableModel->addGetter(1, Qt::ToolTipRole, &QString::size);

You can add or remove rows without calling beginInsertRows, beginRemoveRows etc.

About

Template-based tree and table model creation for Qt MVC in a modern c++11 functional style (More easy than direct using QAbstractItemModel, QAbstractTableModel and QAbstractTreeModel)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published