LibreOffice Module sc (master) 1
prnsave.cxx
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#include <prnsave.hxx>
21#include <address.hxx>
22
23#include <osl/diagnose.h>
24#include <tools/json_writer.hxx>
25
26// Data per table
27
29 mbEntireSheet(false)
30{
31}
32
34{
35}
36
37void ScPrintSaverTab::SetAreas( ScRangeVec&& rRanges, bool bEntireSheet )
38{
39 maPrintRanges = std::move(rRanges);
40 mbEntireSheet = bEntireSheet;
41}
42
43void ScPrintSaverTab::SetRepeat( std::optional<ScRange> oCol, std::optional<ScRange> oRow )
44{
45 moRepeatCol = std::move(oCol);
46 moRepeatRow = std::move(oRow);
47}
48
50{
51 return
52 (moRepeatCol == rCmp.moRepeatCol) &&
53 (moRepeatRow == rCmp.moRepeatRow) &&
54 (mbEntireSheet == rCmp.mbEntireSheet) &&
56}
57
58// Data for the whole document
59
61 nTabCount( nCount )
62{
63 if (nCount > 0)
64 pData.reset( new ScPrintSaverTab[nCount] );
65}
66
68{
69}
70
72{
73 OSL_ENSURE(nTab<nTabCount,"ScPrintRangeSaver Tab too big");
74 return pData[nTab];
75}
76
78{
79 OSL_ENSURE(nTab<nTabCount,"ScPrintRangeSaver Tab too big");
80 return pData[nTab];
81}
82
84{
85 // Array for sheets in the document.
86 auto printRanges = rPrintRanges.startArray("printranges");
87 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
88 {
89 auto sheetNode = rPrintRanges.startStruct();
90 const ScPrintSaverTab& rPsTab = pData[nTab];
91 const std::vector<ScRange>& rRangeVec = rPsTab.GetPrintRanges();
92
93 rPrintRanges.put("sheet", static_cast<sal_Int32>(nTab));
94
95 // Array for ranges within each sheet.
96 auto sheetRanges = rPrintRanges.startArray("ranges");
97 OStringBuffer aRanges;
98 sal_Int32 nLast = rRangeVec.size() - 1;
99 for (sal_Int32 nIdx = 0; nIdx <= nLast; ++nIdx)
100 {
101 const ScRange& rRange = rRangeVec[nIdx];
102 aRanges.append("[ " +
103 OString::number(rRange.aStart.Col()) + ", " +
104 OString::number(rRange.aStart.Row()) + ", " +
105 OString::number(rRange.aEnd.Col()) + ", " +
106 OString::number(rRange.aEnd.Row()) +
107 (nLast == nIdx ? std::string_view("]") : std::string_view("], ")));
108 }
109
110 rPrintRanges.putRaw(aRanges);
111 }
112}
113
115{
116 bool bEqual = ( nTabCount == rCmp.nTabCount );
117 if (bEqual)
118 for (SCTAB i=0; i<nTabCount; i++)
119 if (!(pData[i]==rCmp.pData[i]))
120 {
121 bEqual = false;
122 break;
123 }
124 return bEqual;
125}
126
127/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
ScPrintSaverTab & GetTabData(SCTAB nTab)
Definition: prnsave.cxx:71
void GetPrintRangesInfo(tools::JsonWriter &rPrintRanges) const
Definition: prnsave.cxx:83
std::unique_ptr< ScPrintSaverTab[]> pData
Definition: prnsave.hxx:56
bool operator==(const ScPrintRangeSaver &rCmp) const
Definition: prnsave.cxx:114
ScPrintRangeSaver(SCTAB nCount)
Definition: prnsave.cxx:60
ScRangeVec maPrintRanges
Array.
Definition: prnsave.hxx:33
std::optional< ScRange > moRepeatCol
single
Definition: prnsave.hxx:34
std::optional< ScRange > moRepeatRow
single
Definition: prnsave.hxx:35
::std::vector< ScRange > ScRangeVec
Definition: prnsave.hxx:31
bool operator==(const ScPrintSaverTab &rCmp) const
Definition: prnsave.cxx:49
const ScRangeVec & GetPrintRanges() const
Definition: prnsave.hxx:45
bool mbEntireSheet
Definition: prnsave.hxx:36
void SetRepeat(std::optional< ScRange > oCol, std::optional< ScRange > oRow)
Definition: prnsave.cxx:43
void SetAreas(ScRangeVec &&rRanges, bool bEntireSheet)
Definition: prnsave.cxx:37
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
void put(std::u16string_view pPropName, const OUString &rPropValue)
ScopedJsonWriterStruct startStruct()
void putRaw(std::string_view)
ScopedJsonWriterArray startArray(std::string_view)
int nCount
int i
sal_Int16 SCTAB
Definition: types.hxx:22