Merge pull request #25479 from Syres916/Fix_DlgPropertyLink_Utf8_DocumentName

[Gui] Fix string encoding for document, object and subobject names in PropertyLink, SelectionSearch, PD Sketch Based Tasks, Part Primitives and Document handling.
This commit is contained in:
Chris Hennes
2025-11-23 23:32:20 -06:00
committed by GitHub
7 changed files with 68 additions and 73 deletions

View File

@@ -745,7 +745,7 @@ void DlgPropertyLink::onSelectionChanged(const Gui::SelectionChanges& msg)
ui->treeWidget->scrollToItem(item);
if (allowSubObject) {
QString element = QString::fromLatin1(msg.Object.getOldElementName().c_str());
QString element = QString::fromUtf8(msg.Object.getOldElementName().c_str());
if (element.size()) {
QStringList list;
QString text = item->text(1);
@@ -868,7 +868,7 @@ QString DlgPropertyLink::linksToPython(const QList<App::SubObjectT>& links)
}
if (links.size() == 1) {
return QString::fromLatin1(links.front().getSubObjectPython(false).c_str());
return QString::fromUtf8(links.front().getSubObjectPython(false).c_str());
}
std::ostringstream ss;
@@ -891,7 +891,7 @@ QString DlgPropertyLink::linksToPython(const QList<App::SubObjectT>& links)
ss << ']';
}
return QString::fromLatin1(ss.str().c_str());
return QString::fromUtf8(ss.str().c_str());
}
void DlgPropertyLink::filterObjects()
@@ -1114,7 +1114,7 @@ QTreeWidgetItem* DlgPropertyLink::createTypeItem(Base::Type type)
item = new QTreeWidgetItem(item);
}
item->setExpanded(true);
item->setText(0, QString::fromLatin1(type.getName()));
item->setText(0, QString::fromUtf8(type.getName()));
if (type == App::DocumentObject::getClassTypeId()) {
item->setFlags(Qt::ItemIsEnabled);
}
@@ -1129,7 +1129,7 @@ bool DlgPropertyLink::filterType(QTreeWidgetItem* item)
auto& pitem = typeItems[proxyType];
if (!pitem) {
pitem = new QTreeWidgetItem(ui->typeTree);
pitem->setText(0, QString::fromLatin1(proxyType));
pitem->setText(0, QString::fromUtf8(proxyType));
pitem->setIcon(0, item->icon(0));
pitem->setData(0, Qt::UserRole, proxyType);
}

View File

@@ -1414,11 +1414,11 @@ static bool checkCanonicalPath(const std::map<App::Document*, bool>& docs)
auto docName = [](App::Document* doc) -> QString {
if (doc->Label.getStrValue() == doc->getName()) {
return QString::fromLatin1(doc->getName());
return QString::fromUtf8(doc->getName());
}
return QStringLiteral("%1 (%2)").arg(
QString::fromUtf8(doc->Label.getValue()),
QString::fromLatin1(doc->getName())
QString::fromUtf8(doc->getName())
);
};
int count = 0;

View File

@@ -413,7 +413,7 @@ public:
res = QString::fromUtf8(quote(doc->Label.getStrValue()).c_str());
}
else {
res = QString::fromLatin1(doc->getName());
res = QString::fromUtf8(doc->getName());
}
if (sep) {
res += QLatin1Char('#');

View File

@@ -162,9 +162,9 @@ void SelectionView::onSelectionChanged(const SelectionChanges& Reason)
const char* objName,
const char* subName,
App::DocumentObject* obj) {
str << docName;
str << QString::fromUtf8(docName);
str << "#";
str << objName;
str << QString::fromUtf8(objName);
if (subName != 0 && subName[0] != 0) {
str << ".";
/* Original code doesn't take account of histories in subelement names and displays
@@ -193,8 +193,8 @@ void SelectionView::onSelectionChanged(const SelectionChanges& Reason)
if (Reason.Type == SelectionChanges::AddSelection) {
// save as user data
QStringList list;
list << QString::fromLatin1(Reason.pDocName);
list << QString::fromLatin1(Reason.pObjectName);
list << QString::fromUtf8(Reason.pDocName);
list << QString::fromUtf8(Reason.pObjectName);
App::Document* doc = App::GetApplication().getDocument(Reason.pDocName);
App::DocumentObject* obj = doc->getObject(Reason.pObjectName);
getSelectionName(str, Reason.pDocName, Reason.pObjectName, Reason.pSubName, obj);
@@ -237,8 +237,8 @@ void SelectionView::onSelectionChanged(const SelectionChanges& Reason)
for (const auto& it : objs) {
// save as user data
QStringList list;
list << QString::fromLatin1(it.DocName);
list << QString::fromLatin1(it.FeatName);
list << QString::fromUtf8(it.DocName);
list << QString::fromUtf8(it.FeatName);
App::Document* doc = App::GetApplication().getDocument(it.DocName);
App::DocumentObject* obj = doc->getObject(it.FeatName);
@@ -298,8 +298,8 @@ void SelectionView::search(const QString& text)
QString selObject;
QTextStream str(&selObject);
QStringList list;
list << QString::fromLatin1(doc->getName());
list << QString::fromLatin1(it->getNameInDocument());
list << QString::fromUtf8(doc->getName());
list << QString::fromUtf8(it->getNameInDocument());
// build name
str << QString::fromUtf8(doc->Label.getValue());
str << "#";
@@ -346,11 +346,11 @@ void SelectionView::select(QListWidgetItem* item)
// Gui::Selection().clearSelection();
Gui::Command::runCommand(Gui::Command::Gui, "Gui.Selection.clearSelection()");
// Gui::Selection().addSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QStringLiteral(
QString cmd = QString::fromUtf8(
R"(Gui.Selection.addSelection(App.getDocument("%1").getObject("%2")))"
)
.arg(elements[0], elements[1]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
}
catch (Base::Exception& e) {
e.reportException();
@@ -369,12 +369,12 @@ void SelectionView::deselect()
}
// Gui::Selection().rmvSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QStringLiteral(
QString cmd = QString::fromUtf8(
R"(Gui.Selection.removeSelection(App.getDocument("%1").getObject("%2")))"
)
.arg(elements[0], elements[1]);
try {
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
}
catch (Base::Exception& e) {
e.reportException();
@@ -386,7 +386,7 @@ void SelectionView::toggleSelect(QListWidgetItem* item)
if (!item) {
return;
}
std::string name = item->text().toLatin1().constData();
std::string name = item->text().toUtf8().constData();
char* docname = &name.at(0);
char* objname = std::strchr(docname, '#');
if (!objname) {
@@ -409,32 +409,28 @@ void SelectionView::toggleSelect(QListWidgetItem* item)
}
QString cmd;
if (Gui::Selection().isSelected(docname, objname, subname)) {
cmd = QStringLiteral(
cmd = QString::fromUtf8(
"Gui.Selection.removeSelection("
"App.getDocument('%1').getObject('%2'),'%3')"
)
.arg(
QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname)
QString::fromUtf8(docname),
QString::fromUtf8(objname),
QString::fromUtf8(subname)
);
}
else {
cmd = QStringLiteral(
cmd = QString::fromUtf8(
"Gui.Selection.addSelection("
"App.getDocument('%1').getObject('%2'),'%3',%4,%5,%6)"
)
.arg(
QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname)
)
.arg(QString::fromUtf8(docname), QString::fromUtf8(objname), QString::fromUtf8(subname))
.arg(x)
.arg(y)
.arg(z);
}
try {
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
}
catch (Base::Exception& e) {
e.reportException();
@@ -446,7 +442,7 @@ void SelectionView::preselect(QListWidgetItem* item)
if (!item) {
return;
}
std::string name = item->text().toLatin1().constData();
std::string name = item->text().toUtf8().constData();
char* docname = &name.at(0);
char* objname = std::strchr(docname, '#');
if (!objname) {
@@ -467,17 +463,14 @@ void SelectionView::preselect(QListWidgetItem* item)
*end = 0;
}
}
QString cmd = QStringLiteral(
"Gui.Selection.setPreselection("
"App.getDocument('%1').getObject('%2'),'%3',tp=2)"
)
.arg(
QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname)
);
QString cmd
= QString::fromUtf8(
"Gui.Selection.setPreselection("
"App.getDocument('%1').getObject('%2'),'%3',tp=2)"
)
.arg(QString::fromUtf8(docname), QString::fromUtf8(objname), QString::fromUtf8(subname));
try {
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
}
catch (Base::Exception& e) {
e.reportException();
@@ -516,10 +509,10 @@ void SelectionView::touch()
if (elements.size() < 2) {
return;
}
QString cmd = QStringLiteral(R"(App.getDocument("%1").getObject("%2").touch())")
QString cmd = QString::fromUtf8(R"(App.getDocument("%1").getObject("%2").touch())")
.arg(elements[0], elements[1]);
try {
Gui::Command::runCommand(Gui::Command::Doc, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toUtf8());
}
catch (Base::Exception& e) {
e.reportException();
@@ -538,22 +531,22 @@ void SelectionView::toPython()
}
try {
QString cmd = QStringLiteral(R"(obj = App.getDocument("%1").getObject("%2"))")
QString cmd = QString::fromUtf8(R"(obj = App.getDocument("%1").getObject("%2"))")
.arg(elements[0], elements[1]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
if (elements.length() > 2) {
App::Document* doc = App::GetApplication().getDocument(elements[0].toLatin1());
App::DocumentObject* obj = doc->getObject(elements[1].toLatin1());
App::Document* doc = App::GetApplication().getDocument(elements[0].toUtf8());
App::DocumentObject* obj = doc->getObject(elements[1].toUtf8());
QString property = getProperty(obj);
cmd = QStringLiteral(R"(shp = App.getDocument("%1").getObject("%2").%3)")
cmd = QString::fromUtf8(R"(shp = App.getDocument("%1").getObject("%2").%3)")
.arg(elements[0], elements[1], property);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
if (supportPart(obj, elements[2])) {
cmd = QStringLiteral(R"(elt = App.getDocument("%1").getObject("%2").%3.%4)")
cmd = QString::fromUtf8(R"(elt = App.getDocument("%1").getObject("%2").%3.%4)")
.arg(elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
}
}
}
@@ -570,16 +563,18 @@ void SelectionView::showPart()
}
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.length() > 2) {
App::Document* doc = App::GetApplication().getDocument(elements[0].toLatin1());
App::DocumentObject* obj = doc->getObject(elements[1].toLatin1());
App::Document* doc = App::GetApplication().getDocument(elements[0].toUtf8());
App::DocumentObject* obj = doc->getObject(elements[1].toUtf8());
QString module = getModule(obj->getTypeId().getName());
QString property = getProperty(obj);
if (!module.isEmpty() && !property.isEmpty() && supportPart(obj, elements[2])) {
try {
Gui::Command::addModule(Gui::Command::Gui, module.toLatin1());
QString cmd = QStringLiteral(R"(%1.show(App.getDocument("%2").getObject("%3").%4.%5))")
Gui::Command::addModule(Gui::Command::Gui, module.toUtf8());
QString cmd = QString::fromUtf8(
R"(%1.show(App.getDocument("%2").getObject("%3").%4.%5))"
)
.arg(module, elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toUtf8());
}
catch (const Base::Exception& e) {
e.reportException();
@@ -623,7 +618,7 @@ QString SelectionView::getProperty(App::DocumentObject* obj) const
const App::PropertyComplexGeoData* data = geo->getPropertyOfGeometry();
const char* name = data ? data->getName() : nullptr;
if (App::Property::isValidName(name)) {
property = QString::fromLatin1(name);
property = QString::fromUtf8(name);
}
}
@@ -639,7 +634,7 @@ bool SelectionView::supportPart(App::DocumentObject* obj, const QString& part) c
const Data::ComplexGeoData* geometry = data->getComplexData();
std::vector<const char*> types = geometry->getElementTypes();
for (auto it : types) {
if (part.startsWith(QString::fromLatin1(it))) {
if (part.startsWith(QString::fromUtf8(it))) {
return true;
}
}

View File

@@ -1357,7 +1357,7 @@ void TreeWidget::onCreateGroup()
"App.getDocument(\"%1\").addObject"
"(\"App::DocumentObjectGroup\",\"Group\").Label=\"%2\""
)
.arg(QString::fromLatin1(doc->getName()), name);
.arg(QString::fromUtf8(doc->getName()), name);
Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());
}
else if (this->contextItem->type() == ObjectType) {
@@ -1369,8 +1369,8 @@ void TreeWidget::onCreateGroup()
".newObject(\"App::DocumentObjectGroup\",\"Group\").Label=\"%3\""
)
.arg(
QString::fromLatin1(doc->getName()),
QString::fromLatin1(obj->getNameInDocument()),
QString::fromUtf8(doc->getName()),
QString::fromUtf8(obj->getNameInDocument()),
name
);
Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());

View File

@@ -72,7 +72,7 @@ QString getAutoGroupCommandStr(QString objectName)
"part"
);
if (activePart) {
QString activeObjectName = QString::fromLatin1(activePart->getNameInDocument());
QString activeObjectName = QString::fromUtf8(activePart->getNameInDocument());
return QStringLiteral(
"App.ActiveDocument.getObject('%1\')."
"addObject(App.ActiveDocument.getObject('%2\'))\n"
@@ -131,7 +131,7 @@ void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Documen
// Execute the Python block
doc->openCommand(descr.toUtf8());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toUtf8());
doc->commitCommand();
Gui::Command::runCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::runCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
@@ -189,7 +189,7 @@ public:
Handle(Geom_TrimmedCurve) trim = arc.Value();
Handle(Geom_Circle) circle = Handle(Geom_Circle)::DownCast(trim->BasisCurve());
QString name = QString::fromLatin1(doc->getUniqueObjectName("Circle").c_str());
QString name = QString::fromUtf8(doc->getUniqueObjectName("Circle").c_str());
return QStringLiteral(
"App.ActiveDocument.addObject(\"Part::Circle\",\"%1\")\n"
"App.ActiveDocument.%1.Radius=%2\n"
@@ -2301,7 +2301,7 @@ void DlgPrimitives::tryCreatePrimitive(const QString& placement)
}
std::shared_ptr<AbstractPrimitive> primitive = getPrimitive(ui->PrimitiveTypeCB->currentIndex());
name = QString::fromLatin1(doc->getUniqueObjectName(primitive->getDefaultName()).c_str());
name = QString::fromUtf8(doc->getUniqueObjectName(primitive->getDefaultName()).c_str());
cmd = primitive->create(name, placement);
// Execute the Python block
@@ -2340,8 +2340,8 @@ void DlgPrimitives::acceptChanges(const QString& placement)
App::Document* doc = featurePtr->getDocument();
QString objectName = QStringLiteral("App.getDocument(\"%1\").%2")
.arg(
QString::fromLatin1(doc->getName()),
QString::fromLatin1(featurePtr->getNameInDocument())
QString::fromUtf8(doc->getName()),
QString::fromUtf8(featurePtr->getNameInDocument())
);
// read values from the properties

View File

@@ -77,11 +77,11 @@ const QString TaskSketchBasedParameters::onAddSelection(
// Remove subname for planes and datum features
if (PartDesign::Feature::isDatum(selObj)) {
subname = "";
refStr = QString::fromLatin1(selObj->getNameInDocument());
refStr = QString::fromUtf8(selObj->getNameInDocument());
}
else if (subname.size() > 4) {
int faceId = std::atoi(&subname[4]);
refStr = QString::fromLatin1(selObj->getNameInDocument()) + QStringLiteral(":")
refStr = QString::fromUtf8(selObj->getNameInDocument()) + QStringLiteral(":")
+ QObject::tr("Face") + QString::number(faceId);
}
@@ -249,8 +249,8 @@ QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QS
return {};
}
return QString::fromLatin1(R"((App.getDocument("%1").%2, ["%3"]))")
.arg(QString::fromLatin1(doc->getName()), o, sub);
return QString::fromUtf8(R"((App.getDocument("%1").%2, ["%3"]))")
.arg(QString::fromUtf8(doc->getName()), o, sub);
}
QString TaskSketchBasedParameters::make2DLabel(