New option: Translate formula.
This commit is contained in:
parent
3dddfb39cc
commit
e7f1b09e83
|
@ -41,6 +41,7 @@
|
||||||
- New option: Use Tool Groups.
|
- New option: Use Tool Groups.
|
||||||
- Redesign notch context menu to allow quick selection of the notch type.
|
- Redesign notch context menu to allow quick selection of the notch type.
|
||||||
- Redesign standard path system.
|
- Redesign standard path system.
|
||||||
|
- New option: Translate formula
|
||||||
|
|
||||||
# Valentina 0.7.52 September 12, 2022
|
# Valentina 0.7.52 September 12, 2022
|
||||||
- Fix crash when default locale is ru.
|
- Fix crash when default locale is ru.
|
||||||
|
|
|
@ -97,6 +97,8 @@ TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *pare
|
||||||
connect(ui->resetWarningsButton, &QPushButton::released, this,
|
connect(ui->resetWarningsButton, &QPushButton::released, this,
|
||||||
[]() { MApplication::VApp()->TapeSettings()->SetConfirmFormatRewriting(true); });
|
[]() { MApplication::VApp()->TapeSettings()->SetConfirmFormatRewriting(true); });
|
||||||
|
|
||||||
|
ui->checkBoxTranslateFormula->setChecked(settings->IsTranslateFormula());
|
||||||
|
|
||||||
//----------------------- Toolbar
|
//----------------------- Toolbar
|
||||||
ui->toolBarStyleCheck->setChecked(settings->GetToolBarStyle());
|
ui->toolBarStyleCheck->setChecked(settings->GetToolBarStyle());
|
||||||
|
|
||||||
|
@ -148,6 +150,8 @@ auto TapePreferencesConfigurationPage::Apply() -> QStringList
|
||||||
QGuiApplication::restoreOverrideCursor();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings->SetTranslateFormula(ui->checkBoxTranslateFormula->isChecked());
|
||||||
|
|
||||||
if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked())
|
if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked())
|
||||||
{
|
{
|
||||||
settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked());
|
settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked());
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>522</width>
|
<width>508</width>
|
||||||
<height>617</height>
|
<height>646</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
@ -140,6 +140,16 @@
|
||||||
<string>Measurements editing</string>
|
<string>Measurements editing</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBoxTranslateFormula">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Enable to translate formula according to locale</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Translate formula</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="resetWarningsButton">
|
<widget class="QPushButton" name="resetWarningsButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
|
@ -130,6 +130,7 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
|
||||||
ui->checkBoxFreeCurve->setChecked(settings->IsFreeCurveMode());
|
ui->checkBoxFreeCurve->setChecked(settings->IsFreeCurveMode());
|
||||||
ui->checkBoxZoomFitBestCurrentPP->setChecked(settings->IsDoubleClickZoomFitBestCurrentPP());
|
ui->checkBoxZoomFitBestCurrentPP->setChecked(settings->IsDoubleClickZoomFitBestCurrentPP());
|
||||||
ui->checkBoxInteractiveTools->setChecked(settings->IsInteractiveTools());
|
ui->checkBoxInteractiveTools->setChecked(settings->IsInteractiveTools());
|
||||||
|
ui->checkBoxTranslateFormula->setChecked(settings->IsTranslateFormula());
|
||||||
|
|
||||||
//----------------------- Toolbar
|
//----------------------- Toolbar
|
||||||
ui->toolBarStyleCheck->setChecked(settings->GetToolBarStyle());
|
ui->toolBarStyleCheck->setChecked(settings->GetToolBarStyle());
|
||||||
|
@ -250,6 +251,7 @@ auto PreferencesConfigurationPage::Apply() -> QStringList
|
||||||
settings->SetFreeCurveMode(ui->checkBoxFreeCurve->isChecked());
|
settings->SetFreeCurveMode(ui->checkBoxFreeCurve->isChecked());
|
||||||
settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked());
|
settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked());
|
||||||
settings->SetInteractiveTools(ui->checkBoxInteractiveTools->isChecked());
|
settings->SetInteractiveTools(ui->checkBoxInteractiveTools->isChecked());
|
||||||
|
settings->SetTranslateFormula(ui->checkBoxTranslateFormula->isChecked());
|
||||||
|
|
||||||
if (m_pieceLabelLangChanged)
|
if (m_pieceLabelLangChanged)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,9 +33,9 @@
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>-134</y>
|
<y>-163</y>
|
||||||
<width>624</width>
|
<width>624</width>
|
||||||
<height>966</height>
|
<height>995</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
@ -265,6 +265,19 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBoxTranslateFormula">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Enable to translate formula according to locale</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Translate formula</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -177,6 +177,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternShowAccuracyRadius,
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender, (QLatin1String("pattern/useOpenGLRender")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUseOpenGLRender, (QLatin1String("pattern/useOpenGLRender")))
|
||||||
// NOLINTNEXTLINE
|
// NOLINTNEXTLINE
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput, (QLatin1String("pattern/graphicalOutput")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternGraphicalOutput, (QLatin1String("pattern/graphicalOutput")))
|
||||||
|
// NOLINTNEXTLINE
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingsPatternTranslateFormula, (QLatin1String("pattern/translateFormula")))
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRecentFileList, (QLatin1String("recentFileList"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRecentFileList, (QLatin1String("recentFileList"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRestoreFileList, (QLatin1String("restoreFileList"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralRestoreFileList, (QLatin1String("restoreFileList"))) // NOLINT
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralGeometry, (QLatin1String("geometry"))) // NOLINT
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingGeneralGeometry, (QLatin1String("geometry"))) // NOLINT
|
||||||
|
@ -1631,3 +1633,18 @@ void VCommonSettings::SetClientID(const QString &clientID)
|
||||||
settings.setValue(*settingsStatistictClientID, clientID);
|
settings.setValue(*settingsStatistictClientID, clientID);
|
||||||
settings.sync();
|
settings.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VCommonSettings::IsTranslateFormula() const -> bool
|
||||||
|
{
|
||||||
|
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
|
||||||
|
return settings.value(*settingsPatternTranslateFormula, 1).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VCommonSettings::SetTranslateFormula(bool value)
|
||||||
|
{
|
||||||
|
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
|
||||||
|
settings.setValue(*settingsPatternTranslateFormula, value);
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
|
@ -329,6 +329,9 @@ public:
|
||||||
auto GetClientID() const -> QString;
|
auto GetClientID() const -> QString;
|
||||||
void SetClientID(const QString &clientID);
|
void SetClientID(const QString &clientID);
|
||||||
|
|
||||||
|
auto IsTranslateFormula() const -> bool;
|
||||||
|
void SetTranslateFormula(bool value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SVGFontsPathChanged(const QString &oldPath, const QString &newPath);
|
void SVGFontsPathChanged(const QString &oldPath, const QString &newPath);
|
||||||
|
|
||||||
|
|
|
@ -968,6 +968,12 @@ auto VTranslateVars::VariablesToUser(QString &newFormula, vsizetype position, co
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VTranslateVars::InternalVarToUser(const QString &var) const -> QString
|
auto VTranslateVars::InternalVarToUser(const QString &var) const -> QString
|
||||||
{
|
{
|
||||||
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||||
|
if (!settings->IsTranslateFormula())
|
||||||
|
{
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
QString newVar = var;
|
QString newVar = var;
|
||||||
vsizetype bias = 0;
|
vsizetype bias = 0;
|
||||||
if (VariablesToUser(newVar, 0, var, bias))
|
if (VariablesToUser(newVar, 0, var, bias))
|
||||||
|
@ -987,6 +993,12 @@ auto VTranslateVars::VarToUser(const QString &var) const -> QString
|
||||||
return var; // We do not support translation of variables for these locales
|
return var; // We do not support translation of variables for these locales
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||||
|
if (!settings->IsTranslateFormula())
|
||||||
|
{
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
if (measurements.contains(var))
|
if (measurements.contains(var))
|
||||||
{
|
{
|
||||||
return measurements.value(var).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
return measurements.value(var).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
||||||
|
@ -1009,6 +1021,12 @@ auto VTranslateVars::VarFromUser(const QString &var) const -> QString
|
||||||
return var; // We do not support translation of variables for Chinese
|
return var; // We do not support translation of variables for Chinese
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||||
|
if (!settings->IsTranslateFormula())
|
||||||
|
{
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
QString newVar = var;
|
QString newVar = var;
|
||||||
vsizetype bias = 0;
|
vsizetype bias = 0;
|
||||||
if (MeasurementsFromUser(newVar, 0, var, bias))
|
if (MeasurementsFromUser(newVar, 0, var, bias))
|
||||||
|
@ -1061,6 +1079,12 @@ auto VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator) c
|
||||||
return formula;
|
return formula;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||||
|
if (!settings->IsTranslateFormula())
|
||||||
|
{
|
||||||
|
return formula;
|
||||||
|
}
|
||||||
|
|
||||||
// Eval formula
|
// Eval formula
|
||||||
QScopedPointer<qmu::QmuTokenParser> cal(
|
QScopedPointer<qmu::QmuTokenParser> cal(
|
||||||
new qmu::QmuTokenParser(formula, osSeparator, true, GetTranslatedFunctions()));
|
new qmu::QmuTokenParser(formula, osSeparator, true, GetTranslatedFunctions()));
|
||||||
|
@ -1105,6 +1129,12 @@ auto VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) con
|
||||||
return formula;
|
return formula;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||||
|
if (!settings->IsTranslateFormula())
|
||||||
|
{
|
||||||
|
return formula;
|
||||||
|
}
|
||||||
|
|
||||||
QString newFormula = formula; // Local copy for making changes
|
QString newFormula = formula; // Local copy for making changes
|
||||||
|
|
||||||
QMap<vsizetype, QString> tokens;
|
QMap<vsizetype, QString> tokens;
|
||||||
|
|
|
@ -40,12 +40,6 @@ public:
|
||||||
explicit VTranslateVars();
|
explicit VTranslateVars();
|
||||||
~VTranslateVars() override = default;
|
~VTranslateVars() override = default;
|
||||||
|
|
||||||
auto VariablesFromUser(QString &newFormula, vsizetype position, const QString &token, vsizetype &bias) const
|
|
||||||
-> bool;
|
|
||||||
auto FunctionsFromUser(QString &newFormula, vsizetype position, const QString &token, vsizetype &bias) const
|
|
||||||
-> bool;
|
|
||||||
auto VariablesToUser(QString &newFormula, vsizetype position, const QString &token, vsizetype &bias) const -> bool;
|
|
||||||
|
|
||||||
auto InternalVarToUser(const QString &var) const -> QString;
|
auto InternalVarToUser(const QString &var) const -> QString;
|
||||||
|
|
||||||
auto VarToUser(const QString &var) const -> QString;
|
auto VarToUser(const QString &var) const -> QString;
|
||||||
|
@ -87,6 +81,12 @@ private:
|
||||||
void InitVariables();
|
void InitVariables();
|
||||||
void InitFunctions();
|
void InitFunctions();
|
||||||
|
|
||||||
|
auto VariablesFromUser(QString &newFormula, vsizetype position, const QString &token, vsizetype &bias) const
|
||||||
|
-> bool;
|
||||||
|
auto FunctionsFromUser(QString &newFormula, vsizetype position, const QString &token, vsizetype &bias) const
|
||||||
|
-> bool;
|
||||||
|
auto VariablesToUser(QString &newFormula, vsizetype position, const QString &token, vsizetype &bias) const -> bool;
|
||||||
|
|
||||||
void PrepareFunctionTranslations();
|
void PrepareFunctionTranslations();
|
||||||
|
|
||||||
void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author,
|
void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author,
|
||||||
|
|
|
@ -727,6 +727,7 @@ void DialogEditWrongFormula::ShowFunctions()
|
||||||
ui->tableWidget->setColumnHidden(ColumnFullName, true);
|
ui->tableWidget->setColumnHidden(ColumnFullName, true);
|
||||||
ui->labelDescription->setText(QString());
|
ui->labelDescription->setText(QString());
|
||||||
|
|
||||||
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||||
const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars();
|
const VTranslateVars *trVars = VAbstractApplication::VApp()->TrVars();
|
||||||
const QMap<QString, qmu::QmuTranslation> functionsDescriptions = trVars->GetFunctionsDescriptions();
|
const QMap<QString, qmu::QmuTranslation> functionsDescriptions = trVars->GetFunctionsDescriptions();
|
||||||
const QMap<QString, qmu::QmuTranslation> functions = trVars->GetFunctions();
|
const QMap<QString, qmu::QmuTranslation> functions = trVars->GetFunctions();
|
||||||
|
@ -734,16 +735,30 @@ void DialogEditWrongFormula::ShowFunctions()
|
||||||
while (i != functions.constEnd())
|
while (i != functions.constEnd())
|
||||||
{
|
{
|
||||||
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
|
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
|
||||||
auto *item = new QTableWidgetItem(i.value().translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
|
||||||
|
QString name = (!settings->IsTranslateFormula()
|
||||||
|
? i.value().getMsourceText()
|
||||||
|
: i.value().translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
||||||
|
|
||||||
|
auto *item = new QTableWidgetItem(name);
|
||||||
item->setData(Qt::UserRole, i.key());
|
item->setData(Qt::UserRole, i.key());
|
||||||
QFont font = item->font();
|
QFont font = item->font();
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
item->setFont(font);
|
item->setFont(font);
|
||||||
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnName, item);
|
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, ColumnName, item);
|
||||||
|
|
||||||
functionsDescriptions.contains(i.key()) ? item->setToolTip(functionsDescriptions.value(i.key()).translate(
|
if (functionsDescriptions.contains(i.key()))
|
||||||
VAbstractApplication::VApp()->Settings()->GetLocale()))
|
{
|
||||||
: item->setToolTip(i.value().getMdisambiguation());
|
QString description =
|
||||||
|
(!settings->IsTranslateFormula() ? functionsDescriptions.value(i.key()).getMsourceText()
|
||||||
|
: functionsDescriptions.value(i.key()).translate(
|
||||||
|
VAbstractApplication::VApp()->Settings()->GetLocale()));
|
||||||
|
item->setToolTip(description);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item->setToolTip(i.value().getMdisambiguation());
|
||||||
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,7 +815,8 @@ void DialogEditWrongFormula::FilterVariablesEdited(const QString &filter)
|
||||||
const QList<QTableWidgetItem *> items = ui->tableWidget->findItems(filter, Qt::MatchContains);
|
const QList<QTableWidgetItem *> items = ui->tableWidget->findItems(filter, Qt::MatchContains);
|
||||||
for (auto *item : items)
|
for (auto *item : items)
|
||||||
{
|
{
|
||||||
// If filter is empty findItems() for unknown reason returns nullptr items.
|
// If filter is empty findItems() for unknown reason returns nullptr
|
||||||
|
// items.
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
ui->tableWidget->showRow(item->row());
|
ui->tableWidget->showRow(item->row());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user