Cloning/copying a widget?

I am trying to reuse a combo box over multiple tabs (keeping the same entries and selection).
I’ve tried using the methods Clone() and Copy(), and neither work. From what I gather, it is not possible to share a widget with different parent frames. So I guess a deep copy is what I want. fCombo1 and fCombo2 are in separate tabs.

The original combo box is defined as:

TGComboBox *fCombo1 = new TGComboBox(fBottom1, 88);
int i;
char tmp[28];
for (i = 0; i < 28; i++) 
{
  sprintf(tmp, "Channel %i", i+1);
  fCombo1->AddEntry(tmp, i+1);
}
fBottom1->AddFrame(fCombo1);
fCombo1->Resize(90,20);

Using Copy():

TGComboBox *fCombo2 = new TGComboBox(fBottom2, 88);
fCombo1->Copy(*fCombo2);
fCombo2->ReparentWindow(fBottom2);
fBottom2->AddFrame(fCombo2,buttonLayout);

This makes a combo box in the next tab, but it is not of the same size (unless I call Resize again) and is empty.

Using Clone():

TGComboBox *fCombo2 = (TGComboBox*)fCombo1->Clone();
fCombo2->ReparentWindow(fBottom2);
fBottom2->AddFrame(fCombo2,buttonLayout);

This produces the same results as before, but it now gives me this message:
Error in TGWidget::Streamer: version id <=0 in ClassDef, dummy Streamer() called
Error in TGWidget::Streamer: version id <=0 in ClassDef, dummy Streamer() called
Error in TGWidget::Streamer: version id <=0 in ClassDef, dummy Streamer() called
Error in TGWidget::Streamer: version id <=0 in ClassDef, dummy Streamer() called

Using ‘=’ operator:

*fCombo2 = *fCombo1;
fCombo2->ReparentWindow(fBottom2);
fBottom2->AddFrame(fCombo2,buttonLayout);

This gives an error:

Error: can not call private or protected function myGUI.C:135:
/usr/local/root/lib/libHistPainter.so -1 TGCompositeFrame& TGCompositeFrame::operator=(const TGCompositeFrame&);
Calling : TGCompositeFrame::operator=(TGComboBox);
Match rank: file line signature

  • 10002 /usr/local/root/lib/libHistPainter.so -1 TGCompositeFrame& TGCompositeFrame::operator=(const TGCompositeFrame&);
    *** Interpreter error recovered ***

Any ideas?

Hi,

The Clone() and Copy() methods are inherited from TObject, and have not been overridden in the GUI classes. So I’m afraid you’ll have to do it yourself.

Cheers, Bertrand.

[quote=“bellenot”]Hi,

The Clone() and Copy() methods are inherited from TObject, and have not been overridden in the GUI classes. So I’m afraid you’ll have to do it yourself.

Cheers, Bertrand.[/quote]

If Clone() and Copy() do not work with TGComboBox, maybe they shouldn’t be listed in the ROOT reference.

Hi,

If you select (check) “Show inherited” in the web page, it shows the inherited methods, with name of the base class (for example: virtual TObject* TObject::Clone(const char* newname = “”) const):


And if you uncheck it, it simply doesn’t show them:



Cheers, Bertrand.

[quote=“bellenot”]Hi,

If you select (check) “Show inherited” in the web page, it shows the inherited methods, with name of the base class (for example: virtual TObject* TObject::Clone(const char* newname = “”) const):

And if you uncheck it, it simply doesn’t show them:
Cheers, Bertrand.[/quote]

Right, and how do I know which inherited methods have been overridden or not?

Seems esoteric to inherit a method and include it in the reference guide when it doesn’t work. It makes using ROOT very difficult.

By looking at the header file or even at the source file.

Cheers, Bertrand

[quote=“bellenot”]By looking at the header file or even at the source file.

Cheers, Bertrand[/quote]

You could answer any question about ROOT with “look at the source code”,
but I thought one of the purposes of object oriented programming was to hide source code via abstraction and encapsulation.

I don’t have to read source code when using any of the non-inherited methods, so presumably this is the point of having the reference.

So what do you propose to solve the problem?

EDIT: BTW, if you uncheck the “Show inherited” checkbox, you see if a method is overridden…

[quote=“bellenot”]So what do you propose to solve the problem?

EDIT: BTW, if you uncheck the “Show inherited” checkbox, you see if a method is overridden…[/quote]

If you check the “Show Inherited” checkbox, you see if a method is inherited.
Unless you mean to say that none of the inherited methods have been implemented in their respective classes (which defeats the purpose of inheritance).

To solve the problem, you would have to add something to the automatic documentation generator (TMAP or whatever) which checks for this, and grays out the inherited methods in the reference which lack implementation.

[quote]Seems esoteric to inherit a method and include it in the reference guide when it doesn’t work.[/quote]The documentation tool really can not know that the inherited routine does not work.

[quote]To solve the problem, you would have to add something to the automatic documentation generator (TMAP or whatever) which checks for this, and grays out the inherited methods in the reference which lack implementation.[/quote]‘Lacking an implementation’ is a poor estimator of whether the function does what it needs to do. In the case you are referring to, we should indeed go and overload the Copy/Clone method if the default implementation is not appropriate (if only to document the fact and add some error message).

Cheers,
Philippe.