Exemple #1
0
Qtilities::Core::QtilitiesCategory Qtilities::CoreGui::Command::category() const {
    Observer* obs = OBJECT_MANAGER->observerReference(d_category_context);
    if (obs) {
        QVariant category_variant = obs->getMultiContextPropertyValue(this,qti_prop_CATEGORY_MAP);
        if (category_variant.isValid()) {
            return category_variant.value<QtilitiesCategory>();
        }
    }
    return QtilitiesCategory();
}
void Qtilities::CoreGui::ObjectScopeWidget::updateContents() {
    if (!d->obj)
        return;

    int observer_count = -1;
    int observer_limit = -2;
    int ownership = -1;
    ui->txtName->setText(d->obj->objectName());

    // Observer Count
    MultiContextProperty context_map_prop = ObjectManager::getMultiContextProperty(d->obj,qti_prop_OBSERVER_MAP);
    if (context_map_prop.isValid())
        observer_count = context_map_prop.contextMap().count();

    // Observer Limit
    SharedProperty shared_property = ObjectManager::getSharedProperty(d->obj,qti_prop_OBSERVER_LIMIT);
    if (shared_property.isValid())
        observer_limit = shared_property.value().toInt();

    if (observer_limit == -1)
        ui->txtObserverLimit->setText(tr("Unlimited"));
    else if (observer_limit == -2)
        ui->txtObserverLimit->setText(tr("Unlimited"));
    else
        ui->txtObserverLimit->setText(QString("%1").arg(observer_limit));

    // Ownership
    shared_property = ObjectManager::getSharedProperty(d->obj,qti_prop_OWNERSHIP);
    if (shared_property.isValid())
        ownership = shared_property.value().toInt();

    if (ownership == -1)
        ui->txtOwnership->setText(tr("Manual Ownership"));
    else if (ownership == Observer::ManualOwnership)
        ui->txtOwnership->setText(tr("Manual Ownership"));
    else if (ownership == Observer::SpecificObserverOwnership)
        ui->txtOwnership->setText(tr("Specific Observer Ownership"));
    else if (ownership == Observer::ObserverScopeOwnership)
        ui->txtOwnership->setText(tr("Observer Scope Ownership"));

    ui->observerTable->clearContents();
    ui->observerTable->setRowCount(observer_count);
    QString tooltip_string;
    bool has_instance_names = false;

    for (int i = 0; i < observer_count; i++) {
        int id = context_map_prop.contextMap().keys().at(i);
        Observer* observer = OBJECT_MANAGER->observerReference(id);
        if (!observer)  {
            LOG_ERROR("Object scope widget: Found invalid observer ID on object: " + d->obj->objectName());
            continue;
        }

        // Observer Name
        QTableWidgetItem *nameItem = new QTableWidgetItem(observer->observerName(), id);
        ui->observerTable->setItem(i, 0, nameItem);
        if (ownership == Observer::SpecificObserverOwnership) {
            QVariant observer_parent = observer->getMultiContextPropertyValue(d->obj,qti_prop_PARENT_ID);
            if (observer_parent.isValid() && (observer_parent.toInt() == id)) {
                QTableWidgetItem *ownerItem = new QTableWidgetItem("", id);
                ownerItem->setIcon(QIcon(qti_icon_SUCCESS_16x16));
                ownerItem->setToolTip(tr("This context owns the selected object (Manages its lifetime)."));
                ui->observerTable->setItem(i, OwnerColumn, ownerItem);
            }
        }
        tooltip_string.append(QString(tr("<b>Context Name</b>: %1")).arg(observer->observerName()));
        // Context Description
        tooltip_string.append(QString(tr("<br><b>Context Description</b>: %1")).arg(observer->observerDescription()));
        // Context ID
        tooltip_string.append(QString(tr("<br><b>Context ID</b>: %1")).arg(observer->observerID()));
        // Context Category
        MultiContextProperty category_prop = ObjectManager::getMultiContextProperty(d->obj,qti_prop_CATEGORY_MAP);
        QString category_string;
        if (category_prop.isValid()) {
            if (category_prop.contextMap().keys().contains(observer->observerID()))
                category_string = category_prop.value(observer->observerID()).toString();
            else
                category_string = tr("None");
        } else {
            category_string = tr("None");
        }
        tooltip_string.append(QString(tr("<br><b>Context Category</b>: %1")).arg(category_string));

        // Attributes
        tooltip_string.append(tr("<br><br><b>Attributes: </b> "));
        // Attribute: Activity
        QVariant activity = observer->getMultiContextPropertyValue(d->obj,qti_prop_ACTIVITY_MAP);
        if (activity.isValid() && activity.toBool())
            tooltip_string.append(tr("Active, "));

        // Attribute: Object Name Controller
        QVariant name_manager_id = observer->getMultiContextPropertyValue(d->obj,qti_prop_NAME_MANAGER_ID);
        if (name_manager_id.isValid() && (name_manager_id.toInt() == observer->observerID()))
            tooltip_string.append(tr("Manages Name, "));

        // Attribute: Uses Instance Name
        MultiContextProperty instance_names = ObjectManager::getMultiContextProperty(d->obj,qti_prop_ALIAS_MAP);
        if (instance_names.isValid() && instance_names.hasContext(observer->observerID())) {
            tooltip_string.append(QString(tr("Uses Instance Name (\"%1\"), ").arg(instance_names.value(observer->observerID()).toString())));
            has_instance_names = true;
            QTableWidgetItem *aliasItem = new QTableWidgetItem("", id);
            aliasItem->setIcon(QIcon(qti_icon_SUCCESS_16x16));
            aliasItem->setToolTip(tr("This context uses an instance name (alias) for the selected object."));
            ui->observerTable->setItem(i, UsesInstanceNameColumn, aliasItem);
        }

        // Attribute: Ownership
        int parent_id = ObjectManager::getSharedProperty(d->obj,qti_prop_PARENT_ID).value().toInt();
        if (parent_id == observer->observerID())
            tooltip_string.append(tr("Owner"));

        // Subject Filters
        QString filter_name_string;
        for (int r = 0; r < observer->subjectFilters().count(); r++) {
            if (r == 0)
                filter_name_string.append(observer->subjectFilters().at(r)->filterName());
            else
                filter_name_string.append(", " + observer->subjectFilters().at(r)->filterName());
        }
        tooltip_string.append(QString(tr("<br><b>Filters</b>: %1")).arg(filter_name_string));
        nameItem->setToolTip(tooltip_string);
        tooltip_string.clear();   
    }

    ui->observerTable->resizeRowsToContents();
    ui->observerTable->setColumnCount(OwnerColumn+1);
    ui->observerTable->showColumn(NameColumn);
    ui->observerTable->showColumn(UsesInstanceNameColumn);
    ui->observerTable->setColumnWidth(UsesInstanceNameColumn,40);
    ui->observerTable->showColumn(OwnerColumn);
    ui->observerTable->setColumnWidth(OwnerColumn,40);
    QStringList headers;
    headers << tr("Context List") << tr("Alias") << tr("Owner");
    ui->observerTable->setHorizontalHeaderLabels(headers);
    if (ownership == Observer::SpecificObserverOwnership && has_instance_names) {
        ui->observerTable->horizontalHeader()->setResizeMode(NameColumn,QHeaderView::ResizeToContents);
        //ui->observerTable->horizontalHeader()->setResizeMode(OwnerColumn,QHeaderView::Stretch);
    } else if (ownership == Observer::SpecificObserverOwnership && !has_instance_names) {
        ui->observerTable->hideColumn(UsesInstanceNameColumn);
        ui->observerTable->horizontalHeader()->setResizeMode(NameColumn,QHeaderView::ResizeToContents);
        //ui->observerTable->horizontalHeader()->setResizeMode(OwnerColumn,QHeaderView::Stretch);
    } else if (ownership != Observer::SpecificObserverOwnership && has_instance_names) {
        ui->observerTable->hideColumn(OwnerColumn);
        ui->observerTable->horizontalHeader()->setResizeMode(NameColumn,QHeaderView::ResizeToContents);
        //ui->observerTable->horizontalHeader()->setResizeMode(UsesInstanceNameColumn,QHeaderView::Stretch);
    } else {
        ui->observerTable->hideColumn(UsesInstanceNameColumn);
        ui->observerTable->hideColumn(OwnerColumn);
        //ui->observerTable->horizontalHeader()->setResizeMode(NameColumn,QHeaderView::Stretch);
    }
}