D25315: KDirModel: implement showing "/" as a root node, optionally

David Faure noreply at phabricator.kde.org
Fri Feb 28 21:05:06 GMT 2020


dfaure planned changes to this revision.
dfaure added a comment.


  In D25315#619436 <https://phabricator.kde.org/D25315#619436>, @rrosch wrote:
  
  > Tested on patched KF5 5.64, on Fedora 30 (32bit)... root node shows up! I had to change the call in my code that was originally:
  >
  >   model->dirLister()->openUrl(QUrl::fromLocalFile("/"), KDirLister::Keep); 
  >
  > [to]       model->openUrl(QUrl::fromLocalFile("/"), KDirModel::ShowRoot);
  >  and don't really know the implications of the change at this point. (Will it "Keep"? Does it matter that I now call the model's openURL vs the dirLister's?)
  
  
  It's part of the documentation for this change, that you're actually supposed to call model->openUrl(). So yes it matters :-)
  
  Keep only matters for further calls to openUrl, not the first one. It's about whether to *add* or *replace* the currently open URL.
  KDirModel takes care of that.
  
  > I couldn't however get the following to work:
  > 
  >   QModelIndex index = getIndexFromUrl("/home/myuser");
  
  Invalid URL, that's a path, not a URL. You need QUrl::fromLocalFile().
  
  >   if (index.isValid()) {
  >       treeView->setRootIndex(index.parent());
  >   }
  > 
  >   
  
  
  
  > Which should show the node for "/home" as the root, but is instead giving me a flat listing of all the child nodes without "/home" as the root.
  
  Oh, hmm, that's not how setRootIndex works (that's a *view* feature, we can't change that).
  I changed the model to have one more node for "/", while I see now that what you want is that it *always* shows a root node even when the root is another directory.
  
  > (Also, it would be great to have a setRootPath() that works in conjunction to expandToUrl or openUrl, to save processing cycles wasted on loading the parts of the model that won't be shown in the new rootIndex, like https://doc.qt.io/qt-5/qfilesystemmodel.html#setRootPath )
  
  Yes it sounds like that's exactly what's needed in KDirModel. Damn, I need to rework all this then.
  
  > As it is relevant, I also tested the patch at http://www.davidfaure.fr/2019/kdirmodel_haschildren.diff for `hasChildren()`, which works as expected! Thank you!
  
  Thanks, posted as D27731 <https://phabricator.kde.org/D27731>

REPOSITORY
  R241 KIO

REVISION DETAIL
  https://phabricator.kde.org/D25315

To: dfaure, stefanocrocco, elvisangelaccio, meven, apol
Cc: rrosch, kde-frameworks-devel, LeGast00n, cblack, GB_2, michaelh, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20200228/ca81d6bb/attachment.html>


More information about the Kde-frameworks-devel mailing list