Support editing string properties.

This commit is contained in:
Leonardo Zide
2024-02-19 17:38:04 -08:00
parent 8af44647cf
commit 732dac4c65
9 changed files with 65 additions and 73 deletions
+12 -4
View File
@@ -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<lcCamera*>& 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<int>(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<lcCameraType>(Value.toInt()));
+1 -1
View File
@@ -64,7 +64,7 @@ public:
return mName;
}
void SetName(const QString& Name);
bool SetName(const QString& Name);
void CreateName(const lcArray<lcCamera*>& Cameras);
bool IsSimple() const
+3 -25
View File
@@ -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<lcObject*>& 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
-2
View File
@@ -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();
+25 -32
View File
@@ -583,8 +583,8 @@ void lcPropertiesWidget::AddStepNumberProperty(lcObjectPropertyId PropertyId, co
void lcPropertiesWidget::StringChanged()
{
QLineEdit* Widget = qobject_cast<QLineEdit*>(sender());
lcObjectPropertyId PropertyId = GetEditorWidgetPropertyId(Widget);
QLineEdit* LineEdit = qobject_cast<QLineEdit*>(sender());
lcObjectPropertyId PropertyId = GetEditorWidgetPropertyId(LineEdit);
if (PropertyId == lcObjectPropertyId::Count)
return;
@@ -594,35 +594,32 @@ void lcPropertiesWidget::StringChanged()
if (!Model)
return;
lcCamera* Camera = dynamic_cast<lcCamera*>(mFocusObject);
lcLight* Light = dynamic_cast<lcLight*>(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<lcObject*>{ mFocusObject } : mSelection, PropertyId, Value);
}
void lcPropertiesWidget::UpdateString(lcObjectPropertyId PropertyId, const QString& Text)
void lcPropertiesWidget::UpdateString(lcObjectPropertyId PropertyId)
{
QLineEdit* Widget = qobject_cast<QLineEdit*>(mPropertyWidgets[static_cast<int>(PropertyId)].Editor);
QLineEdit* LineEdit = qobject_cast<QLineEdit*>(mPropertyWidgets[static_cast<int>(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<lcObject*>& 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<lcObject*>& 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<lcObject*>& 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<lcObject*>& Selection, lcObject*
if (Light)
{
Name = Light->GetName();
LightType = Light->GetLightType();
LightAreaShape = Light->GetAreaShape();
@@ -1303,7 +1296,7 @@ void lcPropertiesWidget::SetLight(const lcArray<lcObject*>& Selection, lcObject*
LightAreaShape = lcLightAreaShape::Count;
}
UpdateString(lcObjectPropertyId::LightName, Name);
UpdateString(lcObjectPropertyId::LightName);
UpdateStringList(lcObjectPropertyId::LightType);
UpdateColor(lcObjectPropertyId::LightColor);
+1 -1
View File
@@ -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);
+16 -2
View File
@@ -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<int>(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<int>(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<lcLightType>(Value.toInt()));
+1 -4
View File
@@ -304,10 +304,7 @@ public:
return mCastShadow;
}
void SetName(const QString& Name)
{
mName = Name;
}
bool SetName(const QString& Name);
QString GetName() const override
{
+6 -2
View File
@@ -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");