Lifted method access modes in KURLDrag and KMultipleDrag
divided.mind at gmail.com
Thu Aug 11 00:44:45 BST 2005
On Wednesday, 10 of August 2005 03:03, David Faure wrote:
> On Saturday 06 August 2005 18:22, Rafał Rzepecki wrote:
> > Currently I have worked around the problem by just casting the KURLDrag
> > onto an ancestor and then calling the method (which is public there). But
> > I feel this should be corrected. KMultipleDrag also has this problem.
> Yep, I'm guilty for both ;)
> (OTOH I can't think of a reason why someone would want to call
> format or encodedData directly, those are being called by the receiver
> side, which doesn't know which QDragObject subclass is being used...)
Imagine implementing a custom QDragObject, which should provide URIs beside
whatever other formats. One way of doing this is subclassing KURLDrag, but
this is sometimes not desirable. Another way would be to have a private
KURLDrag object member, and delegate them calls whenever appropriate. For
char *MyDrag::format( int i ) const
if ( i == 0 ) return "application/x-foo";
if ( iHaveAnotherFormat() && i == 1 ) return "application/x-bar";
i -= 1 + ( iHaveAnotherFormat() ? 1 : 0 );
return mUrlDrag->format( i );
Because KURLDrag::format() was protected, you had to have mUrlDrag as a
QDragObject*/QStoredDrag* or QUriDrag*.
> > Another thing about KURLDrag is that it lacks setURL() method. QTextDrag,
> > QUriDrag and QImageDrag all have set*() methods. But one can't use
> > QUriDrag's method to set the uris, as it bypasses KURLDrag's internals
> > and breaks things. There should be a method to set the URLs, and the
> > QUriDrag's method should be overrided not to bypass KURLDrag's internals,
> > or at least set private to prevent abuse.
> Indeed. (well we can hide it by simply naming it KURLDrag::setUris( const
> KURL::List& uris ), this will automatically hide the one from QUriDrag
> ("overloaded virtual" C++ feature). Ah, there's setFileNames and
> setUnicodeUris too, though. Isn't it a bit dirty to make those private in a
> subclass even though they're not virtual? Well it's the best we can do I
Yes, that would be a bit dirty. A good solution would be to override
setUris( const QStringList & ). It's just merely a matter of a wrapper to
translate from QT-style URI strings into KURL::List and calling
setUris( const KURL::List & ). This will solve the problem because
setFileNames and setUnicodeUris both use setUris() internally (and it would
actually be very bad design if they wouldn't).
Unless we don't want to support these methods for whatever reason.
> > I can correct these problems, but I don't have SVN kdelibs installed and
> > have a slow machine, so it would take ages to compile here, so I'd rather
> > have someone else fix it or at least help me test the patches I provide,
> > so that I need not compile the whole kdelibs.
> Ah, hmm, OK. I did the method access change, I'll be happy to commit your
> setURLs or setUris patch once it exists ;)
Ok, thanks, I'll get back to you once they're ready.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
More information about the kde-core-devel