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 
107  virtual OUString GetKey( sal_uInt16 nKey ) const override;
108 };
109 
110 // sort table
112 {
113  sal_uInt16 const nRow;
114 
115  SwSortBoxElement( sal_uInt16 nRC );
116 
117  virtual OUString GetKey( sal_uInt16 nKey ) const override;
118  virtual double GetValue( sal_uInt16 nKey ) const override;
119 };
120 
121 // two-dimensional array of FndBoxes
123 {
124 public:
125  FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox);
126  ~FlatFndBox();
127 
128  bool IsSymmetric() const { return bSym; }
129  sal_uInt16 GetRows() const { return nRows; }
130  sal_uInt16 GetCols() const { return nCols; }
131 
132  const FndBox_* GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const;
133 
134  inline bool HasItemSets() const;
135  const SfxItemSet* GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const;
136 
137 private:
138  bool CheckLineSymmetry(const FndBox_& rBox);
139  bool CheckBoxSymmetry(const FndLine_& rLn);
140  sal_uInt16 GetColCount(const FndBox_& rBox);
141  sal_uInt16 GetRowCount(const FndBox_& rBox);
142  void FillFlat(const FndBox_&, bool bLastBox=false);
143 
145  std::unique_ptr<FndBox_ const *[]> pArr;
146  std::vector<std::unique_ptr<SfxItemSet>> ppItemSets;
147 
148  sal_uInt16 nRows;
149  sal_uInt16 nCols;
150  sal_uInt16 nRow;
151  sal_uInt16 nCol;
152 
153  bool bSym;
154 };
155 
156 inline bool FlatFndBox::HasItemSets() const { return !ppItemSets.empty(); }
157 
158 #endif
159 
160 /* 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:146
static double StrToDouble(const OUString &rStr)
Definition: docsort.cxx:105
sal_uInt16 nRows
Definition: docsort.hxx:148
bool HasItemSets() const
Definition: docsort.hxx:156
SwNodeIndex aPos
Definition: docsort.hxx:103
sal_uIntPtr sal_uLong
static void Finit()
Definition: docsort.cxx:85
bool IsSymmetric() const
Definition: docsort.hxx:128
virtual OUString GetKey(sal_uInt16 nKey) const =0
Definition: doc.hxx:185
SwDoc * pDoc
Definition: docsort.hxx:144
FlatFndBox(SwDoc *pDocPtr, const FndBox_ &rBox)
Generate two-dimensional array of FndBoxes.
Definition: docsort.cxx:730
static SwSortOptions * pOptions
Definition: docsort.hxx:70
sal_uInt16 GetRowCount(const FndBox_ &rBox)
Maximum count of Rows (Lines)
Definition: docsort.cxx:825
sal_uInt16 nCol
Definition: docsort.hxx:151
sal_uInt16 GetPos(const SwTableBox *pTableBox) const
Definition: docsort.cxx:927
static LocaleDataWrapper * pLclData
Definition: docsort.hxx:76
virtual OUString GetKey(sal_uInt16 nKey) const override
Definition: docsort.cxx:190
void push_back(const SwTableBox *&rpTableBox)
Definition: docsort.hxx:54
std::unique_ptr< FndBox_ const *[]> pArr
Definition: docsort.hxx:145
void FillFlat(const FndBox_ &, bool bLastBox=false)
Create a linear array of atomic FndBoxes.
Definition: docsort.cxx:850
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:778
const FndBox_ * GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const
Access a specific Cell.
Definition: docsort.cxx:911
sal_uInt16 nRow
Definition: docsort.hxx:150
void MoveCell(SwDoc *pDoc, const SwTableBox *pSource, const SwTableBox *pTar, bool bMovedBefore, SwUndoSort *pUD=nullptr)
Move a single Cell.
Definition: docsort.cxx:677
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:226
virtual double GetValue(sal_uInt16 nKey) const override
Definition: docsort.cxx:255
sal_uInt16 GetCols() const
Definition: docsort.hxx:130
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:633
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:153
sal_uInt16 const nRow
Definition: docsort.hxx:113
sal_uInt16 GetColCount(const FndBox_ &rBox)
Maximum count of Columns (Boxes)
Definition: docsort.cxx:800
bool CheckLineSymmetry(const FndBox_ &rBox)
All Lines of a Box need to have same number of Boxes.
Definition: docsort.cxx:756
sal_uInt16 nCols
Definition: docsort.hxx:149
const SfxItemSet * GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const
Definition: docsort.cxx:920
static const FlatFndBox * pBox
Definition: docsort.hxx:72
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
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:589
sal_uInt16 GetRows() const
Definition: docsort.hxx:129
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:220