Comparing KFileItems

David Faure faure at kde.org
Tue Oct 23 10:25:48 BST 2012


On Monday 22 October 2012 20:10:23 Frank Reininghaus wrote:
> KFileItem.diff
> diff --git a/kio/kio/kfileitem.cpp b/kio/kio/kfileitem.cpp
> index 482c4b6..ad62246 100644
> --- a/kio/kio/kfileitem.cpp
> +++ b/kio/kio/kfileitem.cpp
> @@ -1307,13 +1307,12 @@ bool KFileItem::cmp( const KFileItem & item ) const
>  
>  bool KFileItem::operator==(const KFileItem& other) const
>  {
> -    // is this enough?
> -    return d == other.d;
> +    return d == other.d || d->m_url == other.d->m_url;
>  }

Yes.

>  bool KFileItem::operator!=(const KFileItem& other) const
>  {
> -    return d != other.d;
> +    return d != other.d && d->m_url != other.d->m_url;
>  }

Or return !operator==(other), inline, for easier maintainance.

>  #ifndef KDE_NO_DEPRECATED
> diff --git a/kio/tests/kfileitemtest.cpp b/kio/tests/kfileitemtest.cpp
> index fa88af7..1ac5d98 100644
> --- a/kio/tests/kfileitemtest.cpp
> +++ b/kio/tests/kfileitemtest.cpp
> @@ -108,11 +108,12 @@ void KFileItemTest::testDetach()
>      fileItem2.mark();
>      QVERIFY(fileItem2.isMarked());
>      QVERIFY(!fileItem.isMarked());
> -    QVERIFY(fileItem != fileItem2);
> +    QVERIFY(fileItem == fileItem2);

The point of that test was to ensure that detaching did happen.
Maybe add "friend class KFileItemTest;" and compare the value of the d 
pointers?
In addition to QVERIFY(fileItem == fileItem2), of course.

>      fileItem = fileItem2;
>      QVERIFY(fileItem2.isMarked());
>      QVERIFY(fileItem == fileItem2);
> +    QVERIFY(!(fileItem != fileItem2));
>  }
>  
>  void KFileItemTest::testBasic()
> @@ -246,7 +247,8 @@ void KFileItemTest::testCmp()
>  
>      KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown,
> KUrl(file.fileName()), true /*on demand*/); KFileItem
> fileItem2(KFileItem::Unknown, KFileItem::Unknown, KUrl(file.fileName()),
> false); -    QVERIFY(fileItem != fileItem2); // created independently so
> not 'equal' +    QVERIFY(fileItem == fileItem2); // created independently,
> but still 'equal' +    QVERIFY(!(fileItem != fileItem2));
>      QVERIFY(fileItem.cmp(fileItem2));

Thank you kmail for messing up the lines in the reply...
The change looks good though.

Could you add a bit of docu while at it, about the difference between == and 
cmp as discussed here? Thanks.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5





More information about the kde-core-devel mailing list