예제 #1
0
/**
 * Updates the representation of the object.
 */
void UMLListViewItem::updateObject()
{
    if (m_object == 0)
        return;

    Uml::Visibility::Enum scope = m_object->visibility();
    UMLObject::ObjectType ot = m_object->baseType();
    QString modelObjText = m_object->name();
    if (Model_Utils::isClassifierListitem(ot)) {
        UMLClassifierListItem *pNarrowed = static_cast<UMLClassifierListItem*>(m_object);
        modelObjText = pNarrowed->toString(Uml::SignatureType::SigNoVis);
    }
    setText(modelObjText);

    Icon_Utils::IconType icon = Icon_Utils::it_Home;
    switch (ot) {
    case UMLObject::ot_Package:
        if (m_object->stereotype() == QLatin1String("subsystem"))
            icon = Icon_Utils::it_Subsystem;
        else
            icon = Icon_Utils::it_Package;
        break;
    case UMLObject::ot_Operation:
        if (scope == Uml::Visibility::Public)
            icon = Icon_Utils::it_Public_Method;
        else if (scope == Uml::Visibility::Private)
            icon = Icon_Utils::it_Private_Method;
        else if (scope == Uml::Visibility::Implementation)
            icon = Icon_Utils::it_Private_Method;
        else
            icon = Icon_Utils::it_Protected_Method;
        break;

    case UMLObject::ot_Attribute:
    case UMLObject::ot_EntityAttribute:
        if (scope == Uml::Visibility::Public)
            icon = Icon_Utils::it_Public_Attribute;
        else if (scope == Uml::Visibility::Private)
            icon = Icon_Utils::it_Private_Attribute;
        else if (scope == Uml::Visibility::Implementation)
            icon = Icon_Utils::it_Private_Attribute;
        else
            icon = Icon_Utils::it_Protected_Attribute;
        break;
    case UMLObject::ot_UniqueConstraint:
        m_type = Model_Utils::convert_OT_LVT(umlObject());
        icon = Model_Utils::convert_LVT_IT(m_type);
        break;

    case UMLObject::ot_Class:
        icon = Model_Utils::convert_LVT_IT(m_type, m_object);
        break;

    default:
        icon = Model_Utils::convert_LVT_IT(m_type);
        break;
    }//end switch
    if (icon)
        setIcon(icon);
}
예제 #2
0
/**
 * Reimplemented from UMLWidget::updateTextItemGroups to
 * calculate the Text strings, their properties and also hide/show
 * them based on the current state.
 */
void ClassifierWidget::updateTextItemGroups()
{
    // Invalidate stuff and recalculate them.
    invalidateDummies();

    TextItemGroup *headerGroup = textItemGroupAt(HeaderGroupIndex);
    TextItemGroup *attribOpGroup = textItemGroupAt(AttribOpGroupIndex);
    TextItemGroup *templateGroup = textItemGroupAt(TemplateGroupIndex);

    attribOpGroup->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
    templateGroup->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);

    UMLClassifier *umlC = classifier();
    UMLClassifierListItemList attribList = umlC->getFilteredList(UMLObject::ot_Attribute);
    UMLClassifierListItemList opList = umlC->getFilteredList(UMLObject::ot_Operation);

    // Set up template group and template text items.
    UMLTemplateList tlist = umlC->getTemplateList();
    templateGroup->setTextItemCount(tlist.size());
    bool templateHide = shouldDrawAsCircle(); // Hide if draw as circle.
    for(int i = 0; i < tlist.size(); ++i) {
        UMLTemplate *t = tlist[i];
        templateGroup->textItemAt(i)->setText(t->toString());
        templateGroup->textItemAt(i)->setExplicitVisibility(!templateHide);
    }

    // Stereo type and name.
    const int headerItemCount = 2;
    headerGroup->setTextItemCount(headerItemCount);

    const int cnt = attribList.count() + opList.count();
    attribOpGroup->setTextItemCount(cnt);

    // Setup Stereo text item.
    TextItem *stereoItem = headerGroup->textItemAt(StereotypeItemIndex);
    stereoItem->setBold(true);
    stereoItem->setText(umlC->stereotype(true));

    bool v = !shouldDrawAsCircle()
        && visualProperty(ShowStereotype)
        && !(umlC->stereotype(false).isEmpty());
    stereoItem->setExplicitVisibility(v);

    // name item is always visible.
    TextItem *nameItem = headerGroup->textItemAt(NameItemIndex);
    nameItem->setBold(true);
    nameItem->setItalic(umlC->isAbstract());
    nameItem->setUnderline(shouldDrawAsCircle());
    QString nameText = name();
    if (visualProperty(ShowPackage) == true) {
        nameText = umlC->fullyQualifiedName();
    }

    bool showNameOnly = (!visualProperty(ShowAttributes) && !visualProperty(ShowOperations)
                         && !visualProperty(ShowStereotype) && !shouldDrawAsCircle());
    nameItem->setText(nameText);

    int attribStartIndex = 0;
    int opStartIndex = attribStartIndex + attribList.size();

    // Now setup attribute texts.
    int visibleAttributes = 0;
    for (int i=0; i < attribList.size(); ++i) {
        UMLClassifierListItem *obj = attribList[i];

        TextItem *item = attribOpGroup->textItemAt(attribStartIndex + i);
        item->setItalic(obj->isAbstract());
        item->setUnderline(obj->isStatic());
        item->setText(obj->toString(m_attributeSignature));

        bool v = !shouldDrawAsCircle()
            && ( !visualProperty(ShowPublicOnly)
                 || obj->visibility() == Uml::Visibility::Public)
            && visualProperty(ShowAttributes) == true;

        item->setExplicitVisibility(v);
        if (v) {
            ++visibleAttributes;
        }
    }

    // Update expander box to reflect current state and also visibility
    m_attributeExpanderBox->setExpanded(visualProperty(ShowAttributes));

    const QString dummyText;
    // Setup line and dummies.
    if (!showNameOnly) {
        // Stuff in a dummy item as spacer if there are no attributes,
        if (!shouldDrawAsCircle() && (visibleAttributes == 0 || !visualProperty(ShowAttributes))) {
            m_dummyAttributeItem = new TextItem(dummyText);
            int index = attribStartIndex;
            if (visibleAttributes == 0 && !attribList.isEmpty()) {
                index = opStartIndex;
            }
            attribOpGroup->insertTextItemAt(index, m_dummyAttributeItem);
            m_lineItem2Index = index;
            ++opStartIndex;
        }
        else {
            // Now set the second index.
            m_lineItem2Index = opStartIndex - 1;
        }
    }

    int visibleOperations = 0;
    for (int i=0; i < opList.size(); ++i) {
        UMLClassifierListItem *obj = opList[i];

        TextItem *item = attribOpGroup->textItemAt(opStartIndex + i);
        item->setItalic(obj->isAbstract());
        item->setUnderline(obj->isStatic());
        item->setText(obj->toString(m_operationSignature));

        bool v = !shouldDrawAsCircle()
            && ( !visualProperty(ShowPublicOnly)
                 || obj->visibility() == Uml::Visibility::Public)
            && visualProperty(ShowOperations);

        item->setExplicitVisibility(v);
        if (v) {
            ++visibleOperations;
        }
    }
    m_operationExpanderBox->setExpanded(visualProperty(ShowOperations));

    if (!showNameOnly) {
        if (!shouldDrawAsCircle() && (visibleOperations == 0 || !visualProperty(ShowOperations))) {
            m_dummyOperationItem = new TextItem(dummyText);
            attribOpGroup->insertTextItemAt(opStartIndex+opList.size(), m_dummyOperationItem);
        }
    }

    UMLWidget::updateTextItemGroups();
}