LibreOffice Module dbaccess (master) 1
TableFieldDescription.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
21
22#include <osl/diagnose.h>
23#include <com/sun/star/sdbc/DataType.hpp>
25
26using namespace ::com::sun::star::sdbc;
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::beans;
29using namespace comphelper;
30using namespace dbaui;
31
32OTableFieldDesc::OTableFieldDesc()
33 :m_pTabWindow(nullptr)
34 ,m_eDataType(1000)
35 ,m_eFunctionType( FKT_NONE )
36 ,m_eFieldType(TAB_NORMAL_FIELD)
37 ,m_eOrderDir( ORDER_NONE )
38 ,m_nIndex(0)
39 ,m_nColWidth(0)
40 ,m_nColumnId(sal_uInt16(-1))
41 ,m_bGroupBy(false)
42 ,m_bVisible(false)
43{
44}
45
47 : ::salhelper::SimpleReferenceObject()
48 , m_pTabWindow(nullptr)
49{
50 *this = rRS;
51}
52
53OTableFieldDesc::OTableFieldDesc(const OUString& rT, const OUString& rF )
54 :m_pTabWindow(nullptr)
55 ,m_eDataType(1000)
56 ,m_eFunctionType( FKT_NONE )
57 ,m_eFieldType(TAB_NORMAL_FIELD)
58 ,m_eOrderDir( ORDER_NONE )
59 ,m_nIndex(0)
60 ,m_nColWidth(0)
61 ,m_nColumnId(sal_uInt16(-1))
62 ,m_bGroupBy(false)
63 ,m_bVisible(false)
64{
65 SetField( rF ); SetTable( rT );
66}
67
69{
70}
71
73{
74 if (&rRS == this)
75 return *this;
76
78 m_aTableName = rRS.GetTable();
79 m_aAliasName = rRS.GetAlias(); // table range
80 m_aFieldName = rRS.GetField(); // column
81 m_aFieldAlias = rRS.GetFieldAlias(); // column alias
88 m_nIndex = rRS.GetFieldIndex();
91 m_bGroupBy = rRS.IsGroupBy();
92 m_bVisible = rRS.IsVisible();
93
94 return *this;
95}
96
97void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const OUString& rCrit)
98{
99 if (nIdx < m_aCriteria.size())
100 m_aCriteria[nIdx] = rCrit;
101 else
102 {
103 m_aCriteria.insert(m_aCriteria.end(), nIdx - m_aCriteria.size(), OUString());
104 m_aCriteria.push_back(rCrit);
105 }
106}
107
108OUString OTableFieldDesc::GetCriteria( sal_uInt16 nIdx ) const
109{
110 OUString aRetStr;
111 if( nIdx < m_aCriteria.size())
112 aRetStr = m_aCriteria[nIdx];
113
114 return aRetStr;
115}
116
117namespace
118{
119 struct SelectPropertyValueAsString
120 {
121 OUString operator()( const PropertyValue& i_rPropValue ) const
122 {
123 OUString sValue;
124 OSL_VERIFY( i_rPropValue.Value >>= sValue );
125 return sValue;
126 }
127 };
128}
129
130void OTableFieldDesc::Load( const css::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria )
131{
132
133 ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value );
134 m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName );
135 m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName );
136 m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName );
137 m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias );
138 m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName );
139 m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType );
140 m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType );
141 m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth );
142 m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy );
143 m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible );
144
145 m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) );
146 m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) );
147
148 if ( i_bIncludingCriteria )
149 {
150 const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) );
151 m_aCriteria.resize( aCriteria.getLength() );
152 std::transform(
153 aCriteria.begin(),
154 aCriteria.end(),
155 m_aCriteria.begin(),
156 SelectPropertyValueAsString()
157 );
158 }
159}
160
161void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria )
162{
163
164 o_rSettings.put( "AliasName", m_aAliasName );
165 o_rSettings.put( "TableName", m_aTableName );
166 o_rSettings.put( "FieldName", m_aFieldName );
167 o_rSettings.put( "FieldAlias", m_aFieldAlias );
168 o_rSettings.put( "FunctionName", m_aFunctionName );
169 o_rSettings.put( "DataType", m_eDataType );
170 o_rSettings.put( "FunctionType", m_eFunctionType );
171 o_rSettings.put( "FieldType", static_cast<sal_Int32>(m_eFieldType) );
172 o_rSettings.put( "OrderDir", static_cast<sal_Int32>(m_eOrderDir) );
173 o_rSettings.put( "ColWidth", m_nColWidth );
174 o_rSettings.put( "GroupBy", m_bGroupBy );
175 o_rSettings.put( "Visible", m_bVisible );
176
177 if ( !i_bIncludingCriteria )
178 return;
179
180 if ( m_aCriteria.empty() )
181 return;
182
183 sal_Int32 c = 0;
184 Sequence< PropertyValue > aCriteria( m_aCriteria.size() );
185 auto pCriteria = aCriteria.getArray();
186 for (auto const& criteria : m_aCriteria)
187 {
188 pCriteria[c].Name = "Criterion_" + OUString::number( c );
189 pCriteria[c].Value <<= criteria;
190 ++c;
191 }
192
193 o_rSettings.put( "Criteria", aCriteria );
194}
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
const std::vector< OUString > & GetCriteria() const
std::vector< OUString > m_aCriteria
const OUString & GetAlias() const
vcl::Window * GetTabWindow() const
void Save(::comphelper::NamedValueCollection &o_rSettings, const bool i_bIncludingCriteria)
OUString m_aFieldAlias
column alias
void SetCriteria(sal_uInt16 nIdx, const OUString &rCrit)
const OUString & GetFieldAlias() const
virtual ~OTableFieldDesc() override
void Load(const css::beans::PropertyValue &i_rSettings, const bool i_bIncludingCriteria)
VclPtr< vcl::Window > m_pTabWindow
OTableFieldDesc & operator=(const OTableFieldDesc &_aField)
OUString m_aFunctionName
contains the function name (only if m_eFunctionType != FKT_NONE)
const OUString & GetFunction() const
ETableFieldType GetFieldType() const
const OUString & GetTable() const
void SetTable(const OUString &rT)
OUString m_aAliasName
table range
void SetField(const OUString &rF)
OUString GetCriteria(sal_uInt16 nIdx) const
const OUString & GetField() const
@ ORDER_NONE
Definition: QEnumTypes.hxx:25
@ FKT_NONE
Definition: QEnumTypes.hxx:32
ETableFieldType
Definition: QEnumTypes.hxx:48
@ TAB_NORMAL_FIELD
Definition: QEnumTypes.hxx:49