43 EXPECT_TRUE(item.
data<QVariant>().isValid());
46 ASSERT_EQ(item.
children().size(), 3);
49 EXPECT_EQ(item.
children().at(0)->parent(), &item);
50 EXPECT_EQ(item.
children().at(1)->parent(), &item);
51 EXPECT_EQ(item.
children().at(2)->parent(), &item);
57 std::vector<std::string>({
"Cylinder",
"Full sphere",
"Anysotropical pyramid"}));
69 EXPECT_TRUE(item.
data<QVariant>().isValid());
70 EXPECT_EQ(item.
children().size(), 3);
76 std::vector<std::string>({
"Cylinder",
"Full sphere",
"Anysotropical pyramid"}));
90 ASSERT_TRUE(item !=
nullptr);
92 EXPECT_EQ(item->currentIndex(), 1);
93 ASSERT_TRUE(item->currentItem() !=
nullptr);
94 EXPECT_TRUE(item->data<QVariant>().isValid());
95 EXPECT_EQ(item->currentType(), item->currentItem()->modelType());
96 EXPECT_EQ(item->children().size(), 3);
99 EXPECT_EQ(item->children().at(0)->parent(), item);
100 EXPECT_EQ(item->children().at(1)->parent(), item);
101 EXPECT_EQ(item->children().at(2)->parent(), item);
104 EXPECT_EQ(item->children().at(0)->model(), &model);
105 EXPECT_EQ(item->children().at(1)->model(), &model);
106 EXPECT_EQ(item->children().at(2)->model(), &model);
113 ASSERT_TRUE(item !=
nullptr);
116 EXPECT_EQ(item->currentIndex(), 1);
125 EXPECT_EQ(item->currentIndex(), 0);
138 EXPECT_EQ(labelItem.data(Qt::DisplayRole).toString().toStdString(),
156 EXPECT_EQ(viewModel.rowCount(), 1);
157 EXPECT_EQ(viewModel.columnCount(), 2);
160 QModelIndex groupIndex = viewModel.index(0, 0);
161 EXPECT_EQ(viewModel.sessionItemFromIndex(groupIndex), groupItem);
162 EXPECT_EQ(viewModel.columnCount(groupIndex), 2);
163 EXPECT_EQ(viewModel.rowCount(groupIndex), 3);
166 QSignalSpy spyRemove(&viewModel, &DefaultViewModel::rowsRemoved);
167 QSignalSpy spyInsert(&viewModel, &DefaultViewModel::rowsInserted);
168 QSignalSpy spyData(&viewModel, &DefaultViewModel::dataChanged);
176 EXPECT_EQ(spyRemove.count(), 0);
177 EXPECT_EQ(spyInsert.count(), 0);
178 EXPECT_EQ(spyData.count(), 1);
181 QList<QVariant> arguments = spyData.takeFirst();
182 QModelIndex dataIndex = viewModel.index(0, 1);
183 EXPECT_EQ(arguments.size(), 3);
184 EXPECT_EQ(arguments.at(0).value<QModelIndex>(), dataIndex);
185 EXPECT_EQ(arguments.at(1).value<QModelIndex>(), dataIndex);
186 QVector<int> expectedRoles = {Qt::DisplayRole, Qt::EditRole};
187 EXPECT_EQ(arguments.at(2).value<QVector<int>>(), expectedRoles);
190 groupIndex = viewModel.index(0, 0);
191 EXPECT_EQ(viewModel.sessionItemFromIndex(groupIndex), groupItem);
192 EXPECT_EQ(viewModel.columnCount(groupIndex), 2);
193 EXPECT_EQ(viewModel.rowCount(groupIndex), 3);
206 ASSERT_TRUE(groupItem !=
nullptr);
217 QModelIndex groupIndex = viewModel.
index(0, 0);
222 EXPECT_EQ(viewModel.
rowCount(groupIndex), 1);
226 QModelIndex radiusLabelIndex = viewModel.
index(0, 0, groupIndex);
227 QModelIndex radiusValueIndex = viewModel.
index(0, 1, groupIndex);
228 auto radiusLabelItem =
230 ASSERT_TRUE(radiusLabelItem !=
nullptr);
232 EXPECT_EQ(radiusLabelItem->item(), radiusPropertyItem);
233 auto radiusValueItem =
235 ASSERT_TRUE(radiusValueItem !=
nullptr);
236 EXPECT_EQ(radiusValueItem->item(), radiusPropertyItem);
240 QSignalSpy spyRemove(&viewModel, &DefaultViewModel::rowsRemoved);
241 QSignalSpy spyInsert(&viewModel, &DefaultViewModel::rowsInserted);
242 QSignalSpy spyData(&viewModel, &DefaultViewModel::dataChanged);
250 EXPECT_EQ(viewModel.
rowCount(groupIndex), 2);
254 QModelIndex radiusLabelIndex = viewModel.
index(0, 0, groupIndex);
255 QModelIndex radiusValueIndex = viewModel.
index(0, 1, groupIndex);
256 auto radiusLabelItem =
258 ASSERT_TRUE(radiusLabelItem !=
nullptr);
259 auto radiusPropertyItem =
261 EXPECT_EQ(radiusLabelItem->item(), radiusPropertyItem);
262 auto radiusValueItem =
264 ASSERT_TRUE(radiusValueItem !=
nullptr);
265 EXPECT_EQ(radiusValueItem->item(), radiusPropertyItem);
270 QModelIndex heightLabelIndex = viewModel.
index(1, 0, groupIndex);
271 QModelIndex heightValueIndex = viewModel.
index(1, 1, groupIndex);
272 auto heightLabelItem =
274 ASSERT_TRUE(heightLabelItem !=
nullptr);
275 auto heightPropertyItem =
277 EXPECT_EQ(heightLabelItem->item(), heightPropertyItem);
278 auto heightValueItem =
280 ASSERT_TRUE(heightPropertyItem !=
nullptr);
281 EXPECT_EQ(heightValueItem->item(), heightPropertyItem);
285 EXPECT_EQ(spyRemove.count(), 1);
286 EXPECT_EQ(spyInsert.count(), 2);
287 EXPECT_EQ(spyData.count(), 1);
Custom property to define list of string values with multiple selections.
std::vector< std::string > values() const
void setCurrentIndex(int index)
View model to show content of SessionModel in Qt widgets: two column tree with label/data.
const SessionItem * currentItem() const
Returns currently selected item.
void setCurrentType(const std::string &model_type)
Sets item corresponding to given model type.
std::string currentType() const
View model to show content of SessionModel in Qt widgets.
The main object representing an editable/displayable/serializable entity.
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.
T property(const std::string &tag) const
Returns data stored in property item.
model_type modelType() const
Returns item's model type.
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
bool setData(SessionItem *item, const Variant &value, int role)
Sets the data for given item.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Variant data(SessionItem *item, int role) const
Returns the data for given item and role.
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Represents data role of SessionItem in any cell of Qt's trees and tables.
QVariant data(int role) const override
Returns the data for given role according to Qt::ItemDataRole namespace definitions.
Represents display name of SessionItem in any cell of Qt's trees and tables.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
ViewItem * itemFromIndex(const QModelIndex &index) const
Returns a pointer to the RefViewItem associated with the given index.
void setRootSessionItem(SessionItem *item)
SessionItem * sessionItemFromIndex(const QModelIndex &index) const
Tests of toy ShapeGroup in the context of model and viewmodel.
~ToyItemsShapeGroupTest()
static const std::string P_HEIGHT
static const std::string P_RADIUS
Represents a group item holding a collection of shapes.
static const std::string P_RADIUS
const int DATA
main data role
materialitems.h Collection of materials to populate MaterialModel.
const ModelView::model_type SphereItemType
const ModelView::model_type CylinderItemType
const ModelView::model_type ShapeGroupItemType
TEST_F(ToyItemsShapeGroupTest, initialState)
Toy multilayer as produced bo toy SampleModel.