Exemple #1
0
void QuickEdit::AddOperation()
{
    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());

    BrowserClass* classNode;

    int newItemPosition = 0;
    if(currentNode->TypeID()  == TypeIdentifier<BrowserClass>::id())
    {
        classNode = static_cast<BrowserClass*>(currentNode);
        newItemPosition = itemAsInterface->childCount();
    }
    else if(currentNode->TypeID()  == TypeIdentifier<BrowserOperation>::id() && current.parent().isValid())
    {
        itemAsInterface = static_cast<TreeItemInterface*>(current.parent().internalPointer());
        classNode = static_cast<BrowserClass*>(itemAsInterface->InternalPointer());
        newItemPosition = current.row()+1;
        current = current.parent();
    }
    else
        return;

    if(!classNode)
        return;
    BrowserOperation* newOperation = static_cast<BrowserOperation*>(classNode->addOperation());
    classNode->move(newOperation, currentNode);
    classNode->select_in_browser();
    QModelIndex parentIndex;
    TreeItemInterface* parent;
    if(treeModel->parent(current).isValid())
    {
        parentIndex = treeModel->parent(current);
        parentIndex = parentIndex.sibling(parentIndex.row(), 0);
        parent =  static_cast<TreeItemInterface*>(parentIndex.internalPointer());
    }
    else
        parent = treeModel->RootItem();
    int insertIndex = parent->GetIndexOfChild(itemAsInterface);
    QSharedPointer<TreeItemInterface> sharedOfOperation =  parent->GetChildren()[insertIndex];

    if(!treeModel->insertRows(newItemPosition-1, 1, current))
        return;

    if(!current.isValid())
        return;

    QModelIndex newItem = treeModel->index(newItemPosition-1,0,current);
    TreeItemInterface *newItemInterface = static_cast<TreeItemInterface*>(newItem.internalPointer());
    TreeItem<BrowserNode>* newItemAsNode = static_cast<TreeItem<BrowserNode>*>(newItemInterface);
    newItemAsNode->SetController(operationController);
    newItemAsNode->SetParent(sharedOfOperation);
    newItemAsNode->SetInternalData(newOperation);
}
Exemple #2
0
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);
}
Exemple #3
0
void QuickEdit::OnContextMenu(QPoint point)
{
    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());
    if(!itemAsInterface)
        return;

    CreateMenu();
    SetupMenu(itemAsInterface);
    if(currentNode->TypeID()  !=  TypeIdentifier<BrowserOperationAttribute>::id())
    {
        contextMenu->removeAction(actBefore);
        contextMenu->removeAction(actAfter);
    }

    contextMenu->popup(ui->tvEditor->mapToGlobal(point));
}