D16484: Add scratchpad plugin

Kevin Funk noreply at phabricator.kde.org
Tue Dec 11 08:51:04 GMT 2018


kfunk added inline comments.

INLINE COMMENTS

> aaronpuchert wrote in scratchpad.cpp:136
> It seems that the `QStandardItemModel` pointed to by `m_model` is owned by `Scratchpad`, so I wouldn't return a non-const pointer from a const method. But why not have both?
> 
>   QStandardItemModel* model();
>   const QStandardItemModel* model() const;
> 
> I'm not sure why the Qt documentation suggests that `const` “falls apart” there. It works pretty well for the STL, see e.g. std::vector::data <https://en.cppreference.com/w/cpp/container/vector/data>. The rule is not to generally not return non-const pointers/references from const functions, only when the returned pointer/reference points to something we consider a subobject. If it's a reference to something else that we don't own, the rule doesn't apply.

Please let's not create additional confusion for newcomers.  `QStandardItemModel* model() const` is the canonical way in the Qt world (cf. most other Qt API) if this method doesn't change the `this` object, so let's please stick to it. STL is a different beast.

Regarding:

> But why not have both?

This clutters the class interface, to be honest. You might have to create two versions of a getter, for no real gain.

REPOSITORY
  R32 KDevelop

BRANCH
  scratchpad

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

To: amhndu, #kdevelop, kfunk
Cc: aaronpuchert, kfunk, gregormi, brauch, kdevelop-devel, glebaccon, hase, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20181211/5949a79b/attachment.html>


More information about the KDevelop-devel mailing list