QJsonObject ObjectContainer::getData(int id) { ObjectItem* item = getItem(id); if (!item) { StaticLogger::logit("WARNING: Object not found! The object with id '" + QString::number(id) + "' does not exist."); return QJsonObject(); } return item->data().toJsonObject(); }
QVariant TreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (role != Qt::DisplayRole) return QVariant(); ObjectItem *item = static_cast<ObjectItem*>(index.internalPointer()); return item->data(index.column()); }
void ObjectContainer::modifyCmd(const QJsonObject& data, Modifications mod) { ObjectItem* item = getItem(data["id"].toInt()); if (!item) return; QJsonObject oldData = item->data().toJsonObject(); if (oldData != data) { QUndoCommand* cmd = new ModifyObjectCmd(oldData, data, item, mod); g_undoStack.push(cmd); } }
bool ObjectContainer::remove(int id) { ObjectItem* item = getItem(id); if (!item) { StaticLogger::logit("WARNING: Object not removed! The object with id '" + QString::number(id) + "' does not exist."); return false; } QJsonObject json = item->data().toJsonObject(); m_model.removeRow(item->row()); m_ids.erase(json["id"].toInt()); return true; }
void ObjectContainer::rendererModification(std::vector<QJsonObject> data) { QUndoCommand * transformation = new QUndoCommand(); transformation->setText("Modify via 3D view"); for (const auto& json : data) { ObjectItem* item = getItem(json["id"].toInt()); if (!item) continue; new ModifyObjectCmd(item->data().toJsonObject(), json, item, Position | Scaling | Rotation, transformation); // Add command to command group } g_undoStack.push(transformation); }
// ツリービュー ダブルクリック void AnimationForm::slot_treeViewDoubleClicked(QModelIndex index) { CObjectModel *pModel = m_pEditData->getObjectModel() ; if ( !pModel->isLayer(index) ) { return ; } ObjectItem *pItem = pModel->getItemFromIndex(index) ; if ( !pItem ) { return ; } QVariant flag = pItem->data(Qt::CheckStateRole) ; int f = flag.toInt() ; if ( f & ObjectItem::kState_Disp ) { f &= ~ObjectItem::kState_Disp ; } else { f |= ObjectItem::kState_Disp ; } pItem->setData(f, Qt::CheckStateRole); m_pGlWidget->update(); ui->treeView->update(index) ; }
ObjectItem* ObjectContainer::getItem(int id) { // count may be 0 or 1 for sets if (!m_ids.count(id)) { OutputDebugStringA(("ID:" + std::to_string(id) + " not found in id list!").c_str()); return nullptr; } //Iterate all items in list int rc = m_model.rowCount(); for (int i = 0; i < rc; ++i) { ObjectItem* item = static_cast<ObjectItem*>(m_model.item(i)); if (id == item->data().toJsonObject()["id"].toInt()) // Given id equals the id of the current object { return item; } } return nullptr; }
QVariant CObjectModel::data(const QModelIndex &index, int role) const { ObjectItem *p = getItemFromIndex(index) ; return p->data(role) ; }