Gui: fix clang-tidy warnings in EditableDatumLabel
and fix two further memory leaks
This commit is contained in:
@@ -44,7 +44,10 @@ struct NodeData {
|
||||
EditableDatumLabel* label;
|
||||
};
|
||||
|
||||
EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view, Base::Placement plc, SbColor color, bool autoDistance)
|
||||
EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view,
|
||||
const Base::Placement& plc,
|
||||
SbColor color,
|
||||
bool autoDistance)
|
||||
: isSet(false)
|
||||
, autoDistance(autoDistance)
|
||||
, autoDistanceReverse(false)
|
||||
@@ -52,6 +55,7 @@ EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view, Base::Placeme
|
||||
, spinBox(nullptr)
|
||||
, cameraSensor(nullptr)
|
||||
{
|
||||
// NOLINTBEGIN
|
||||
root = new SoAnnotation;
|
||||
root->ref();
|
||||
root->renderCaching = SoSeparator::OFF;
|
||||
@@ -70,11 +74,13 @@ EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view, Base::Placeme
|
||||
label->datumtype = SoDatumLabel::DISTANCE;
|
||||
label->param1 = 0.;
|
||||
label->param2 = 0.;
|
||||
if (autoDistance)
|
||||
if (autoDistance) {
|
||||
setLabelRecommendedDistance();
|
||||
}
|
||||
root->addChild(label);
|
||||
|
||||
setPlacement(plc);
|
||||
// NOLINTEND
|
||||
}
|
||||
|
||||
EditableDatumLabel::~EditableDatumLabel()
|
||||
@@ -87,18 +93,21 @@ EditableDatumLabel::~EditableDatumLabel()
|
||||
|
||||
void EditableDatumLabel::activate()
|
||||
{
|
||||
if (viewer) {
|
||||
static_cast<SoSeparator*>(viewer->getSceneGraph())->addChild(root);
|
||||
if (!viewer) {
|
||||
return;
|
||||
}
|
||||
|
||||
static_cast<SoSeparator*>(viewer->getSceneGraph())->addChild(root); // NOLINT
|
||||
|
||||
//track camera movements to update spinbox position.
|
||||
NodeData* info = new NodeData{ this };
|
||||
auto info = new NodeData{ this };
|
||||
cameraSensor = new SoNodeSensor([](void* data, SoSensor* sensor) {
|
||||
Q_UNUSED(sensor);
|
||||
NodeData* info = static_cast<NodeData*>(data);
|
||||
auto info = static_cast<NodeData*>(data);
|
||||
info->label->positionSpinbox();
|
||||
if (info->label->autoDistance)
|
||||
if (info->label->autoDistance) {
|
||||
info->label->setLabelRecommendedDistance();
|
||||
}
|
||||
}, info);
|
||||
cameraSensor->attach(viewer->getCamera());
|
||||
}
|
||||
@@ -107,11 +116,16 @@ void EditableDatumLabel::deactivate()
|
||||
{
|
||||
stopEdit();
|
||||
|
||||
if (cameraSensor)
|
||||
if (cameraSensor) {
|
||||
auto data = static_cast<NodeData*>(cameraSensor->getData());
|
||||
delete data;
|
||||
cameraSensor->detach();
|
||||
delete cameraSensor;
|
||||
cameraSensor = nullptr;
|
||||
}
|
||||
|
||||
if (viewer) {
|
||||
static_cast<SoSeparator*>(viewer->getSceneGraph())->removeChild(root);
|
||||
static_cast<SoSeparator*>(viewer->getSceneGraph())->removeChild(root); // NOLINT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,19 +141,20 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj)
|
||||
spinBox->setMaximum(INT_MAX);
|
||||
spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
|
||||
spinBox->setKeyboardTracking(false);
|
||||
if(eventFilteringObj)
|
||||
if (eventFilteringObj) {
|
||||
spinBox->installEventFilter(eventFilteringObj);
|
||||
}
|
||||
|
||||
spinBox->show();
|
||||
setSpinboxValue(val);
|
||||
//Note: adjustSize apparantly uses the Min/Max values to set the size. So if we don't set them to INT_MAX, the spinbox are much to big.
|
||||
//Note: adjustSize apparently uses the Min/Max values to set the size. So if we don't set them to INT_MAX, the spinbox are much too big.
|
||||
spinBox->adjustSize();
|
||||
setFocusToSpinbox();
|
||||
|
||||
connect(spinBox, qOverload<double>(&QuantitySpinBox::valueChanged),
|
||||
this, [this](double value) {
|
||||
this->isSet = true;
|
||||
this->valueChanged(value);
|
||||
Q_EMIT this->valueChanged(value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -171,6 +186,7 @@ void EditableDatumLabel::setSpinboxValue(double val)
|
||||
spinBox->selectNumber();
|
||||
}
|
||||
}
|
||||
|
||||
void EditableDatumLabel::setFocusToSpinbox()
|
||||
{
|
||||
if (!spinBox) {
|
||||
@@ -195,7 +211,7 @@ void EditableDatumLabel::positionSpinbox()
|
||||
spinBox->move(pxCoord);
|
||||
}
|
||||
|
||||
const SbVec3f EditableDatumLabel::getTextCenterPoint()
|
||||
SbVec3f EditableDatumLabel::getTextCenterPoint() const
|
||||
{
|
||||
//Here we need the 3d point and not the 2d point as are the SoLabel points.
|
||||
// First we get the 2D point (on the sketch/image plane) of the middle of the text label.
|
||||
@@ -210,7 +226,8 @@ const SbVec3f EditableDatumLabel::getTextCenterPoint()
|
||||
|
||||
// Transform the 2D coordinates to 3D
|
||||
// Plane form
|
||||
SbVec3f RX(1, 0, 0), RY(0, 1, 0);
|
||||
SbVec3f RX(1, 0, 0);
|
||||
SbVec3f RY(0, 1, 0);
|
||||
|
||||
// move to position of Sketch
|
||||
invRotation.multVec(RX, RX);
|
||||
@@ -225,23 +242,24 @@ const SbVec3f EditableDatumLabel::getTextCenterPoint()
|
||||
Base::Vector3d P2D(point2D[0], point2D[1], point2D[2]);
|
||||
P2D.TransformToCoordinateSystem(pos, RXb, RYb);
|
||||
|
||||
return SbVec3f(P2D.x, P2D.y, P2D.z);
|
||||
return {float(P2D.x), float(P2D.y), float(P2D.z)};
|
||||
}
|
||||
|
||||
void EditableDatumLabel::setPlacement(Base::Placement plc)
|
||||
void EditableDatumLabel::setPlacement(const Base::Placement& plc)
|
||||
{
|
||||
double x, y, z, w;
|
||||
double x{}, y{}, z{}, w{}; // NOLINT
|
||||
plc.getRotation().getValue(x, y, z, w);
|
||||
//Base::Console().Warning("x%f, y%f, z%f, w%f\n", x, y, z, w);
|
||||
transform->rotation.setValue(x, y, z, w);
|
||||
transform->rotation.setValue(x, y, z, w); // NOLINT
|
||||
|
||||
Base::Vector3d pos = plc.getPosition();
|
||||
transform->translation.setValue(pos.x, pos.y, pos.z);
|
||||
transform->translation.setValue(float(pos.x), float(pos.y), float(pos.z));
|
||||
|
||||
Base::Vector3d RN(0, 0, 1);
|
||||
RN = plc.getRotation().multVec(RN);
|
||||
label->norm.setValue(SbVec3f(RN.x, RN.y, RN.z));
|
||||
label->norm.setValue(SbVec3f(float(RN.x), float(RN.y), float(RN.z)));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
void EditableDatumLabel::setColor(SbColor color)
|
||||
{
|
||||
label->textColor = color;
|
||||
@@ -261,23 +279,27 @@ void EditableDatumLabel::setPoints(SbVec3f p1, SbVec3f p2)
|
||||
// is not updated yet. it will be only on redraw so it is actually positioning on previous position.
|
||||
|
||||
positionSpinbox();
|
||||
if (autoDistance)
|
||||
if (autoDistance) {
|
||||
setLabelRecommendedDistance();
|
||||
}
|
||||
}
|
||||
|
||||
void EditableDatumLabel::setPoints(Base::Vector3d p1, Base::Vector3d p2)
|
||||
{
|
||||
setPoints(SbVec3f(p1.x, p1.y, p1.z), SbVec3f(p2.x, p2.y, p2.z));
|
||||
setPoints(SbVec3f(float(p1.x), float(p1.y), float(p1.z)),
|
||||
SbVec3f(float(p2.x), float(p2.y), float(p2.z)));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
void EditableDatumLabel::setLabelType(SoDatumLabel::Type type)
|
||||
{
|
||||
label->datumtype = type;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
void EditableDatumLabel::setLabelDistance(double distance)
|
||||
{
|
||||
label->param1 = distance;
|
||||
label->param1 = float(distance);
|
||||
}
|
||||
|
||||
void EditableDatumLabel::setLabelRecommendedDistance()
|
||||
@@ -287,10 +309,11 @@ void EditableDatumLabel::setLabelRecommendedDistance()
|
||||
float length = -1.;
|
||||
viewer->getDimensions(width, length);
|
||||
|
||||
if (width == -1. || length == -1.)
|
||||
if (width == -1. || length == -1.) {
|
||||
return;
|
||||
}
|
||||
|
||||
label->param1 = (autoDistanceReverse ? -1 : 1) * (width + length) * 0.03;
|
||||
label->param1 = (autoDistanceReverse ? -1.0F : 1.0F) * (width + length) * 0.03F; // NOLINT
|
||||
}
|
||||
|
||||
void EditableDatumLabel::setLabelAutoDistanceReverse(bool val)
|
||||
|
||||
@@ -42,9 +42,11 @@ class View3DInventorViewer;
|
||||
class GuiExport EditableDatumLabel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(EditableDatumLabel)
|
||||
|
||||
public:
|
||||
EditableDatumLabel(View3DInventorViewer* view, Base::Placement plc, SbColor color, bool autoDistance = false);
|
||||
~EditableDatumLabel();
|
||||
EditableDatumLabel(View3DInventorViewer* view, const Base::Placement& plc, SbColor color, bool autoDistance = false);
|
||||
~EditableDatumLabel() override;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
@@ -53,7 +55,7 @@ public:
|
||||
void stopEdit();
|
||||
double getValue();
|
||||
void setSpinboxValue(double val);
|
||||
void setPlacement(Base::Placement plc);
|
||||
void setPlacement(const Base::Placement& plc);
|
||||
void setColor(SbColor color);
|
||||
void setFocus();
|
||||
void setPoints(SbVec3f p1, SbVec3f p2);
|
||||
@@ -64,17 +66,19 @@ public:
|
||||
void setLabelRecommendedDistance();
|
||||
void setLabelAutoDistanceReverse(bool val);
|
||||
|
||||
// NOLINTBEGIN
|
||||
SoDatumLabel* label;
|
||||
bool isSet;
|
||||
bool autoDistance;
|
||||
bool autoDistanceReverse;
|
||||
// NOLINTEND
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(double val);
|
||||
|
||||
private:
|
||||
void positionSpinbox();
|
||||
const SbVec3f getTextCenterPoint();
|
||||
SbVec3f getTextCenterPoint() const;
|
||||
|
||||
private:
|
||||
SoSeparator* root;
|
||||
|
||||
Reference in New Issue
Block a user