Exemple #1
0
struct node *copy_branch(struct tree *dst, struct node *src)
{
    switch (src->token) {
    case token_x:
        return new_var(dst, token_x);
    case token_y:
        return new_var(dst, token_y);
    case token_z:
        return new_var(dst, token_z);
    case token_a:
        return new_var(dst, token_a);
    case token_num:
        return new_num(dst, src->value);
    case token_pow:
        return new_pow(dst, copy_branch(dst, src->left), src->value);
    case token_mul:
        return new_node(dst, copy_branch(dst, src->left), token_mul, copy_branch(dst, src->right));
    case token_add:
        return new_node(dst, copy_branch(dst, src->left), token_add, copy_branch(dst, src->right));
    case token_sub:
        return new_node(dst, copy_branch(dst, src->left), token_sub, copy_branch(dst, src->right));
    case token_neg:
        return new_node(dst, 0, token_neg, copy_branch(dst, src->right));
    case token_sqrt:
        return new_node(dst, 0, token_sqrt, copy_branch(dst, src->right));
    case token_err:
        return 0;
    default:
        error::set_num(error::unknown_token);
        return 0;
    }
}
Exemple #2
0
int copy(struct tree *dst, struct tree *src)
{
    error::set_num_pos(error::empty_expression, 0);
    reset_tree(dst);
    dst->root = copy_branch(dst, src->root);
    return 0 != dst->root;
}
void TreeScreen::setupActions(void)
{
    QAction *ac;

// Разворачивание всех подветок
// a->setShortcut(tr("Ctrl+X"));
    ac=new QAction(tr("Expand all sub items"), this);
    ac->setStatusTip(tr("Expand all sub items"));
    ac->setIcon(QIcon(":/resource/pic/expand_all_subbranch.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(expand_all_subbranch()));
    actionList["expandAllSubbranch"]=ac;

// Сворачивание всех подветок
    ac = new QAction(tr("Collapse all sub items"), this);
    ac->setStatusTip(tr("Collapse all sub items"));
    ac->setIcon(QIcon(":/resource/pic/collapse_all_subbranch.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(collapse_all_subbranch()));
    actionList["collapseAllSubbranch"]=ac;

// Перемещение ветки вверх
    ac = new QAction(tr("Move item up"), this);
    ac->setStatusTip(tr("Move item up"));
    ac->setIcon(QIcon(":/resource/pic/move_up.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(move_up_branch()));
    actionList["moveUpBranch"]=ac;

// Перемещение ветки вниз
    ac = new QAction(tr("Move item down"), this);
    ac->setStatusTip(tr("Move item down"));
    ac->setIcon(QIcon(":/resource/pic/move_dn.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(move_dn_branch()));
    actionList["moveDnBranch"]=ac;

// Вставка новой подветки
    ac = new QAction(tr("Insert a new sub item"), this);
    ac->setStatusTip(tr("Insert a new sub item into selected"));
    ac->setIcon(QIcon(":/resource/pic/add_subbranch.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(ins_subbranch()));
    actionList["insSubbranch"]=ac;

// Вставка новой ветки
    ac = new QAction(tr("Insert a new sibling item"), this);
    ac->setStatusTip(tr("Insert a new sibling item after selected"));
    ac->setIcon(QIcon(":/resource/pic/add_branch.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(ins_branch()));
    actionList["insBranch"]=ac;

// Редактирование ветки
    ac = new QAction(tr("Edit item name"), this);
    ac->setStatusTip(tr("Edit name of selected item"));
    ac->setIcon(QIcon(":/resource/pic/note_edit.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(edit_branch()));
    actionList["editBranch"]=ac;

// Удаление ветки
    ac = new QAction(tr("Delete item"), this);
    ac->setStatusTip(tr("Delete selected item and all sub items"));
    ac->setIcon(QIcon(":/resource/pic/note_delete.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(del_branch()));
    actionList["delBranch"]=ac;

// Удаление ветки с сохранением копии в буфер обмена
    ac = new QAction(tr("Cut item"), this);
    ac->setStatusTip(tr("Cut item including sub items"));
    ac->setIcon(QIcon(":/resource/pic/branch_cut.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(cut_branch()));
    actionList["cutBranch"]=ac;

// Копирование ветки в буфер обмена
    ac = new QAction(tr("Copy item"), this);
    ac->setStatusTip(tr("Copy item including sub items"));
    ac->setIcon(QIcon(":/resource/pic/branch_copy.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(copy_branch()));
    actionList["copyBranch"]=ac;

// Вставка ветки из буфера обмена
    ac = new QAction(tr("Paste item"), this);
    ac->setStatusTip(tr("Paste sibling item after selected"));
    ac->setIcon(QIcon(":/resource/pic/branch_paste.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(paste_branch()));
    actionList["pasteBranch"]=ac;

// Вставка ветки из буфера обмена в виде подветки
    ac = new QAction(tr("Paste as sub item"), this);
    ac->setStatusTip(tr("Paste item as sub item for selected"));
    ac->setIcon(QIcon(":/resource/pic/branch_paste.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(paste_subbranch()));
    actionList["pasteSubbranch"]=ac;

// Шифрование ветки
    ac = new QAction(tr("Encrypt item"), this);
    ac->setStatusTip(tr("Encrypt item and all subitem"));
// actionEncryptBranch->setIcon(QIcon(":/resource/pic/branch_paste.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(encrypt_branch()));
    actionList["encryptBranch"]=ac;

// Расшифровка ветки (снятие пароля)
    ac = new QAction(tr("Decrypt item"), this);
    ac->setStatusTip(tr("Decrypt item and all subitem"));
// actionDecryptBranch->setIcon(QIcon(":/resource/pic/branch_paste.svg"));
    connect(ac, SIGNAL(triggered()), this, SLOT(decrypt_branch()));
    actionList["decryptBranch"]=ac;

// Открытие поиска по базе (связывание клика происходит в MainWindows)
    ac = new QAction(tr("Find in base"), this);
    ac->setStatusTip(tr("Find in base"));
    ac->setIcon(QIcon(":/resource/pic/find_in_base.svg"));
    actionList["findInBase"]=ac;
}