Any clever QT programmers out there?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Any clever QT programmers out there?

Post by keithsloan52 »

Wondering if there are any knowledgeable Qt developers out there? Least I assume it would need Qt programming.

What I would like to see is a facility for setting a set of FreeCAD object properties. What I envisage is an option to create a pie chart
with 2 to n parameters and allow the user to drag/rotate the division between the different values. That is I have a number of situations where
a FreeCAD object has 2 to n parameters that have to add up to 100%. How difficult would this be to implement? Rather than have a heavy
learning curve it would be great if somebody with existing knowledge was able to implement something.

I might be wrong but with the current ability to change properties I can only see having to check values and issue warning message if
values do not add up to 100.

Thanks in anticipation.
User avatar
fosselius
Posts: 381
Joined: Sat Apr 23, 2016 10:03 am
Contact:

Re: Any clever QT programmers out there?

Post by fosselius »

hmm. i think you should provide some concept art on what you want to get implemented. ;)

also learning curve is not that steep. mostly copy-paste
https://doc.qt.io/qtforpython/tutorials ... ialog.html
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Any clever QT programmers out there?

Post by jmaustpc »

G'day Keith
keithsloan52 wrote: Thu Aug 01, 2019 6:41 pm knowledgeable Qt developers out there?
i am definitely not one of those, however I have some questions, I have been thinking about your post all evening. I have some questions.

I asked my mates Phil, Trevor , Jagger and Simon what they thought. They just stared back at me, vomited up their dinner into their mouths, chewed it again for a bit and then swallowed it again......the only verbal response they gave was "Moooo".....but they are steers. :D Sorry but I couldn't help myself,...more cow references.


But seriously, now some questions. How would these work? Is it your intention to store this as a single FreeCAD object property containing a list or tuple etc. of values or "n" inter dependent separate properties? If the first I assume you would have to fire up a dialogue if someone tried to edit via the standard property editor to ensure that the total did not exceed 100%, sounds complex. If the second, then for the case of n=2, it seems to me a simple solution could be to simple make property 1 editable in a spinbox in the normal property editor like some other properties and then make property 2 read only and derived from "100%-property 1".

Do your users ever need to be able to directly edit the value of "n value" or can it always just be read only derived from "100%- (sum of 1 to n-1)"?

Where n>2, if you change one, where does it deduct its portion from? What is the logic? For example, do the n values have a hierarchy where gains in one are deducted from the next value until that next value reaches 0 at which point it remains 0 and further increases in the original are then deducted from the next+1 value, etc.? Or would the increase in one value be deducted from all other values, if so then on what basis? Lineally or proportionally to the other values proportion of the remainder?

It is possible to have unlimited semi-independent number like placement angle XZY today where 45 degrees with XYZ all = 1 gives the same result as xyz all =10, where the percentage is calculated on the properties proportion of the total of the N values. But I doubt you would want to do that.

Jim
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Any clever QT programmers out there?

Post by tanderson69 »

You could create some kind 'pie' control, but you would probably have to get into custom drawing of control. I think a simpler solution is to use sliders that modify other sliders equally to maintain your desired sum. You could also lock values so other slider changes wouldn't affect those locked values.
sliders.png
sliders.png (13.98 KiB) Viewed 1625 times
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Any clever QT programmers out there?

Post by keithsloan52 »

Okay let me elaborate.

The situation is occurring trying to deal with GDML materials and elements

Here is an example of how each is defined in GDML i.e. an XML file.

Code: Select all

<element name="Iron0x56070eea0880">
    <fraction n="0.05845" ref="Fe540x56070ee87130" />
    <fraction n="0.91754" ref="Fe560x56070ee95300" />
    <fraction n="0.02119" ref="Fe570x56070ee8eff0" />
    <fraction n="0.00282" ref="Fe580x56070ee8d300" />
    </element>

Code: Select all

<material name="SSteel0x56070ee87d10">
    <T unit="K" value="293.15" />
    <MEE unit="eV" value="282.530633667015" />
    <D unit="g/cm3" value="1.286547719061e-18" />
    <fraction n="0.74" ref="Iron0x56070eea0880" />
    <fraction n="0.18" ref="Chromium0x56070eea004" />
    <fraction n="0.08" ref="Nickel0x56070ee81420" />
    </material>
In both cases the sum of fractions need to add upto one. i.e. 100%

Currently as there is a variable number of fractions I implement these as groups
top.png
top.png (111.32 KiB) Viewed 1518 times
iron.png
iron.png (155.72 KiB) Viewed 1518 times
ssteel.png
ssteel.png (170.71 KiB) Viewed 1518 times
I would therefore see the facility as working on groups i.e. an edit option for the group.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Any clever QT programmers out there?

Post by keithsloan52 »

tanderson69 wrote: Fri Aug 02, 2019 5:26 pm You could create some kind 'pie' control, but you would probably have to get into custom drawing of control. I think a simpler solution is to use sliders that modify other sliders equally to maintain your desired sum. You could also lock values so other slider changes wouldn't affect those locked values.

sliders.png
Can one display the current value of the slider?

Think it would have to work on the basis if I change one slider it also adjust the one immediately below so that they all add up to one or 100%
Think evenly adjusting all the other values not being adjusted would make it HARD for the user to get to a desired result.
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Any clever QT programmers out there?

Post by tanderson69 »

keithsloan52 wrote: Tue Aug 06, 2019 3:46 am Can one display the current value of the slider?
Sure and make it an edit box so user can type in a value also.


keithsloan52 wrote: Tue Aug 06, 2019 3:46 am Think evenly adjusting all the other values not being adjusted would make it HARD for the user to get to a desired result.
That is what the 'lock' is for.
exargon
Posts: 1
Joined: Wed Aug 14, 2019 8:16 pm

Re: Any clever QT programmers out there?

Post by exargon »

So..., I kind off made an implementation to explore the concept. https://github.com/exargon/Qt-PieChartWidget
Probably more elegant ways to implement it, but it is a working implementation you could use as a starting point or inspiration.

A few notes:
I made an abstract base class with the logic. It could be used for other visualizations (e.g. a linear version more aligned with normal sliders).
I only implemented color as the visual for the different sectors (as well as their index I guess), as string labels are more complicated to visualize nicely.
The widget should accept simple styling, but it has no custom styleoptions.
I made an example widget (you can make it with example.pro) that you can use to experiment with the inputs and outputs of the widget.
Post Reply