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:
committed by
Chris Hennes
parent
f9d1391588
commit
0ee3c9f8e6
@@ -34,7 +34,6 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Base/Writer.h>
|
||||
|
||||
@@ -1090,7 +1089,6 @@ App::Color Cell::decodeColor(const std::string& color, const App::Color& default
|
||||
// roughly based on Spreadsheet/Gui/SheetModel.cpp
|
||||
std::string Cell::getFormattedQuantity()
|
||||
{
|
||||
std::string result;
|
||||
QString qFormatted;
|
||||
App::CellAddress thisCell = getAddress();
|
||||
Property* prop = owner->sheet()->getPropertyByName(thisCell.toString().c_str());
|
||||
@@ -1111,7 +1109,7 @@ std::string Cell::getFormattedQuantity()
|
||||
if (computedUnit.isEmpty() || computedUnit == du.unit) {
|
||||
QString number =
|
||||
QLocale().toString(rawVal / duScale, 'f', Base::UnitsApi::getDecimals());
|
||||
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
qFormatted = number + QString::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1124,7 +1122,7 @@ std::string Cell::getFormattedQuantity()
|
||||
if (hasDisplayUnit) {
|
||||
QString number =
|
||||
QLocale().toString(rawVal / duScale, 'f', Base::UnitsApi::getDecimals());
|
||||
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
qFormatted = number + QString::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
}
|
||||
else if (prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
|
||||
@@ -1137,9 +1135,8 @@ std::string Cell::getFormattedQuantity()
|
||||
if (hasDisplayUnit) {
|
||||
QString number =
|
||||
QLocale().toString(rawVal / duScale, 'f', Base::UnitsApi::getDecimals());
|
||||
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
qFormatted = number + QString::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
}
|
||||
result = Base::Tools::toStdString(qFormatted);
|
||||
return result;
|
||||
return qFormatted.toStdString();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Stream.h>
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include "Sheet.h"
|
||||
#include "SheetObserver.h"
|
||||
@@ -907,7 +906,7 @@ void Sheet::recomputeCell(CellAddress p)
|
||||
catch (const Base::Exception& e) {
|
||||
QString msg = QString::fromUtf8("ERR: %1").arg(QString::fromUtf8(e.what()));
|
||||
|
||||
setStringProperty(p, Base::Tools::toStdString(msg));
|
||||
setStringProperty(p, msg.toStdString());
|
||||
if (cell) {
|
||||
cell->setException(e.what());
|
||||
}
|
||||
|
||||
@@ -111,9 +111,9 @@ PropertiesDialog::PropertiesDialog(Sheet* _sheet,
|
||||
ui->styleUnderline->setChecked(true);
|
||||
}
|
||||
|
||||
ui->displayUnit->setText(Base::Tools::fromStdString(displayUnit.stringRep));
|
||||
ui->displayUnit->setText(QString::fromStdString(displayUnit.stringRep));
|
||||
|
||||
ui->alias->setText(Base::Tools::fromStdString(alias));
|
||||
ui->alias->setText(QString::fromStdString(alias));
|
||||
|
||||
// Colors
|
||||
connect(ui->foregroundColor,
|
||||
@@ -241,9 +241,9 @@ void PropertiesDialog::aliasChanged(const QString& text)
|
||||
{
|
||||
QPalette palette = ui->alias->palette();
|
||||
|
||||
aliasOk = text.isEmpty() || sheet->isValidAlias(Base::Tools::toStdString(text));
|
||||
aliasOk = text.isEmpty() || sheet->isValidAlias(text.toStdString());
|
||||
|
||||
alias = aliasOk ? Base::Tools::toStdString(text) : "";
|
||||
alias = aliasOk ? text.toStdString() : "";
|
||||
palette.setColor(QPalette::Text, aliasOk ? Qt::black : Qt::red);
|
||||
ui->alias->setPalette(palette);
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(displayUnitOk && aliasOk);
|
||||
|
||||
@@ -57,12 +57,12 @@ SheetModel::SheetModel(Sheet* _sheet, QObject* parent)
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Spreadsheet");
|
||||
aliasBgColor =
|
||||
QColor(Base::Tools::fromStdString(hGrp->GetASCII("AliasedCellBackgroundColor", "#feff9e")));
|
||||
textFgColor = QColor(Base::Tools::fromStdString(hGrp->GetASCII("TextColor", "#000000")));
|
||||
QColor(QString::fromStdString(hGrp->GetASCII("AliasedCellBackgroundColor", "#feff9e")));
|
||||
textFgColor = QColor(QString::fromStdString(hGrp->GetASCII("TextColor", "#000000")));
|
||||
positiveFgColor =
|
||||
QColor(Base::Tools::fromStdString(hGrp->GetASCII("PositiveNumberColor", "#000000")));
|
||||
QColor(QString::fromStdString(hGrp->GetASCII("PositiveNumberColor", "#000000")));
|
||||
negativeFgColor =
|
||||
QColor(Base::Tools::fromStdString(hGrp->GetASCII("NegativeNumberColor", "#000000")));
|
||||
QColor(QString::fromStdString(hGrp->GetASCII("NegativeNumberColor", "#000000")));
|
||||
}
|
||||
|
||||
SheetModel::~SheetModel()
|
||||
@@ -145,7 +145,7 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
|
||||
if (!cell->hasException() && role == Qt::ToolTipRole) {
|
||||
std::string alias;
|
||||
if (cell->getAlias(alias)) {
|
||||
return QVariant(Base::Tools::fromStdString(alias));
|
||||
return QVariant(QString::fromStdString(alias));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -153,7 +153,7 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
|
||||
if (cell->hasException()) {
|
||||
switch (role) {
|
||||
case Qt::ToolTipRole: {
|
||||
QString txt(Base::Tools::fromStdString(cell->getException()).toHtmlEscaped());
|
||||
QString txt(QString::fromStdString(cell->getException()).toHtmlEscaped());
|
||||
return QVariant(QString::fromLatin1("<pre>%1</pre>").arg(txt));
|
||||
}
|
||||
case Qt::DisplayRole: {
|
||||
@@ -367,7 +367,7 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
|
||||
Base::UnitsApi::getDecimals());
|
||||
// QString number = QString::number(floatProp->getValue() /
|
||||
// displayUnit.scaler);
|
||||
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
v = number + QString::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
else {
|
||||
v = QString::fromUtf8("#ERR: unit");
|
||||
@@ -439,7 +439,7 @@ QVariant SheetModel::data(const QModelIndex& index, int role) const
|
||||
'f',
|
||||
Base::UnitsApi::getDecimals());
|
||||
// QString number = QString::number(d / displayUnit.scaler);
|
||||
v = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
v = number + QString::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
else if (!isInteger) {
|
||||
v = QLocale::system().toString(d, 'f', Base::UnitsApi::getDecimals());
|
||||
|
||||
@@ -432,7 +432,7 @@ void SheetView::confirmAliasChanged(const QString& text)
|
||||
bool aliasOkay = true;
|
||||
|
||||
ui->cellAlias->setDocumentObject(sheet);
|
||||
if (text.length() != 0 && !sheet->isValidAlias(Base::Tools::toStdString(text))) {
|
||||
if (text.length() != 0 && !sheet->isValidAlias(text.toStdString())) {
|
||||
aliasOkay = false;
|
||||
}
|
||||
|
||||
@@ -444,8 +444,7 @@ void SheetView::confirmAliasChanged(const QString& text)
|
||||
std::string current_alias;
|
||||
(void)cell->getAlias(current_alias);
|
||||
if (text != QString::fromUtf8(current_alias.c_str())) {
|
||||
Base::Console().Error("Unable to set alias: %s\n",
|
||||
Base::Tools::toStdString(text).c_str());
|
||||
Base::Console().Error("Unable to set alias: %s\n", text.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -479,7 +478,7 @@ void SheetView::aliasChanged(const QString& text)
|
||||
warningColor = QLatin1String("rgb(200,0,0)"); // Dark red for light mode
|
||||
}
|
||||
|
||||
if (!text.isEmpty() && !sheet->isValidAlias(Base::Tools::toStdString(text))) {
|
||||
if (!text.isEmpty() && !sheet->isValidAlias(text.toStdString())) {
|
||||
aliasOk = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user