Skip to content

Commit a6db458

Browse files
committed
fix(page_layout): apply margins to current page in Apply To selection
Apply Margins used to skip m_pageId even when the dialog included the current page (e.g. "This page and the following every other page"), so alternating margin workflows did not persist settings for the active page. Add PageSequence unit tests for the 75-page every-other pattern from #144.
1 parent 04cb736 commit a6db458

3 files changed

Lines changed: 84 additions & 4 deletions

File tree

src/core/filters/page_layout/OptionsWidget.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ void OptionsWidget::applyMargins(const std::set<PageId>& pages,
319319

320320
const bool autoMarginsEnabled = m_settings->isPageAutoMarginsEnabled(m_pageId);
321321
for (const PageId& pageId : pages) {
322-
if (pageId == m_pageId) {
323-
continue;
324-
}
325-
326322
m_settings->setPageAutoMarginsEnabled(pageId, autoMarginsEnabled);
327323
if (autoMarginsEnabled) {
328324
m_settings->invalidateContentSize(pageId);

src/core/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(sources
77
TestMargins.cpp
88
TestPageId.cpp
99
TestPageRange.cpp
10+
TestPageSequence.cpp
1011
TestSelectContentApply.cpp
1112
TestSmartFilenameOrdering.cpp
1213
TestUnits.cpp)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (C) 2019 Joseph Artsimovich <joseph.artsimovich@gmail.com>, 4lex4 <4lex49@zoho.com>
2+
// Use of this source code is governed by the GNU GPLv3 license that can be found in the LICENSE file.
3+
4+
#include <ImageId.h>
5+
#include <PageId.h>
6+
#include <PageInfo.h>
7+
#include <PageSequence.h>
8+
9+
#include <boost/test/unit_test.hpp>
10+
#include <set>
11+
#include <vector>
12+
13+
namespace Tests {
14+
15+
static PageInfo makePage(const char* path, const int imageIdx) {
16+
PageInfo info;
17+
info.setId(PageId(ImageId(path, imageIdx), PageId::SINGLE_PAGE));
18+
return info;
19+
}
20+
21+
BOOST_AUTO_TEST_SUITE(PageSequenceTestSuite)
22+
23+
BOOST_AUTO_TEST_CASE(select_this_page_and_following_every_other_from_first) {
24+
PageSequence seq;
25+
std::vector<PageInfo> pages;
26+
for (int i = 0; i < 75; ++i) {
27+
pages.push_back(makePage("/scan", i));
28+
seq.append(pages.back());
29+
}
30+
31+
const PageId base = pages[0].id();
32+
const std::set<PageId> result = seq.selectThisPageAndFollowingEveryOther(base);
33+
34+
BOOST_CHECK_EQUAL(result.size(), 38u);
35+
for (int i = 0; i < 75; i += 2) {
36+
BOOST_CHECK(result.count(pages[static_cast<size_t>(i)].id()) == 1);
37+
}
38+
for (int i = 1; i < 75; i += 2) {
39+
BOOST_CHECK(result.count(pages[static_cast<size_t>(i)].id()) == 0);
40+
}
41+
}
42+
43+
BOOST_AUTO_TEST_CASE(select_this_page_and_following_every_other_from_second) {
44+
PageSequence seq;
45+
std::vector<PageInfo> pages;
46+
for (int i = 0; i < 75; ++i) {
47+
pages.push_back(makePage("/scan", i));
48+
seq.append(pages.back());
49+
}
50+
51+
const PageId base = pages[1].id();
52+
const std::set<PageId> result = seq.selectThisPageAndFollowingEveryOther(base);
53+
54+
BOOST_CHECK_EQUAL(result.size(), 37u);
55+
for (int i = 1; i < 75; i += 2) {
56+
BOOST_CHECK(result.count(pages[static_cast<size_t>(i)].id()) == 1);
57+
}
58+
for (int i = 0; i < 75; i += 2) {
59+
BOOST_CHECK(result.count(pages[static_cast<size_t>(i)].id()) == 0);
60+
}
61+
}
62+
63+
BOOST_AUTO_TEST_CASE(select_this_page_and_following_every_other_partitions_75_pages) {
64+
PageSequence seq;
65+
std::vector<PageInfo> pages;
66+
for (int i = 0; i < 75; ++i) {
67+
pages.push_back(makePage("/scan", i));
68+
seq.append(pages.back());
69+
}
70+
71+
const std::set<PageId> oddFromFirst = seq.selectThisPageAndFollowingEveryOther(pages[0].id());
72+
const std::set<PageId> evenFromSecond = seq.selectThisPageAndFollowingEveryOther(pages[1].id());
73+
74+
for (int i = 0; i < 75; ++i) {
75+
const bool inOdd = oddFromFirst.count(pages[static_cast<size_t>(i)].id()) != 0;
76+
const bool inEven = evenFromSecond.count(pages[static_cast<size_t>(i)].id()) != 0;
77+
BOOST_CHECK(inOdd != inEven);
78+
}
79+
}
80+
81+
BOOST_AUTO_TEST_SUITE_END()
82+
83+
} // namespace Tests

0 commit comments

Comments
 (0)