-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default Model Values #123
Default Model Values #123
Conversation
0fe571e
to
2fce30a
Compare
Models/MessageModel.cpp
Outdated
@@ -131,7 +132,7 @@ QVariant MessageModel::data(const QModelIndex &index, int role) const { | |||
} | |||
|
|||
// If the field has't been initialized return an invalid QVariant. (see QVariant.isValid()) | |||
if (!refl->HasField(*_protobuf, field)) return QVariant(); | |||
if (HasField && !refl->HasField(*_protobuf, field)) return QVariant(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rusky says we should treat this as an error/with an assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; you can enforce the optimization of HasField by making a separate if constexpr
for it, but the optimizer should have no trouble with it as-is.
Models/RepeatedMessageModel.cpp
Outdated
@@ -41,5 +41,7 @@ bool RepeatedMessageModel::setData(const QModelIndex &index, const QVariant &val | |||
} | |||
|
|||
QVariant RepeatedMessageModel::data(const QModelIndex &index, int role) const { | |||
// protobuf field number with 0 is impossible, use as sentinel to get model itself | |||
if (index.column() == 0) return QVariant::fromValue(_subModels[index.row()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any implications of this? This is otherwise just an error condition. Unless later we add field number offsets to MessageModel so that we can use field number 0 for whatever reason fundies wanted to. We could possibly just add a custom role for this instead too.
This is how Josh would like to resolve #122 by making it explicit when you are ok accepting the default value from the model. I had to also allow column 0 as a special sentinel for
RepeatedMessageModel
to return a pointer to the requested model so that I have an actual way to calldataOrDefault
on repeated messages. The hack avoids the complication of having to adddataOrDefault
on all the higher level models and interfaces, such as the sort filter proxy model.