Added support for fractional inch user setting.
This commit is contained in:
@@ -1576,6 +1576,11 @@ void Application::initApplication(void)
|
||||
UnitsApi::setSchema((UnitSystem)hGrp->GetInt("UserSchema",0));
|
||||
UnitsApi::setDecimals(hGrp->GetInt("Decimals", Base::UnitsApi::getDecimals()));
|
||||
|
||||
// In case we are using fractional inches, get user setting for min unit
|
||||
int denom = hGrp->GetInt("FracInch", Base::QuantityFormat::getDenominator());
|
||||
Base::QuantityFormat::setDenominator(denom);
|
||||
|
||||
|
||||
#if defined (_DEBUG)
|
||||
Console().Log("Application is built with debug information\n");
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,10 @@
|
||||
|
||||
using namespace Base;
|
||||
|
||||
// ====== Static attributes =========================
|
||||
int QuantityFormat::defaultDenominator = 8; // for 1/8"
|
||||
|
||||
|
||||
QuantityFormat::QuantityFormat()
|
||||
: option(static_cast<NumberOption>(OmitGroupSeparator | RejectGroupSeparator))
|
||||
, format(Fixed)
|
||||
|
||||
@@ -52,6 +52,19 @@ struct QuantityFormat {
|
||||
NumberFormat format;
|
||||
int precision;
|
||||
|
||||
// Default denominator of minimum fractional inch. Only used in certain
|
||||
// schemas.
|
||||
static int defaultDenominator; // i.e 8 for 1/8"
|
||||
|
||||
static inline int getDenominator() {
|
||||
return defaultDenominator;
|
||||
}
|
||||
|
||||
static inline void setDenominator(int denom)
|
||||
{
|
||||
defaultDenominator = denom;
|
||||
}
|
||||
|
||||
QuantityFormat();
|
||||
inline char toFormat() const {
|
||||
switch (format) {
|
||||
|
||||
@@ -229,10 +229,8 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity &quant, doub
|
||||
int a,b,d; // used to compute greatest common denominator
|
||||
int tmp; // temporary variable for GCD
|
||||
|
||||
// TEMPORARY: This will be replaced by a user setting when time permits.
|
||||
// For now, it will be hardcoded to emulate the previous (1/8")
|
||||
// behavior.
|
||||
minden = 8; // 1/8"
|
||||
// Get the current user specified minimum denominator
|
||||
minden = Base::QuantityFormat::getDenominator();
|
||||
|
||||
// Compute and round the total number of fractional units
|
||||
ntot = (int)std::round(totalInches * (double)minden);
|
||||
|
||||
@@ -98,6 +98,9 @@ void DlgSettingsUnitsImp::saveSettings()
|
||||
// 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::setDenominator(FracInch);
|
||||
}
|
||||
|
||||
void DlgSettingsUnitsImp::loadSettings()
|
||||
@@ -111,7 +114,7 @@ void DlgSettingsUnitsImp::loadSettings()
|
||||
ui->spinBoxDecimals->setValue(hGrp->GetInt("Decimals",Base::UnitsApi::getDecimals()));
|
||||
|
||||
// Get the current user setting for the minimum fractional inch
|
||||
FracInch = hGrp->GetInt("FracInch",8); // 8==1/8"
|
||||
FracInch = hGrp->GetInt("FracInch", Base::QuantityFormat::getDenominator());
|
||||
|
||||
// Convert fractional inch to the corresponding combobox index using this
|
||||
// handy little equation.
|
||||
|
||||
Reference in New Issue
Block a user