Skip to content

Commit c5b2688

Browse files
author
Steve Canny
committed
style: add BaseStyle.quick_format setter
1 parent 7dafb70 commit c5b2688

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

docx/oxml/styles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def qFormat_val(self):
121121
return False
122122
return qFormat.val
123123

124+
@qFormat_val.setter
125+
def qFormat_val(self, value):
126+
self._remove_qFormat()
127+
if bool(value):
128+
self._add_qFormat()
129+
124130
@property
125131
def semiHidden_val(self):
126132
"""

docx/styles/style.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def quick_style(self):
109109
"""
110110
return self._element.qFormat_val
111111

112+
@quick_style.setter
113+
def quick_style(self, value):
114+
self._element.qFormat_val = value
115+
112116
@property
113117
def style_id(self):
114118
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Feature: Get and set style properties
9292
| no setting | False |
9393

9494

95-
@wip
9695
Scenario Outline: Set quick-style value
9796
Given a style having quick-style set <setting>
9897
When I assign <new-value> to style.quick_style

tests/styles/test_style.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def it_knows_its_quick_style_setting(self, quick_get_fixture):
154154
style, expected_value = quick_get_fixture
155155
assert style.quick_style == expected_value
156156

157+
def it_can_change_its_quick_style_setting(self, quick_set_fixture):
158+
style, new_value, expected_xml = quick_set_fixture
159+
style.quick_style = new_value
160+
assert style._element.xml == expected_xml
161+
157162
def it_can_delete_itself_from_the_document(self, delete_fixture):
158163
style, styles, expected_xml = delete_fixture
159164
style.delete()
@@ -280,6 +285,19 @@ def quick_get_fixture(self, request):
280285
style = BaseStyle(element(style_cxml))
281286
return style, expected_value
282287

288+
@pytest.fixture(params=[
289+
('w:style', True, 'w:style/w:qFormat'),
290+
('w:style/w:qFormat', False, 'w:style'),
291+
('w:style/w:qFormat', True, 'w:style/w:qFormat'),
292+
('w:style/w:qFormat{w:val=0}', False, 'w:style'),
293+
('w:style/w:qFormat{w:val=on}', True, 'w:style/w:qFormat'),
294+
])
295+
def quick_set_fixture(self, request):
296+
style_cxml, new_value, expected_style_cxml = request.param
297+
style = BaseStyle(element(style_cxml))
298+
expected_xml = xml(expected_style_cxml)
299+
return style, new_value, expected_xml
300+
283301
@pytest.fixture(params=[
284302
('w:style', WD_STYLE_TYPE.PARAGRAPH),
285303
('w:style{w:type=paragraph}', WD_STYLE_TYPE.PARAGRAPH),

0 commit comments

Comments
 (0)