Пример #1
0
BrowserNode *QuickEdit::GetCurrentNode()
{
    QModelIndex current = ui->tvEditor->currentIndex();
    TreeItemInterface *itemAsInterface = static_cast<TreeItemInterface*>(current.internalPointer());
    BrowserNode* itemAsNode = static_cast<BrowserNode*>(itemAsInterface->InternalPointer());
    return itemAsNode;
}
Пример #2
0
void QuickEdit::SetupExtraNodeController()
{

    extraNodeController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>());
    extraNodeController->SetColumns(columns);
    ADD_GETSET(BrowserExtraMember, extraNodeController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString().toLatin1().constData, get_name, set_name);

    ADD_GETSET(BrowserExtraMember, extraNodeController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, deletedp, set_deleted);

    ADD_PIXMAP_GETTER(BrowserExtraMember, extraNodeController, columns.indexOf("name"), QVector<int>({Qt::DecorationRole}), pixmap);

    extraNodeController->AddFlagsFunctor
            (
                [&](const QModelIndex& index)
    {
        Qt::ItemFlags result;
        result |= Qt::ItemIsSelectable;
        if(!(index.column() *in(columns.indexOf("name"), columns.indexOf("deleted"))))
            return result;

        TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer());
        if(!iface)
            return result;
        BrowserNode* pointer = static_cast<BrowserNode*>(iface->InternalPointer());
        if(!pointer)
            return result;
        if(pointer->is_writable())
            result |= Qt::ItemIsEditable;
        result |=  Qt::ItemIsEnabled;
        return result;
    }
    );
}
Пример #3
0
QSharedPointer<TreeItemInterface> QuickEdit::GetSharedOfOperation(const QModelIndex & index)
{
    QModelIndex parentIndex = index.parent();
    parentIndex = parentIndex.sibling(parentIndex.row(), 0);
    TreeItemInterface* parent =  static_cast<TreeItemInterface*>(parentIndex.internalPointer());
    if(!parent)
        parent = treeModel->RootItem();
    TreeItemInterface *itemAsInterface = static_cast<TreeItemInterface*>(index.internalPointer());
    int operationIndex = parent->GetIndexOfChild(itemAsInterface);
    return parent->GetChildren()[operationIndex];
}
Пример #4
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);
}
Пример #5
0
void QuickEdit::SetupClassController()
{
    classController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>());
    classController->SetColumns(columns);
    ADD_GETSET(BrowserClass, classController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_name, set_name);
    ADD_GETSET(BrowserClass, classController, columns.indexOf("stereotype"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_stereotype, def->set_stereotype);

    ADD_GETSET(BrowserClass, classController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, deletedp, set_deleted);

    ADD_GETSET_CONVERTED(BrowserClass, classController, columns.indexOf("visibility"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                         toString,BrowserNode::encode_visibility,visibility_as_string, pointer->def->set_uml_visibility);

    ADD_GETSET(BrowserClass, classController, columns.indexOf("abstract"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, def->get_is_abstract, def->set_is_abstract);

    ADD_PIXMAP_GETTER(BrowserClass, classController, columns.indexOf("name"),QVector<int>({Qt::DecorationRole}), pixmap);


    classController->AddFlagsFunctor
            (
                [&](const QModelIndex& index)
    {
        Qt::ItemFlags result;
        result |= Qt::ItemIsSelectable;
        if(!(index.column() *in(columns.indexOf("name"),columns.indexOf("stereotype"),columns.indexOf("visibility"),columns.indexOf("abstract"), columns.indexOf("deleted"))))
            return result;

        TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer());
        if(!iface)
            return result;
        BrowserNode* pointer = static_cast<BrowserNode*>(iface->InternalPointer());
        if(!pointer)
            return result;
        if(pointer->is_writable())
            result |= Qt::ItemIsEditable;
        result |=  Qt::ItemIsEnabled;
        return result;
    }
    );
}
Пример #6
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));
}
Пример #7
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);
}
Пример #8
0
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();

}
Пример #9
0
void QuickEdit::SetupRelationController()
{
    relationController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>());
    relationController->SetColumns(columns);

    ADD_GETSET(BrowserRelation, relationController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_name, set_name);
    ADD_GETSET_DIRECT(BrowserRelation, relationController, columns.indexOf("default"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                      toString, def->a.init_value.operator QString());

    ADD_GETSET(BrowserRelation, relationController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, deletedp, set_deleted);

    std::function<void(RoleData& , UmlVisibility ) > f = [](RoleData& data, UmlVisibility vis){data.uml_visibility = vis;};

    ADD_PIXMAP_GETTER(BrowserRelation, relationController, columns.indexOf("name"), QVector<int>({Qt::DecorationRole}), pixmap);


    relationController->AddGetter(columns.indexOf("visibility"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (const BrowserNode* data, const QModelIndex& index)
{
    Q_UNUSED(index);
        if(!data)
    return QVariant();
    const BrowserRelation* pointer = static_cast<const BrowserRelation*>(data);
    if(pointer)
    return QVariant(pointer->visibility_as_string());
    else
    return QVariant();
    }
    );
    relationController->AddSetter(columns.indexOf("visibility"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (BrowserNode* data, QVariant value, const QModelIndex& index)
{
    Q_UNUSED(index);
        if(!data)
    return false;
    BrowserRelation* pointer = static_cast<BrowserRelation*>(data);
    if(pointer)
        pointer->def->a.uml_visibility = BrowserNode::encode_visibility(value.toString());
    pointer->modified();
    return true;
    }
    );


    ADD_GETSET_DIRECT(BrowserRelation, relationController, columns.indexOf("static"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                      toBool, def->a.isa_class_relation);
    ADD_GETSET_DIRECT(BrowserRelation, relationController, columns.indexOf("multiplicity"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                      toString, def->a.multiplicity.operator QString());

    relationController->AddGetter(columns.indexOf("type"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                                  [] (const BrowserNode* data, const QModelIndex& )
    {

        if(!data)
            return QVariant();
        const BrowserRelation* pointer = static_cast<const BrowserRelation*>(data);
        if(pointer)
            return QVariant(pointer->def->get_end_class()->get_name());
        else
            return QVariant();
    }
    );
    relationController->AddSetter(1,QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                                  [] (BrowserNode* data, QVariant value, const QModelIndex& )
    {
        if(!data)
            return false;
        BrowserRelation* pointer = static_cast<BrowserRelation*>(data);
        if(pointer)
            pointer->def->get_end_class()->set_name(value.toString());
        pointer->modified();
        return true;
    });


    relationController->AddFlagsFunctor
            (
                [&](const QModelIndex& index)
    {
        Qt::ItemFlags result;
        result |= Qt::ItemIsSelectable;
        if(!(index.column() *in(columns.indexOf("name"),columns.indexOf("type"),columns.indexOf("default"),columns.indexOf("visibility"), columns.indexOf("deleted"))))
            return result;

        TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer());
        if(!iface)
            return result;
        BrowserNode* pointer = static_cast<BrowserNode*>(iface->InternalPointer());
        if(!pointer)
            return result;
        if(pointer->is_writable() && (index.column() *in(columns.indexOf("name"),columns.indexOf("default"),columns.indexOf("visibility"))))
            result |= Qt::ItemIsEditable;
        result |=  Qt::ItemIsEnabled ;
        return result;
    }
    );
}
Пример #10
0
void QuickEdit::SetupOperationAttributeController()
{
    operationAttributeController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>());
    operationAttributeController->SetColumns(columns);
    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_name, set_name);
    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("type"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_param_type().get_type, set_param_type);
    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("default_value"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_default_value, set_default_value);
    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("direction"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_direction, set_direction);
    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, deletedp, set_deleted);

//    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("prefix"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
//               toString, get_specifier, set_specifier);

    ADD_GETSET(BrowserOperationAttribute, operationAttributeController, columns.indexOf("mark"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, markedp, set_marked);

    operationAttributeController->AddGetter(columns.indexOf("deleted"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (const BrowserNode* data, const QModelIndex& index)
{
        Q_UNUSED(index);
        if(!data)
    return QVariant();
    const BrowserOperationAttribute* pointer = static_cast<const BrowserOperationAttribute*>(data);
    if(pointer)
    return QVariant(pointer->deletedp());
    else
    return QVariant();
    }
    );
    operationAttributeController->AddSetter(columns.indexOf("deleted"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (BrowserNode* data, QVariant value, const QModelIndex& index)
 {
    if(!data)
    return false;
    BrowserOperationAttribute* pointer = static_cast<BrowserOperationAttribute*>(data);
    if(pointer)
    {
        pointer->set_deleted(value.toBool(), index.row());
        pointer->modified();
    }
    return true;
    }
    );

    operationAttributeController->AddGetter(columns.indexOf("prefix"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (const BrowserNode* data, const QModelIndex& index)
{
        Q_UNUSED(index);
        if(!data)
    return QVariant();
    const BrowserOperationAttribute* pointer = static_cast<const BrowserOperationAttribute*>(data);
    if(pointer)
        return QVariant(pointer->get_specifier(index.row()));
    else
    return QVariant();
    }
    );
    operationAttributeController->AddSetter(columns.indexOf("prefix"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (BrowserNode* data, QVariant value, const QModelIndex& index)
 {
    if(!data)
    return false;
    BrowserOperationAttribute* pointer = static_cast<BrowserOperationAttribute*>(data);
    if(pointer)
    {
        pointer->set_specifier(value.toString(), index.row());
        pointer->modified();
    }
    return true;
    }
    );

    operationAttributeController->AddGetter(columns.indexOf("postfix"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (const BrowserNode* data, const QModelIndex& index)
{
        Q_UNUSED(index);
        if(!data)
    return QVariant();
    const BrowserOperationAttribute* pointer = static_cast<const BrowserOperationAttribute*>(data);
    if(pointer)
        return QVariant(pointer->get_passage_type(index.row()));
    else
    return QVariant();
    }
    );
    operationAttributeController->AddSetter(columns.indexOf("postfix"),QVector<int>({Qt::DisplayRole,Qt::EditRole}),
    [] (BrowserNode* data, QVariant value, const QModelIndex& index)
 {
    if(!data)
    return false;
    BrowserOperationAttribute* pointer = static_cast<BrowserOperationAttribute*>(data);
    if(pointer)
    {
        pointer->set_passage_type(value.toString(), index.row());
        pointer->modified();
    }
    return true;
    }
    );





    std::function<void(BrowserNode* , const QModelIndex&)> f = [](BrowserNode* node, const QModelIndex& index)
    {
        BrowserOperationAttribute* oper = static_cast<BrowserOperationAttribute*>(node);
        OperationFuncs::recompute_param(oper->get_operation(),index.row(),true);
    };
    operationAttributeController->AddPostProcessors(columns.indexOf("direction"), QVector<int>(QVector<int>({Qt::DisplayRole,Qt::EditRole})),f);

    ADD_PIXMAP_GETTER(BrowserOperationAttribute, operationAttributeController, columns.indexOf("name"), QVector<int>({Qt::DecorationRole}), pixmap);



    operationAttributeController->AddFlagsFunctor
            (
                [&](const QModelIndex& index)
    {
        Qt::ItemFlags result;
        result |= Qt::ItemIsSelectable;
        if(!(index.column() *in(columns.indexOf("name"),columns.indexOf("type"),columns.indexOf("default_value"),
                                columns.indexOf("direction"), columns.indexOf("deleted"), columns.indexOf("mark"),
                                columns.indexOf("prefix"), columns.indexOf("postfix"))))
            return result;

        TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer());
        if(!iface)
            return result;
        BrowserOperationAttribute* pointer = static_cast<BrowserOperationAttribute*>(iface->InternalPointer());
        if(!pointer)
            return result;

        if(pointer->is_writable() && !pointer->is_get_set())
            result |= Qt::ItemIsEditable;
        result |=  Qt::ItemIsEnabled ;
        return result;
    }
    );
}
Пример #11
0
void QuickEdit::SetupAttributeController()
{
    attributeController = QSharedPointer<ItemController<BrowserNode> >( new ItemController<BrowserNode>());
    attributeController->SetColumns(columns);
    ADD_GETSET(BrowserAttribute, attributeController, columns.indexOf("name"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_name, set_name);
    ADD_GETSET_DATA(BrowserAttribute, AttributeData, attributeController, columns.indexOf("type"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                    toString, get_type().get_type, set_type);
    ADD_GETSET_DATA(BrowserAttribute, AttributeData, attributeController, columns.indexOf("default_value"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                    toString, get_init_value, set_init_value);
    ADD_GETSET(BrowserAttribute, attributeController, columns.indexOf("stereotype"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toString, get_stereotype, def->set_stereotype);

    ADD_GETSET(BrowserAttribute, attributeController, columns.indexOf("deleted"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
               toBool, deletedp, set_deleted);

//    ADD_GETSET_DIRECT_ASSIGNMENT(BrowserAttribute, attributeController, columns.indexOf("visibility"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
//                                 visibility_as_string(), BrowserNode::encode_visibility(value.toString()));
    ADD_GETSET_CONVERTED(BrowserAttribute, attributeController, columns.indexOf("visibility"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                         toString,BrowserNode::encode_visibility,visibility_as_string, pointer->def->set_visibility);



    ADD_GETSET_DATA(BrowserAttribute, AttributeData, attributeController, columns.indexOf("static"), QVector<int>({Qt::DisplayRole,Qt::EditRole}),
                    toBool,get_isa_class_attribute, set_isa_class_attribute);





    ADD_PIXMAP_GETTER(BrowserAttribute, attributeController, columns.indexOf("name"), QVector<int>({Qt::DecorationRole}), pixmap);

    attributeController->AddFlagsFunctor
            (
                [&](const QModelIndex& index)
    {
        Qt::ItemFlags result;
        result |= Qt::ItemIsSelectable;
        if(!(index.column() *in(columns.indexOf("name"),columns.indexOf("type"),columns.indexOf("default_value"),columns.indexOf("stereotype"),
                                columns.indexOf("visibility"), columns.indexOf("static"), columns.indexOf("deleted"))))
            return result;

        TreeItemInterface* iface = static_cast<TreeItemInterface*>(index.internalPointer());
        if(!iface)
            return result;
        BrowserNode* pointer = static_cast<BrowserNode*>(iface->InternalPointer());
        if(!pointer)
            return result;
        if(pointer->is_writable())
            result |= Qt::ItemIsEditable;
        result |=  Qt::ItemIsEnabled ;
        return result;
    }
    );

    std::function<void(BrowserNode*,const QModelIndex& index)> f = [](BrowserNode* node ,const QModelIndex& index)
    {
        Q_UNUSED(index);
        BrowserAttribute* attr = static_cast<BrowserAttribute*>(node);
        attr->modified();
        attr->setText(0,attr->get_name() );
        attr->package_modified();
        attr->get_data()->modified();
    };
    attributeController->AddPostProcessors(columns.indexOf("name"), QVector<int>(QVector<int>({Qt::DisplayRole,Qt::EditRole})),f);
}
Пример #12
0
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;
    }
    );
}