Move the unit schema into Project Information and remove all Project Unit System code (#11266)

* Add unit system to Project Information and store with document.

* Remove the project unit system

* Restore correct document activation signalling to fix test fail

* Remove commented out dead lines

* Restore ignore option for project unit schemas

* Whitespace fix

* Refresh after changing units

* Remove field label

* Property editor changes applied to unit system
This commit is contained in:
bgbsww
2023-12-04 14:04:53 -05:00
committed by GitHub
parent 0aa328622d
commit c2bab7a2fa
12 changed files with 125 additions and 150 deletions

View File

@@ -35,6 +35,7 @@
# include <boost/filesystem.hpp>
#endif
#include <App/Document.h>
#include <Base/Parameter.h>
#include <Base/UnitsApi.h>
@@ -98,7 +99,6 @@ DlgSettingsGeneral::DlgSettingsGeneral( QWidget* parent )
for (int i = 0; i < num; i++) {
QString item = Base::UnitsApi::getDescription(static_cast<Base::UnitSystem>(i));
ui->comboBox_UnitSystem->addItem(item, i);
ui->comboBox_projectUnitSystem->addItem(item, i);
}
// Enable/disable the fractional inch option depending on system
@@ -191,6 +191,7 @@ void DlgSettingsGeneral::saveSettings()
("User parameter:BaseApp/Preferences/Units");
hGrpu->SetInt("UserSchema", ui->comboBox_UnitSystem->currentIndex());
hGrpu->SetInt("Decimals", ui->spinBoxDecimals->value());
hGrpu->SetBool("IgnoreProjectSchema", ui->checkBox_projectUnitSystemIgnore->isChecked());
// Set actual value
Base::UnitsApi::setDecimals(ui->spinBoxDecimals->value());
@@ -208,22 +209,15 @@ void DlgSettingsGeneral::saveSettings()
Base::QuantityFormat::setDefaultDenominator(FracInch);
// Set and save the Unit System
viewSystemIndex = ui->comboBox_UnitSystem->currentIndex();
auto activeDoc = Gui::Application::Instance->activeDocument();
bool projectUnitSystemIgnore = ui->checkBox_projectUnitSystemIgnore->isChecked();
if(activeDoc){
activeDoc->setProjectUnitSystemIgnore( projectUnitSystemIgnore );
if(!projectUnitSystemIgnore){
int projectUnitSystemIndex = ui->comboBox_projectUnitSystem->currentIndex();
activeDoc->setProjectUnitSystem( projectUnitSystemIndex );
UnitsApi::setSchema(static_cast<UnitSystem>(projectUnitSystemIndex));
}else{
UnitsApi::setSchema(static_cast<UnitSystem>(viewSystemIndex));
}
}else{
UnitsApi::setSchema(static_cast<UnitSystem>(viewSystemIndex));
if ( ui->checkBox_projectUnitSystemIgnore->isChecked() ) {
viewSystemIndex = ui->comboBox_UnitSystem->currentIndex();
UnitsApi::setSchema(static_cast<UnitSystem>(viewSystemIndex));
} else {
App::Document* doc = App::GetApplication().getActiveDocument();
if ( doc != nullptr ) {
UnitsApi::setSchema(static_cast<UnitSystem>(doc->UnitSystem.getValue()));
}
}
//
ui->SubstituteDecimal->onSave();
ui->UseLocaleFormatting->onSave();
@@ -268,6 +262,7 @@ void DlgSettingsGeneral::loadSettings()
("User parameter:BaseApp/Preferences/Units");
ui->comboBox_UnitSystem->setCurrentIndex(hGrpu->GetInt("UserSchema", 0));
ui->spinBoxDecimals->setValue(hGrpu->GetInt("Decimals", Base::UnitsApi::getDecimals()));
ui->checkBox_projectUnitSystemIgnore->setChecked(hGrpu->GetBool("IgnoreProjectSchema", false));
// Get the current user setting for the minimum fractional inch
FracInch = hGrpu->GetInt("FracInch", Base::QuantityFormat::getDefaultDenominator());
@@ -276,26 +271,6 @@ void DlgSettingsGeneral::loadSettings()
// handy little equation.
cbIndex = std::log2(FracInch) - 1;
ui->comboBox_FracInch->setCurrentIndex(cbIndex);
auto activeDoc = Gui::Application::Instance->activeDocument();
if(activeDoc){
int us = activeDoc->getProjectUnitSystem();
if(us >= 0){//Valid unit system:
ui->comboBox_projectUnitSystem->setCurrentIndex( us );
int pusIgnore = activeDoc->getProjectUnitSystemIgnore();
ui->checkBox_projectUnitSystemIgnore->setChecked( pusIgnore );
}else{
ui->comboBox_projectUnitSystem->setCurrentIndex( 0 );
ui->checkBox_projectUnitSystemIgnore->setChecked( false );
}
}else{
ui->checkBox_projectUnitSystemIgnore->setEnabled(false);
ui->comboBox_projectUnitSystem->setEnabled(false);
}
ui->SubstituteDecimal->onRestore();
ui->UseLocaleFormatting->onRestore();
ui->RecentFiles->onRestore();
@@ -433,11 +408,9 @@ void DlgSettingsGeneral::changeEvent(QEvent *event)
if (event->type() == QEvent::LanguageChange) {
int index = ui->UseLocaleFormatting->currentIndex();
int index2 = ui->comboBox_UnitSystem->currentIndex();
int pusIndex = ui->comboBox_projectUnitSystem->currentIndex();
ui->retranslateUi(this);
ui->UseLocaleFormatting->setCurrentIndex(index);
ui->comboBox_UnitSystem->setCurrentIndex(index2);
ui->comboBox_projectUnitSystem->setCurrentIndex(pusIndex);
}
else {
QWidget::changeEvent(event);
@@ -646,19 +619,6 @@ void DlgSettingsGeneral::onUnitSystemIndexChanged(int index)
}
}
void DlgSettingsGeneral::on_checkBox_projectUnitSystemIgnore_stateChanged(int state)
{
if (state < 0)
return; // happens when clearing the combo box in retranslateUi()
// Enable/disable the projectUnitSystem if being ignored:
if(state == 2){//ignore
ui->comboBox_projectUnitSystem->setEnabled(false);
}else if(state == 0){
ui->comboBox_projectUnitSystem->setEnabled(true);
}
}
void DlgSettingsGeneral::onThemeChanged(int index) {
Q_UNUSED(index);
themeChanged = true;