PD: Use the helix property docs as tooltip in the task panel

By reusing the property docs as tooltip we avoid maintaining the same
information in two places. The propery descriptions have been made
translatable, too, to ensure a fully translatable UI.
The ground work for this was layed by the work on Issue 0002524, long
time ago: https://tracker.freecadweb.org/view.php?id=0002524
This commit is contained in:
Jonas Bähr
2021-12-05 21:44:56 +01:00
committed by wwmayer
parent 36fe42d869
commit 5266ecf36f
4 changed files with 75 additions and 22 deletions

View File

@@ -80,40 +80,40 @@ Helix::Helix()
const char* group = "Helix";
ADD_PROPERTY_TYPE(Base, (Base::Vector3d(0.0, 0.0, 0.0)), group, App::Prop_ReadOnly,
"The center point of the helix' start; derived from the reference axis.");
QT_TRANSLATE_NOOP("App::Property", "The center point of the helix' start; derived from the reference axis."));
ADD_PROPERTY_TYPE(Axis, (Base::Vector3d(0.0, 1.0, 0.0)), group, App::Prop_ReadOnly,
"The helix' direction; derived from the reference axis.");
QT_TRANSLATE_NOOP("App::Property", "The helix' direction; derived from the reference axis."));
ADD_PROPERTY_TYPE(ReferenceAxis, (0), group, App::Prop_None,
"The reference axis of the helix.");
QT_TRANSLATE_NOOP("App::Property", "The reference axis of the helix."));
ADD_PROPERTY_TYPE(Mode, (long(initialMode)), group, App::Prop_None,
"The helix input mode specifies which properties are set by the user.\n"
"Dependent properties are then calculated.");
QT_TRANSLATE_NOOP("App::Property", "The helix input mode specifies which properties are set by the user.\n"
"Dependent properties are then calculated."));
Mode.setEnums(ModeEnums);
ADD_PROPERTY_TYPE(Pitch, (10.0), group, App::Prop_None,
"The axial distance between two turns.");
QT_TRANSLATE_NOOP("App::Property", "The axial distance between two turns."));
ADD_PROPERTY_TYPE(Height, (30.0), group, App::Prop_None,
"The height of the helix' path, not accounting for the extent of the profile.");
QT_TRANSLATE_NOOP("App::Property", "The height of the helix' path, not accounting for the extent of the profile."));
ADD_PROPERTY_TYPE(Turns, (3.0), group, App::Prop_None,
"The number of turns in the helix.");
QT_TRANSLATE_NOOP("App::Property", "The number of turns in the helix."));
Turns.setConstraints(&floatTurns);
ADD_PROPERTY_TYPE(Angle, (0.0), group, App::Prop_None,
"The angle of the cone that forms a hull around the helix.\n"
"Non-zero values turn the helix into a conical spiral.\n"
"Positive values make the radius grow, nevatige shrink.");
QT_TRANSLATE_NOOP("App::Property", "The angle of the cone that forms a hull around the helix.\n"
"Non-zero values turn the helix into a conical spiral.\n"
"Positive values make the radius grow, nevatige shrink."));
Angle.setConstraints(&floatAngle);
ADD_PROPERTY_TYPE(Growth, (0.0), group, App::Prop_None,
"The growth of the helix' radius per turn.\n"
"Non-zero values turn the helix into a conical spiral.");
QT_TRANSLATE_NOOP("App::Property", "The growth of the helix' radius per turn.\n"
"Non-zero values turn the helix into a conical spiral."));
ADD_PROPERTY_TYPE(LeftHanded, (false), group, App::Prop_None,
"Sets the turning direction to left handed,\n"
"i.e. counter-clockwise when moving along its axis.");
QT_TRANSLATE_NOOP("App::Property", "Sets the turning direction to left handed,\n"
"i.e. counter-clockwise when moving along its axis."));
ADD_PROPERTY_TYPE(Reversed, (false), group, App::Prop_None,
"Determines whether the helix points in the opposite direction of the axis.");
QT_TRANSLATE_NOOP("App::Property", "Determines whether the helix points in the opposite direction of the axis."));
ADD_PROPERTY_TYPE(Outside, (false), group, App::Prop_None,
"If set, the result will be the intersection of the profile and the preexisting body.");
QT_TRANSLATE_NOOP("App::Property", "If set, the result will be the intersection of the profile and the preexisting body."));
ADD_PROPERTY_TYPE(HasBeenEdited, (false), group, App::Prop_Hidden,
"If false, the tool will propose an initial value for the pitch based on the profile bounding box,\n"
"so that self intersection is avoided.");
QT_TRANSLATE_NOOP("App::Property", "If false, the tool will propose an initial value for the pitch based on the profile bounding box,\n"
"so that self intersection is avoided."));
setReadWriteStatusForMode(initialMode);
}

View File

@@ -301,9 +301,13 @@ void TaskHelixParameters::updateStatus()
void TaskHelixParameters::updateUI()
{
fillAxisCombo();
assignToolTipsFromPropertyDocs();
updateStatus();
adaptVisibilityToMode();
}
void TaskHelixParameters::adaptVisibilityToMode()
{
bool isPitchVisible = false;
bool isHeightVisible = false;
bool isTurnsVisible = false;
@@ -358,6 +362,52 @@ void TaskHelixParameters::updateUI()
ui->checkBoxOutside->setVisible(isOutsideVisible);
}
void TaskHelixParameters::assignToolTipsFromPropertyDocs()
{
auto pcHelix = static_cast<PartDesign::Helix*>(vp->getObject());
const char* propCategory = "App::Property"; // cf. https://tracker.freecadweb.org/view.php?id=0002524
QString toolTip;
// Beware that "Axis" in the GUI actually represents the property "ReferenceAxis"!
// The property "Axis" holds only the directional part of the reference axis and has no corresponding GUI element.
toolTip = QApplication::translate(propCategory, pcHelix->ReferenceAxis.getDocumentation());
ui->axis->setToolTip(toolTip);
ui->labelAxis->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Mode.getDocumentation());
ui->inputMode->setToolTip(toolTip);
ui->labelInputMode->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Pitch.getDocumentation());
ui->pitch->setToolTip(toolTip);
ui->labelPitch->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Height.getDocumentation());
ui->height->setToolTip(toolTip);
ui->labelHeight->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Turns.getDocumentation());
ui->turns->setToolTip(toolTip);
ui->labelTurns->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Angle.getDocumentation());
ui->coneAngle->setToolTip(toolTip);
ui->labelConeAngle->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Growth.getDocumentation());
ui->growth->setToolTip(toolTip);
ui->labelGrowth->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->LeftHanded.getDocumentation());
ui->checkBoxLeftHanded->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Reversed.getDocumentation());
ui->checkBoxReversed->setToolTip(toolTip);
toolTip = QApplication::translate(propCategory, pcHelix->Outside.getDocumentation());
ui->checkBoxOutside->setToolTip(toolTip);
}
void TaskHelixParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
@@ -529,6 +579,7 @@ void TaskHelixParameters::changeEvent(QEvent* e)
int axis = ui->axis->currentIndex();
int mode = ui->inputMode->currentIndex();
ui->retranslateUi(proxy);
assignToolTipsFromPropertyDocs();
// Axes added by the user cannot be restored
fillAxisCombo(true);

View File

@@ -69,6 +69,8 @@ private:
void addSketchAxes();
void addPartAxes();
int addCurrentLink();
void assignToolTipsFromPropertyDocs();
void adaptVisibilityToMode();
private Q_SLOTS:
void onPitchChanged(double);

View File

@@ -35,7 +35,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label0">
<widget class="QLabel" name="labelAxis">
<property name="text">
<string>Axis:</string>
</property>
@@ -88,7 +88,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayoutMode">
<item>
<widget class="QLabel" name="label4">
<widget class="QLabel" name="labelInputMode">
<property name="text">
<string>Mode:</string>
</property>