Cloning data grids... text properties problematic [SOLVED]

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Cloning data grids... text properties problematic [SOLVED]

Post by stam » Fri Mar 11, 2022 3:58 am

Hi all,
Hoping there may be a data grid guru around?
I'm needed to clone data grids to other stacks, so just rolling my own solution and making good progress.

It all works well except for group level text settings (ie text settings not set in the row template, but with the data grid selected changing text style, color etc).
These don't seem to be in the group properties, dgProps or row/column templates and aren't replicated in the destination data grid...
Am i missing something or do i also need to copy these across separately?

Essentially what i've done is
- copy the properties from the source DG to the destination DG on the target stack
- copy the customPropertySet "dgProps" from the source DG to the destination DG on the target stack
- clone the source DG's behaviour substack, rename it and set it's mainstack to the destination stack
- iterate through the dgProps of the destination DG on the target stack to point to the new substack
- obviously multiple checks - if same stack not to clone the substack etc

This replicates the the source data grid nearly perfectly.
However if for example i've selected the data grid and hit command-B to make it's text bold, or set the textColor and then do the above, this isn't copied across to the target data grid... should this not be in the properties copied across? Other properties like row colours copy across as expected...

Many thanks
Stam

--------------
edit: on further investigation: If i select the source data grid, change it's text colour, make it bold and increase its font size in the IDE the visible changes are not reflected in it's properties.
it's fairly quick to list all the properties in the multiline message box with

Code: Select all

local myArray
put the properties of the selectedObject into myArray
combine myArray using return and ": "
put myArray
this shows all the text props to be empty:

Code: Select all

...
tabGroupBehavior: false
textFont: 
textSize: 
textStyle: 
threeD: false
toolTip: source data grid
...
The text properties mush be stored somewhere however! Any suggestions?
Last edited by stam on Mon Mar 14, 2022 2:52 am, edited 1 time in total.

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cloning data grids... text properties problematic

Post by Klaus » Fri Mar 11, 2022 9:39 am

Hi stam,

check the "custom property set" -> dgProps of a datagrid, all this stuff is stored in there.
So you will need to copy that, too.


Best

Klaus

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Fri Mar 11, 2022 10:18 am

Klaus wrote:
Fri Mar 11, 2022 9:39 am
check the "custom property set" -> dgProps of a datagrid, all this stuff is stored in there.
So you will need to copy that, too.
erm...
stam wrote:
Fri Mar 11, 2022 3:58 am
<snip>
Essentially what i've done is
- copy the properties from the source DG to the destination DG on the target stack
- copy the customPropertySet "dgProps" from the source DG to the destination DG on the target stack
- clone the source DG's behaviour substack, rename it and set it's mainstack to the destination stack
- iterate through the dgProps of the destination DG on the target stack to point to the new substack
<snip>
The problem is that the textFont/textColor/textSize are stored neither in the properties of the data grid group, nor in the custom property set "dgProps"...
They must be stored somewhere but can't figure out where!
The point of this exercise is to make the target DG the same as the source DG - but this is super-annoying me ;)

I can do this effectively by copying the source data grid and if to a different stack then also create a copy of the behaviour substack and this does work well - using "copy to card" preserves all the properties and dgProps as well as the text properties (just need to wire up the dgProps to a new substack if copying to a card on a different stack). The fact that when using copy these properties are preserved even when pasting to a new stack means they are not linked to the datagrid template substack. I'm stumped.

I'll probably leave it at that, but i hate it when i can't solve a problem ;)

Stam

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cloning data grids... text properties problematic

Post by Klaus » Fri Mar 11, 2022 10:35 am

Oops, sorry, my fault. :oops:

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cloning data grids... text properties problematic

Post by Klaus » Fri Mar 11, 2022 10:55 am

Hm, after taking a second look at a datagrid, I see that textfont/textsize/textcolor is in fact stored in the props of the dg group!?
Seems logical, since that is what we can set in the inspector for the group.

If that is not what you mean, please explain.

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Fri Mar 11, 2022 12:31 pm

Klaus wrote:
Fri Mar 11, 2022 10:55 am
Hm, after taking a second look at a datagrid, I see that textfont/textsize/textcolor is in fact stored in the props of the dg group!?
Seems logical, since that is what we can set in the inspector for the group.

If that is not what you mean, please explain.
Hi Klaus - thank you for trying to help but now i'm confused. And not entirely sure i agree....

As mentioned, in script i do this:

Code: Select all

set the properties of destinationDatagrid to the properties of sourceDataGrid
set the customProperties["dgProps"] of destinationDatagrid to the customProperties["dgProps"] of sourceDataGrid
Everything is copied across except for the text properties

No values are returned if the textSize is set to 18 and in the messageBox i run this command:

Code: Select all

put the textSize of group "data grid 1" 

This really was evident from my post above:
stam wrote:
Fri Mar 11, 2022 3:58 am
If i select the source data grid, change it's text colour, make it bold and increase its font size in the IDE the visible changes are not reflected in it's properties.
it's fairly quick to list all the properties in the multiline message box with

Code: Select all

local myArray
put the properties of the selectedObject into myArray
combine myArray using return and ": "
put myArray
this shows all the text props to be empty:

Code: Select all

...
tabGroupBehavior: false
textFont: 
textSize: 
textStyle: 
threeD: false
toolTip: source data grid
...
i.e., the textFont, textSize and textStyle are empty in the group's properties.
All other properties, like the tooltip for the group, do list correctly (which is why i included this in this example).

What do you mean by
is in fact stored in the props of the dg group!?
Am i not looking at the properties correctly?

I suspect the difference with the standard inspector panel is you get 2 different targets for the text attributes - one of the rows and one for the headers - and I suspect these are therefore stored in some esoterical part of the group.

I don't mean to be contrary and appreciate your help - just trying to understand. I'll try hunt this down...

Stam

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cloning data grids... text properties problematic

Post by Klaus » Fri Mar 11, 2022 12:39 pm

Ah, now I get it! :-)

OK, you need to query the "effective" textsize etc. of the DG grp.
All these props are inherited from the card or stack if not set explicitely.

And be aware that not all "settable" properties are listed in the LC inspector!
Like:
the dgprops["header height"]
and
the dgprops["header text size"]

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Fri Mar 11, 2022 12:49 pm

Klaus wrote:
Fri Mar 11, 2022 12:39 pm
Ah, now I get it! :-)

OK, you need to query the "effective" textsize etc. of the DG grp.
All these props are inherited from the card or stack if not set explicitely.

And be aware that not all "settable" properties are listed in the LC inspector!
Like:
the dgprops["header height"]
and
the dgprops["header text size"]
Actually dgprops["header text size"] is settable;) just head to the text panel.
The 'effective textSize' returns the default (ie wrong) size of 13 even when creating a new DG and setting it's textSize to 24 in the properties panel...
For the life of me i can't see where this is stored...

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cloning data grids... text properties problematic

Post by Klaus » Fri Mar 11, 2022 12:54 pm

Oh yes, sorry, never took a deeper look at the inspector...
I actually meant: the dgprops["header height"]

But the issue with the textsize is really strange!?

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Fri Mar 11, 2022 1:19 pm

Klaus wrote:
Fri Mar 11, 2022 12:54 pm
But the issue with the textsize is really strange!?
it gets weirder.
I put a button on the same card as the data grid with the follow script to allow me to look at the dgProps in the IDE:

Code: Select all

on mouseUp
    local tArr
    put the customProperties["dgProps"] of group "datagrid 1" into tArr
    breakpoint
end mouseUp
The last dgProp listed is style

However if i put in the message box

Code: Select all

put the dgProp["text size"] of group "datagrid 1"
it returns the correct size of 24!!!!!

I wonder if dgProps alphabetically after style just don't get listed and can't be copied by assigning the customProperties["dgProps"]
Super weird... if true, also means that *any* properties alphabetically beyond this point aren't copied....

Can you confirm?

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Cloning data grids... text properties problematic

Post by Klaus » Fri Mar 11, 2022 1:30 pm

Hi stam,

confirmed!
Funky, funky... :shock:


Best

Klaus

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Fri Mar 11, 2022 2:20 pm

Klaus wrote:
Fri Mar 11, 2022 1:30 pm
Hi stam,

confirmed!
Funky, funky... :shock:


Best

Klaus
Indeed!
Thanks Klaus - reported: https://quality.livecode.com/show_bug.cgi?id=23614

As far as i can tell it only affects these dgProps:
text color
text font
text size
text style
visible columns


so might as well just add manually - will try this and see how it goes.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Cloning data grids... text properties problematic

Post by dunbarx » Fri Mar 11, 2022 2:48 pm

Stam.

Can you create a dataSet of all the controls that comprise the DG? Every one of those controls has at least a unique ID, and so should be accessible when rebuilding the properties you are having trouble identifying.

Not sure any of the above makes sense.

Craig

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Fri Mar 11, 2022 4:45 pm

Hi Craig,
It does make sense (and it now works fully, by manually adding the missing 5 dgProps)

I’ll post the code when I can - actual work gets in the way right now.

Basically if you’re cloning in the *same* stack it will just use the existing data grid template substack and it will work fine. No need to recreate anything of the complexity of the DG.

For use in other stacks I *clone* this template substack, rename it so there’s no conflict with the source stack and the re-wire the 6 dpProps that point to the substack so it works correctly.

On brief tests both copying and cloning stacks (ie making another stack identical in all except the data it contains) works beautifully now - the missing dgProps are added manually (basically if you look in the IDE you won’t see the dgProp[“text size”] although it does exist - that’s the bug report above).

The only hiccup now is that if “cloning” - ie making the destination DG the same as the source DG, it doesn’t automatically update its appearance unless I manually “refresh data grid” in the properties panel.

I’ll share once more polished… and once more testing is done. I need to ensure that adding more data grids isn’t an issue for example.

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Cloning data grids... text properties problematic

Post by stam » Mon Mar 14, 2022 2:34 am

@klaus @craig thanks both for your inputs.

The problem my OP was concerned about was indeed solved by individually assigning the dgProps affecting row text.

As mentioned above these do not list in the IDE when viewing the dgProps custom properties (the anything after 'style' doesn't show) and don't copy when setting the customProperties["dgProps"] as a collection from source to destination.
But you can get/set the dgProps for text attributes (like dgProp["text size"]) individually. Weird and bug reported as above.

I've put together a solution that can clone a data grid (ie make another data grid the same was the source) or copy a data grid, either to the same or another stack and in my testing works fine.

If you have some spare time would be grateful if others could test to make sure it's OK (just make sure you're backed up first ;) )

EDIT - updated the stack as forgot to wire up widgets as buttons correctly :oops:
Attachments
skDataGridCloner.livecode.zip
(6.85 KiB) Downloaded 65 times
skDataGridCloner.jpg

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”