From a1b70c294ceea0580a10c79ca1caf949b2a0bd0f Mon Sep 17 00:00:00 2001 From: Paddle Date: Fri, 31 Mar 2023 22:23:44 +0200 Subject: [PATCH] Pref: Remove Unit tab and move settings back to main page. --- src/Gui/CMakeLists.txt | 4 - src/Gui/DlgGeneral.ui | 95 +++++++++++++++- src/Gui/DlgGeneralImp.cpp | 93 ++++++++++++++++ src/Gui/DlgGeneralImp.h | 3 + src/Gui/DlgSettingsUnits.ui | 162 --------------------------- src/Gui/DlgSettingsUnitsImp.cpp | 175 ------------------------------ src/Gui/DlgSettingsUnitsImp.h | 62 ----------- src/Gui/DlgUnitsCalculatorImp.cpp | 2 +- src/Gui/MainWindow.cpp | 2 +- src/Gui/resource.cpp | 2 - 10 files changed, 189 insertions(+), 411 deletions(-) delete mode 100644 src/Gui/DlgSettingsUnits.ui delete mode 100644 src/Gui/DlgSettingsUnitsImp.cpp delete mode 100644 src/Gui/DlgSettingsUnitsImp.h diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 76117d2ea5..5edf33f0fe 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -320,7 +320,6 @@ SET(Gui_UIC_SRCS DlgSettingsCacheDirectory.ui DlgSettingsNavigation.ui DlgSettingsSelection.ui - DlgSettingsUnits.ui DlgSettingsViewColor.ui DlgSettingsColorGradient.ui DlgSettingsDocument.ui @@ -562,7 +561,6 @@ SET(Dialog_Settings_CPP_SRCS DlgSettingsCacheDirectory.cpp DlgSettingsNavigation.cpp DlgSettingsSelection.cpp - DlgSettingsUnitsImp.cpp DlgSettingsViewColor.cpp DlgSettingsColorGradientImp.cpp DlgSettingsDocumentImp.cpp @@ -582,7 +580,6 @@ SET(Dialog_Settings_HPP_SRCS DlgSettingsCacheDirectory.h DlgSettingsNavigation.h DlgSettingsSelection.h - DlgSettingsUnitsImp.h DlgSettingsViewColor.h DlgSettingsColorGradientImp.h DlgSettingsDocumentImp.h @@ -604,7 +601,6 @@ SET(Dialog_Settings_SRCS DlgSettingsCacheDirectory.ui DlgSettingsNavigation.ui DlgSettingsSelection.ui - DlgSettingsUnits.ui DlgSettingsViewColor.ui DlgSettingsColorGradient.ui DlgSettingsDocument.ui diff --git a/src/Gui/DlgGeneral.ui b/src/Gui/DlgGeneral.ui index b54c5e08dd..13205c3e06 100644 --- a/src/Gui/DlgGeneral.ui +++ b/src/Gui/DlgGeneral.ui @@ -38,7 +38,7 @@ - Language + Language and number format @@ -59,7 +59,7 @@ - Change language: + Language: @@ -71,13 +71,100 @@ + + + Unit system: + + + + + + + Unit system that should be used for all parts the application + + + + + + + + + Number of decimals: + + + + + + + Number of decimals that should be shown for numbers and dimensions + + + 1 + + + 12 + + + + + + + + + Minimum fractional inch: + + + + + + + Minimum fractional inch to be displayed + + + + 1/2" + + + + + 1/4" + + + + + 1/8" + + + + + 1/16" + + + + + 1/32" + + + + + 1/64" + + + + + 1/128" + + + + + Number format: - + UseLocaleFormatting @@ -102,7 +189,7 @@ - + If enabled, numerical keypad decimal separator diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index bc5edc477e..457e444f7c 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -25,6 +25,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include +# include # include # include # include @@ -33,6 +35,9 @@ # include #endif +#include +#include + #include "DlgGeneralImp.h" #include "ui_DlgGeneral.h" #include "Action.h" @@ -47,6 +52,7 @@ using namespace Gui::Dialog; namespace fs = boost::filesystem; +using namespace Base; /* TRANSLATOR Gui::Dialog::DlgGeneralImp */ @@ -76,6 +82,26 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent ) const auto & backups = Application::Instance->prefPackManager()->configBackups(); ui->RevertToSavedConfig->setEnabled(backups.empty()); connect(ui->RevertToSavedConfig, &QPushButton::clicked, this, &DlgGeneralImp::revertToSavedConfig); + + ui->spinBoxDecimals->setMaximum(std::numeric_limits::digits10 + 1); + + int num = static_cast(Base::UnitSystem::NumUnitSystemTypes); + for (int i = 0; i < num; i++) { + QString item = qApp->translate("Gui::Dialog::DlgGeneralImp", Base::UnitsApi::getDescription(static_cast(i))); + ui->comboBox_UnitSystem->addItem(item, i); + } + + // Enable/disable the fractional inch option depending on system + if (UnitsApi::getSchema() == UnitSystem::ImperialBuilding) + { + ui->comboBox_FracInch->setVisible(true); + ui->fractionalInchLabel->setVisible(true); + } + else + { + ui->comboBox_FracInch->setVisible(false); + ui->fractionalInchLabel->setVisible(false); + } } /** @@ -148,6 +174,35 @@ void DlgGeneralImp::setDecimalPointConversion(bool on) void DlgGeneralImp::saveSettings() { + // must be done as very first because we create a new instance of NavigatorStyle + // where we set some attributes afterwards + int FracInch; // minimum fractional inch to display + int viewSystemIndex; // currently selected View System (unit system) + + ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Units"); + hGrpu->SetInt("UserSchema", ui->comboBox_UnitSystem->currentIndex()); + hGrpu->SetInt("Decimals", ui->spinBoxDecimals->value()); + + // Set actual value + Base::UnitsApi::setDecimals(ui->spinBoxDecimals->value()); + + // Convert the combobox index to the its integer denominator. Currently + // with 1/2, 1/4, through 1/128, this little equation directly computes the + // denominator given the combobox integer. + // + // The inverse conversion is done when loaded. That way only one thing (the + // numerical fractional inch value) needs to be stored. + FracInch = std::pow(2, ui->comboBox_FracInch->currentIndex() + 1); + hGrpu->SetInt("FracInch", FracInch); + + // Set the actual format value + Base::QuantityFormat::setDefaultDenominator(FracInch); + + // Set and save the Unit System + viewSystemIndex = ui->comboBox_UnitSystem->currentIndex(); + UnitsApi::setSchema(static_cast(viewSystemIndex)); + ui->SubstituteDecimal->onSave(); ui->UseLocaleFormatting->onSave(); ui->RecentFiles->onSave(); @@ -197,6 +252,23 @@ void DlgGeneralImp::saveSettings() void DlgGeneralImp::loadSettings() { + int FracInch; + int cbIndex; + + ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Units"); + ui->comboBox_UnitSystem->setCurrentIndex(hGrpu->GetInt("UserSchema", 0)); + ui->spinBoxDecimals->setValue(hGrpu->GetInt("Decimals", Base::UnitsApi::getDecimals())); + + // Get the current user setting for the minimum fractional inch + FracInch = hGrpu->GetInt("FracInch", Base::QuantityFormat::getDefaultDenominator()); + + // Convert fractional inch to the corresponding combobox index using this + // handy little equation. + cbIndex = std::log2(FracInch) - 1; + ui->comboBox_FracInch->setCurrentIndex(cbIndex); + + ui->SubstituteDecimal->onRestore(); ui->UseLocaleFormatting->onRestore(); ui->RecentFiles->onRestore(); @@ -323,8 +395,10 @@ void DlgGeneralImp::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { int index = ui->UseLocaleFormatting->currentIndex(); + int index2 = ui->comboBox_UnitSystem->currentIndex(); ui->retranslateUi(this); ui->UseLocaleFormatting->setCurrentIndex(index); + ui->comboBox_UnitSystem->setCurrentIndex(index2); } else { QWidget::changeEvent(event); @@ -462,4 +536,23 @@ void DlgGeneralImp::onLoadPreferencePackClicked(const std::string& packName) } } + +void DlgGeneralImp::on_comboBox_UnitSystem_currentIndexChanged(int index) +{ + if (index < 0) + return; // happens when clearing the combo box in retranslateUi() + + // Enable/disable the fractional inch option depending on system + if (static_cast(index) == UnitSystem::ImperialBuilding) + { + ui->comboBox_FracInch->setVisible(true); + ui->fractionalInchLabel->setVisible(true); + } + else + { + ui->comboBox_FracInch->setVisible(false); + ui->fractionalInchLabel->setVisible(false); + } +} + #include "moc_DlgGeneralImp.cpp" diff --git a/src/Gui/DlgGeneralImp.h b/src/Gui/DlgGeneralImp.h index d3aa1afecb..4e18cb783a 100644 --- a/src/Gui/DlgGeneralImp.h +++ b/src/Gui/DlgGeneralImp.h @@ -64,6 +64,9 @@ protected Q_SLOTS: void onManagePreferencePacksClicked(); void onImportConfigClicked(); +public Q_SLOTS: + void on_comboBox_UnitSystem_currentIndexChanged(int index); + private: void setRecentFileSize(); void saveAsNewPreferencePack(); diff --git a/src/Gui/DlgSettingsUnits.ui b/src/Gui/DlgSettingsUnits.ui deleted file mode 100644 index 8209a978a6..0000000000 --- a/src/Gui/DlgSettingsUnits.ui +++ /dev/null @@ -1,162 +0,0 @@ - - - Gui::Dialog::DlgSettingsUnits - - - - 0 - 0 - 484 - 388 - - - - Units - - - - - - Units settings - - - - - - - - Unit system: - - - - - - - Unit system that should be used for all parts the application - - - - - - - - - - - Number of decimals: - - - - - - - Number of decimals that should be shown for numbers and dimensions - - - 1 - - - 12 - - - - - - - - - - - Minimum fractional inch: - - - - - - - Minimum fractional inch to be displayed - - - - 1/2" - - - - - 1/4" - - - - - 1/8" - - - - - 1/16" - - - - - 1/32" - - - - - 1/64" - - - - - 1/128" - - - - - - - - - - - 0 - 0 - - - - QAbstractItemView::NoEditTriggers - - - - Magnitude - - - - - Unit - - - - - - - - Qt::Vertical - - - - 20 - 79 - - - - - - - - - - - - - diff --git a/src/Gui/DlgSettingsUnitsImp.cpp b/src/Gui/DlgSettingsUnitsImp.cpp deleted file mode 100644 index 5805976699..0000000000 --- a/src/Gui/DlgSettingsUnitsImp.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -# include -# include -#endif - -#include -#include -#include - -#include "ui_DlgSettingsUnits.h" -#include "DlgSettingsUnitsImp.h" - - -using namespace Gui::Dialog; -using namespace Base; - -/* TRANSLATOR Gui::Dialog::DlgSettingsUnitsImp */ - -#if 0 // needed for Qt's lupdate utility - qApp->translate("Gui::Dialog::DlgSettingsUnits", "Standard (mm/kg/s/degree)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "MKS (m/kg/s/degree)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "US customary (in/lb)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "Imperial decimal (in/lb)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "Building Euro (cm/m²/m³)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "Building US (ft-in/sqft/cft)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "Metric small parts & CNC(mm, mm/min)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "Imperial for Civil Eng (ft, ft/sec)"); - qApp->translate("Gui::Dialog::DlgSettingsUnits", "FEM (mm, N, s)"); -#endif - -/** - * Constructs a DlgSettingsUnitsImp which is a child of 'parent', with the - * name 'name' and widget flags set to 'f' - */ -DlgSettingsUnitsImp::DlgSettingsUnitsImp(QWidget* parent) - : PreferencePage( parent ), ui(new Ui_DlgSettingsUnits) -{ - ui->setupUi(this); - ui->spinBoxDecimals->setMaximum(std::numeric_limits::digits10 + 1); - - int num = static_cast(Base::UnitSystem::NumUnitSystemTypes); - for (int i = 0; i < num; i++) { - QString item = qApp->translate("Gui::Dialog::DlgSettingsUnits", Base::UnitsApi::getDescription(static_cast(i))); - ui->comboBox_ViewSystem->addItem(item, i); - } - - ui->tableWidget->setVisible(false); - // - // Enable/disable the fractional inch option depending on system - if( UnitsApi::getSchema() == UnitSystem::ImperialBuilding ) - { - ui->comboBox_FracInch->setEnabled(true); - } - else - { - ui->comboBox_FracInch->setEnabled(false); - } -} - -/** - * Destroys the object and frees any allocated resources - */ -DlgSettingsUnitsImp::~DlgSettingsUnitsImp() -{ - // no need to delete child widgets, Qt does it all for us - delete ui; -} - -void DlgSettingsUnitsImp::on_comboBox_ViewSystem_currentIndexChanged(int index) -{ - if (index < 0) - return; // happens when clearing the combo box in retranslateUi() - - // Enable/disable the fractional inch option depending on system - if( static_cast(index) == UnitSystem::ImperialBuilding ) - { - ui->comboBox_FracInch->setEnabled(true); - } - else - { - ui->comboBox_FracInch->setEnabled(false); - } -} - -void DlgSettingsUnitsImp::saveSettings() -{ - // must be done as very first because we create a new instance of NavigatorStyle - // where we set some attributes afterwards - int FracInch; // minimum fractional inch to display - int viewSystemIndex; // currently selected View System (unit system) - - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Units"); - hGrp->SetInt("UserSchema", ui->comboBox_ViewSystem->currentIndex()); - hGrp->SetInt("Decimals", ui->spinBoxDecimals->value()); - - // Set actual value - Base::UnitsApi::setDecimals(ui->spinBoxDecimals->value()); - - // Convert the combobox index to the its integer denominator. Currently - // with 1/2, 1/4, through 1/128, this little equation directly computes the - // denominator given the combobox integer. - // - // The inverse conversion is done when loaded. That way only one thing (the - // numerical fractional inch value) needs to be stored. - FracInch = std::pow(2, ui->comboBox_FracInch->currentIndex() + 1); - hGrp->SetInt("FracInch", FracInch); - - // Set the actual format value - Base::QuantityFormat::setDefaultDenominator(FracInch); - - // Set and save the Unit System - viewSystemIndex = ui->comboBox_ViewSystem->currentIndex(); - UnitsApi::setSchema(static_cast(viewSystemIndex)); -} - -void DlgSettingsUnitsImp::loadSettings() -{ - int FracInch; - int cbIndex; - - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Units"); - ui->comboBox_ViewSystem->setCurrentIndex(hGrp->GetInt("UserSchema",0)); - ui->spinBoxDecimals->setValue(hGrp->GetInt("Decimals",Base::UnitsApi::getDecimals())); - - // Get the current user setting for the minimum fractional inch - FracInch = hGrp->GetInt("FracInch", Base::QuantityFormat::getDefaultDenominator()); - - // Convert fractional inch to the corresponding combobox index using this - // handy little equation. - cbIndex = std::log2(FracInch) - 1; - ui->comboBox_FracInch->setCurrentIndex(cbIndex); -} - -/** - * Sets the strings of the subwidgets using the current language. - */ -void DlgSettingsUnitsImp::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::LanguageChange) { - int index = ui->comboBox_ViewSystem->currentIndex(); - ui->retranslateUi(this); - ui->comboBox_ViewSystem->setCurrentIndex(index); - } - else { - QWidget::changeEvent(e); - } -} - -#include "moc_DlgSettingsUnitsImp.cpp" diff --git a/src/Gui/DlgSettingsUnitsImp.h b/src/Gui/DlgSettingsUnitsImp.h deleted file mode 100644 index 5fe7c33bc2..0000000000 --- a/src/Gui/DlgSettingsUnitsImp.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef GUI_DIALOG_DLGSETTINGSUnitsIMP_H -#define GUI_DIALOG_DLGSETTINGSUnitsIMP_H - -#include "PropertyPage.h" - -namespace Gui { -namespace Dialog { - -/** - * The DlgSettingsUnitsImp class implements a preference page to change settings - * for the Unit system. - * \author Jürgen Riegel - */ -class Ui_DlgSettingsUnits; -class DlgSettingsUnitsImp : public PreferencePage -{ - Q_OBJECT - -public: - explicit DlgSettingsUnitsImp(QWidget* parent = nullptr); - ~DlgSettingsUnitsImp() override; - - void saveSettings() override; - void loadSettings() override; - -protected: - void changeEvent(QEvent *e) override; - -public Q_SLOTS: - void on_comboBox_ViewSystem_currentIndexChanged(int index); - -private: - Ui_DlgSettingsUnits* ui; -}; - -} // namespace Dialog -} // namespace Gui - -#endif // GUI_DIALOG_DLGSETTINGSUnitsIMP_H diff --git a/src/Gui/DlgUnitsCalculatorImp.cpp b/src/Gui/DlgUnitsCalculatorImp.cpp index 0b2e63fb6c..5a7b514eb0 100644 --- a/src/Gui/DlgUnitsCalculatorImp.cpp +++ b/src/Gui/DlgUnitsCalculatorImp.cpp @@ -53,7 +53,7 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WindowFlags fl ) ui->comboBoxScheme->addItem(QString::fromLatin1("Preference system"), static_cast(-1)); int num = static_cast(Base::UnitSystem::NumUnitSystemTypes); for (int i=0; itranslate("Gui::Dialog::DlgSettingsUnits", Base::UnitsApi::getDescription(static_cast(i))); + QString item = qApp->translate("Gui::Dialog::DlgGeneralImp", Base::UnitsApi::getDescription(static_cast(i))); ui->comboBoxScheme->addItem(item, i); } diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index f1e49e145f..ac51fb904a 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -230,7 +230,7 @@ private: assert(actions.size() <= maxSchema); for(int i = 0; i < maxSchema ; i++) { - actions[i]->setText(qApp->translate("Gui::Dialog::DlgSettingsUnits", + actions[i]->setText(qApp->translate("Gui::Dialog::DlgGeneralImp", Base::UnitsApi::getDescription(static_cast(i)))); } } diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index b0ec59c799..4a7f942c31 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -39,7 +39,6 @@ #include "DlgSettingsNotificationArea.h" #include "DlgSettingsPythonConsole.h" #include "DlgSettingsMacroImp.h" -#include "DlgSettingsUnitsImp.h" #include "DlgSettingsDocumentImp.h" #include "DlgReportViewImp.h" #include "DlgSettingsWorkbenchesImp.h" @@ -75,7 +74,6 @@ WidgetFactorySupplier::WidgetFactorySupplier() new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","General") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","General") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","General") ); - new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","General") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") );