LibreOffice Module sw (master) 1
docsort.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SW_SOURCE_CORE_INC_DOCSORT_HXX
21#define INCLUDED_SW_SOURCE_CORE_INC_DOCSORT_HXX
22
23#include <ndindex.hxx>
24
25#include <memory>
26#include <vector>
27
28class SwDoc;
29class SwTableBox;
30class SwUndoSort;
31class FlatFndBox;
32struct SwSortOptions;
33class FndBox_;
34class FndLine_;
35class CollatorWrapper;
37namespace com::sun::star::lang { struct Locale; }
38
40{
41private:
42 std::vector<const SwTableBox*> mBoxes;
43
44public:
45 void push_back(const SwTableBox* &rpTableBox) {mBoxes.push_back(rpTableBox);}
46
47 sal_uInt16 GetPos(const SwTableBox* pTableBox) const;
48};
49
50// Functions for moving boxes
51void MoveCol(SwDoc* pDoc, const FlatFndBox& rBox,
52 sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
53void MoveRow(SwDoc* pDoc, const FlatFndBox& rBox,
54 sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
55void MoveCell(SwDoc* pDoc, const SwTableBox* pSource,
56 const SwTableBox* pTar, bool bMovedBefore, SwUndoSort* pUD=nullptr);
57
58// Elements for sorting text and table content
60{
62 static SwDoc* pDoc;
63 static const FlatFndBox* pBox;
65 static css::lang::Locale* pLocale;
66 static std::optional<OUString> xLastAlgorithm;
68
69 static void Init( SwDoc*, const SwSortOptions& rOpt, FlatFndBox const * = nullptr );
70 static void Finit();
71
72 SwSortElement() = default;
73 SwSortElement(SwSortElement const &) = default;
77
78 virtual ~SwSortElement();
79
80 virtual OUString GetKey(sal_uInt16 nKey ) const = 0;
81 virtual double GetValue(sal_uInt16 nKey ) const;
82
83 bool operator<(const SwSortElement& ) const;
84
85 static double StrToDouble(std::u16string_view rStr);
86private:
87 int keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const;
88};
89
90// sort text
91struct SwSortTextElement final : public SwSortElement
92{
95
96 SwSortTextElement( const SwNodeIndex& rPos );
97
98 virtual OUString GetKey( sal_uInt16 nKey ) const override;
99};
100
101// sort table
102struct SwSortBoxElement final : public SwSortElement
103{
104 sal_uInt16 nRow;
105
106 SwSortBoxElement( sal_uInt16 nRC );
107
108 virtual OUString GetKey( sal_uInt16 nKey ) const override;
109 virtual double GetValue( sal_uInt16 nKey ) const override;
110};
111
112// two-dimensional array of FndBoxes
114{
115public:
116 FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox);
117 ~FlatFndBox();
118
119 bool IsSymmetric() const { return m_bSym; }
120 sal_uInt16 GetRows() const { return m_nRows; }
121 sal_uInt16 GetCols() const { return m_nCols; }
122
123 const FndBox_* GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const;
124
125 inline bool HasItemSets() const;
126 const SfxItemSet* GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const;
127
128private:
129 bool CheckLineSymmetry(const FndBox_& rBox);
130 bool CheckBoxSymmetry(const FndLine_& rLn);
131 sal_uInt16 GetColCount(const FndBox_& rBox);
132 sal_uInt16 GetRowCount(const FndBox_& rBox);
133 void FillFlat(const FndBox_&, bool bLastBox=false);
134
136 std::unique_ptr<FndBox_ const *[]> m_pArr;
138 std::vector<std::optional<SfxItemSet>> m_vItemSets;
139
140 sal_uInt16 m_nRows;
141 sal_uInt16 m_nCols;
142 sal_uInt16 m_nRow;
143 sal_uInt16 m_nCol;
144
145 bool m_bSym;
146};
147
148inline bool FlatFndBox::HasItemSets() const { return !m_vItemSets.empty(); }
149
150#endif
151
152/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FlatFndBox(SwDoc *pDocPtr, const FndBox_ &rBox)
Generate two-dimensional array of FndBoxes.
Definition: docsort.cxx:727
sal_uInt16 GetColCount(const FndBox_ &rBox)
Maximum count of Columns (Boxes)
Definition: docsort.cxx:797
bool IsSymmetric() const
Definition: docsort.hxx:119
sal_uInt16 m_nCols
Definition: docsort.hxx:141
sal_uInt16 m_nRow
Definition: docsort.hxx:142
std::unique_ptr< FndBox_ const *[]> m_pArr
Definition: docsort.hxx:136
SwDoc * m_pDoc
Definition: docsort.hxx:135
bool CheckLineSymmetry(const FndBox_ &rBox)
All Lines of a Box need to have same number of Boxes.
Definition: docsort.cxx:753
const SfxItemSet * GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const
Definition: docsort.cxx:916
sal_uInt16 GetRowCount(const FndBox_ &rBox)
Maximum count of Rows (Lines)
Definition: docsort.cxx:822
sal_uInt16 m_nCol
Definition: docsort.hxx:143
bool HasItemSets() const
Definition: docsort.hxx:148
bool m_bSym
Definition: docsort.hxx:145
void FillFlat(const FndBox_ &, bool bLastBox=false)
Create a linear array of atomic FndBoxes.
Definition: docsort.cxx:847
sal_uInt16 GetCols() const
Definition: docsort.hxx:121
sal_uInt16 GetRows() const
Definition: docsort.hxx:120
const FndBox_ * GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const
Access a specific Cell.
Definition: docsort.cxx:907
std::vector< std::optional< SfxItemSet > > m_vItemSets
using optional because SfxItemSet has no default constructor
Definition: docsort.hxx:138
bool CheckBoxSymmetry(const FndLine_ &rLn)
Check Box for symmetry (All Boxes of a Line need to have same number of Lines)
Definition: docsort.cxx:775
sal_uInt16 m_nRows
Definition: docsort.hxx:140
Definition: doc.hxx:197
sal_uInt16 GetPos(const SwTableBox *pTableBox) const
Definition: docsort.cxx:927
std::vector< const SwTableBox * > mBoxes
Definition: docsort.hxx:42
void push_back(const SwTableBox *&rpTableBox)
Definition: docsort.hxx:45
Marks a node in the document model.
Definition: ndindex.hxx:31
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
void MoveCell(SwDoc *pDoc, const SwTableBox *pSource, const SwTableBox *pTar, bool bMovedBefore, SwUndoSort *pUD=nullptr)
Move a single Cell.
Definition: docsort.cxx:674
void MoveCol(SwDoc *pDoc, const FlatFndBox &rBox, sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes &rMovedList, SwUndoSort *pUD)
Move a column.
Definition: docsort.cxx:630
void MoveRow(SwDoc *pDoc, const FlatFndBox &rBox, sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes &rMovedList, SwUndoSort *pUD)
Move a row.
Definition: docsort.cxx:586
SwSortBoxElement(sal_uInt16 nRC)
SortingElement for Tables.
Definition: docsort.cxx:219
sal_uInt16 nRow
Definition: docsort.hxx:104
virtual double GetValue(sal_uInt16 nKey) const override
Definition: docsort.cxx:257
virtual OUString GetKey(sal_uInt16 nKey) const override
Get Key for a cell.
Definition: docsort.cxx:225
static double StrToDouble(std::u16string_view rStr)
Definition: docsort.cxx:104
SwSortElement(SwSortElement const &)=default
static void Finit()
Definition: docsort.cxx:85
static SwDoc * pDoc
Definition: docsort.hxx:62
static std::optional< OUString > xLastAlgorithm
Definition: docsort.hxx:66
SwSortElement(SwSortElement &&)=default
bool operator<(const SwSortElement &) const
Definition: docsort.cxx:159
static SwSortOptions * pOptions
Definition: docsort.hxx:61
static css::lang::Locale * pLocale
Definition: docsort.hxx:65
static const FlatFndBox * pBox
Definition: docsort.hxx:63
int keycompare(const SwSortElement &rCmp, sal_uInt16 nKey) const
Definition: docsort.cxx:118
static void Init(SwDoc *, const SwSortOptions &rOpt, FlatFndBox const *=nullptr)
Construct a SortElement for the Sort.
Definition: docsort.cxx:67
virtual double GetValue(sal_uInt16 nKey) const
Definition: docsort.cxx:175
static CollatorWrapper * pSortCollator
Definition: docsort.hxx:64
SwSortElement & operator=(SwSortElement const &)=default
SwSortElement()=default
virtual OUString GetKey(sal_uInt16 nKey) const =0
virtual ~SwSortElement()
Definition: docsort.cxx:100
static LocaleDataWrapper * pLclData
Definition: docsort.hxx:67
virtual OUString GetKey(sal_uInt16 nKey) const override
Definition: docsort.cxx:186
SwNodeIndex aPos
Definition: docsort.hxx:94
SwNodeOffset nOrg
Definition: docsort.hxx:93
SwSortTextElement(const SwNodeIndex &rPos)
SortingElement for Text.
Definition: docsort.cxx:181