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),
SearchTerm(
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),
SearchTerm(card_state=SearchTerm.CardState.NEW),
SearchTerm(card_state=SearchTerm.CARD_STATE_NEW),
),
(
tr(TR.SCHEDULING_LEARNING),
SearchTerm(card_state=SearchTerm.CardState.LEARN),
SearchTerm(card_state=SearchTerm.CARD_STATE_LEARN),
),
(
tr(TR.SCHEDULING_REVIEW),
SearchTerm(card_state=SearchTerm.CardState.REVIEW),
SearchTerm(card_state=SearchTerm.CARD_STATE_REVIEW),
),
(
tr(TR.FILTERING_IS_DUE),
SearchTerm(card_state=SearchTerm.CardState.DUE),
SearchTerm(card_state=SearchTerm.CARD_STATE_DUE),
),
None,
(
tr(TR.BROWSING_SUSPENDED),
SearchTerm(card_state=SearchTerm.CardState.SUSPENDED),
SearchTerm(card_state=SearchTerm.CARD_STATE_SUSPENDED),
),
(
tr(TR.BROWSING_BURIED),
SearchTerm(card_state=SearchTerm.CardState.BURIED),
SearchTerm(card_state=SearchTerm.CARD_STATE_BURIED),
),
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),
SearchTerm(flag=SearchTerm.Flag.ORANGE),
SearchTerm(flag=SearchTerm.FLAG_ORANGE),
),
(tr(TR.ACTIONS_GREEN_FLAG), SearchTerm(flag=SearchTerm.Flag.GREEN)),
(tr(TR.ACTIONS_BLUE_FLAG), SearchTerm(flag=SearchTerm.Flag.BLUE)),
(tr(TR.BROWSING_NO_FLAG), SearchTerm(flag=SearchTerm.Flag.WITHOUT)),
(tr(TR.BROWSING_ANY_FLAG), SearchTerm(flag=SearchTerm.Flag.ANY)),
(tr(TR.ACTIONS_GREEN_FLAG), SearchTerm(flag=SearchTerm.FLAG_GREEN)),
(tr(TR.ACTIONS_BLUE_FLAG), SearchTerm(flag=SearchTerm.FLAG_BLUE)),
(tr(TR.BROWSING_NO_FLAG), SearchTerm(flag=SearchTerm.FLAG_NONE)),
(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(
SearchTerm(
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
elif i == RADIO_PREVIEW:
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),
)
dyn["terms"][0] = [search, DYN_MAX_SIZE, DYN_OLDEST]
@ -184,19 +184,19 @@ class CustomStudy(QDialog):
type = f.cardType.currentRow()
if type == TYPE_NEW:
terms = self.mw.col.build_search_string(
SearchTerm(card_state=SearchTerm.CardState.NEW)
SearchTerm(card_state=SearchTerm.CARD_STATE_NEW)
)
ord = DYN_ADDED
dyn["resched"] = True
elif type == TYPE_DUE:
terms = self.mw.col.build_search_string(
SearchTerm(card_state=SearchTerm.CardState.DUE)
SearchTerm(card_state=SearchTerm.CARD_STATE_DUE)
)
ord = DYN_DUE
dyn["resched"] = True
elif type == TYPE_REVIEW:
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
dyn["resched"] = True

View File

@ -48,11 +48,11 @@ class DeckConf(QDialog):
self.loadConf()
if search:
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)
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.selectAll()

View File

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

View File

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