Пример #1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool PdmUiTableViewModel::setData(const QModelIndex &index, const QVariant &value, int role /*= Qt::EditRole*/)
{
    if (role == Qt::CheckStateRole)
    {
        if (isRepresentingBoolean(index))
        {
            // Clear current selection, UI does not behave well for multiple selection
            SelectionManager::instance()->clear(SelectionManager::CURRENT);

            bool toggleOn = (value == Qt::Checked);
            PdmFieldHandle* field = getField(index);

            PdmUiFieldHandle* uiFieldHandle = field->uiCapability();
            PdmUiCommandSystemProxy::instance()->setUiValueToField(uiFieldHandle, toggleOn);

            return true;
        }
    }   

     return false;
}
Пример #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
QVariant PdmUiTableViewModel::data(const QModelIndex &index, int role /*= Qt::DisplayRole */) const
{
    if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
        PdmFieldHandle* fieldHandle = getField(index);
        PdmUiFieldHandle* uiFieldHandle = fieldHandle->uiCapability();
        if (uiFieldHandle)
        {
            bool fromMenuOnly = false;
            QList<PdmOptionItemInfo> valueOptions = uiFieldHandle->valueOptions(&fromMenuOnly);
            if (!valueOptions.isEmpty())
            {
                int listIndex = uiFieldHandle->uiValue().toInt();
                if (listIndex == -1)
                {
                    return "";
                }

                return valueOptions[listIndex].optionUiText;
            }

            QVariant val;

            PdmObjectHandle* objForRow = this->pdmObjectForRow(index.row());
            PdmUiObjectHandle* uiObjForRow = uiObj(objForRow);
            if (uiObjForRow)
            {
                // NOTE: Redesign
                // To be able to get formatted string, an editor attribute concept is used
                // TODO: Create a function in pdmObject like this
                // virtual void            defineDisplayString(const PdmFieldHandle* field, QString uiConfigName) {}

                PdmUiLineEditorAttributeUiDisplayString leab;
                uiObjForRow->editorAttribute(fieldHandle, m_currentConfigName, &leab);

                if (!leab.m_displayString.isEmpty())
                {
                    val = leab.m_displayString;
                }
                else
                {
                    val = uiFieldHandle->uiValue();
                }
            }
            else
            {
                val = uiFieldHandle->uiValue();
            }

            return val;
        }
        else
        {
            assert(false);
        }
    }
    else if (role == Qt::CheckStateRole)
    {
        if (isRepresentingBoolean(index))
        {
            PdmUiFieldHandle* uiFieldHandle = getField(index)->uiCapability();
            if (uiFieldHandle)
            {
                QVariant val = uiFieldHandle->uiValue();
                bool isToggledOn = val.toBool();
                if (isToggledOn)
                {
                    return Qt::Checked;
                }
                else
                {
                    return Qt::Unchecked;
                }
            }
            else
            {
                return QVariant();
            }
        }
    }

    return QVariant();
}
Пример #3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
QVariant UiTreeModelPdm::data(const QModelIndex &index, int role /*= Qt::DisplayRole */) const
{
    if (!m_treeItemRoot)
        return QVariant();

    if (!index.isValid())
        return QVariant();

    PdmUiTreeItem* treeItem = UiTreeModelPdm::getTreeItemFromIndex(index);
    assert(treeItem);

    PdmObject* obj = treeItem->dataObject();

    if (obj == NULL) return QVariant();

    // We try to find the context of the object first: The parent field
    // If found, use its data to describe the thing
    // Note: This code will only find first field pointing at the current object. Its valid for now,
    // but will not generally be valid if references is introduced in the pdm system

    PdmFieldHandle* parentField = 0;

    PdmUiTreeItem* parentTreeItem = treeItem->parent();
    if (parentTreeItem)
    {
        PdmObject* parentObj = parentTreeItem->dataObject();
        if (parentObj)
        {
            std::vector<PdmFieldHandle*> fields;
            parentObj->fields(fields);

            size_t i;
            for (i = 0; i < fields.size(); ++i)
            {
                std::vector<PdmObject*> children;
                if (fields[i]) fields[i]->childObjects(&children);
                size_t cIdx;
                for (cIdx = 0; cIdx < children.size(); ++ cIdx)
                {
                    if (children[cIdx] == obj)
                    { 
                        parentField = fields[i];
                        break;
                    }
                }
                if (parentField) break;
            }
        }
    }

    assert(obj);

    if (role == Qt::DisplayRole || role == Qt::EditRole)
    {
        if (obj->userDescriptionField())
        {
            return obj->userDescriptionField()->uiValue();
        }
        else
        {
            if (parentField && !parentField->uiName().isEmpty())
                return parentField->uiName();
            else
                return  obj->uiName();
        }
    }
    else if (role == Qt::DecorationRole)
    {
        if (parentField && !parentField->uiIcon().isNull())
            return parentField->uiIcon();
        else
            return obj->uiIcon();
    }
    else if (role == Qt::ToolTipRole)
    {
        if (parentField && !parentField->uiToolTip().isEmpty())
            return parentField->uiToolTip();
        else
            return  obj->uiToolTip();
    }
    else if (role == Qt::WhatsThisRole)
    {
        if (parentField && !parentField->uiWhatsThis().isEmpty())
            return parentField->uiWhatsThis();
        else
            return  obj->uiWhatsThis();
    }
    else if (role == Qt::CheckStateRole)
    {
        if (obj->objectToggleField())
        {
            bool isToggledOn = obj->objectToggleField()->uiValue().toBool();
            if (isToggledOn)
            {
                return Qt::Checked;
            }
            else
            {
                return Qt::Unchecked;
            }
        }
    }

    return QVariant();
}
Пример #4
0
//--------------------------------------------------------------------------------------------------
/// Reads all the fields into this PdmObject
/// Assumes xmlStream points to the start element token of the PdmObject for which to read fields.
/// ( and not first token of object content)
/// This makes attribute based field storage possible.
/// Leaves the xmlStream pointing to the EndElement of the PdmObject.
//--------------------------------------------------------------------------------------------------
void PdmObject::readFields (QXmlStreamReader& xmlStream )
{
   bool isObjectFinished = false;
   QXmlStreamReader::TokenType type;
   while(!isObjectFinished)
   {
       type = xmlStream.readNext();

       switch (type)
       {
       case QXmlStreamReader::StartElement:
           {
               QString name = xmlStream.name().toString();
               if (name == QString("SimpleObjPtrField"))
               {
                   int a;
                   a = 2 + 7;
               }
               PdmFieldHandle* currentField = findField(name);
               if (currentField)
               {
                   if (currentField->isIOReadable())
                   {
                       // readFieldData assumes that the xmlStream points to first token of field content.
                       // After reading, the xmlStream is supposed to point to the first token after the field content.
                       // (typically an "endElement")
                       QXmlStreamReader::TokenType tt;
                       tt = xmlStream.readNext();
                       currentField->readFieldData( xmlStream );
                   }
                   else
                   {
                       xmlStream.skipCurrentElement();
                   }
               }
               else
               {
                   std::cout << "Line "<< xmlStream.lineNumber() << ": Warning: Could not find a field with name " << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data() << std::endl;
                   xmlStream.skipCurrentElement();
               }
               break;
           }
           break;
       case QXmlStreamReader::EndElement:
           {
               // End of object.
               QString name = xmlStream.name().toString(); // For debugging
               isObjectFinished = true;
           }
           break;
       case QXmlStreamReader::EndDocument:
           {
               // End of object.
               isObjectFinished = true;
           }
           break;
       default:
           {
               // Just read on
               // Todo: Error handling   
           }
           break;
       }
   }

}