On 04/11/2014 04:19 PM, Dirk Hohndel wrote:

I think I had something slightly different in mind:

The prefs variable should contain a member for each setting. And we need
to redo those members so they are actually identical to the name of the
setting (it's ridiculous that we have these tiny variations between the
string used as key in QSettings and the member of the struct
preferences).

Whenever the code needs to check a preference, just use

        if (prefs.whatever == ...)

And when you need to set a preference from the code (we have that in a
few places now) have it call
subsurface_set_conf(const char *name, const char *value)
subsurface_set_conf_bool(const char *name, bool value)
subsurface_set_conf_int(const char *name, int value)
and then implement these three functions so they figure out the matching
settings group and update both.
Actually, I think we may get away with only ever setting things from UI
code... you'll have to double check this, but I don't see how C code
right now could even call into QSettings code, so most likely all you
need is subsurface_set_conf(name, value) and then have three
implementations for different type.
And the subsurface_set_conf() call modifies the matching prefs variable
and then updates the setting.

Once you cleaned up the variable name / settings name inconsistency you
could implement this as a macro

#define subsurface_set_conf(_n, _v) \
        prefs.##_n = _v; \
        subsurfaceSetConf(_n, _v)

Or something along this line. I haven't had enough coffee yet to fully
think this through, but maybe the gist of what I wanted becomes clear?

Yes Thanks, I understood that.

I Made a list of all Qsettings in subsurface there is 18 settings Group and 92 keys, we have to make prefs members for all the 92 keys (some of them is used while initialization only) ?

Also I think if we didn't add all the settings to the prefs structure using that macro can be dangerous.

I attached the list of all Keys.

--
Regards,
Gehad Elrobey

## "Animations" ## 
- "animation_speed" 
--------------------- 

## "Display" ## 
- "displayinvalid" 
- "divelist_font" 
- "font_size" 
--------------------- 

## "DiveListColumnState" ## 
- "showColumn0" 
--------------------- 

## "FileDialog" ## 
- "LastDir" 
--------------------- 

## "GeneralSettings" ## 
- "default_cylinder" 
- "default_filename" 
--------------------- 

## "Language" ## 
- "UiLanguage" 
- "UseSystemLanguage" 
--------------------- 

## "ListWidget" ## 
- "colwidth0" 
- "colwidth1" 
- "colwidth13" 
- "colwidth2" 
- "colwidth3" 
- "colwidth4" 
--------------------- 

## "MainWindow" ## 
- "infoProfileSplitter" 
- "lastState" 
- "listGlobeSplitter" 
- "mainSplitter" 
- "maximized" 
- "size" 
--------------------- 

## "ProfileMap" ## 
- "tooltip_position" 
--------------------- 

## "Recent_Files" ## 
- "File_1" 
- "File_2" 
- "File_3" 
- "File_4" 
--------------------- 

## "TecDetails" ## 
- "calcalltissues" 
- "calcceiling" 
- "calcceiling3m" 
- "calcndltts" 
- "dcceiling" 
- "display_unused_tanks" 
- "ead" 
- "gf_low_at_maxdepth" 
- "gfhigh" 
- "gflow" 
- "mod" 
- "modppO2" 
- "phegraph" 
- "phethreshold" 
- "pn2graph" 
- "pn2threshold" 
- "po2graph" 
- "po2threshold" 
- "profile_red_ceiling" 
- "redceiling" 
- "rulergraph" 
- "show_average_depth" 
- "show_sac" 
- "zoomed_plot" 
--------------------- 

## "Units" ## 
- "length" 
- "pressure" 
- "temperature" 
- "text_label_with_units" 
- "unit_system" 
- "vertical_speed_time" 
- "volume" 
- "weight" 
--------------------- 

## "cylinderTableWidget" ## 
- "colwidth0" 
- "colwidth1" 
- "colwidth2" 
- "colwidth3" 
- "colwidth4" 
- "colwidth5" 
- "colwidth6" 
- "colwidth7" 
--------------------- 

## "cylinders" ## 
- "colwidth0" 
- "colwidth1" 
- "colwidth2" 
- "colwidth3" 
- "colwidth4" 
- "colwidth5" 
- "colwidth6" 
- "colwidth7" 
--------------------- 

## "cylinders_dialog" ## 
- "column2_hidden" 
- "column3_hidden" 
- "column4_hidden" 
- "column5_hidden" 
- "column6_hidden" 
- "column7_hidden" 
--------------------- 

## "tableWidget" ## 
- "colwidth0" 
- "colwidth1" 
- "colwidth2" 
- "colwidth3" 
- "colwidth4" 
--------------------- 

## "tableWidgetComp" ## 
- "colwidth0" 
- "colwidth1" 
- "colwidth2" 
--------------------- 

## "weights" ## 
- "colwidth0" 
- "colwidth1" 
- "colwidth2" 
--------------------- 
_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to