[PATCH] KFileDialog overwrite confirmation

Michael Pyne mpyne at purinchu.net
Mon Jul 14 02:55:40 BST 2008


On Sunday 13 July 2008, Rafael Fernández López wrote:
> Hi,
>
> > You could then have a non-virtual function in KAbstractFileWidget whose
> > implementation packages up the parameters for virtual_hook() and then
> > calls virtual_hook().  Subclasses would then have to reimplement
> > virtual_hook() if they needed to change the behavior though so it may not
> > be the best way I guess if there's an easier way.
>
> Cool !! Didn't notice it ! The question now is, does it need to be virtual
> ?


A class's implementation does not need to be but you would need to redefine 
virtual_hook() in the subclass if a different implementation is desired:


i.e.: (2 space shiftwidth for email purposes)


void KAbstractFileWidget::setConfirmOverride(bool b)
{
  virtual_hook(0, static_cast<void*>(&b)); // 0 is id of call
}


Now in a subclass:


void KFileWidget::virtual_hook(int id, void *data)
{
  if(id == 0) // setConfirmOverride(bool)
  {
    bool *b = static_cast<bool*>(data);
    setConfirmOverrideInternal(b); // not virtual
  }
  else
  {
    // Unhandled, pass it to superclass.
    KAbstractFileWidget::virtual_hook(id, data);
  }
}


Since the implementation is done in virtual_hook, and 
KAbstractFileWidget::setConfirmOverride() calls virtual_hook(), the right 
virtual implementation will always get called.  KFileWidget's implementation 
could be changed by handling virtual_hook() in a subclass.


Now if for whatever reason you override setConfirmOverride() in a subclass you 
would need to ensure calling virtual_hook() as setConfirmOverride() cannot be 
virtual, but there's really no reason to override setConfirmOverride in a 
subclass, the reimplementation belongs in virtual_hook().


Regards,
 - Michael Pyne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080713/94798eb4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080713/94798eb4/attachment.sig>


More information about the kde-core-devel mailing list