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 
28 class SwDoc;
29 class SwTableBox;
30 class SwUndoSort;
31 class FlatFndBox;
32 struct SwSortOptions;
33 class FndBox_;
34 class FndLine_;
35 class CollatorWrapper;
36 class LocaleDataWrapper;
37 namespace com::sun::star::lang { struct Locale; }
38 
40 {
41 private:
42  std::vector<const SwTableBox*> mBoxes;
43 
44 public:
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
51 void MoveCol(SwDoc* pDoc, const FlatFndBox& rBox,
52  sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
53 void MoveRow(SwDoc* pDoc, const FlatFndBox& rBox,
54  sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
55 void 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 OUString* pLastAlgorithm;
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;
74  SwSortElement(SwSortElement &&) = default;
75  SwSortElement & operator =(SwSortElement const &) = default;
76  SwSortElement & operator =(SwSortElement &&) = 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(const OUString& rStr);
86 private:
87  int keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const;
88 };
89 
90 // sort text
92 {
95 
96  SwSortTextElement( const SwNodeIndex& rPos );
97 
98  virtual OUString GetKey( sal_uInt16 nKey ) const override;
99 };
100 
101 // sort table
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 {
115 public:
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 
128 private:
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;
137  std::vector<std::unique_ptr<SfxItemSet>> m_ppItemSets;
138 
139  sal_uInt16 m_nRows;
140  sal_uInt16 m_nCols;
141  sal_uInt16 m_nRow;
142  sal_uInt16 m_nCol;
143 
144  bool m_bSym;
145 };
146 
147 inline bool FlatFndBox::HasItemSets() const { return !m_ppItemSets.empty(); }
148 
149 #endif
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwSortTextElement(const SwNodeIndex &rPos)
SortingElement for Text.
Definition: docsort.cxx:184
static double StrToDouble(const OUString &rStr)
Definition: docsort.cxx:104
bool HasItemSets() const
Definition: docsort.hxx:147
bool m_bSym
Definition: docsort.hxx:144
sal_uInt16 m_nRows
Definition: docsort.hxx:139
SwNodeIndex aPos
Definition: docsort.hxx:94
sal_uIntPtr sal_uLong
static void Finit()
Definition: docsort.cxx:84
bool IsSymmetric() const
Definition: docsort.hxx:119
virtual OUString GetKey(sal_uInt16 nKey) const =0
Definition: doc.hxx:186
sal_uInt16 nRow
Definition: docsort.hxx:104
FlatFndBox(SwDoc *pDocPtr, const FndBox_ &rBox)
Generate two-dimensional array of FndBoxes.
Definition: docsort.cxx:738
static SwSortOptions * pOptions
Definition: docsort.hxx:61
sal_uInt16 GetRowCount(const FndBox_ &rBox)
Maximum count of Rows (Lines)
Definition: docsort.cxx:833
sal_uInt16 GetPos(const SwTableBox *pTableBox) const
Definition: docsort.cxx:935
static LocaleDataWrapper * pLclData
Definition: docsort.hxx:67
virtual OUString GetKey(sal_uInt16 nKey) const override
Definition: docsort.cxx:189
void push_back(const SwTableBox *&rpTableBox)
Definition: docsort.hxx:45
void FillFlat(const FndBox_ &, bool bLastBox=false)
Create a linear array of atomic FndBoxes.
Definition: docsort.cxx:858
std::vector< const SwTableBox * > mBoxes
Definition: docsort.hxx:42
bool CheckBoxSymmetry(const FndLine_ &rLn)
Check Box for symmetry (All Boxes of a Line need to have same number of Lines)
Definition: docsort.cxx:786
const FndBox_ * GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const
Access a specific Cell.
Definition: docsort.cxx:919
void MoveCell(SwDoc *pDoc, const SwTableBox *pSource, const SwTableBox *pTar, bool bMovedBefore, SwUndoSort *pUD=nullptr)
Move a single Cell.
Definition: docsort.cxx:685
SwDoc * m_pDoc
Definition: docsort.hxx:135
static css::lang::Locale * pLocale
Definition: docsort.hxx:65
SwSortElement & operator=(SwSortElement const &)=default
virtual double GetValue(sal_uInt16 nKey) const
Definition: docsort.cxx:178
virtual OUString GetKey(sal_uInt16 nKey) const override
Get Key for a cell.
Definition: docsort.cxx:228
virtual double GetValue(sal_uInt16 nKey) const override
Definition: docsort.cxx:260
std::unique_ptr< FndBox_ const *[]> m_pArr
Definition: docsort.hxx:136
sal_uInt16 GetCols() const
Definition: docsort.hxx:121
sal_uInt16 m_nCol
Definition: docsort.hxx:142
static void Init(SwDoc *, const SwSortOptions &rOpt, FlatFndBox const *=nullptr)
Construct a SortElement for the Sort.
Definition: docsort.cxx:66
void MoveCol(SwDoc *pDoc, const FlatFndBox &rBox, sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes &rMovedList, SwUndoSort *pUD)
Move a column.
Definition: docsort.cxx:641
static CollatorWrapper * pSortCollator
Definition: docsort.hxx:64
Marks a node in the document model.
Definition: ndindex.hxx:31
static SwDoc * pDoc
Definition: docsort.hxx:62
bool operator<(const SwSortElement &) const
Definition: docsort.cxx:162
sal_uInt16 GetColCount(const FndBox_ &rBox)
Maximum count of Columns (Boxes)
Definition: docsort.cxx:808
sal_uInt16 m_nCols
Definition: docsort.hxx:140
bool CheckLineSymmetry(const FndBox_ &rBox)
All Lines of a Box need to have same number of Boxes.
Definition: docsort.cxx:764
const SfxItemSet * GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const
Definition: docsort.cxx:928
std::vector< std::unique_ptr< SfxItemSet > > m_ppItemSets
Definition: docsort.hxx:137
static const FlatFndBox * pBox
Definition: docsort.hxx:63
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:393
sal_uLong nOrg
Definition: docsort.hxx:93
SwSortElement()=default
virtual ~SwSortElement()
Definition: docsort.cxx:100
void MoveRow(SwDoc *pDoc, const FlatFndBox &rBox, sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes &rMovedList, SwUndoSort *pUD)
Move a row.
Definition: docsort.cxx:597
sal_uInt16 GetRows() const
Definition: docsort.hxx:120
sal_uInt16 m_nRow
Definition: docsort.hxx:141
int keycompare(const SwSortElement &rCmp, sal_uInt16 nKey) const
Definition: docsort.cxx:118
static OUString * pLastAlgorithm
Definition: docsort.hxx:66
SwSortBoxElement(sal_uInt16 nRC)
SortingElement for Tables.
Definition: docsort.cxx:222