diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-05-28 14:44:04 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-05-28 16:20:57 +0300 |
commit | 100014e25b72f01d86c940cecff78018c7a82253 (patch) | |
tree | f669e84d6c17427298e62bb53adb61437bbd4cf2 | |
parent | 2d1bd330a141e83a7d79dcb945557d9703995081 (diff) |
Allow specifying range property precision
- Add a new (optional) attribute "decimals" to range properties. If
the decimals attribute is present, the property will show number of
decimals as set, else the number of decimals will be calculated
automatically.
- Few tweaks.
Task-number: QT3DS-3523
Change-Id: I7ebb5075253effe5d91a12c0b29127e6c5fb8b95
Reviewed-by: Jari Karppinen <jari.karppinen@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
8 files changed, 49 insertions, 50 deletions
diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaData.cpp b/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaData.cpp index bc4e905d..66f56ce8 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaData.cpp +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaData.cpp @@ -2103,8 +2103,9 @@ public: if (!inItem.empty()) { if (inType == AdditionalMetaDataType::Range) { SMetaDataRange theRange(get<SMetaDataRange>(inItem)); - inWriter.Att(L"min", theRange.m_Min); - inWriter.Att(L"max", theRange.m_Max); + inWriter.Att(L"min", theRange.m_min); + inWriter.Att(L"max", theRange.m_max); + inWriter.Att(L"decimals", theRange.m_decimals); } else if (inType == AdditionalMetaDataType::StringList) { const TMetaDataStringList &theList(get<TMetaDataStringList>(inItem)); TCharStr theBuffer; @@ -2170,7 +2171,8 @@ public: // Use the meta data extra information to force the type // to something that works correctly. SMetaDataRange theRange; - if (inReader.Att("min", theRange.m_Min) && inReader.Att("max", theRange.m_Max)) { + if (inReader.Att("min", theRange.m_min) && inReader.Att("max", theRange.m_max)) { + inReader.Att("decimals", theRange.m_decimals); ioItem = theRange; if (ioType == CompleteMetaDataType::Long) ioType = CompleteMetaDataType::LongRange; diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaDataValue.h b/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaDataValue.h index eb3433ab..b981b956 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaDataValue.h +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMMetaDataValue.h @@ -71,25 +71,24 @@ typedef eastl::vector<TCharStr> TMetaDataStringList; // Float type metadata struct SMetaDataRange { - SMetaDataRange() - : m_Min(0.0f) - , m_Max(0.0f) - { - } + SMetaDataRange() {} - SMetaDataRange(float inMin, float inMax) - : m_Min(inMin) - , m_Max(inMax) + SMetaDataRange(float min, float max, int decimals = -1) + : m_min(min) + , m_max(max) + , m_decimals(decimals) { } bool operator==(const SMetaDataRange &other) const { - return m_Min == other.m_Min && m_Max == other.m_Max; + // no need to check m_decimals for quality as it is not significant to the range value + return m_min == other.m_min && m_max == other.m_max; } - float m_Min; - float m_Max; + float m_min = 0.0f; + float m_max = 0.0f; + int m_decimals = -1; // num decimals to show, -1: dynamically calculated }; } diff --git a/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml b/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml index 13e36516..7019dff2 100644 --- a/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml +++ b/src/Authoring/Studio/Palettes/Action/HandlerPropertyBaseSlider.qml @@ -43,8 +43,10 @@ Row { property alias desiredValue: slider.value // This is value adjusted by user property alias sliderMin: slider.from property alias sliderMax: slider.to + property real sliderDecimals: -1 property bool intSlider: false - property int decimalSlider: Math.min(precision(slider.stepSize), 3) + property int decimalSlider: sliderDecimals >= 0 ? sliderDecimals + : Math.min(precision(slider.stepSize), 3) property Item tabItem1: textField signal previewValue // Indicates desiredValue contains a preview value @@ -226,7 +228,6 @@ Row { text = sliderMin slider.value = text root.doCommitValue(); - } function setTextFieldValue() { diff --git a/src/Authoring/Studio/Palettes/Action/PropertyModel.cpp b/src/Authoring/Studio/Palettes/Action/PropertyModel.cpp index b19e2117..8024204d 100644 --- a/src/Authoring/Studio/Palettes/Action/PropertyModel.cpp +++ b/src/Authoring/Studio/Palettes/Action/PropertyModel.cpp @@ -89,8 +89,8 @@ void PropertyModel::setAction(const qt3dsdm::Qt3DSDMActionHandle &action) property.m_handle); qt3dsdm::SMetaDataRange minMax = qt3dsdm::get<qt3dsdm::SMetaDataRange>(metaDataData); - property.m_min = minMax.m_Min; - property.m_max = minMax.m_Max; + property.m_min = minMax.m_min; + property.m_max = minMax.m_max; break; } case qt3dsdm::AdditionalMetaDataType::StringList: { diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp index 7fb01bc2..53519573 100644 --- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp +++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp @@ -52,6 +52,7 @@ #include "Dispatch.h" #include "VariantsGroupModel.h" #include "StudioProjectSettings.h" +#include "Literals.h" #include <QtCore/qfileinfo.h> @@ -92,8 +93,8 @@ static std::pair<bool, bool> getSlideCharacteristics(qt3dsdm::Qt3DSDMInstanceHan // Get the slide from the instance. qt3dsdm::Qt3DSDMSlideHandle slide = slideCore.GetSlideByInstance(instance); qt3dsdm::Qt3DSDMSlideHandle master = slideSystem.GetMasterSlide(slide); - int index = (int)slideSystem.GetSlideIndex(slide); - int count = (int)slideSystem.GetSlideCount(master); + int index = int(slideSystem.GetSlideIndex(slide)); + int count = int(slideSystem.GetSlideCount(master)); bool hasNextSlide = index > 0 && index < count - 1; bool hasPreviousSlide = index > 1; return std::make_pair(hasNextSlide, hasPreviousSlide); @@ -127,27 +128,15 @@ CInspectableBase *InspectorControlModel::inspectable() const return m_inspectableBase; } -qt3dsdm::Qt3DSDMInstanceHandle getReferenceMaterial(CInspectableBase *inspectable) +qt3dsdm::Qt3DSDMInstanceHandle InspectorControlModel::getReferenceMaterial( + CInspectableBase *inspectable) const { - const auto bridge = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem() - ->GetClientDataModelBridge(); - if (inspectable) - return bridge->getMaterialReference(inspectable->getInstance()); + return getBridge()->getMaterialReference(inspectable->getInstance()); return 0; } -CInspectableBase *getReferenceMaterialInspectable(CInspectableBase *inspectable) -{ - auto refMaterial = getReferenceMaterial(inspectable); - - if (refMaterial.Valid()) - return g_StudioApp.getInspectableFromInstance(refMaterial); - - return nullptr; -} - void InspectorControlModel::notifyPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance, qt3dsdm::Qt3DSDMPropertyHandle inProperty) { @@ -1136,7 +1125,9 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c } element->m_value = stringValue; - } // intentional fall-through for other String-derived datatypes + } + Q_FALLTHROUGH(); // fall-through for other String-derived datatypes + case qt3dsdm::DataModelDataType::StringOrInt: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::StringList) { QStringList stringlist; @@ -1186,7 +1177,7 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c // Add the slide names (exclude the master slide) auto slideHandle = slideSystem->GetSlideByInstance(instance); auto masterSlide = slideSystem->GetMasterSlide(slideHandle); - long slideCount = (long)slideSystem->GetSlideCount(masterSlide); + long slideCount = long(slideSystem->GetSlideCount(masterSlide)); for (long slideIndex = 1; slideIndex < slideCount; ++slideIndex) { auto currentSlide = slideSystem->GetSlideByIndex(masterSlide, slideIndex); auto currentInstance = slideSystem->GetSlideInstance(currentSlide); @@ -1219,14 +1210,8 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c updateFontValues(element); skipEmits = true; // updateFontValues handles emits in correct order } else if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Mesh) { - QString meshValue = qt3dsdm::get<QString>(value); - Q3DStudio::CFilePath theSelectionItem(Q3DStudio::CString::fromQString(meshValue)); - Q3DStudio::CFilePath theSelectionWithoutId(theSelectionItem.filePath()); - QString theSelectionWithoutIdName = theSelectionWithoutId.GetFileName().toQString(); - if (theSelectionWithoutIdName.size()) - element->m_value = theSelectionWithoutIdName; - else - element->m_value = theSelectionItem.GetIdentifier().toQString(); + QString meshValue = QFileInfo(qt3dsdm::get<QString>(value)).fileName(); + element->m_value = meshValue.startsWith('#'_L1) ? meshValue.mid(1) : meshValue; } else if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Texture) { QFileInfo fileInfo(qt3dsdm::get<QString>(value)); element->m_value = fileInfo.fileName(); @@ -1241,14 +1226,17 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c << element->m_propertyType; } break; + case qt3dsdm::DataModelDataType::StringRef: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::None) { element->m_value = qt3dsdm::get<QString>(value); } break; + case qt3dsdm::DataModelDataType::Bool: element->m_value = qt3dsdm::get<bool>(value); break; + case qt3dsdm::DataModelDataType::Long4: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Image) { qt3dsdm::Option<qt3dsdm::SLong4> guid = qt3dsdm::get<qt3dsdm::SLong4>(value); @@ -1266,6 +1254,7 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c << element->m_dataType << " " << element->m_title; } break; + case qt3dsdm::DataModelDataType::Long: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Range) { element->m_value = qt3dsdm::get<int>(value); @@ -1273,12 +1262,12 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c if (m_guideInspectable) { const auto prop = m_guideInspectable->properties() [handleToGuidePropIndex(element->m_property)]; - ranges.m_Min = prop->GetInspectableMin(); - ranges.m_Max = prop->GetInspectableMax(); + ranges.m_min = prop->GetInspectableMin(); + ranges.m_max = prop->GetInspectableMax(); } else { ranges = qt3dsdm::get<qt3dsdm::SMetaDataRange>(info->m_MetaDataData); } - const QList<double> rangesValues{ranges.m_Min, ranges.m_Max}; + const QList<double> rangesValues{ranges.m_min, ranges.m_max, double(ranges.m_decimals)}; element->m_values = QVariant::fromValue<QList<double> >(rangesValues); } else if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::ShadowMapResolution) { @@ -1288,6 +1277,7 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c << element->m_dataType; } break; + case qt3dsdm::DataModelDataType::Float3: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Color) { element->m_value = qt3dsdm::get<QColor>(value); @@ -1301,11 +1291,13 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c element->m_values = QVariant::fromValue<QList<double> >(float3Values); } break; + case qt3dsdm::DataModelDataType::Float4: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Color) { element->m_value = qt3dsdm::get<QColor>(value); } break; + case qt3dsdm::DataModelDataType::Float2: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::None) { const QVector2D theFloat2 = qt3dsdm::get<QVector2D>(value); @@ -1316,18 +1308,20 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c << element->m_dataType << element->m_propertyType; } break; + case qt3dsdm::DataModelDataType::Float: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::None) { element->m_value = qt3dsdm::get<float>(value); } else if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::Range) { element->m_value = qt3dsdm::get<float>(value); const qt3dsdm::SMetaDataRange ranges = qt3dsdm::get<qt3dsdm::SMetaDataRange>(info->m_MetaDataData); - const QList<double> rangesValues{ranges.m_Min, ranges.m_Max}; + const QList<double> rangesValues{ranges.m_min, ranges.m_max, double(ranges.m_decimals)}; element->m_values = QVariant::fromValue<QList<double> >(rangesValues); } else if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::FontSize) { element->m_value = qt3dsdm::get<float>(value); } break; + case qt3dsdm::DataModelDataType::ObjectRef: if (element->m_propertyType == qt3dsdm::AdditionalMetaDataType::ObjectRef) { IObjectReferenceHelper *objRefHelper = doc->GetDataModelObjectReferenceHelper(); @@ -1347,6 +1341,7 @@ void InspectorControlModel::updatePropertyValue(InspectorControlBase *element) c } } break; + default: qWarning() << "TODO: InspectorControlModel::updatePropertyValue: I've no idea how to handle this datatype" << element->m_dataType; diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h index e2f12831..3063f047 100644 --- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h +++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h @@ -219,6 +219,7 @@ private: bool isBasicMaterial(CInspectableBase *inspectable) const; void updateMaterialValues(const QStringList &values, int elementIndex, bool updatingShaders = false); + qt3dsdm::Qt3DSDMInstanceHandle getReferenceMaterial(CInspectableBase *inspectable) const; void updateShaderValues(); void updateMatDataValues(); void updatePropertyValue(InspectorControlBase *element) const; diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml index ebb56023..c291de7b 100644 --- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml +++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlView.qml @@ -777,6 +777,7 @@ Rectangle { value: parent.modelData.value sliderMin: values[0] sliderMax: values[1] + sliderDecimals: values[2] onCommitValue: _inspectorModel.setPropertyValue(instance, handle, desiredValue, true) onPreviewValue: _inspectorModel.setPropertyValue(instance, handle, desiredValue, false) diff --git a/src/Runtime/Source/datamodel/Qt3DSMetadata.cpp b/src/Runtime/Source/datamodel/Qt3DSMetadata.cpp index 197582b0..89bb4de7 100644 --- a/src/Runtime/Source/datamodel/Qt3DSMetadata.cpp +++ b/src/Runtime/Source/datamodel/Qt3DSMetadata.cpp @@ -608,7 +608,7 @@ public: } break; case qt3dsdm::AdditionalMetaDataType::Range: { const SMetaDataRange &range = argInfo.m_MetaDataData.getData<SMetaDataRange>(); - arg.m_MetaDataRange = eastl::make_pair(range.m_Min, range.m_Max); + arg.m_MetaDataRange = eastl::make_pair(range.m_min, range.m_max); } break; default: break; |