/********************************************************************
 * FUNCTION output_one_typedef_diff
 * 
 *  Output the differences report for one typedef definition
 *
 * INPUTS:
 *    cp == parameter block to use
 *    oldtyp == old typedef
 *    newtyp == new typedef
 *
 *********************************************************************/
static void
    output_one_typedef_diff (yangdiff_diffparms_t *cp,
                             typ_template_t *oldtyp,
                             typ_template_t *newtyp)
{
    yangdiff_cdb_t  typcdb[5];
    uint32          changecnt, i;
    boolean         isrev, tchanged;

    isrev = (cp->edifftype==YANGDIFF_DT_REVISION) ? TRUE : FALSE;

    tchanged = FALSE;
    changecnt = 0;

    if (type_changed(cp, &oldtyp->typdef, &newtyp->typdef)) {
        tchanged = TRUE;
        changecnt++;
    }

    changecnt += str_field_changed(YANG_K_UNITS,
                                   oldtyp->units, newtyp->units, 
                                   isrev, &typcdb[0]);
    changecnt += str_field_changed(YANG_K_DEFAULT,
                                   oldtyp->defval, newtyp->defval, 
                                   isrev, &typcdb[1]);
    changecnt += status_field_changed(YANG_K_STATUS,
                                      oldtyp->status, newtyp->status, 
                                      isrev, &typcdb[2]);
    changecnt += str_field_changed(YANG_K_DESCRIPTION,
                                   oldtyp->descr, newtyp->descr, 
                                   isrev, &typcdb[3]);
    changecnt += str_field_changed(YANG_K_REFERENCE,
                                   oldtyp->ref, newtyp->ref, 
                                   isrev, &typcdb[4]);
    if (changecnt == 0) {
        return;
    }

    /* generate the diff output, based on the requested format */
    output_mstart_line(cp, YANG_K_TYPEDEF, oldtyp->name, TRUE);

    if (cp->edifftype == YANGDIFF_DT_TERSE) {
        return;
    }

    indent_in(cp);

    for (i=0; i<5; i++) {
        if (typcdb[i].changed) {
            output_cdb_line(cp, &typcdb[i]);
        }
    }

    if (tchanged) {
        output_one_type_diff(cp, &oldtyp->typdef, &newtyp->typdef);
    }

    indent_out(cp);

} /* output_one_typedef_diff */
/********************************************************************
* FUNCTION unQ_match
*
* Find the specified type in the unionnode Q
*
* INPUTS:
*   cp == comparison parameters to use
*   oldval == old typ_unionnode_t struct to check
*   newQ == Q of new typ_unionnode_t structs to check
*   idx == address of return index
*
* OUTPUTS:
*   *idx == index of the unionnode entry found [0..N-1 numbering]
*
* RETURNS:
*   pointer to the found entry
*   NULL if not found
*********************************************************************/
static typ_unionnode_t *
    unQ_match (yangdiff_diffparms_t *cp,
               typ_unionnode_t *oldval,
               dlq_hdr_t *newQ,
               uint32 *idx)
{
    typ_unionnode_t     *newval;
    typ_def_t           *olddef, *newdef;

    *idx = 0;

    olddef = typ_get_unionnode_ptr(oldval);

    for (newval = (typ_unionnode_t *)dlq_firstEntry(newQ);
         newval != NULL;
         newval = (typ_unionnode_t *)dlq_nextEntry(newval)) {
        if (!newval->seen) {
            newdef = typ_get_unionnode_ptr(newval);
            if (!type_changed(cp, olddef, newdef)) {
                return newval;
            }
        }
        (*idx)++;
    }

    return NULL;
    
}  /* unQ_match */
/********************************************************************
 * FUNCTION typedef_changed
 * 
 *  Check if a (nested) typedef changed
 *
 * INPUTS:
 *    cp == parameter block to use
 *    oldtyp == old typ_template_t to use
 *    newtyp == new typ_template_t to use
 *
 * RETURNS:
 *    1 if field changed
 *    0 if field not changed
 *********************************************************************/
uint32
    typedef_changed (yangdiff_diffparms_t *cp,
                     typ_template_t *oldtyp,
                     typ_template_t *newtyp)
{
    if (type_changed(cp, &oldtyp->typdef, &newtyp->typdef)) {
        return 1;
    }

    if (str_field_changed(YANG_K_UNITS,
                          oldtyp->units, 
                          newtyp->units, 
                          FALSE, 
                          NULL)) {
        return 1;
    }
    if (str_field_changed(YANG_K_DEFAULT,
                          oldtyp->defval, 
                          newtyp->defval, 
                          FALSE, 
                          NULL)) {
        return 1;
    }
    if (status_field_changed(YANG_K_STATUS,
                             oldtyp->status, 
                             newtyp->status, 
                             FALSE,
                             NULL)) {
        return 1;
    }
    if (str_field_changed(YANG_K_DESCRIPTION,
                          oldtyp->descr,
                          newtyp->descr, 
                          FALSE,
                          NULL)) {
        return 1;
    }
    if (str_field_changed(YANG_K_REFERENCE,
                          oldtyp->ref,
                          newtyp->ref, 
                          FALSE,
                          NULL)) {
        return 1;
    }

    return 0;

} /* typedef_changed */
Example #4
0
void ClassInstanceDialog::menu_class()
{
    QMenu m(0);

    MenuFactory::addItem(m, tr("Choose"), -1);
    m.addSeparator();

    int index = list.indexOf(edtype->currentText().trimmed());

    if (index != -1)
        MenuFactory::addItem(m, tr("Select in browser"), 0);

    BrowserNode * bn = 0;

    if (! visit) {
        bn = BrowserView::selected_item();

        if ((bn != 0) && (bn->get_type() == UmlClass) && !bn->deletedp())
            MenuFactory::addItem(m, tr("Choose class selected in browser"), 1);
        else
            bn = 0;

        if (cl_container != 0)
            MenuFactory::addItem(m, tr("Create class and choose it"), 2);
    }

    if ((index != -1) || (bn != 0) || (cl_container != 0)) {
        QAction* retAction = m.exec(QCursor::pos());
        if(retAction)
        {
            switch (retAction->data().toInt()) {
            case 0:
                nodes.at(index)->select_in_browser();
                break;

            case 2:
                bn = BrowserClass::add_class(FALSE, cl_container);

                if (bn == 0)
                    return;

                bn->select_in_browser();

                // no break
            case 1: {
                if ((index = nodes.indexOf(bn)) == -1) {
                    // new class, may be created through an other dialog
                    QStringList::Iterator iter = list.begin();
                    QStringList::Iterator iter_end = list.end();
                    QString s = bn->full_name(TRUE);

                    index = 0;

                    while ((iter != iter_end) && (*iter < s)) {
                        ++iter;
                        index += 1;
                    }

                    nodes.insert((unsigned) index, bn);
                    list.insert(iter, s);
                    edtype->insertItem(index,s);
                }
            }

                edtype->setCurrentIndex(index);
                type_changed(index);
                break;

            default:
                break;
            }
        }
    }
}
Example #5
0
ClassInstanceDialog::ClassInstanceDialog(ClassInstanceData * i)
    : TabDialog(0, "class instance dialog", FALSE, Qt::WA_DeleteOnClose),
      inst(i), atbl(0), rtbl(0)
{
    setWindowTitle(tr("Class instance dialog"));

    BrowserNode * bn = inst->get_browser_node();

    bn->edit_start();

    if (bn->is_writable()) {
        setOkButton(tr("OK"));
        setCancelButton(tr("Cancel"));
    }
    else {
        setOkButton(QString());
        setCancelButton(tr("Close"));
    }

    visit = !hasOkButton();

    GridBox * grid;

    // general tab

    grid = new GridBox(2, this);
    grid->setMargin(5);
    grid->setSpacing(5);

    grid->addWidget(new QLabel(tr("name : "), grid));
    grid->addWidget(edname = new LineEdit(bn->get_name(), grid));

    if (visit)
        edname->setReadOnly(TRUE);

    grid->addWidget(new QLabel(tr("stereotype :"), grid));
    grid->addWidget(edstereotype = new QComboBox( grid));
    edstereotype->setEditable(!visit);
    edstereotype->addItem(toUnicode(bn->get_stereotype()));

    if (! visit) {
        edstereotype->addItems(ProfiledStereotypes::defaults(UmlClassInstance));
        edstereotype->setAutoCompletion(completion());
    }

    SmallPushButton  * b;
    grid->addWidget(b = new SmallPushButton(tr("class :"), grid));

    connect(b, SIGNAL(clicked()), this, SLOT(menu_class()));

    grid->addWidget(edtype = new QComboBox(grid));

    if (visit) {
        edtype->addItem(inst->get_class()->full_name());
        nodes.append(inst->get_class());
    }
    else {
        BrowserClass::instances(nodes);
        nodes.full_names(list);
        edtype->addItems(list);
        edtype->setCurrentIndex(nodes.indexOf(inst->get_class()));
        connect(edtype, SIGNAL(activated(int)), this, SLOT(type_changed(int)));
    }

    if (visit)
        cl_container = 0;
    else {
        cl_container = (BrowserNode *) bn->parent();

        if ((cl_container != 0) && !cl_container->is_writable())
            cl_container = 0;
    }

    VVBox * vtab;
    grid->addWidget(vtab = new VVBox(grid));

    vtab->addWidget(new QLabel(tr("description :"), vtab));

    if (! visit) {
        connect(b =new SmallPushButton(tr("Editor"), vtab), SIGNAL(clicked()),
                this, SLOT(edit_description()));
        vtab->addWidget(b);
    }

    grid->addWidget(comment = new MultiLineEdit(grid));
    comment->setReadOnly(visit);
    comment->setText(bn->get_comment());

    QFont font = comment->font();

    if (! hasCodec())
        font.setFamily("Courier");

    font.setFixedPitch(TRUE);

    comment->setFont(font);

    addTab(grid, "Uml");

    // attributes tab

    atbl = new MyTable(this);
    atbl->setColumnCount(3);
    //atbl->setSortingEnabled(true);
    atbl->setSelectionMode(QTableWidget::NoSelection);	// single does not work
    atbl->verticalHeader()->setSectionsMovable(true);
    atbl->verticalHeader()->setSectionsMovable(true);
    atbl->setHorizontalHeaderLabel(0, tr(" Attribute "));
    atbl->setHorizontalHeaderLabel(1, tr(" Class "));
    atbl->setHorizontalHeaderLabel(2, tr(" Value "));

    addTab(atbl, tr("Attributes"));

    // relation tab

    if (! inst->relations.isEmpty()) {
        rtbl = new RelTable(this, inst, visit);
        addTab(rtbl, tr("Relations"));
    }

    // USER : list key - value

    grid = new GridBox(2, this);
    grid->setMargin(5);
    grid->setSpacing(5);

    grid->addWidget(kvtable = new KeyValuesTable(bn, grid, visit));
    addTab(grid, tr("Properties"));

    type_changed(edtype->currentIndex());

    connect(m_tabWidget, SIGNAL(currentChanged(int)),
            this, SLOT(update_all_tabs(int)));

    open_dialog(this);
}
Example #6
0
//*******************************************************************
// QBtPackDialog                                         CONSTRUCTOR
//*******************************************************************
QBtPackDialog::QBtPackDialog( QWidget* const in_parent ) : QDialog( in_parent )
, name_          ( QString() )
, dst_dir_       ( QString() )
, dst_path_      ( QString() )
, source_        ( new QBtInfoField )
, destination_   ( new QBtInfoField )
, compression_   ( new QCheckBox( tr( COMPRESSION ) ) )
, remove_        ( new QCheckBox( tr( REMOVE ) ) )
, ratio_         ( new QComboBox )
, run_           ( new QPushButton( tr( RUN ) ) )
, cancel_        ( new QPushButton( tr( CANCEL ) ) )
, tool_gbox_     ( new QGroupBox( tr( TOOL ) ) )
, gzip_          ( new QRadioButton( tr( GZIP ) ) )
, bzip2_         ( new QRadioButton( tr( BZIP2 ) ) )
, zip_           ( new QRadioButton( tr( ZIP ) ) )
, started_       ( false )
, break_         ( false )
, compress_type_ ( USE_TAR )
, fm_            ( font() )
, data_          ( SelectionsSet() )
{
   setWindowTitle( tr( CAPTION ) );

   QGroupBox* const src_dst_gbox = new QGroupBox( tr( SRC_AND_DST ) );
   QGridLayout* src_dst_layout = new QGridLayout( src_dst_gbox );
   src_dst_layout->setMargin( 4 );
   src_dst_layout->setSpacing( 2 );
   src_dst_layout->addWidget( new QLabel( tr( SOURCE ) ), 0, 0, Qt::AlignRight );
   src_dst_layout->addWidget( new QLabel( tr( DESTINATION ) ), 1, 0, Qt::AlignRight );
   src_dst_layout->addWidget( source_, 0, 1 );
   src_dst_layout->addWidget( destination_, 1, 1 );

   QGridLayout* const btn_layout = new QGridLayout;
   btn_layout->addWidget( compression_, 0, 0 );
   btn_layout->addWidget( remove_, 1, 0 );
   btn_layout->addWidget( ratio_, 0, 1 );
   btn_layout->addWidget( run_, 0, 2 );
   btn_layout->addWidget( cancel_, 1, 2 );
   btn_layout->setColumnStretch( 0, 100 );
   btn_layout->setColumnStretch( 1, 30 );

   QHBoxLayout* const tool_layout = new QHBoxLayout( tool_gbox_ );
   tool_layout->addWidget( gzip_ );
   tool_layout->addWidget( bzip2_ );
   tool_layout->addWidget( zip_ );

   QVBoxLayout* const main_layout = new QVBoxLayout;
   main_layout->addWidget( src_dst_gbox );
   main_layout->addLayout( btn_layout );
   main_layout->addWidget( tool_gbox_ );
   setLayout( main_layout );

   for( qint32 i = 9; i >= 1; --i ) {
      ratio_->addItem( QString::number( i ) );
   }
   gzip_->setChecked( true );
   tool_gbox_->setEnabled( false );
   ratio_->setEnabled( false );

   connect( run_        , SIGNAL( clicked() )      , this, SLOT( run() ) );
   connect( cancel_     , SIGNAL( clicked() )      , this, SLOT( reject() ) );
   connect( compression_, SIGNAL( toggled( bool ) ), this, SLOT( compression( bool ) ) );
   connect( gzip_       , SIGNAL( clicked() )      , this, SLOT( type_changed() ) );
   connect( bzip2_      , SIGNAL( clicked() )      , this, SLOT( type_changed() ) );
   connect( zip_        , SIGNAL( clicked() )      , this, SLOT( type_changed() ) );
}
/********************************************************************
* FUNCTION type_changed
*
* Check if the type clause and sub-clauses changed at all
*
* INPUTS:
*   cp == compare parameters to use
*   oldtypdef == old type def struct to check
*   newtypdef == new type def struct to check
*
* RETURNS:
*   1 if field changed
*   0 if field not changed
*********************************************************************/
uint32
    type_changed (yangdiff_diffparms_t *cp,
                  typ_def_t *oldtypdef,
                  typ_def_t *newtypdef)
{
    typ_def_t         *oldtest, *newtest;
    const xmlChar     *oldpath, *newpath;
    ncx_btype_t        oldbtyp, newbtyp;

#ifdef DEBUG
    if (!oldtypdef || !newtypdef) {
        SET_ERROR(ERR_INTERNAL_PTR);
        return 1;
    }
#endif

    if (oldtypdef->tclass != newtypdef->tclass) {
        return 1;
    }
    if (prefix_field_changed(cp->oldmod, 
                             cp->newmod,
                             oldtypdef->prefix, 
                             newtypdef->prefix)) {
        return 1;
    }
    if (str_field_changed(NULL, 
                          oldtypdef->typenamestr, 
                          newtypdef->typenamestr, 
                          FALSE, 
                          NULL)) {
        return 1;
    }

    switch (oldtypdef->tclass) {
    case NCX_CL_BASE:
        return (uint32)((oldtypdef->def.base == newtypdef->def.base) ? 0 : 1);
    case NCX_CL_SIMPLE:
        oldbtyp = typ_get_basetype(oldtypdef);
        newbtyp = typ_get_basetype(newtypdef);
        if (oldbtyp != newbtyp) {
            return 1;
        }
        if (oldbtyp == NCX_BT_LEAFREF) {
            oldpath = typ_get_leafref_path(oldtypdef);
            newpath = typ_get_leafref_path(newtypdef);
            return str_field_changed(YANG_K_PATH, 
                                     oldpath, 
                                     newpath, 
                                     FALSE, 
                                     NULL);
        } else if (typ_is_string(oldbtyp)) {
            if (patternQ_changed(oldtypdef, newtypdef)) {
                return 1;
            }
            if (range_changed(oldtypdef, newtypdef)) {
                return 1;
            }
        } else if (typ_is_number(oldbtyp)) {
            if (range_changed(oldtypdef, newtypdef)) {
                return 1;
            }
        } else {
            switch (oldbtyp) {
            case NCX_BT_BITS:
                return ebQ_changed(&oldtypdef->def.simple.valQ,
                                   &newtypdef->def.simple.valQ, 
                                   TRUE);
            case NCX_BT_ENUM:
                return ebQ_changed(&oldtypdef->def.simple.valQ,
                                   &newtypdef->def.simple.valQ,
                                   FALSE);
            case NCX_BT_UNION:
                return unQ_changed(cp, 
                                   &oldtypdef->def.simple.unionQ,
                                   &newtypdef->def.simple.unionQ);
            default:
                ;
            }
        }
        return 0;
    case NCX_CL_COMPLEX:
        /* not supported for NCX complex types!!! */
        return 0;     
    case NCX_CL_NAMED:
        oldtest = typ_get_new_named(oldtypdef);
        newtest = typ_get_new_named(newtypdef);
        if ((!oldtest && newtest) || (oldtest && !newtest)) {
            return 1;
        } else if (oldtest && newtest) {
            if (type_changed(cp, oldtest, newtest)) {
                return 1;
            }
        }
        return 0;
        /*** do not look deep into named typed
         *** add switch to check this
         *** type_changed(cp, &oldtypdef->def.named.typ->typdef,
         ***                &newtypdef->def.named.typ->typdef);
         ***/
    case NCX_CL_REF:
        return type_changed(cp, 
                            oldtypdef->def.ref.typdef,
                            newtypdef->def.ref.typdef);
    default:
        SET_ERROR(ERR_INTERNAL_VAL);
        return 0;
    }
    /*NOTREACHED*/

} /* type_changed */
/********************************************************************
 * FUNCTION output_union_diff
 * 
 *  Output the differences report for one union sub-clauses
 *  within a leaf, leaf-list, or typedef definition
 *
 * INPUTS:
 *    cp == parameter block to use
 *    oldtypdef == old internal typedef
 *    newtypdef == new internal typedef
 *********************************************************************/
static void
    output_union_diff (yangdiff_diffparms_t *cp,
                       typ_def_t *oldtypdef,
                       typ_def_t *newtypdef)
{
    typ_unionnode_t     *oldval, *newval, *curnew;
    dlq_hdr_t           *oldQ, *newQ;
    typ_def_t           *olddef, *newdef;
    uint32               oldid, newid;
    char                 oldnum[NCX_MAX_NUMLEN];
    char                 newnum[NCX_MAX_NUMLEN];

    olddef = typ_get_base_typdef(oldtypdef);
    newdef = typ_get_base_typdef(newtypdef);

    oldQ = &olddef->def.simple.unionQ,
    newQ = &newdef->def.simple.unionQ;

    if (!unQ_changed(cp, oldQ, newQ)) {
        return;
    }

    oldid = 0;
    newid = 0;

    /* clear the seen flag to be safe */
    for (newval = (typ_unionnode_t *)dlq_firstEntry(newQ);
         newval != NULL;
         newval = (typ_unionnode_t *)dlq_nextEntry(newval)) {
        newval->seen = FALSE;
    }

    /* start the diff output */
    output_mstart_line(cp, YANG_K_UNION, NULL, FALSE);
    if (cp->edifftype == YANGDIFF_DT_TERSE) {
        return;
    }

    indent_in(cp);

    /* check for matching unionnode entries */
    for (oldval = (typ_unionnode_t *)dlq_firstEntry(oldQ);
         oldval != NULL;
         oldval = (typ_unionnode_t *)dlq_nextEntry(oldval), oldid++) {

        curnew = NULL;
        sprintf(oldnum, "[%u]", oldid);
        olddef = typ_get_unionnode_ptr(oldval);

        /* first try the corresponded entry if available */
        newval = unQ_match_id(oldid, newQ);
        if (newval) {
            curnew = newval;
            newid = oldid;
            sprintf(newnum, "[%u]", newid);
            newdef = typ_get_unionnode_ptr(newval);

            /* if the corresponding entry did not change
             * then this is a match and continue to next type
             */
            if (!type_changed(cp, olddef, newdef)) {
                newval->seen = TRUE;
                continue;
            }
        }
            
        /* did not match the corresponding entry,
         * so see if the typdef moved in the new union
         */
        newval = unQ_match(cp, oldval, newQ, &newid);
        if (newval) {
            newval->seen = TRUE;
            if (oldid != newid) {
                sprintf(newnum, "[%u]", newid);
                /* old union node was moved in new version */
                output_diff(cp, YANG_K_TYPE, 
                            (const xmlChar *)oldnum, 
                            (const xmlChar *)newnum, TRUE);
            }
        } else if (curnew) {
            /* type node was changed in the new union */
            curnew->seen = TRUE;
            newdef = typ_get_unionnode_ptr(curnew);
            sprintf(newnum, "[%u]", oldid);
            output_one_type_diff(cp, olddef, newdef);
        } else {
            /* old union node was removed in new version */
            output_diff(cp, YANG_K_TYPE,
                        (const xmlChar *)oldnum, NULL, TRUE);
        }
    }

    indent_out(cp);

    /* check for new entries */
    newid = 0;
    for (newval = (typ_unionnode_t *)dlq_firstEntry(newQ);
         newval != NULL;
         newval = (typ_unionnode_t *)dlq_nextEntry(newval)) {
        if (!newval->seen) {
            sprintf(newnum, "[%u]", newid);
            output_diff(cp, YANG_K_TYPE, NULL,
                        (const xmlChar *)newnum, TRUE);
        }
        newid++;
    }

} /* output_union_diff */
/********************************************************************
* FUNCTION unQ_changed
*
* Check if the union Q in the typdef has changed
*
* INPUTS:
*   cp == comparison parameter block to use
*   oldQ == Q of old typ_unionnode_t structs to check
*   newQ == Q of new typ_unionnode_t structs to check
*
* RETURNS:
*   1 if field changed
*   0 if field not changed
*********************************************************************/
static uint32
    unQ_changed (yangdiff_diffparms_t *cp,
                 dlq_hdr_t *oldQ,
                 dlq_hdr_t *newQ)
{
    typ_unionnode_t     *oldval, *newval;
    typ_def_t           *olddef, *newdef;
    boolean              done;


    if (dlq_count(oldQ) != dlq_count(newQ)) {
        return 1;
    }

    /* clear the seen flag to be safe */
    for (newval = (typ_unionnode_t *)dlq_firstEntry(newQ);
         newval != NULL;
         newval = (typ_unionnode_t *)dlq_nextEntry(newval)) {
        newval->seen = FALSE;
    }

    oldval = (typ_unionnode_t *)dlq_firstEntry(oldQ);
    newval = (typ_unionnode_t *)dlq_firstEntry(newQ);


    /* check for matching entries */
    done = FALSE;
    while (!done) {
        if (!oldval && !newval) {
            return 0;
        } else if (!oldval && newval) {
            return 1;
        } else if (oldval && !newval) {
            return 1;
        } /* else both old val and new val exist */

        olddef = typ_get_unionnode_ptr(oldval);
        newdef = typ_get_unionnode_ptr(newval);

        if (type_changed(cp, olddef, newdef)) {
            return 1;
        }

        newval->seen = TRUE;

        oldval = (typ_unionnode_t *)dlq_nextEntry(oldval);
        newval = (typ_unionnode_t *)dlq_nextEntry(newval);
    }

    /* check for new entries */
    for (newval = (typ_unionnode_t *)dlq_firstEntry(newQ);
         newval != NULL;
         newval = (typ_unionnode_t *)dlq_nextEntry(newval)) {
        if (!newval->seen) {
            return 1;
        }
    }

    return 0;
    
}  /* unQ_changed */