From 732dac4c65e83d6040d54424da7eec0851fb9e36 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Mon, 19 Feb 2024 17:38:04 -0800 Subject: [PATCH] Support editing string properties. --- common/camera.cpp | 16 +++++++--- common/camera.h | 2 +- common/lc_model.cpp | 28 ++--------------- common/lc_model.h | 2 -- common/lc_propertieswidget.cpp | 57 +++++++++++++++------------------- common/lc_propertieswidget.h | 2 +- common/light.cpp | 18 +++++++++-- common/light.h | 5 +-- common/object.cpp | 8 +++-- 9 files changed, 65 insertions(+), 73 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index 2c0610ad..ba77bb1b 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -115,9 +115,14 @@ void lcCamera::Initialize() mState = 0; } -void lcCamera::SetName(const QString& Name) +bool lcCamera::SetName(const QString& Name) { + if (mName == Name) + return false; + mName = Name; + + return true; } void lcCamera::CreateName(const lcArray& Cameras) @@ -614,9 +619,11 @@ QVariant lcCamera::GetPropertyValue(lcObjectPropertyId PropertyId) const case lcObjectPropertyId::PieceColor: case lcObjectPropertyId::PieceStepShow: case lcObjectPropertyId::PieceStepHide: - case lcObjectPropertyId::CameraName: break; + case lcObjectPropertyId::CameraName: + return GetName(); + case lcObjectPropertyId::CameraType: return static_cast(GetCameraType()); @@ -668,7 +675,6 @@ bool lcCamera::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool { Q_UNUSED(Step); Q_UNUSED(AddKey); - Q_UNUSED(Value); switch (PropertyId) { @@ -676,9 +682,11 @@ bool lcCamera::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool case lcObjectPropertyId::PieceColor: case lcObjectPropertyId::PieceStepShow: case lcObjectPropertyId::PieceStepHide: - case lcObjectPropertyId::CameraName: break; + case lcObjectPropertyId::CameraName: + return SetName(Value.toString()); + case lcObjectPropertyId::CameraType: return SetCameraType(static_cast(Value.toInt())); diff --git a/common/camera.h b/common/camera.h index 418e1140..bda2c182 100644 --- a/common/camera.h +++ b/common/camera.h @@ -64,7 +64,7 @@ public: return mName; } - void SetName(const QString& Name); + bool SetName(const QString& Name); void CreateName(const lcArray& Cameras); bool IsSimple() const diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 01b160a5..d9bbc390 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -3159,19 +3159,6 @@ void lcModel::SetCameraZFar(lcCamera* Camera, float ZFar) UpdateAllViews(); } -void lcModel::SetCameraName(lcCamera* Camera, const QString& Name) -{ - if (Camera->GetName() == Name) - return; - - Camera->SetName(Name); - - SaveCheckpoint(tr("Renaming Camera")); - gMainWindow->UpdateSelectedObjects(false); - UpdateAllViews(); - gMainWindow->UpdateCameraMenu(); -} - void lcModel::SetLightAttenuationDistance(lcLight* Light, float Distance) { Light->SetAttenuationDistance(Distance, mCurrentStep, gMainWindow->GetAddKeys()); @@ -3263,19 +3250,10 @@ void lcModel::SetObjectsProperty(const lcArray& Objects, lcObjectProp SaveCheckpoint(lcObject::GetCheckpointString(PropertyId)); gMainWindow->UpdateSelectedObjects(false); UpdateAllViews(); -} -void lcModel::SetLightName(lcLight* Light, const QString &Name) -{ - if (Light->GetName() == Name) - return; - - Light->SetName(Name); - - SaveCheckpoint(tr("Renaming Light")); - gMainWindow->UpdateSelectedObjects(false); - UpdateAllViews(); - gMainWindow->UpdateCameraMenu(); + // todo: fix hacky camera menu update + if (PropertyId == lcObjectPropertyId::CameraName) + gMainWindow->UpdateCameraMenu(); } bool lcModel::AnyPiecesSelected() const diff --git a/common/lc_model.h b/common/lc_model.h index b7544e7d..3f85210d 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -371,7 +371,6 @@ public: void SetCameraFOV(lcCamera* Camera, float FOV); void SetCameraZNear(lcCamera* Camera, float ZNear); void SetCameraZFar(lcCamera* Camera, float ZFar); - void SetCameraName(lcCamera* Camera, const QString& Name); void SetLightAttenuationDistance(lcLight* Light, float Distance); void SetLightAttenuationPower(lcLight* Light, float Power); @@ -380,7 +379,6 @@ public: void SetSpotLightTightness(lcLight* Light, float Tightness); void SetLightSize(lcLight* Light, lcVector2 LightAreaSize); void SetLightPower(lcLight* Light, float Power); - void SetLightName(lcLight* Light, const QString& Name); void ShowPropertiesDialog(); void ShowSelectByNameDialog(); diff --git a/common/lc_propertieswidget.cpp b/common/lc_propertieswidget.cpp index 3465438e..290f8703 100644 --- a/common/lc_propertieswidget.cpp +++ b/common/lc_propertieswidget.cpp @@ -583,8 +583,8 @@ void lcPropertiesWidget::AddStepNumberProperty(lcObjectPropertyId PropertyId, co void lcPropertiesWidget::StringChanged() { - QLineEdit* Widget = qobject_cast(sender()); - lcObjectPropertyId PropertyId = GetEditorWidgetPropertyId(Widget); + QLineEdit* LineEdit = qobject_cast(sender()); + lcObjectPropertyId PropertyId = GetEditorWidgetPropertyId(LineEdit); if (PropertyId == lcObjectPropertyId::Count) return; @@ -594,35 +594,32 @@ void lcPropertiesWidget::StringChanged() if (!Model) return; - lcCamera* Camera = dynamic_cast(mFocusObject); - lcLight* Light = dynamic_cast(mFocusObject); - QString Text = Widget->text(); - - if (Camera) - { - if (PropertyId == lcObjectPropertyId::CameraName) - { - Model->SetCameraName(Camera, Text); - } - } - else if (Light) - { - if (PropertyId == lcObjectPropertyId::LightName) - { - Model->SetLightName(Light, Text); - } - } + QString Value = LineEdit->text(); + Model->SetObjectsProperty(mFocusObject ? lcArray{ mFocusObject } : mSelection, PropertyId, Value); } -void lcPropertiesWidget::UpdateString(lcObjectPropertyId PropertyId, const QString& Text) +void lcPropertiesWidget::UpdateString(lcObjectPropertyId PropertyId) { - QLineEdit* Widget = qobject_cast(mPropertyWidgets[static_cast(PropertyId)].Editor); + QLineEdit* LineEdit = qobject_cast(mPropertyWidgets[static_cast(PropertyId)].Editor); - if (Widget) + if (!LineEdit) + return; + + QSignalBlocker Blocker(LineEdit); + QVariant Value; + bool Partial; + + std::tie(Value, Partial) = GetUpdateValue(PropertyId, QString()); + + if (Partial) { - QSignalBlocker Blocker(Widget); - - Widget->setText(Text); + LineEdit->clear(); + LineEdit->setPlaceholderText(tr("Multiple Values")); + } + else + { + LineEdit->setText(Value.toString()); + LineEdit->setPlaceholderText(QString()); } UpdateKeyFrameWidget(PropertyId); @@ -1199,7 +1196,6 @@ void lcPropertiesWidget::SetCamera(const lcArray& Selection, lcObject float FoV = 60.0f; float ZNear = 1.0f; float ZFar = 100.0f; - QString Name; if (Camera) { @@ -1210,10 +1206,9 @@ void lcPropertiesWidget::SetCamera(const lcArray& Selection, lcObject FoV = Camera->m_fovy; ZNear = Camera->m_zNear; ZFar = Camera->m_zFar; - Name = Camera->GetName(); } - UpdateString(lcObjectPropertyId::CameraName, Name); + UpdateString(lcObjectPropertyId::CameraName); UpdateStringList(lcObjectPropertyId::CameraType); UpdateFloat(lcObjectPropertyId::CameraFOV, FoV); @@ -1241,7 +1236,6 @@ void lcPropertiesWidget::SetLight(const lcArray& Selection, lcObject* mSelection = Selection; mFocusObject = Light; - QString Name; lcLightType LightType = lcLightType::Count; lcLightAreaShape LightAreaShape = lcLightAreaShape::Count; lcVector2 LightSize(0.0f, 0.0f); @@ -1254,7 +1248,6 @@ void lcPropertiesWidget::SetLight(const lcArray& Selection, lcObject* if (Light) { - Name = Light->GetName(); LightType = Light->GetLightType(); LightAreaShape = Light->GetAreaShape(); @@ -1303,7 +1296,7 @@ void lcPropertiesWidget::SetLight(const lcArray& Selection, lcObject* LightAreaShape = lcLightAreaShape::Count; } - UpdateString(lcObjectPropertyId::LightName, Name); + UpdateString(lcObjectPropertyId::LightName); UpdateStringList(lcObjectPropertyId::LightType); UpdateColor(lcObjectPropertyId::LightColor); diff --git a/common/lc_propertieswidget.h b/common/lc_propertieswidget.h index 9ed0ab70..b7073476 100644 --- a/common/lc_propertieswidget.h +++ b/common/lc_propertieswidget.h @@ -102,7 +102,7 @@ protected: void UpdateFloat(lcObjectPropertyId PropertyId, float Value); void UpdateInteger(lcObjectPropertyId PropertyId); void UpdateStepNumber(lcObjectPropertyId PropertyId, lcStep Step, lcStep Min, lcStep Max); - void UpdateString(lcObjectPropertyId PropertyId, const QString& Text); + void UpdateString(lcObjectPropertyId PropertyId); void UpdateStringList(lcObjectPropertyId PropertyId); void UpdateColor(lcObjectPropertyId PropertyId); void UpdatePieceColor(lcObjectPropertyId PropertyId, int ColorIndex); diff --git a/common/light.cpp b/common/light.cpp index e7d89451..f75385ae 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -484,6 +484,16 @@ void lcLight::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix, SetRotation(NewLocalToWorldMatrix, Step, AddKey); } +bool lcLight::SetName(const QString& Name) +{ + if (mName == Name) + return false; + + mName = Name; + + return true; +} + bool lcLight::SetLightType(lcLightType LightType) { if (static_cast(LightType) < 0 || LightType >= lcLightType::Count) @@ -1060,9 +1070,11 @@ QVariant lcLight::GetPropertyValue(lcObjectPropertyId PropertyId) const case lcObjectPropertyId::CameraUpX: case lcObjectPropertyId::CameraUpY: case lcObjectPropertyId::CameraUpZ: - case lcObjectPropertyId::LightName: break; + case lcObjectPropertyId::LightName: + return GetName(); + case lcObjectPropertyId::LightType: return static_cast(GetLightType()); @@ -1132,9 +1144,11 @@ bool lcLight::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool case lcObjectPropertyId::CameraUpX: case lcObjectPropertyId::CameraUpY: case lcObjectPropertyId::CameraUpZ: - case lcObjectPropertyId::LightName: break; + case lcObjectPropertyId::LightName: + return SetName(Value.toString()); + case lcObjectPropertyId::LightType: return SetLightType(static_cast(Value.toInt())); diff --git a/common/light.h b/common/light.h index 1524adff..6cce77dc 100644 --- a/common/light.h +++ b/common/light.h @@ -304,10 +304,7 @@ public: return mCastShadow; } - void SetName(const QString& Name) - { - mName = Name; - } + bool SetName(const QString& Name); QString GetName() const override { diff --git a/common/object.cpp b/common/object.cpp index 93a26e1c..bb8f7be7 100644 --- a/common/object.cpp +++ b/common/object.cpp @@ -18,9 +18,11 @@ QString lcObject::GetCheckpointString(lcObjectPropertyId PropertyId) case lcObjectPropertyId::PieceColor: case lcObjectPropertyId::PieceStepShow: case lcObjectPropertyId::PieceStepHide: - case lcObjectPropertyId::CameraName: break; + case lcObjectPropertyId::CameraName: + return QT_TRANSLATE_NOOP("Checkpoint", "Renaming Camera"); + case lcObjectPropertyId::CameraType: return QT_TRANSLATE_NOOP("Checkpoint", "Changing Camera Type"); @@ -36,9 +38,11 @@ QString lcObject::GetCheckpointString(lcObjectPropertyId PropertyId) case lcObjectPropertyId::CameraUpX: case lcObjectPropertyId::CameraUpY: case lcObjectPropertyId::CameraUpZ: - case lcObjectPropertyId::LightName: break; + case lcObjectPropertyId::LightName: + return QT_TRANSLATE_NOOP("Checkpoint", "Renaming Light"); + case lcObjectPropertyId::LightType: return QT_TRANSLATE_NOOP("Checkpoint", "Changing Light Type");