23 #include <QDataWidgetMapper>
24 #include <QStyleOptionViewItem>
42 mapper.setModel(&view_model);
43 mapper.setItemDelegate(&delegate);
48 return std::unique_ptr<CustomEditor>(
dynamic_cast<CustomEditor*
>(
49 delegate.
createEditor(
nullptr, QStyleOptionViewItem(), index)));
54 mapper.setRootIndex(index.parent());
55 mapper.setCurrentModelIndex(index.sibling(index.row(), 0));
56 mapper.addMapping(widget, 1);
60 std::unique_ptr<TestData>
test_data() {
return std::make_unique<TestData>(); }
70 auto parent_index = test_data.view_model.index(0, 0);
71 auto x_value_index = test_data.view_model.index(0, 1, parent_index);
73 EXPECT_TRUE(test_data.create_editor(x_value_index).get() !=
nullptr);
81 auto vector_item = test_data.model.insertItem<
VectorItem>();
86 auto x_value_index = test_data.view_model.indexOfSessionItem(x_item).at(1);
87 auto editor = test_data.create_editor(x_value_index);
89 test_data.map_to_index(editor.get(), x_value_index);
92 editor->dataChanged(editor->data());
93 EXPECT_EQ(x_item->
data<
double>(), 43.0);
Base class for all custom variant editors.
View model to show content of SessionModel in Qt widgets: two column tree with label/data.
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Main class to hold hierarchy of SessionItem objects.
Vector item with three x,y,z property items.
static const std::string P_X
Model delegate to provide editing/painting for custom variants.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Tests of ViewModelDelegate class.
std::unique_ptr< TestData > test_data()
materialitems.h Collection of materials to populate MaterialModel.
DefaultViewModel view_model
std::unique_ptr< CustomEditor > create_editor(const QModelIndex &index)
ViewModelDelegate delegate
void map_to_index(QWidget *widget, const QModelIndex &index)
TEST_F(ViewModelDelegateTest, createEditor)