Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / inc / columnspanset.hxx
blobd8cfc41f524b9aa67f13005d533cf0913ba01cc0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #pragma once
12 #include "address.hxx"
14 #include <optional>
15 #include <vector>
16 #include <mdds/flat_segment_tree.hpp>
18 class ScDocument;
19 class ScColumn;
20 class ScMarkData;
21 class ScRangeList;
22 struct ScSheetLimits;
24 namespace sc {
26 struct ColumnBlockConstPosition;
27 class SingleColumnSpanSet;
29 struct RowSpan
31 SCROW mnRow1;
32 SCROW mnRow2;
34 RowSpan(SCROW nRow1, SCROW nRow2);
37 struct SC_DLLPUBLIC ColRowSpan
39 SCCOLROW mnStart;
40 SCCOLROW mnEnd;
42 ColRowSpan(SCCOLROW nStart, SCCOLROW nEnd);
45 /**
46 * Structure that stores segments of boolean flags per column, and perform
47 * custom action on those segments.
49 class ColumnSpanSet
51 public:
52 typedef mdds::flat_segment_tree<SCROW, bool> ColumnSpansType;
54 private:
55 struct ColumnType
57 ColumnSpansType maSpans;
58 ColumnSpansType::const_iterator miPos;
60 ColumnType(SCROW nStart, SCROW nEnd, bool bInit);
63 typedef std::vector<std::optional<ColumnType>> TableType;
65 std::vector<TableType> maTables;
67 ColumnType& getColumn(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol);
69 public:
70 class Action
72 public:
73 virtual ~Action() = 0;
74 virtual void startColumn(SCTAB nTab, SCCOL nCol);
75 virtual void execute(const ScAddress& rPos, SCROW nLength, bool bVal) = 0;
78 class ColumnAction
80 public:
81 virtual ~ColumnAction() = 0;
82 virtual void startColumn(ScColumn* pCol) = 0;
83 virtual void execute(SCROW nRow1, SCROW nRow2, bool bVal) = 0;
86 ColumnSpanSet();
87 ColumnSpanSet(const ColumnSpanSet&) = delete;
88 ColumnSpanSet& operator=(const ColumnSpanSet&) = delete;
89 ColumnSpanSet(ColumnSpanSet&&) = default;
90 ColumnSpanSet& operator=(ColumnSpanSet&&) = default;
91 ~ColumnSpanSet();
93 void set(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol, SCROW nRow, bool bVal);
94 void set(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2, bool bVal);
95 void set(const ScDocument& rDoc, const ScRange& rRange, bool bVal);
97 void set(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol, const SingleColumnSpanSet& rSingleSet, bool bVal );
99 /**
100 * Scan specified range in a specified sheet and mark all non-empty cells
101 * with specified boolean value.
103 void scan(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bVal);
105 void executeAction(ScDocument& rDoc, Action& ac) const;
106 void executeColumnAction(ScDocument& rDoc, ColumnAction& ac) const;
110 * Keep track of spans in a single column only.
112 class SingleColumnSpanSet
114 public:
115 typedef mdds::flat_segment_tree<SCROW, bool> ColumnSpansType;
117 typedef std::vector<RowSpan> SpansType;
119 SingleColumnSpanSet(ScSheetLimits const &);
122 * Scan an entire column and tag all non-empty cell positions.
124 void scan(const ScColumn& rColumn);
127 * Scan a column between specified range, and tag all non-empty cell
128 * positions.
130 void scan(const ScColumn& rColumn, SCROW nStart, SCROW nEnd);
132 void scan(
133 ColumnBlockConstPosition& rBlockPos, const ScColumn& rColumn, SCROW nStart, SCROW nEnd);
136 * Scan all marked data and tag all marked segments in specified column.
138 void scan(const ScMarkData& rMark, SCTAB nTab, SCCOL nCol);
140 void scan(const ScRangeList& rRanges, SCTAB nTab, SCCOL nCol);
142 void set(SCROW nRow1, SCROW nRow2, bool bVal);
144 void getRows(std::vector<SCROW> &rRows) const;
146 void getSpans(SpansType& rSpans) const;
148 void swap( SingleColumnSpanSet& r );
150 /** Whether there isn't any row tagged. */
151 bool empty() const;
153 private:
154 ScSheetLimits const & mrSheetLimits;
155 ColumnSpansType maSpans;
159 * Optimized ColumnSpanSet version that operates on a single ScRange.
161 class RangeColumnSpanSet
163 public:
164 RangeColumnSpanSet( const ScRange& spanRange )
165 : range( spanRange ) {}
166 void executeColumnAction(ScDocument& rDoc, sc::ColumnSpanSet::ColumnAction& ac) const;
167 private:
168 ScRange range;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */