Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/dbfld.hxx
Line
Count
Source
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
#pragma once
20
21
#include "swdllapi.h"
22
#include "fldbas.hxx"
23
#include "swdbdata.hxx"
24
25
class SwDoc;
26
27
// Database field.
28
class SW_DLLPUBLIC SwDBFieldType final : public SwValueFieldType
29
{
30
    SwDBData    m_aDBData;
31
    UIName m_sName;          ///< only used in ::GetName() !
32
    OUString m_sColumn;
33
    tools::Long        m_nRefCnt;
34
35
public:
36
37
    SwDBFieldType(SwDoc* pDocPtr, const OUString& rColumnName, SwDBData aDBData);
38
    virtual ~SwDBFieldType() override;
39
40
    virtual UIName GetName() const override;
41
    virtual void SetName(const UIName& newName) override;
42
    virtual std::unique_ptr<SwFieldType> Copy() const override;
43
44
4.94k
    void     AddRef() { m_nRefCnt++; }
45
    void            ReleaseRef();
46
47
4.94k
    const OUString&     GetColumnName() const {return m_sColumn;}
48
0
    const SwDBData& GetDBData() const {return m_aDBData;}
49
50
    virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
51
    virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
52
180
    virtual void UpdateFields() override {};
53
};
54
55
// Classes derived from SwFields. They overlay the expand-function.
56
// Content is formatted according to the format (if available).
57
class SW_DLLPUBLIC SwDBField final : public SwValueField
58
{
59
    OUString m_aContent;
60
    OUString m_sFieldCode; ///< contains Word's field code
61
    SwDBFieldSubType m_nSubType;
62
    bool    m_bIsInBodyText    : 1;
63
    bool    m_bValidValue     : 1;
64
    bool    m_bInitialized    : 1;
65
66
    virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
67
    virtual std::unique_ptr<SwField> Copy() const override;
68
69
public:
70
    SwDBField(SwDBFieldType*, sal_uInt32 nFormat = 0, SwDBFieldSubType nSubType = SwDBFieldSubType::None);
71
    virtual ~SwDBField() override;
72
73
    virtual SwFieldType*    ChgTyp( SwFieldType* ) override;
74
75
    /// Current text.
76
    inline  void        SetExpansion(const OUString& rStr);
77
78
    SwDBFieldSubType GetSubType() const;
79
    void SetSubType(SwDBFieldSubType nType);
80
81
    virtual OUString    GetFieldName() const override;
82
83
    /// For calculations in expressions.
84
    void                ChgValue( double d, bool bVal );
85
86
    /// Get the evaluation via DBManager string.
87
    void                Evaluate();
88
89
    /// Evaluation for header and footer.
90
    void                InitContent();
91
    void                InitContent(const OUString& rExpansion);
92
93
    inline void         ChgBodyTextFlag( bool bIsInBody );
94
95
4.94k
    bool         IsInitialized() const   { return m_bInitialized; }
96
0
    void         ClearInitialized()      { m_bInitialized = false; }
97
0
    void         SetInitialized()        { m_bInitialized = true; }
98
99
    /// Get name.
100
    virtual OUString    GetPar1() const override;
101
102
    /// access to the command string
103
0
    void                SetFieldCode(const OUString& rStr) { m_sFieldCode = rStr; }
104
105
    /// DBName
106
0
    const SwDBData&  GetDBData() const { return static_cast<SwDBFieldType*>(GetTyp())->GetDBData(); }
107
    virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
108
    virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
109
110
    static bool FormatValue( SvNumberFormatter const * pDocFormatter, OUString const &aString, sal_uInt32 nFormat,
111
                             double &aNumber, sal_Int32 nColumnType, SwDBField *pField = nullptr );
112
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
113
};
114
115
inline  void SwDBField::SetExpansion(const OUString& rStr)
116
727
    { m_aContent = rStr; }
117
118
/// set from UpdateExpFields (the Node-Position is known there)
119
inline void SwDBField::ChgBodyTextFlag( bool bIsInBody )
120
616
    { m_bIsInBodyText = bIsInBody; }
121
122
// Base class for all other database fields.
123
class SW_DLLPUBLIC SwDBNameInfField : public SwField
124
{
125
    SwDBData        m_aDBData;
126
    SwDBFieldSubType m_nSubType;
127
    sal_uInt32      m_nFormat;
128
129
protected:
130
0
    const SwDBData& GetDBData() const {return m_aDBData;}
131
0
    SwDBData&       GetDBData() {return m_aDBData;}
132
133
    SwDBNameInfField(SwFieldType* pTyp, SwDBData aDBData, sal_uInt32 nFormat = 0);
134
135
public:
136
0
    sal_uInt32 GetFormat() const { return m_nFormat; }
137
0
    void SetFormat(sal_uInt32 nFormat) { m_nFormat = nFormat; }
138
139
    /// DBName
140
0
    const SwDBData&  GetRealDBData() const { return m_aDBData; }
141
0
    SwDBData&        GetRealDBData() { return m_aDBData; }
142
143
    SwDBData                GetDBData(SwDoc* pDoc);
144
    void                    SetDBData(const SwDBData& rDBData);
145
146
    virtual OUString        GetFieldName() const override;
147
148
    virtual bool            QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
149
    virtual bool            PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
150
    SwDBFieldSubType        GetSubType() const;
151
    void                    SetSubType(SwDBFieldSubType nType);
152
};
153
154
// Database field next record.
155
class SW_DLLPUBLIC SwDBNextSetFieldType final : public SwFieldType
156
{
157
public:
158
    SwDBNextSetFieldType();
159
160
    virtual std::unique_ptr<SwFieldType> Copy() const override;
161
};
162
163
// Next data record with condition.
164
class SW_DLLPUBLIC SwDBNextSetField final : public SwDBNameInfField
165
{
166
    OUString  m_aCond;
167
    bool    m_bCondValid;
168
169
public:
170
    SwDBNextSetField( SwDBNextSetFieldType*,
171
                      OUString aCond, const SwDBData& rDBData);
172
173
    virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
174
    virtual std::unique_ptr<SwField> Copy() const override;
175
176
    void                    Evaluate(const SwDoc&);
177
    inline void             SetCondValid(bool bCond);
178
    inline bool             IsCondValid() const;
179
180
    // Condition
181
    virtual OUString    GetPar1() const override;
182
    virtual void        SetPar1(const OUString& rStr) override;
183
    virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
184
    virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
185
};
186
187
inline bool SwDBNextSetField::IsCondValid() const
188
0
    { return m_bCondValid; }
189
190
inline void SwDBNextSetField::SetCondValid(bool bCond)
191
0
    { m_bCondValid = bCond; }
192
193
// Database field next record.
194
class SwDBNumSetFieldType final : public SwFieldType
195
{
196
public:
197
    SwDBNumSetFieldType();
198
199
    virtual std::unique_ptr<SwFieldType> Copy() const override;
200
};
201
202
// Data record with number xxx.
203
// Number is in nFormat (bit of a misuse!)
204
class SwDBNumSetField final : public SwDBNameInfField
205
{
206
    OUString  m_aCond;
207
    OUString  m_aPar2;
208
    bool    m_bCondValid;
209
210
public:
211
    SwDBNumSetField(SwDBNumSetFieldType*, OUString aCond, OUString aDBNum, const SwDBData& rDBData);
212
213
    virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
214
    virtual std::unique_ptr<SwField> Copy() const override;
215
216
    inline bool             IsCondValid() const;
217
    inline void             SetCondValid(bool bCond);
218
    void                    Evaluate(const SwDoc&);
219
220
    // Condition
221
    virtual OUString        GetPar1() const override;
222
    virtual void            SetPar1(const OUString& rStr) override;
223
224
    // Number of data record.
225
    virtual OUString   GetPar2()   const override;
226
    virtual void            SetPar2(const OUString& rStr) override;
227
228
    // Number of data record is in nFormat!!
229
    virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
230
    virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
231
};
232
233
inline bool SwDBNumSetField::IsCondValid() const
234
0
    { return m_bCondValid; }
235
236
inline void SwDBNumSetField::SetCondValid(bool bCond)
237
0
    { m_bCondValid = bCond; }
238
239
// Database name.
240
class SwDBNameFieldType final : public SwFieldType
241
{
242
        SwDoc *m_pDoc;
243
public:
244
    SwDBNameFieldType(SwDoc*);
245
246
    OUString                Expand() const;
247
    virtual std::unique_ptr<SwFieldType> Copy() const override;
248
};
249
250
// Database field.
251
class SwDBNameField final : public SwDBNameInfField
252
{
253
public:
254
    SwDBNameField(SwDBNameFieldType*, const SwDBData& rDBData, sal_uInt32 nFormat = 0);
255
256
    virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
257
    virtual std::unique_ptr<SwField> Copy() const override;
258
    virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
259
    virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
260
};
261
262
// Number of data record.
263
class SW_DLLPUBLIC SwDBSetNumberFieldType final : public SwFieldType
264
{
265
public:
266
    SwDBSetNumberFieldType();
267
268
    virtual std::unique_ptr<SwFieldType> Copy() const override;
269
};
270
271
// Database field.
272
class SW_DLLPUBLIC SwDBSetNumberField final : public SwDBNameInfField
273
{
274
    tools::Long    m_nNumber;
275
public:
276
    SwDBSetNumberField(SwDBSetNumberFieldType*, const SwDBData& rDBData, sal_uInt32 nFormat = 0);
277
278
    virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
279
    virtual std::unique_ptr<SwField> Copy() const override;
280
    void            Evaluate(const SwDoc&);
281
282
    inline tools::Long     GetSetNumber() const;
283
    inline void     SetSetNumber(tools::Long nNum);
284
    virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
285
    virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
286
};
287
288
inline tools::Long SwDBSetNumberField::GetSetNumber() const
289
0
    { return m_nNumber; }
290
291
inline void SwDBSetNumberField::SetSetNumber(tools::Long nNum)
292
0
    { m_nNumber = nNum; }
293
294
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */