Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdfsdk_annotiteration.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fpdfsdk/cpdfsdk_annotiteration.h"
8
9#include <algorithm>
10
11#include "fpdfsdk/cpdfsdk_annot.h"
12#include "fpdfsdk/cpdfsdk_pageview.h"
13
14// static
16 CPDFSDK_PageView* page_view) {
17 CPDFSDK_AnnotIteration result(page_view);
18 return CPDFSDK_AnnotIteration(page_view, /*put_focused_annot_at_end=*/true);
19}
20
22 : CPDFSDK_AnnotIteration(page_view, /*put_focused_annot_at_end=*/false) {}
23
24CPDFSDK_AnnotIteration::CPDFSDK_AnnotIteration(CPDFSDK_PageView* page_view,
25 bool put_focused_annot_at_end) {
26 // Copying ObservedPtrs is expensive, so do it once at the end.
27 std::vector<CPDFSDK_Annot*> copied_list = page_view->GetAnnotList();
28 std::stable_sort(copied_list.begin(), copied_list.end(),
29 [](const CPDFSDK_Annot* p1, const CPDFSDK_Annot* p2) {
31 });
32
33 CPDFSDK_Annot* pTopMostAnnot = page_view->GetFocusAnnot();
34 if (pTopMostAnnot) {
35 auto it = std::find(copied_list.begin(), copied_list.end(), pTopMostAnnot);
36 if (it != copied_list.end()) {
37 copied_list.erase(it);
38 auto insert_it =
39 put_focused_annot_at_end ? copied_list.end() : copied_list.begin();
40 copied_list.insert(insert_it, pTopMostAnnot);
41 }
42 }
43
44 list_.reserve(copied_list.size());
45 for (auto* pAnnot : copied_list)
46 list_.emplace_back(pAnnot);
47}
48
CPDFSDK_AnnotIteration(CPDFSDK_PageView *page_view)
static CPDFSDK_AnnotIteration CreateForDrawing(CPDFSDK_PageView *page_view)
virtual int GetLayoutOrder() const
CPDFSDK_Annot * GetFocusAnnot()