tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / slidesorter / model / SlsPageEnumeration.cxx
bloba0a3db221dedadedd049257d823944c91e1821f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <sal/config.h>
23 #include <utility>
25 #include <model/SlsPageEnumeration.hxx>
26 #include <model/SlideSorterModel.hxx>
28 using namespace ::sd::slidesorter;
29 using namespace ::sd::slidesorter::model;
31 namespace {
33 class PageEnumerationImpl
34 : public Enumeration<SharedPageDescriptor>
36 public:
37 PageEnumerationImpl (
38 const SlideSorterModel& rModel,
39 PageEnumeration::PagePredicate aPredicate);
40 PageEnumerationImpl(const PageEnumerationImpl&) = delete;
41 PageEnumerationImpl& operator=(const PageEnumerationImpl&) = delete;
42 /** Create a copy of the called enumeration object.
44 virtual ::std::unique_ptr<Enumeration<SharedPageDescriptor> > Clone() override;
46 virtual bool HasMoreElements() const override;
47 virtual SharedPageDescriptor GetNextElement() override;
48 virtual void Rewind() override;
50 private:
51 const SlideSorterModel& mrModel;
52 const PageEnumeration::PagePredicate maPredicate;
53 int mnIndex;
55 /** This constructor sets the internal page index to the given value.
56 It does not call AdvanceToNextValidElement() to skip elements that
57 do not fulfill Predicate.
59 PageEnumerationImpl (
60 const SlideSorterModel& rModel,
61 PageEnumeration::PagePredicate aPredicate,
62 int nIndex);
64 /** Skip all elements that do not fulfill Predicate starting with the
65 one pointed to by mnIndex.
67 void AdvanceToNextValidElement();
70 } // end of anonymous namespace
72 namespace sd::slidesorter::model {
74 PageEnumeration PageEnumeration::Create (
75 const SlideSorterModel& rModel,
76 const PagePredicate& rPredicate)
78 return PageEnumeration(::std::unique_ptr<Enumeration<SharedPageDescriptor> >(
79 new PageEnumerationImpl(rModel, rPredicate)));
82 PageEnumeration::PageEnumeration (
83 ::std::unique_ptr<Enumeration<SharedPageDescriptor> > && pImpl)
84 : mpImpl(std::move(pImpl))
88 PageEnumeration::PageEnumeration (const PageEnumeration& rEnumeration )
89 : sd::slidesorter::model::Enumeration<sd::slidesorter::model::SharedPageDescriptor>()
91 mpImpl = rEnumeration.mpImpl->Clone();
94 PageEnumeration::~PageEnumeration()
98 PageEnumeration& PageEnumeration::operator= (
99 const PageEnumeration& rEnumeration)
101 mpImpl = rEnumeration.mpImpl->Clone();
102 return *this;
105 ::std::unique_ptr<Enumeration<SharedPageDescriptor> > PageEnumeration::Clone()
107 return ::std::unique_ptr<Enumeration<SharedPageDescriptor> >(
108 new PageEnumeration (*this));
111 bool PageEnumeration::HasMoreElements() const
113 return mpImpl->HasMoreElements();
116 SharedPageDescriptor PageEnumeration::GetNextElement()
118 return mpImpl->GetNextElement();
121 void PageEnumeration::Rewind()
123 return mpImpl->Rewind();
126 } // end of namespace ::sd::slidesorter::model
128 namespace {
130 PageEnumerationImpl::PageEnumerationImpl (
131 const SlideSorterModel& rModel,
132 PageEnumeration::PagePredicate aPredicate)
133 : mrModel(rModel),
134 maPredicate(std::move(aPredicate)),
135 mnIndex(0)
137 Rewind();
140 PageEnumerationImpl::PageEnumerationImpl (
141 const SlideSorterModel& rModel,
142 PageEnumeration::PagePredicate aPredicate,
143 int nIndex)
144 : mrModel(rModel),
145 maPredicate(std::move(aPredicate)),
146 mnIndex(nIndex)
150 ::std::unique_ptr<Enumeration<SharedPageDescriptor> >
151 PageEnumerationImpl::Clone()
153 return ::std::unique_ptr<Enumeration<SharedPageDescriptor> >(
154 new PageEnumerationImpl(mrModel,maPredicate,mnIndex));
157 bool PageEnumerationImpl::HasMoreElements() const
159 return (mnIndex < mrModel.GetPageCount());
162 SharedPageDescriptor PageEnumerationImpl::GetNextElement()
164 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
166 // Go to the following valid element.
167 mnIndex += 1;
168 AdvanceToNextValidElement();
170 return pDescriptor;
173 void PageEnumerationImpl::Rewind()
175 // Go to first valid element.
176 mnIndex = 0;
177 AdvanceToNextValidElement();
180 void PageEnumerationImpl::AdvanceToNextValidElement()
182 while (mnIndex < mrModel.GetPageCount())
184 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
186 // Test for the predicate being fulfilled.
187 if (pDescriptor && maPredicate(pDescriptor))
189 // This predicate is valid.
190 break;
192 else
194 // Advance to next predicate.
195 mnIndex += 1;
200 } // end of anonymous namespace
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */