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 
38 namespace com {
39  namespace sun {
40  namespace star {
41  namespace lang {
42  struct Locale;
43  }
44  }
45  }
46 }
47 
49 {
50 private:
51  std::vector<const SwTableBox*> mBoxes;
52 
53 public:
54  void push_back(const SwTableBox* &rpTableBox) {mBoxes.push_back(rpTableBox);}
55 
56  sal_uInt16 GetPos(const SwTableBox* pTableBox) const;
57 };
58 
59 // Functions for moving boxes
60 void MoveCol(SwDoc* pDoc, const FlatFndBox& rBox,
61  sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
62 void MoveRow(SwDoc* pDoc, const FlatFndBox& rBox,
63  sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
64 void MoveCell(SwDoc* pDoc, const SwTableBox* pSource,
65  const SwTableBox* pTar, bool bMovedBefore, SwUndoSort* pUD=nullptr);
66 
67 // Elements for sorting text and table content
69 {
71  static SwDoc* pDoc;
72  static const FlatFndBox* pBox;
74  static css::lang::Locale* pLocale;
75  static OUString* pLastAlgorithm;
77 
78  static void Init( SwDoc*, const SwSortOptions& rOpt, FlatFndBox const * = nullptr );
79  static void Finit();
80 
81  SwSortElement() = default;
82  SwSortElement(SwSortElement const &) = default;
83  SwSortElement(SwSortElement &&) = default;
84  SwSortElement & operator =(SwSortElement const &) = default;
85  SwSortElement & operator =(SwSortElement &&) = default;
86 
87  virtual ~SwSortElement();
88 
89  virtual OUString GetKey(sal_uInt16 nKey ) const = 0;
90  virtual double GetValue(sal_uInt16 nKey ) const;
91 
92  bool operator<(const SwSortElement& ) const;
93 
94  static double StrToDouble(const OUString& rStr);
95 private:
96  int keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const;
97 };
98 
99 // sort text
101 {
104 
105  SwSortTextElement( const SwNodeIndex& rPos );
106  virtual ~SwSortTextElement() override;
107 
108  virtual OUString GetKey( sal_uInt16 nKey ) const override;
109 };
110 
111 // sort table
113 {
114  sal_uInt16 const nRow;
115 
116  SwSortBoxElement( sal_uInt16 nRC );
117  virtual ~SwSortBoxElement() override;
118 
119  virtual OUString GetKey( sal_uInt16 nKey ) const override;
120  virtual double GetValue( sal_uInt16 nKey ) const override;
121 };
122 
123 // two-dimensional array of FndBoxes
125 {
126 public:
127  FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox);
128  ~FlatFndBox();
129 
130  bool IsSymmetric() const { return bSym; }
131  sal_uInt16 GetRows() const { return nRows; }
132  sal_uInt16 GetCols() const { return nCols; }
133 
134  const FndBox_* GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const;
135 
136  inline bool HasItemSets() const;
137  const SfxItemSet* GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const;
138 
139 private:
140  bool CheckLineSymmetry(const FndBox_& rBox);
141  bool CheckBoxSymmetry(const FndLine_& rLn);
142  sal_uInt16 GetColCount(const FndBox_& rBox);
143  sal_uInt16 GetRowCount(const FndBox_& rBox);
144  void FillFlat(const FndBox_&, bool bLastBox=false);
145 
147  std::unique_ptr<FndBox_ const *[]> pArr;
148  std::vector<std::unique_ptr<SfxItemSet>> ppItemSets;
149 
150  sal_uInt16 nRows;
151  sal_uInt16 nCols;
152  sal_uInt16 nRow;
153  sal_uInt16 nCol;
154 
155  bool bSym;
156 };
157 
158 inline bool FlatFndBox::HasItemSets() const { return !ppItemSets.empty(); }
159 
160 #endif
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwSortTextElement(const SwNodeIndex &rPos)
SortingElement for Text.
Definition: docsort.cxx:185
std::vector< std::unique_ptr< SfxItemSet > > ppItemSets
Definition: docsort.hxx:148
static double StrToDouble(const OUString &rStr)
Definition: docsort.cxx:105
sal_uInt16 nRows
Definition: docsort.hxx:150
bool HasItemSets() const
Definition: docsort.hxx:158
SwNodeIndex aPos
Definition: docsort.hxx:103
sal_uIntPtr sal_uLong
static void Finit()
Definition: docsort.cxx:85
bool IsSymmetric() const
Definition: docsort.hxx:130
virtual OUString GetKey(sal_uInt16 nKey) const =0
Definition: doc.hxx:185
SwDoc * pDoc
Definition: docsort.hxx:146
FlatFndBox(SwDoc *pDocPtr, const FndBox_ &rBox)
Generate two-dimensional array of FndBoxes.
Definition: docsort.cxx:738
static SwSortOptions * pOptions
Definition: docsort.hxx:70
sal_uInt16 GetRowCount(const FndBox_ &rBox)
Maximum count of Rows (Lines)
Definition: docsort.cxx:833
sal_uInt16 nCol
Definition: docsort.hxx:153
sal_uInt16 GetPos(const SwTableBox *pTableBox) const
Definition: docsort.cxx:935
static LocaleDataWrapper * pLclData
Definition: docsort.hxx:76
virtual OUString GetKey(sal_uInt16 nKey) const override
Definition: docsort.cxx:194
void push_back(const SwTableBox *&rpTableBox)
Definition: docsort.hxx:54
std::unique_ptr< FndBox_ const *[]> pArr
Definition: docsort.hxx:147
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:51
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
sal_uInt16 nRow
Definition: docsort.hxx:152
void MoveCell(SwDoc *pDoc, const SwTableBox *pSource, const SwTableBox *pTar, bool bMovedBefore, SwUndoSort *pUD=nullptr)
Move a single Cell.
Definition: docsort.cxx:685
static css::lang::Locale * pLocale
Definition: docsort.hxx:74
SwSortElement & operator=(SwSortElement const &)=default
virtual double GetValue(sal_uInt16 nKey) const
Definition: docsort.cxx:179
virtual OUString GetKey(sal_uInt16 nKey) const override
Get Key for a cell.
Definition: docsort.cxx:234
virtual double GetValue(sal_uInt16 nKey) const override
Definition: docsort.cxx:263
sal_uInt16 GetCols() const
Definition: docsort.hxx:132
static void Init(SwDoc *, const SwSortOptions &rOpt, FlatFndBox const *=nullptr)
Construct a SortElement for the Sort.
Definition: docsort.cxx:67
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:73
Marks a node in the document model.
Definition: ndindex.hxx:31
static SwDoc * pDoc
Definition: docsort.hxx:71
bool operator<(const SwSortElement &) const
Definition: docsort.cxx:163
bool bSym
Definition: docsort.hxx:155
virtual ~SwSortBoxElement() override
Definition: docsort.cxx:229
sal_uInt16 const nRow
Definition: docsort.hxx:114
sal_uInt16 GetColCount(const FndBox_ &rBox)
Maximum count of Columns (Boxes)
Definition: docsort.cxx:808
bool CheckLineSymmetry(const FndBox_ &rBox)
All Lines of a Box need to have same number of Boxes.
Definition: docsort.cxx:764
sal_uInt16 nCols
Definition: docsort.hxx:151
const SfxItemSet * GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const
Definition: docsort.cxx:928
static const FlatFndBox * pBox
Definition: docsort.hxx:72
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
virtual ~SwSortTextElement() override
Definition: docsort.cxx:190
SwSortElement()=default
sal_uLong const nOrg
Definition: docsort.hxx:102
virtual ~SwSortElement()
Definition: docsort.cxx:101
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:131
int keycompare(const SwSortElement &rCmp, sal_uInt16 nKey) const
Definition: docsort.cxx:119
static OUString * pLastAlgorithm
Definition: docsort.hxx:75
SwSortBoxElement(sal_uInt16 nRC)
SortingElement for Tables.
Definition: docsort.cxx:224