Manually namespace enum variants in SearchTerm

In protobuf "...enum values use C++ scoping rules, meaning that
enum values are siblings of their type, not children of it.
Therefore, [an enum variant] must be unique within [a message],
not just within [the enum.]"
So we must prefix enum variants with their enum's name, but can
also call them directly from the message namespace.
The protobuf crate is smart, though, and strips the prefixes.

(Simultaneously change some SearchTerm variant names.)
This commit is contained in:
RumovZ 2021-01-30 17:56:29 +01:00
parent 375794893f
commit b0890b0e47
5 changed files with 45 additions and 45 deletions

View File

@ -997,7 +997,7 @@ QTableView {{ gridline-color: {grid} }}
tr(TR.BROWSING_AGAIN_TODAY), tr(TR.BROWSING_AGAIN_TODAY),
SearchTerm( SearchTerm(
rated=SearchTerm.Rated( rated=SearchTerm.Rated(
days=1, rating=SearchTerm.Rating.ANSWER_BUTTON_1 days=1, rating=SearchTerm.RATING_AGAIN
) )
), ),
), ),
@ -1013,39 +1013,39 @@ QTableView {{ gridline-color: {grid} }}
( (
( (
tr(TR.ACTIONS_NEW), tr(TR.ACTIONS_NEW),
SearchTerm(card_state=SearchTerm.CardState.NEW), SearchTerm(card_state=SearchTerm.CARD_STATE_NEW),
), ),
( (
tr(TR.SCHEDULING_LEARNING), tr(TR.SCHEDULING_LEARNING),
SearchTerm(card_state=SearchTerm.CardState.LEARN), SearchTerm(card_state=SearchTerm.CARD_STATE_LEARN),
), ),
( (
tr(TR.SCHEDULING_REVIEW), tr(TR.SCHEDULING_REVIEW),
SearchTerm(card_state=SearchTerm.CardState.REVIEW), SearchTerm(card_state=SearchTerm.CARD_STATE_REVIEW),
), ),
( (
tr(TR.FILTERING_IS_DUE), tr(TR.FILTERING_IS_DUE),
SearchTerm(card_state=SearchTerm.CardState.DUE), SearchTerm(card_state=SearchTerm.CARD_STATE_DUE),
), ),
None, None,
( (
tr(TR.BROWSING_SUSPENDED), tr(TR.BROWSING_SUSPENDED),
SearchTerm(card_state=SearchTerm.CardState.SUSPENDED), SearchTerm(card_state=SearchTerm.CARD_STATE_SUSPENDED),
), ),
( (
tr(TR.BROWSING_BURIED), tr(TR.BROWSING_BURIED),
SearchTerm(card_state=SearchTerm.CardState.BURIED), SearchTerm(card_state=SearchTerm.CARD_STATE_BURIED),
), ),
None, None,
(tr(TR.ACTIONS_RED_FLAG), SearchTerm(flag=SearchTerm.Flag.RED)), (tr(TR.ACTIONS_RED_FLAG), SearchTerm(flag=SearchTerm.FLAG_RED)),
( (
tr(TR.ACTIONS_ORANGE_FLAG), tr(TR.ACTIONS_ORANGE_FLAG),
SearchTerm(flag=SearchTerm.Flag.ORANGE), SearchTerm(flag=SearchTerm.FLAG_ORANGE),
), ),
(tr(TR.ACTIONS_GREEN_FLAG), SearchTerm(flag=SearchTerm.Flag.GREEN)), (tr(TR.ACTIONS_GREEN_FLAG), SearchTerm(flag=SearchTerm.FLAG_GREEN)),
(tr(TR.ACTIONS_BLUE_FLAG), SearchTerm(flag=SearchTerm.Flag.BLUE)), (tr(TR.ACTIONS_BLUE_FLAG), SearchTerm(flag=SearchTerm.FLAG_BLUE)),
(tr(TR.BROWSING_NO_FLAG), SearchTerm(flag=SearchTerm.Flag.WITHOUT)), (tr(TR.BROWSING_NO_FLAG), SearchTerm(flag=SearchTerm.FLAG_NONE)),
(tr(TR.BROWSING_ANY_FLAG), SearchTerm(flag=SearchTerm.Flag.ANY)), (tr(TR.BROWSING_ANY_FLAG), SearchTerm(flag=SearchTerm.FLAG_ANY)),
) )
) )
) )

View File

@ -163,7 +163,7 @@ class CustomStudy(QDialog):
search = self.mw.col.build_search_string( search = self.mw.col.build_search_string(
SearchTerm( SearchTerm(
rated=SearchTerm.Rated( rated=SearchTerm.Rated(
days=spin, rating=SearchTerm.Rating.ANSWER_BUTTON_1 days=spin, rating=SearchTerm.RATING_AGAIN
) )
) )
) )
@ -175,7 +175,7 @@ class CustomStudy(QDialog):
dyn["resched"] = True dyn["resched"] = True
elif i == RADIO_PREVIEW: elif i == RADIO_PREVIEW:
search = self.mw.col.build_search_string( search = self.mw.col.build_search_string(
SearchTerm(card_state=SearchTerm.CardState.NEW), SearchTerm(card_state=SearchTerm.CARD_STATE_NEW),
SearchTerm(added_in_days=spin), SearchTerm(added_in_days=spin),
) )
dyn["terms"][0] = [search, DYN_MAX_SIZE, DYN_OLDEST] dyn["terms"][0] = [search, DYN_MAX_SIZE, DYN_OLDEST]
@ -184,19 +184,19 @@ class CustomStudy(QDialog):
type = f.cardType.currentRow() type = f.cardType.currentRow()
if type == TYPE_NEW: if type == TYPE_NEW:
terms = self.mw.col.build_search_string( terms = self.mw.col.build_search_string(
SearchTerm(card_state=SearchTerm.CardState.NEW) SearchTerm(card_state=SearchTerm.CARD_STATE_NEW)
) )
ord = DYN_ADDED ord = DYN_ADDED
dyn["resched"] = True dyn["resched"] = True
elif type == TYPE_DUE: elif type == TYPE_DUE:
terms = self.mw.col.build_search_string( terms = self.mw.col.build_search_string(
SearchTerm(card_state=SearchTerm.CardState.DUE) SearchTerm(card_state=SearchTerm.CARD_STATE_DUE)
) )
ord = DYN_DUE ord = DYN_DUE
dyn["resched"] = True dyn["resched"] = True
elif type == TYPE_REVIEW: elif type == TYPE_REVIEW:
terms = self.mw.col.build_search_string( terms = self.mw.col.build_search_string(
SearchTerm(card_state=SearchTerm.CardState.NEW), negate=True SearchTerm(card_state=SearchTerm.CARD_STATE_NEW), negate=True
) )
ord = DYN_RANDOM ord = DYN_RANDOM
dyn["resched"] = True dyn["resched"] = True

View File

@ -48,11 +48,11 @@ class DeckConf(QDialog):
self.loadConf() self.loadConf()
if search: if search:
search = self.mw.col.build_search_string( search = self.mw.col.build_search_string(
search, SearchTerm(card_state=SearchTerm.CardState.DUE) search, SearchTerm(card_state=SearchTerm.CARD_STATE_DUE)
) )
self.form.search.setText(search) self.form.search.setText(search)
search_2 = self.mw.col.build_search_string( search_2 = self.mw.col.build_search_string(
search, SearchTerm(card_state=SearchTerm.CardState.NEW) search, SearchTerm(card_state=SearchTerm.CARD_STATE_NEW)
) )
self.form.search_2.setText(search_2) self.form.search_2.setText(search_2)
self.form.search.selectAll() self.form.search.selectAll()

View File

@ -766,32 +766,32 @@ message SearchTerm {
string first_field = 2; string first_field = 2;
} }
enum Flag { enum Flag {
WITHOUT = 0; FLAG_NONE = 0;
ANY = 1; FLAG_ANY = 1;
RED = 2; FLAG_RED = 2;
ORANGE = 3; FLAG_ORANGE = 3;
GREEN = 4; FLAG_GREEN = 4;
BLUE = 5; FLAG_BLUE = 5;
} }
enum Rating { enum Rating {
ANY_ANSWER_BUTTON = 0; RATING_ANY = 0;
ANSWER_BUTTON_1 = 1; RATING_AGAIN = 1;
ANSWER_BUTTON_2 = 2; RATING_HARD = 2;
ANSWER_BUTTON_3 = 3; RATING_GOOD = 3;
ANSWER_BUTTON_4 = 4; RATING_EASY = 4;
MANUAL_RESCHEDULE = 5; RATING_BY_RESCHEDULE = 5;
} }
message Rated { message Rated {
uint32 days = 1; uint32 days = 1;
Rating rating = 2; Rating rating = 2;
} }
enum CardState { enum CardState {
NEW = 0; CARD_STATE_NEW = 0;
LEARN = 1; CARD_STATE_LEARN = 1;
REVIEW = 2; CARD_STATE_REVIEW = 2;
DUE = 3; CARD_STATE_DUE = 3;
SUSPENDED = 4; CARD_STATE_SUSPENDED = 4;
BURIED = 5; CARD_STATE_BURIED = 5;
} }
message IdList { message IdList {
repeated int64 ids = 1; repeated int64 ids = 1;

View File

@ -335,7 +335,7 @@ impl From<pb::SearchTerm> for Node<'_> {
.into(), .into(),
)), )),
Filter::Flag(flag) => match Flag::from_i32(flag).unwrap_or(Flag::Any) { Filter::Flag(flag) => match Flag::from_i32(flag).unwrap_or(Flag::Any) {
Flag::Without => Node::Search(SearchNode::Flag(0)), Flag::None => Node::Search(SearchNode::Flag(0)),
Flag::Any => Node::Not(Box::new(Node::Search(SearchNode::Flag(0)))), Flag::Any => Node::Not(Box::new(Node::Search(SearchNode::Flag(0)))),
Flag::Red => Node::Search(SearchNode::Flag(1)), Flag::Red => Node::Search(SearchNode::Flag(1)),
Flag::Orange => Node::Search(SearchNode::Flag(2)), Flag::Orange => Node::Search(SearchNode::Flag(2)),
@ -358,12 +358,12 @@ impl From<BoolSeparatorProto> for BoolSeparator {
impl From<pb::search_term::Rating> for EaseKind { impl From<pb::search_term::Rating> for EaseKind {
fn from(r: pb::search_term::Rating) -> Self { fn from(r: pb::search_term::Rating) -> Self {
match r { match r {
pb::search_term::Rating::AnswerButton1 => EaseKind::AnswerButton(1), pb::search_term::Rating::Again => EaseKind::AnswerButton(1),
pb::search_term::Rating::AnswerButton2 => EaseKind::AnswerButton(2), pb::search_term::Rating::Hard => EaseKind::AnswerButton(2),
pb::search_term::Rating::AnswerButton3 => EaseKind::AnswerButton(3), pb::search_term::Rating::Good => EaseKind::AnswerButton(3),
pb::search_term::Rating::AnswerButton4 => EaseKind::AnswerButton(4), pb::search_term::Rating::Easy => EaseKind::AnswerButton(4),
pb::search_term::Rating::AnyAnswerButton => EaseKind::AnyAnswerButton, pb::search_term::Rating::Any => EaseKind::AnyAnswerButton,
pb::search_term::Rating::ManualReschedule => EaseKind::ManualReschedule, pb::search_term::Rating::ByReschedule => EaseKind::ManualReschedule,
} }
} }
} }