コード例 #1
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiDoubleValueEditor::configureAndUpdateUi(const QString& uiConfigName)
{
    CAF_ASSERT(!m_lineEdit.isNull());

    PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);

    m_lineEdit->setEnabled(!uiField()->isUiReadOnly(uiConfigName));

    caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
    if (uiObject)
    {
        uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &m_attributes);
    }

    bool    valueOk = false;
    double  value   = uiField()->uiValue().toDouble(&valueOk);
    QString textValue;
    if (valueOk)
    {
        textValue = QString::number(value, 'g', m_attributes.m_decimals);
    }
    else
    {
        textValue = uiField()->uiValue().toString();
    }

    m_lineEdit->setText(textValue);
}
コード例 #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RimCommandIssueFieldChanged::findObjectByName(caf::PdmObjectHandle* pdmObject, const QString& objectName)
{
    std::vector<caf::PdmFieldHandle*> fields;
    pdmObject->fields(fields);

    caf::PdmUiObjectHandle* uiObjectHandle = uiObj(pdmObject);

    if (uiObjectHandle && uiObjectHandle->uiName() == objectName)
    {
        return pdmObject;
    }
    
    for (size_t fIdx = 0; fIdx < fields.size(); fIdx++)
    {
        if (fields[fIdx])
        {
            std::vector<caf::PdmObjectHandle*> children;
            fields[fIdx]->childObjects(&children);

            for (size_t cIdx = 0; cIdx < children.size(); cIdx++)
            {
                PdmObjectHandle* candidateObj = findObjectByName(children[cIdx], objectName);
                if (candidateObj)
                {
                    return candidateObj;
                }
            }
        }
    }

    return NULL;
}
コード例 #3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void PdmUiObjectEditorHandle::setPdmObject(PdmObjectHandle* object)
{
    cleanupBeforeSettingPdmObject();

    caf::PdmUiObjectHandle* uiObject = uiObj(object);
    this->bindToPdmItem(uiObject);
}
コード例 #4
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
PdmUiTableItemEditor::PdmUiTableItemEditor(PdmUiTableViewModel* model, caf::PdmObjectHandle* pdmObject, int row)
{
    m_model = model;
    m_row = row;

    caf::PdmUiObjectHandle* uiObject = uiObj(pdmObject);
    this->bindToPdmItem(uiObject);
}
コード例 #5
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void caf::UiListViewModelPdm::setPdmData(PdmObjectCollection* objectGroup, const QString& configName)
{
    m_pdmObjectGroup = objectGroup;
    m_configName = configName;

    if (m_pdmObjectGroup)
    {
        caf::PdmUiObjectHandle* uiObject = uiObj(m_pdmObjectGroup);
        if (uiObject)
        {
            uiObject->objectEditorAttribute(m_configName, &m_editorAttribute);
        }
    }

    computeColumnCount();

    reset();
}
コード例 #6
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void PdmUiFieldHandle::notifyFieldChanged(const QVariant& oldFieldValue, const QVariant& newFieldValue)
{
    if (oldFieldValue != newFieldValue)
    {
        PdmFieldHandle* fieldHandle = this->fieldHandle();
        assert(fieldHandle && fieldHandle->ownerObject());

        PdmUiObjectHandle* uiObjHandle = uiObj(fieldHandle->ownerObject());
        if (uiObjHandle)
        {
            uiObjHandle->fieldChangedByUi(fieldHandle, oldFieldValue, newFieldValue);
            uiObjHandle->updateConnectedEditors();
        }

        // Update field editors
        this->updateConnectedEditors();
    }
}
コード例 #7
0
bool RicToggleItemsFeatureImpl::isToggleCommandsAvailable()
{
    std::vector<caf::PdmUiItem*> selectedItems;
    caf::SelectionManager::instance()->selectedItems(selectedItems);

    if (selectedItems.size() == 1)
    {
        QModelIndex modIndex = RiuMainWindow::instance()->projectTreeView()->findModelIndex(selectedItems[0]);
        caf::PdmUiTreeOrdering* treeItem = static_cast<caf::PdmUiTreeOrdering*>(modIndex.internalPointer()); 
        if (!treeItem) return false;

        for (int cIdx = 0; cIdx < treeItem->childCount(); ++ cIdx)
        {
            caf::PdmUiTreeOrdering*  child = treeItem->child(cIdx);
            if (!child) continue;
            if (!child->isRepresentingObject()) continue;

            caf::PdmObjectHandle* childObj = child->object();
            caf::PdmUiObjectHandle* uiObjectHandleChild = uiObj(childObj);

            if (uiObjectHandleChild &&
                uiObjectHandleChild->objectToggleField() &&
                !uiObjectHandleChild->objectToggleField()->uiCapability()->isUiReadOnly())
            {
                return true;
            }
        }
    }
    else
    {
        for (size_t i = 0; i < selectedItems.size(); ++i)
        {
            caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast<caf::PdmUiObjectHandle*>(selectedItems[i]);

            if (uiObjectHandle && uiObjectHandle->objectToggleField())
            {
                return true;
            }
        }
    }

    return false;
}
コード例 #8
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void PdmUiFieldHandle::notifyFieldChanged(const QVariant& oldFieldValue, const QVariant& newFieldValue)
{
    if (oldFieldValue != newFieldValue)
    {
        PdmFieldHandle* fieldHandle = this->fieldHandle();
        CAF_ASSERT(fieldHandle && fieldHandle->ownerObject());

        PdmUiObjectHandle* uiObjHandle = uiObj(fieldHandle->ownerObject());
        if (uiObjHandle)
        {
            uiObjHandle->fieldChangedByUi(fieldHandle, oldFieldValue, newFieldValue);
            uiObjHandle->updateConnectedEditors();
        }

        // Update field editors
        this->updateConnectedEditors();

        PdmUiModelChangeDetector::instance()->setModelChanged();
    }
}
コード例 #9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void PdmUiDateEditor::configureAndUpdateUi(const QString& uiConfigName)
{
    CAF_ASSERT(!m_dateEdit.isNull());

    PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);

    m_dateEdit->setEnabled(!field()->isUiReadOnly(uiConfigName));

    caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
    if (uiObject)
    {
        uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &m_attributes);
    }

    if (!m_attributes.dateFormat.isEmpty())
    {
        m_dateEdit->setDisplayFormat(m_attributes.dateFormat);
    }

    m_dateEdit->setDate(field()->uiValue().toDate());
}
コード例 #10
0
ファイル: cafPdmUiLineEditor.cpp プロジェクト: OPM/ResInsight
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void PdmUiLineEditor::configureAndUpdateUi(const QString& uiConfigName)
{
    if (!m_label.isNull())
    {
        PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
    }

    if (!m_lineEdit.isNull())
    {
        bool isReadOnly = uiField()->isUiReadOnly(uiConfigName);
        if (isReadOnly)
        {
            m_lineEdit->setReadOnly(true);

            m_lineEdit->setStyleSheet("QLineEdit {"
                "color: #808080;"
                "background-color: #F0F0F0;}");
        }
        else
        {
            m_lineEdit->setReadOnly(false);
            m_lineEdit->setStyleSheet("");
        }

        m_lineEdit->setToolTip(uiField()->uiToolTip(uiConfigName));

        {
            PdmUiLineEditorAttribute leab;
            caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
            if (uiObject)
            {
                uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &leab);
            }

            if (leab.validator)
            {
                m_lineEdit->setValidator(leab.validator);
            }

            m_lineEdit->setAvoidSendingEnterEventToParentWidget(leab.avoidSendingEnterEventToParentWidget);
        }

        bool fromMenuOnly = true;
        QList<PdmOptionItemInfo> enumNames = uiField()->valueOptions(&fromMenuOnly);
        CAF_ASSERT(fromMenuOnly); // Not supported

        if (!enumNames.isEmpty() && fromMenuOnly == true)
        {
            int enumValue = uiField()->uiValue().toInt();

            if (enumValue < enumNames.size() && enumValue > -1)
            {
                m_lineEdit->setText(enumNames[enumValue].optionUiText());
            }
        }
        else
        {
            PdmUiLineEditorAttributeUiDisplayString leab;
            caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
            if (uiObject)
            {
                uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &leab);
            }

            QString displayString;
            if (leab.m_displayString.isEmpty())
            {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
                bool valueOk = false;
                double  value = uiField()->uiValue().toDouble(&valueOk);
                if (valueOk)
                {
                    // Workaround for issue seen on Qt 5.6.1 on Linux
                    int precision = 8;
                    displayString = QString::number(value, 'g', precision);
                }
                else
                {
                    displayString = uiField()->uiValue().toString();
                }
#else
                displayString = uiField()->uiValue().toString();
#endif
            }
            else
            {
                displayString = leab.m_displayString;
            }

            m_lineEdit->setText(displayString);
        }
    }
}
コード例 #11
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void PdmUiTableViewModel::setPdmData(PdmChildArrayFieldHandle* listField, const QString& configName)
{
    beginResetModel();

    m_pdmList = listField;
    m_currentConfigName = configName;

    PdmUiOrdering config;

    if (m_pdmList && m_pdmList->size() > 0)
    {
        PdmObjectHandle* firstObject = m_pdmList->at(0);

        PdmUiObjectHandle* uiObject = uiObj(firstObject);
        if (uiObject)
        {
            uiObject->uiOrdering(configName, config);
        }
    }

    const std::vector<PdmUiItem*>& uiItems = config.uiItems();

    // Set all fieldViews to be unvisited
    std::map<QString, PdmUiFieldEditorHandle*>::iterator it;
    for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it)
    {
        it->second->setField(NULL);
    }

    m_modelColumnIndexToFieldIndex.clear();

    for (size_t i = 0; i < uiItems.size(); ++i)
    {
        if (uiItems[i]->isUiHidden(configName)) continue;

        if (uiItems[i]->isUiGroup()) continue;

        {
            PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*>(uiItems[i]);
            PdmUiFieldEditorHandle* fieldEditor = NULL;

            // Find or create FieldEditor
            std::map<QString, PdmUiFieldEditorHandle*>::iterator it;
            it = m_fieldEditors.find(field->fieldHandle()->keyword());

            if (it == m_fieldEditors.end())
            {
                // If editor type is specified, find in factory
                if ( !uiItems[i]->uiEditorTypeName(configName).isEmpty() )
                {
                    fieldEditor = Factory<PdmUiFieldEditorHandle, QString>::instance()->create(field->uiEditorTypeName(configName));
                }
                else
                { 
                    // Find the default field editor

                    QString editorTypeName = qStringTypeName(*(field->fieldHandle()));

                    // Handle a single value field with valueOptions: Make a combobox

                    if (field->uiValue().type() != QVariant::List)
                    {
                        bool useOptionsOnly = true; 
                        QList<PdmOptionItemInfo> options = field->valueOptions( &useOptionsOnly);

                        if (!options.empty())
                        {
                            editorTypeName = PdmUiComboBoxEditor::uiEditorTypeName();
                        }
                    }

                    fieldEditor = Factory<PdmUiFieldEditorHandle, QString>::instance()->create(editorTypeName);
                }

                if (fieldEditor)
                {
                    m_fieldEditors[field->fieldHandle()->keyword()] = fieldEditor;
                }
            }
            else
            {
                fieldEditor = it->second;
            }

            if (fieldEditor)
            {
                fieldEditor->setField(field); 

                //TODO: Create/update is not required at this point, as UI is recreated in getEditorWidgetAndTransferOwnership()
                // Can be moved, but a move will require changes in PdmUiFieldEditorHandle
                fieldEditor->createWidgets(NULL);
                fieldEditor->updateUi(configName);

                int fieldIndex = getFieldIndex(field->fieldHandle());
                m_modelColumnIndexToFieldIndex.push_back(fieldIndex);
            }
        }
    }


    // Remove all fieldViews not mentioned by the configuration from the layout

    std::vector< QString > fvhToRemoveFromMap;
    for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it)
    {
        if (it->second->field() == 0)
        {
            PdmUiFieldEditorHandle* fvh = it->second;
            delete fvh;
            fvhToRemoveFromMap.push_back(it->first);               
        }
    }

    for (size_t i = 0; i < fvhToRemoveFromMap.size(); ++i)
    {
        m_fieldEditors.erase(fvhToRemoveFromMap[i]);
    }

    recreateTableItemEditors();

    endResetModel();
}
コード例 #12
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();
}
コード例 #13
0
//--------------------------------------------------------------------------------------------------
/// Set toggle state for list of model indices. 
//--------------------------------------------------------------------------------------------------
void RicToggleItemsFeatureImpl::setObjectToggleStateForSelection(SelectionToggleType state)
{
    std::vector<caf::PdmUiItem*> selectedItems;
    caf::SelectionManager::instance()->selectedItems(selectedItems);
    if (state != TOGGLE && selectedItems.size() == 1)
    {
        // If only one item is selected, loop over its children, and toggle them instead of the 
        // selected item directly

        // We need to get the children through the tree view, because that is where the actually shown children is 
        
        QModelIndex modIndex = RiuMainWindow::instance()->projectTreeView()->findModelIndex(selectedItems[0]);
        caf::PdmUiTreeOrdering* treeItem = reinterpret_cast<caf::PdmUiTreeOrdering*>(modIndex.internalPointer()); 

        for (int cIdx = 0; cIdx < treeItem->childCount(); ++ cIdx)
        {
            caf::PdmUiTreeOrdering*  child = treeItem->child(cIdx);
            if (!child) continue;
            if (!child->isRepresentingObject()) continue;

            caf::PdmObjectHandle* childObj = child->object();
            caf::PdmUiObjectHandle* uiObjectHandleChild = uiObj(childObj);

            if (uiObjectHandleChild && uiObjectHandleChild->objectToggleField())
            {
                caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>(uiObjectHandleChild->objectToggleField());

                caf::PdmUiFieldHandle* uiFieldHandle = field->uiCapability();
                if (uiFieldHandle)
                {
                    if (state == TOGGLE_ON)  uiFieldHandle->setValueFromUi(true);
                    if (state == TOGGLE_OFF) uiFieldHandle->setValueFromUi(false);
                    if (state == TOGGLE_SUBITEMS)     uiFieldHandle->setValueFromUi(!(field->v()));
                }
            }
        }
    }
    else
    {
        for (size_t i = 0; i < selectedItems.size(); ++i)
        {
            caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast< caf::PdmUiObjectHandle*>(selectedItems[i]);

            if (uiObjectHandle && uiObjectHandle->objectToggleField())
            {
                caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>* >(uiObjectHandle->objectToggleField());

                caf::PdmUiFieldHandle* uiFieldHandle = field->uiCapability();
                if (uiFieldHandle)
                {
                    if (state == TOGGLE_ON)  uiFieldHandle->setValueFromUi(true);
                    if (state == TOGGLE_OFF) uiFieldHandle->setValueFromUi(false);
                    if (state == TOGGLE_SUBITEMS || state == TOGGLE)
                    {
                        uiFieldHandle->setValueFromUi(!(field->v()));
                    }
                }
            } 
        }
    }
}