| 38 | } |
| 39 | |
| 40 | Query Sheet::query(const StatefulStyle& compound) |
| 41 | { |
| 42 | const Style* firstStyle = &compound.style(); |
| 43 | const Style* style; |
| 44 | Query query; |
| 45 | std::string name; |
| 46 | |
| 47 | // We create a string with all states. This is the style with |
| 48 | // highest priority. |
| 49 | std::string states; |
| 50 | for (States::const_iterator |
| 51 | state_it = compound.states().begin(), |
| 52 | state_end = compound.states().end(); state_it != state_end; ++state_it) { |
| 53 | states += StatefulStyle::kSeparator; |
| 54 | states += (*state_it)->name(); |
| 55 | } |
| 56 | |
| 57 | // Query by priority for the following styles: |
| 58 | // style:state1:state2:... |
| 59 | // ... |
| 60 | // base1:state1:state2:... |
| 61 | // base0:state1:state2:... |
| 62 | for (style=firstStyle; style != NULL; style=style->base()) { |
| 63 | name = style->name(); |
| 64 | name += states; |
| 65 | |
| 66 | const Style* style2 = m_styles[name]; |
| 67 | if (style2) |
| 68 | query.addFromStyle(style2); |
| 69 | } |
| 70 | |
| 71 | // Query for: |
| 72 | // style:state2 |
| 73 | // style:state1 |
| 74 | // ... |
| 75 | // base1:state2 |
| 76 | // base1:state1 |
| 77 | // base0:state2 |
| 78 | // base0:state1 |
| 79 | for (States::const_reverse_iterator |
| 80 | state_it = compound.states().rbegin(), |
| 81 | state_end = compound.states().rend(); state_it != state_end; ++state_it) { |
| 82 | for (style=firstStyle; style != NULL; style=style->base()) { |
| 83 | name = style->name(); |
| 84 | name += StatefulStyle::kSeparator; |
| 85 | name += (*state_it)->name(); |
| 86 | |
| 87 | const Style* style2 = m_styles[name]; |
| 88 | if (style2) |
| 89 | query.addFromStyle(style2); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Query for: |
| 94 | // style |
| 95 | // ... |
| 96 | // base1 |
| 97 | // base0 |