void QuickEdit::AssignItemsForOperation(QSharedPointer<TreeItemInterface> root, BrowserNode* node) { QList<QSharedPointer<TreeItemInterface>> items; auto interfaceItem = CreateInterfaceNode(root, operationController, node); BrowserOperation* operationNode = static_cast<BrowserOperation*>(node); // first we make a dummy node for return type QSharedPointer<BrowserNode> returnType(new BrowserOperationReturnType(dummyView, operationNode)); QList<QSharedPointer<BrowserNode>> operationNodes; operationNodes << returnType; // next we make dummy nodes for all attributes int paramCount = ((OperationData*)operationNode->get_data())->nparams; for (int i = 0; i < paramCount; ++i) { QSharedPointer<BrowserNode> param(new BrowserOperationAttribute(dummyView, operationNode, ((OperationData*)operationNode->get_data())->params[i])); operationNodes << param; items << CreateInterfaceNode(interfaceItem, operationAttributeController, param.data()); } interfaceItem->AddChildren(items); root->AddChildren(QList<QSharedPointer<TreeItemInterface>>() << interfaceItem); localNodeHolder.append(operationNodes); }
void QuickEdit::AddParameter() { QModelIndex current = ui->tvEditor->selectionModel()->currentIndex(); if (!current.isValid()) return; current = current.sibling(current.row(), 0); TreeItemInterface* itemAsInterface = static_cast<TreeItemInterface*>(current.internalPointer()); BrowserNode* currentNode = static_cast<BrowserNode*>(itemAsInterface->InternalPointer()); BrowserOperation* operationNode; if (currentNode->TypeID() == TypeIdentifier<BrowserOperation>::id()) { operationNode = static_cast<BrowserOperation*>(currentNode); } else if (currentNode->TypeID() == TypeIdentifier<BrowserOperationAttribute>::id()) { operationNode = static_cast<BrowserOperationAttribute*>(currentNode)->get_operation(); itemAsInterface = itemAsInterface->parent(); current = current.parent(); } else return; OperationData* currentData = static_cast<OperationData*>(operationNode->get_data()); int originalParamCount = currentData->nparams; currentData->set_n_params(originalParamCount + 1); QModelIndex parentIndex = current.parent(); parentIndex = parentIndex.sibling(parentIndex.row(), 0); TreeItemInterface* parent = static_cast<TreeItemInterface*>(parentIndex.internalPointer()); if (!parent) parent = treeModel->RootItem(); int insertIndex = parent->GetIndexOfChild(itemAsInterface); auto sharedOfOperation = parent->GetChildren()[insertIndex]; int newItemPosition = currentData->nparams; if (!treeModel->insertRows(sharedOfOperation->childCount(), 1, current)) return; QSharedPointer<BrowserNode> param(new BrowserOperationAttribute(dummyView, static_cast<BrowserOperation*>(operationNode), currentData->params.last())); localNodeHolder.push_back(param); if (!current.isValid()) return; QModelIndex newItem = treeModel->index(sharedOfOperation->childCount() - 1, 0, current); TreeItemInterface *newItemInterface = static_cast<TreeItemInterface*>(newItem.internalPointer()); TreeItem<BrowserNode>* newItemAsNode = static_cast<TreeItem<BrowserNode>*>(newItemInterface); newItemAsNode->SetController(operationAttributeController); newItemAsNode->SetParent(sharedOfOperation); newItemAsNode->SetInternalData(param.data()); operationNode->modified(); OperationFuncs::recompute_param(operationNode, newItemPosition - 1, true); }
OperationListDialog::OperationListDialog(const char * m, Q3PtrList<BrowserOperation> & l) : QDialog(0, m, TRUE) { setCaption(m); move(QCursor::pos()); Q3VBoxLayout * vbox = new Q3VBoxLayout(this); Q3HBoxLayout * hbox; vbox->setMargin(5); cb = new Q3ComboBox(FALSE, this); vbox->addWidget(cb); for (BrowserOperation * oper = l.first(); oper; oper = l.next()) { QString s = ((BrowserNode *) oper->parent())->get_name() + QString("::") + oper->get_data()->definition(TRUE, FALSE); if (((OperationData *) oper->get_data())->get_is_abstract()) cb->insertItem("[a] " + s); else cb->insertItem(s); } hbox = new Q3HBoxLayout(vbox); hbox->setMargin(5); QPushButton * ok = new QPushButton(TR("&OK"), this); QPushButton * cancel = new QPushButton(TR("&Cancel"), this); QSize bs(cancel->sizeHint()); ok->setDefault(TRUE); ok->setFixedSize(bs); cancel->setFixedSize(bs); hbox->addWidget(ok); hbox->addWidget(cancel); UmlDesktop::limitsize_center(this, previous_size, 0.8, 0.8); connect(ok, SIGNAL(clicked()), this, SLOT(accept())); connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); }
void QuickEdit::MoveMarked(bool before) { QModelIndex current = ui->tvEditor->currentIndex(); if(!current.isValid()) return; TreeItemInterface *itemAsInterface = static_cast<TreeItemInterface*>(current.internalPointer()); BrowserNode* currentNode = static_cast<BrowserNode*>(itemAsInterface->InternalPointer()); //next we reorganize nodes in parent TreeItemInterface* parentInterface = itemAsInterface->parent(); QList<QSharedPointer<TreeItemInterface>> children = parentInterface->GetChildren(); QList<QSharedPointer<TreeItemInterface>> markedChildren; // we store all marked nodes QList<BrowserNode*> parentList; for(QSharedPointer<TreeItemInterface> child : children) { BrowserNode* childNode = static_cast<BrowserNode*>(child->InternalPointer()); if(!parentList.contains(static_cast<BrowserNode*>(childNode->parent()))) parentList.append(static_cast<BrowserNode*>(childNode->parent())); if(childNode->markedp()) markedChildren.append(child); } if(parentList.size() > 1) return; // remove all marked from children for(QSharedPointer<TreeItemInterface> child : markedChildren) { children.remove(child); } //get the new position of origin node int newPositionOfCurrent = -1; for(QSharedPointer<TreeItemInterface> child : children) { newPositionOfCurrent++; BrowserNode* childNode = static_cast<BrowserNode*>(child->InternalPointer()); if(childNode == currentNode) { if(!before) newPositionOfCurrent++; break; } } //insert the nodes back std::reverse(markedChildren.begin(), markedChildren.end()); for(QSharedPointer<TreeItemInterface> child : markedChildren) { children.insert(newPositionOfCurrent, child); } QSharedPointer<TreeItemInterface> sharedOfOperation = GetSharedOfOperation(current.parent()); TreeItem<BrowserNode>* operationItemAsNode = static_cast<TreeItem<BrowserNode>*>(sharedOfOperation.data()); // reorganize params vector BrowserOperation* operationNode = static_cast<BrowserOperation*>(operationItemAsNode->InternalPointer()); OperationData* operationData = static_cast<OperationData*>(operationNode->get_data()); operationData->params.clear(); for(QSharedPointer<TreeItemInterface> child : children) { BrowserOperationAttribute* attributeNode = static_cast<BrowserOperationAttribute*>(child->InternalPointer()); operationData->params.append(attributeNode->get_param()); } // install children back QModelIndex parentIndex = current.parent(); treeModel->removeRows(0 , children.count(), parentIndex); treeModel->insertRows(0 , children.count(), parentIndex); int pos = -1; for(QSharedPointer<TreeItemInterface> child : children) { pos++; QModelIndex newItem = treeModel->index(pos,0,parentIndex); if(!newItem.isValid()) continue; TreeItemInterface *newItemInterface = static_cast<TreeItemInterface*>(newItem.internalPointer()); TreeItem<BrowserNode>* newItemAsNode = static_cast<TreeItem<BrowserNode>*>(newItemInterface); newItemAsNode->SetController(operationAttributeController); newItemAsNode->SetParent(sharedOfOperation); newItemAsNode->SetInternalData(static_cast<BrowserNode*>(child->InternalPointer())); } pos = -1; for(QSharedPointer<TreeItemInterface> child : children) { pos++; QModelIndex newItem = treeModel->index(pos,0,parentIndex); if(!newItem.isValid()) continue; BrowserNode* node = static_cast<BrowserNode*>(child->InternalPointer()); node->set_marked(false); } QModelIndex newItem = treeModel->index(pos,0,parentIndex); if(newItem.isValid()) pos++; operationNode->modified(); }
void QuickEdit::SetupOperationController() { operationController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>()); operationController->SetColumns(columns); ADD_GETSET(BrowserOperation, operationController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toString().toLatin1().constData, get_name, set_name); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("type"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toString, get_return_type().get_type, set_return_type); ADD_GETSET_CONVERTED(BrowserOperation, operationController, columns.indexOf("visibility"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toString,BrowserNode::encode_visibility,visibility_as_string, pointer->def->set_uml_visibility); ADD_GETSET(BrowserOperation, operationController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool, deletedp, set_deleted); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("static"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_isa_class_operation, set_isa_class_operation); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("abstract"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_is_abstract, set_is_abstract); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("const"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_const, set_cpp_const); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("volatile"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_is_volatile, set_is_volatile); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("friend"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_friend, set_cpp_friend); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("virtual"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_virtual, set_cpp_virtual); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("inline"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_inline, set_cpp_inline); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("defaulted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_default, set_cpp_default); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("delete"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_delete, set_cpp_delete); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("override"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_override, set_cpp_override); ADD_GETSET_DATA(BrowserOperation, OperationData, operationController, columns.indexOf("final"), QVector<int>({Qt::DisplayRole,Qt::EditRole}), toBool,get_cpp_final, set_cpp_final); std::function<void(BrowserNode*,const QModelIndex& index)> f = [](BrowserNode* node ,const QModelIndex& index) { Q_UNUSED(index); BrowserOperation* oper = static_cast<BrowserOperation*>(node); oper->modified(); oper->setText(0,oper->get_name() ); oper->package_modified(); oper->get_data()->modified(); }; operationController->AddPostProcessors(columns.indexOf("name"), QVector<int>(QVector<int>({Qt::DisplayRole,Qt::EditRole})),f); ADD_PIXMAP_GETTER(BrowserOperation, operationController, columns.indexOf("name"),QVector<int>({Qt::DecorationRole}), pixmap); operationController->AddFlagsFunctor ( [&](const QModelIndex& index) { Qt::ItemFlags result; result |= Qt::ItemIsSelectable; if(!(index.column() *in(columns.indexOf("name"),columns.indexOf("type"),columns.indexOf("static"),columns.indexOf("visibility"),columns.indexOf("abstract"), columns.indexOf("const"), columns.indexOf("volatile"),columns.indexOf("friend"),columns.indexOf("virtual"),columns.indexOf("inline") ,columns.indexOf("defaulted"),columns.indexOf("delete"),columns.indexOf("override"),columns.indexOf("final"), columns.indexOf("deleted")))) return result; TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer()); if(!iface) return result; BrowserOperation* pointer = static_cast<BrowserOperation*>(iface->InternalPointer()); if(!pointer) return result; if(pointer->is_writable() && !((OperationData*)pointer->get_data())->get_or_set()) result |= Qt::ItemIsEditable; result |= Qt::ItemIsEnabled; return result; } ); }