[Qt-interest] QAbstractItemModel::match and MatchFlags
Eric Clark
eclark at ara.com
Mon Jun 20 18:59:02 CEST 2011
Thank you Andre. I see what you are saying about how to test the flag, but it still seems like an error in the code. I am truly surprised that none of the Qt folks have responded to this post. I agree that what you said MatchContains should not equal MatchStartsWith | MatchEndsWith. The only reason I pointed this out is because it seems as though that is what they wanted to do, but made an error when doing it. It is true though that if you set the MatchContains flag, that MatchStartsWith and MatchEndsWith is a valid solution to MatchContains. They are not the only solutions, but they are valid for being contained within the string.
Any Qt folks out there have any comments about this? Or should I just go ahead and report it as a bug and hope that it gets fixed?
Thanks,
Eric
From: qt-interest-bounces+eclark=ara.com at qt.nokia.com [mailto:qt-interest-bounces+eclark=ara.com at qt.nokia.com] On Behalf Of Andre Somers
Sent: Saturday, June 18, 2011 1:16 AM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QAbstractItemModel::match and MatchFlags
Op 18-6-2011 0:51, Eric Clark schreef:
Hello Everyone,
I have been looking at this for quite some time trying to figure why it is the way it is because the Qt guys are usually pretty darn good and usually have a very good reason for why they do things the way they do, but I cannot figure this one out. I am making a custom match function in my model and I am trying to handle all of the flags that can be passed into the function, but there are a few flags that are really throwing me off:
MatchFlag::MatchContains = 1
MatchFlag::MatchStartsWith = 2
MatchFlag::MatchEndsWIth = 3
The flag for MatchEndsWith has two bits flipped, and the two bits (position 0 and 1) match the bits for MatchContains and MatchStartsWith. In other words:
MatchEndsWith == MatchContains | MatchStartsWith;
This seems very wrong to me. To me, it seems like it should really be:
MatchFlag::MatchContains = 3
MatchFlag::MatchStartsWith = 2
MatchFlag::MatchEndsWIth = 1
MatchContains == MatchEndsWith | MatchStartsWith;
I do not see how setting the ends with flag should also be setting the starts with and contains flag. I hope I explained this right. Please can someone explain to me what I am seeing? Is this my imagination or this an actual error in the code?
Good question!
If I look at the Qt::MatchFlags documentation, it seems like the flags are a combination of a traditional enum with some flags functionality added on top. I disagree that MatchContains == MatchEndsWith | MatchStartsWith. That just isn't true. It seems to me, that you need to use it like this:
if ((matchValue && 0xF) == myRequiredMatchType) { ...
and test for the modifier flags (with values 16 and up) using the normal
matchValue.testFlag(Qt::MatchRecursive);
I must say: it is not very pretty, because even though it is a Flags, you can not use testFlag() on the lower end of the values.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110620/59950a16/attachment.html
More information about the Qt-interest-old
mailing list