Base: Drop QString-std::string conversion functions from Tools

Convenience helpers function Tools::toStdString and Tools::fromStdString
were implemented for Qt4 or older to perform utf8 aware conversion as
QString::toStdString/QString::fromStdString were using toAscii/fromAscii
internally (see https://dreamswork.github.io/qt4/classQString.html).

Since Qt5 QString uses toUtf8/fromUTf8, which makes the helper functions
obsolete (see https://doc.qt.io/qt-5/qstring.html#fromStdString).
This commit is contained in:
Ladislav Michl
2024-12-02 12:34:11 +01:00
committed by Chris Hennes
parent 1a13d25811
commit e62b91ada4
54 changed files with 190 additions and 255 deletions

View File

@@ -29,7 +29,6 @@
#include <App/Document.h>
#include <App/Link.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
@@ -149,13 +148,13 @@ void TaskComplexSection::setUiPrimary()
setUiCommon();
if (m_baseView) {
ui->leBaseView->setText(Base::Tools::fromStdString(m_baseView->getNameInDocument()));
ui->leBaseView->setText(QString::fromStdString(m_baseView->getNameInDocument()));
//if there is a baseView, we don't know the sectionNormal yet and have to wait until
//one is picked in the dialog
Base::Vector3d defaultNormal(-1.0, 0.0, 0.0);
m_saveNormal = defaultNormal;
m_saveXDir = Base::Vector3d(0.0, 1.0, 0.0);
ui->leBaseView->setText(Base::Tools::fromStdString(m_baseView->getNameInDocument()));
ui->leBaseView->setText(QString::fromStdString(m_baseView->getNameInDocument()));
m_compass->setDialAngle(0.0);
m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(1.0, 0.0, 0.0));
}
@@ -179,10 +178,10 @@ void TaskComplexSection::setUiEdit()
setWindowTitle(QObject::tr("Edit Complex Section"));
if (m_baseView) {
ui->leBaseView->setText(Base::Tools::fromStdString(m_baseView->getNameInDocument()));
ui->leBaseView->setText(QString::fromStdString(m_baseView->getNameInDocument()));
}
ui->cmbStrategy->setCurrentIndex(m_section->ProjectionStrategy.getValue());
ui->leSymbol->setText(Base::Tools::fromStdString(m_section->SectionSymbol.getValue()));
ui->leSymbol->setText(QString::fromStdString(m_section->SectionSymbol.getValue()));
ui->sbScale->setValue(m_section->Scale.getValue());
ui->cmbScaleType->setCurrentIndex(m_section->getScaleType());
@@ -190,7 +189,7 @@ void TaskComplexSection::setUiEdit()
Base::Vector3d sectionNormalVec = m_section->SectionNormal.getValue();
if (m_baseView) {
ui->leBaseView->setText(Base::Tools::fromStdString(m_baseView->getNameInDocument()));
ui->leBaseView->setText(QString::fromStdString(m_baseView->getNameInDocument()));
Base::Vector3d projectedViewDirection = m_baseView->projectPoint(sectionNormalVec, false);
double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x);
m_compass->setDialAngle(viewAngle * 180.0 / M_PI);
@@ -205,9 +204,9 @@ void TaskComplexSection::setUiEdit()
void TaskComplexSection::setUiCommon()
{
ui->leSectionObjects->setText(sourcesToString());
ui->leProfileObject->setText(Base::Tools::fromStdString(m_profileObject->getNameInDocument())
ui->leProfileObject->setText(QString::fromStdString(m_profileObject->getNameInDocument())
+ QString::fromUtf8(" / ")
+ Base::Tools::fromStdString(m_profileObject->Label.getValue()));
+ QString::fromStdString(m_profileObject->Label.getValue()));
m_compass = new CompassWidget(this);
auto layout = ui->compassLayout;
@@ -383,9 +382,9 @@ void TaskComplexSection::onProfileObjectsUseSelectionClicked()
if (!selection.empty()) {
m_profileObject = selection.front().getObject();
ui->leProfileObject->setText(
Base::Tools::fromStdString(m_profileObject->getNameInDocument())
QString::fromStdString(m_profileObject->getNameInDocument())
+ QString::fromUtf8(" / ")
+ Base::Tools::fromStdString(m_profileObject->Label.getValue()));
+ QString::fromStdString(m_profileObject->Label.getValue()));
}
}
void TaskComplexSection::scaleTypeChanged(int index)
@@ -452,25 +451,25 @@ QString TaskComplexSection::sourcesToString()
QString currentSeparator;
if (m_baseView) {
for (auto& obj : m_baseView->Source.getValues()) {
result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue());
result += currentSeparator + QString::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + QString::fromStdString(obj->Label.getValue());
currentSeparator = separator;
}
currentSeparator = QString();
for (auto& obj : m_baseView->XSource.getValues()) {
result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue());
result += currentSeparator + QString::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + QString::fromStdString(obj->Label.getValue());
}
}
else {
for (auto& obj : m_shapes) {
result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue());
result += currentSeparator + QString::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + QString::fromStdString(obj->Label.getValue());
}
currentSeparator = QString();
for (auto& obj : m_xShapes) {
result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue());
result += currentSeparator + QString::fromStdString(obj->getNameInDocument())
+ QString::fromUtf8(" / ") + QString::fromStdString(obj->Label.getValue());
}
}
return result;
@@ -568,7 +567,7 @@ void TaskComplexSection::createComplexSection()
// we pluck the generated suffix from the object name and append it to "Section" to generate
// unique Labels
QString qTemp = ui->leSymbol->text();
std::string temp = Base::Tools::toStdString(qTemp);
std::string temp = qTemp.toStdString();
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionSymbol = '%s'",
m_sectionName.c_str(), temp.c_str());
@@ -653,7 +652,7 @@ void TaskComplexSection::updateComplexSection()
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Edit Section View"));
if (m_section) {
QString qTemp = ui->leSymbol->text();
std::string temp = Base::Tools::toStdString(qTemp);
std::string temp = qTemp.toStdString();
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionSymbol = '%s'",
m_sectionName.c_str(), temp.c_str());
@@ -704,14 +703,14 @@ std::string TaskComplexSection::makeSectionLabel(QString symbol)
const std::string objectName{QT_TR_NOOP("ComplexSection")};
std::string uniqueSuffix{m_sectionName.substr(objectName.length(), std::string::npos)};
std::string uniqueLabel = "Section" + uniqueSuffix;
std::string temp = Base::Tools::toStdString(symbol);
std::string temp = symbol.toStdString();
return ( uniqueLabel + " " + temp + " - " + temp );
}
void TaskComplexSection::failNoObject(void)
{
QString qsectionName = Base::Tools::fromStdString(m_sectionName);
QString qbaseName = Base::Tools::fromStdString(m_saveBaseName);
QString qsectionName = QString::fromStdString(m_sectionName);
QString qbaseName = QString::fromStdString(m_saveBaseName);
QString msg = tr("Can not continue. Object * %1 or %2 not found.").arg(qsectionName, qbaseName);
QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Operation Failed"), msg);
Gui::Control().closeDialog();