23 #include <QTextStream>
38 auto all_selected = selection_model->selectedMaterials();
39 auto selected = all_selected.empty() ? nullptr : all_selected.back();
41 return {selected->parent(), selected->tagRow().next()};
42 return {root_item(),
TagRow{}};
49 return selection_model->viewModel()->sessionItemFromIndex(QModelIndex());
53 MaterialEditorActions::MaterialEditorActions(QObject* parent)
60 p_impl->material_model = model;
65 p_impl->selection_model = selection_model;
70 if (!
p_impl->material_model)
73 auto [parent, tagrow] =
p_impl->locateInsertPlace();
74 auto material =
p_impl->material_model->addDefaultMaterial(tagrow);
75 p_impl->selection_model->selectItem(material);
82 if (!
p_impl->material_model)
85 std::vector<ModelView::SessionItem*> new_selection;
86 for (
const auto item :
p_impl->selection_model->selectedMaterials())
87 new_selection.push_back(
p_impl->material_model->cloneMaterial(item));
88 p_impl->selection_model->selectItems(new_selection);
93 if (!
p_impl->selection_model)
96 for (
auto item :
p_impl->selection_model->selectedMaterials())
102 if (!
p_impl->selection_model)
105 for (
auto item :
p_impl->selection_model->selectedMaterials())
111 if (!
p_impl->selection_model)
114 auto items =
p_impl->selection_model->selectedMaterials();
115 std::reverse(items.begin(), items.end());
116 for (
auto item :
p_impl->selection_model->selectedMaterials())
122 auto item =
p_impl->root_item();
123 const auto containers = item->children();
129 for (
auto container : containers) {
130 auto data = container->modelType();
131 for (
auto fields :
dynamic_cast<MaterialBaseItem*
>(container)->children()) {
133 titleData += (fields->displayName()).c_str();
136 auto val = fields->data<QVariant>(1);
137 if (strcmp(val.typeName(),
"std::string") == 0) {
138 tableData += val.value<std::string>().c_str();
140 }
else if (strcmp(val.typeName(),
"int") == 0) {
141 auto int_val = val.value<
int>();
142 tableData += QString::number(int_val);
144 }
else if (strcmp(val.typeName(),
"double") == 0) {
145 auto double_val = val.value<
double>();
146 tableData += QString::number(double_val);
148 }
else if (strcmp(val.typeName(),
"float") == 0) {
149 auto float_val = val.value<
float>();
150 tableData += QString::number(float_val);
153 auto color_str = val.toString();
154 tableData += color_str;
160 tableData = titleData + tableData;
166 QFile txtFile(
"materialdata");
167 if (txtFile.open(QIODevice::WriteOnly)) {
169 QTextStream out(&txtFile);
The main object representing an editable/displayable/serializable entity.
Aggregate to hold (tag, row) information for SessionModel.
Base class with all materials with name and color defined.
void setMaterialSelectionModel(MaterialSelectionModel *selection_model)
void onCloneMaterial()
Processes request to clone selected materials.
std::unique_ptr< MaterialEditorActionsImpl > p_impl
void setModel(MaterialModel *model)
Model to hold MaterialItems.
Custom selection model for material view model (AbstractViewModel).
MVVM_MODEL_EXPORT void MoveDown(SessionItem *item)
Moves item down (increments row of the item). Works on children belonging to single tag.
MVVM_MODEL_EXPORT void MoveUp(SessionItem *item)
Moves item up (decrements row of the item). Works on children belonging to single tag.
MVVM_MODEL_EXPORT void DeleteItemFromModel(SessionItem *item)
Removes and deletes item from its model.
materialitems.h Collection of materials to populate MaterialModel.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
ModelView::SessionItem * root_item()
Returns a multi layer playing the role of invisible root item.
MaterialEditorActionsImpl()
std::pair< SessionItem *, TagRow > locateInsertPlace()
Finds parent and tagrow to insert new item.