Default format - small fix

Discussions about the development of the TechDraw workbench
User avatar
babaroga
Posts: 75
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Default format - small fix

Postby babaroga » Sun Apr 14, 2019 10:04 pm

After introduction of default format in TD I realised that diameter and radius symbol on dimensions were overriden by deafault format entered in preferences dialog. So if you enter anything as default format, diameter and radius symbol is missing on dimensions.

This is my small fix for this issue. @WandererFan can you please test it and consider change it since I am not Github guru?

This code in DrawViewDimension.cpp somewhere end of the file

Code: Select all

std::string DrawViewDimension::getDefaultFormatSpec() const
{
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
                                         .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
    std::string prefFormat = hGrp->GetASCII("formatSpec","");
    QString formatSpec;
    if (prefFormat.empty()) {
        QString format1 = Base::Tools::fromStdString("%.");
        QString format2 = Base::Tools::fromStdString("f");
        int precision;
        if (useDecimals()) {
            precision = Base::UnitsApi::getDecimals();
        } else {
            precision = hGrp->GetInt("AltDecimals", 2);
        }
        QString formatPrecision = QString::number(precision);

        std::string prefix = getPrefix();
        QString qPrefix;
        if (!prefix.empty()) {
            qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
        }

        formatSpec = qPrefix + format1 + formatPrecision + format2;
    } else {
        return prefFormat;
    }
    
    return Base::Tools::toStdString(formatSpec);
}

is to be replaced by :

Code: Select all

std::string DrawViewDimension::getDefaultFormatSpec() const
{
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
                                         .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
    std::string prefFormat = hGrp->GetASCII("formatSpec","");
    QString formatSpec;
    QString qPrefix; //Move it here
    if (prefFormat.empty()) {
        QString format1 = Base::Tools::fromStdString("%.");
        QString format2 = Base::Tools::fromStdString("f");
        int precision;
        if (useDecimals()) {
            precision = Base::UnitsApi::getDecimals();
        } else {
            precision = hGrp->GetInt("AltDecimals", 2);
        }
        QString formatPrecision = QString::number(precision);

        std::string prefix = getPrefix();
        //QString qPrefix;
        if (!prefix.empty()) {
            qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
        }

        formatSpec = qPrefix + format1 + formatPrecision + format2;
    } else {
        //return prefFormat;
        
        std::string prefix = getPrefix();
        qPrefix = QString::fromUtf8(prefix.data(),prefix.size());
        formatSpec = qPrefix + QString::fromStdString(prefFormat);
        
    }
    
    return Base::Tools::toStdString(formatSpec);
}
wandererfan
Posts: 2888
Joined: Tue Nov 06, 2012 5:42 pm

Re: Default format - small fix

Postby wandererfan » Tue Apr 16, 2019 11:35 am

babaroga wrote:
Sun Apr 14, 2019 10:04 pm
This is my small fix for this issue. @WandererFan can you please test it and consider change it since I am not Github guru?
Thanks. Desk check looks good. My devl environment is crowded right now, might take a few days to get to this.

If you can read and modify code, you can do Github. Somewhere in the forum there are step by step instructions. I'll see if I can find them.
wandererfan
Posts: 2888
Joined: Tue Nov 06, 2012 5:42 pm

Re: Default format - small fix

Postby wandererfan » Tue Apr 16, 2019 11:54 am

User avatar
babaroga
Posts: 75
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Default format - small fix

Postby babaroga » Tue Apr 16, 2019 12:08 pm

OK, I will study it :oops:

THX
User avatar
babaroga
Posts: 75
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Default format - small fix

Postby babaroga » Wed Apr 17, 2019 10:27 am

So, I did my first Pull request. It says checks are OK.

What now? Is there something else I should do?
wandererfan
Posts: 2888
Joined: Tue Nov 06, 2012 5:42 pm

Re: Default format - small fix

Postby wandererfan » Wed Apr 17, 2019 12:34 pm

babaroga wrote:
Wed Apr 17, 2019 10:27 am
So, I did my first Pull request. It says checks are OK.
Awesome! Your change has been merged into master branch. You are now a FreeCAD developer!
What now? Is there something else I should do?
Find another bug to fix? :D
User avatar
babaroga
Posts: 75
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Default format - small fix

Postby babaroga » Wed Apr 17, 2019 1:11 pm

Yeeeeah,

I will drink a beer in that name... :D

Of course, there is one more I am working on. If "Show unit of measure" is ticked off in preferences, " ° " degree sign is missing on angular measures.
wandererfan
Posts: 2888
Joined: Tue Nov 06, 2012 5:42 pm

Re: Default format - small fix

Postby wandererfan » Wed Apr 17, 2019 1:17 pm

babaroga wrote:
Wed Apr 17, 2019 1:11 pm
Of course, there is one more I am working on. If "Show unit of measure" is ticked off in preferences, " ° " degree sign is missing on angular measures.
Lots more fixes to be made. I may have to figure our how to send you a case of beer.