1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "TableFieldDescription.hxx"
22 #include <tools/debug.hxx>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <comphelper/namedvaluecollection.hxx>
28 using namespace ::com::sun::star::sdbc
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::beans
;
31 using namespace comphelper
;
32 using namespace dbaui
;
34 DBG_NAME(OTableFieldDesc
)
35 //==============================================================================
36 OTableFieldDesc::OTableFieldDesc()
39 ,m_eFunctionType( FKT_NONE
)
40 ,m_eFieldType(TAB_NORMAL_FIELD
)
41 ,m_eOrderDir( ORDER_NONE
)
44 ,m_nColumnId((sal_uInt16
)-1)
45 ,m_bGroupBy(sal_False
)
46 ,m_bVisible(sal_False
)
48 DBG_CTOR(OTableFieldDesc
,NULL
);
50 //------------------------------------------------------------------------------
51 OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc
& rRS
)
52 : ::salhelper::SimpleReferenceObject()
55 DBG_CTOR(OTableFieldDesc
,NULL
);
59 //------------------------------------------------------------------------------
60 OTableFieldDesc::OTableFieldDesc(const OUString
& rT
, const OUString
& rF
)
62 ,m_eFunctionType( FKT_NONE
)
63 ,m_eOrderDir( ORDER_NONE
)
64 ,m_nColumnId((sal_uInt16
)-1)
65 ,m_bGroupBy(sal_False
)
66 ,m_bVisible(sal_False
)
68 DBG_CTOR(OTableFieldDesc
,NULL
);
69 SetField( rF
); SetTable( rT
);
72 //------------------------------------------------------------------------------
73 OTableFieldDesc::~OTableFieldDesc()
75 DBG_DTOR(OTableFieldDesc
,NULL
);
77 //------------------------------------------------------------------------------
78 OTableFieldDesc
& OTableFieldDesc::operator=( const OTableFieldDesc
& rRS
)
83 m_aCriteria
= rRS
.GetCriteria();
84 m_aTableName
= rRS
.GetTable();
85 m_aAliasName
= rRS
.GetAlias(); // table range
86 m_aFieldName
= rRS
.GetField(); // column
87 m_aFieldAlias
= rRS
.GetFieldAlias(); // column alias
88 m_aFunctionName
= rRS
.GetFunction(); // Funktionsname
89 m_pTabWindow
= rRS
.GetTabWindow();
90 m_eDataType
= rRS
.GetDataType();
91 m_eFunctionType
= rRS
.GetFunctionType();
92 m_eFieldType
= rRS
.GetFieldType();
93 m_eOrderDir
= rRS
.GetOrderDir();
94 m_nIndex
= rRS
.GetFieldIndex();
95 m_nColWidth
= rRS
.GetColWidth();
96 m_nColumnId
= rRS
.m_nColumnId
;
97 m_bGroupBy
= rRS
.IsGroupBy();
98 m_bVisible
= rRS
.IsVisible();
102 //------------------------------------------------------------------------------
103 sal_Bool
OTableFieldDesc::operator==( const OTableFieldDesc
& rDesc
)
105 DBG_CHKTHIS(OTableFieldDesc
,NULL
);
107 return ( m_eOrderDir
!= rDesc
.GetOrderDir() ||
108 m_eDataType
!= rDesc
.GetDataType() ||
109 m_aAliasName
!= rDesc
.GetAlias() ||
110 m_aFunctionName
!= rDesc
.GetFunction() ||
111 m_aFieldName
!= rDesc
.GetField() ||
112 m_aTableName
!= rDesc
.GetTable() ||
113 m_bGroupBy
!= rDesc
.IsGroupBy() ||
114 m_aCriteria
!= rDesc
.GetCriteria() ||
115 m_bVisible
!= rDesc
.IsVisible() );
119 //------------------------------------------------------------------------------
120 void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx
, const OUString
& rCrit
)
122 DBG_CHKTHIS(OTableFieldDesc
,NULL
);
123 if (nIdx
< m_aCriteria
.size())
124 m_aCriteria
[nIdx
] = rCrit
;
127 for(sal_Int32 i
=m_aCriteria
.size();i
<nIdx
;++i
)
128 m_aCriteria
.push_back( OUString());
129 m_aCriteria
.push_back(rCrit
);
133 //------------------------------------------------------------------------------
134 OUString
OTableFieldDesc::GetCriteria( sal_uInt16 nIdx
) const
136 DBG_CHKTHIS(OTableFieldDesc
,NULL
);
138 if( nIdx
< m_aCriteria
.size())
139 aRetStr
= m_aCriteria
[nIdx
];
144 // -----------------------------------------------------------------------------
147 struct SelectPropertyValueAsString
: public ::std::unary_function
< PropertyValue
, OUString
>
149 OUString
operator()( const PropertyValue
& i_rPropValue
) const
152 OSL_VERIFY( i_rPropValue
.Value
>>= sValue
);
158 // -----------------------------------------------------------------------------
159 void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue
& i_rSettings
, const bool i_bIncludingCriteria
)
161 DBG_CHKTHIS(OTableFieldDesc
,NULL
);
163 ::comphelper::NamedValueCollection
aFieldDesc( i_rSettings
.Value
);
164 m_aAliasName
= aFieldDesc
.getOrDefault( "AliasName", m_aAliasName
);
165 m_aTableName
= aFieldDesc
.getOrDefault( "TableName", m_aTableName
);
166 m_aFieldName
= aFieldDesc
.getOrDefault( "FieldName", m_aFieldName
);
167 m_aFieldAlias
= aFieldDesc
.getOrDefault( "FieldAlias", m_aFieldAlias
);
168 m_aFunctionName
= aFieldDesc
.getOrDefault( "FunctionName", m_aFunctionName
);
169 m_eDataType
= aFieldDesc
.getOrDefault( "DataType", m_eDataType
);
170 m_eFunctionType
= aFieldDesc
.getOrDefault( "FunctionType", m_eFunctionType
);
171 m_nColWidth
= aFieldDesc
.getOrDefault( "ColWidth", m_nColWidth
);
172 m_bGroupBy
= aFieldDesc
.getOrDefault( "GroupBy", m_bGroupBy
);
173 m_bVisible
= aFieldDesc
.getOrDefault( "Visible", m_bVisible
);
175 m_eFieldType
= static_cast< ETableFieldType
>( aFieldDesc
.getOrDefault( "FieldType", static_cast< sal_Int32
>( m_eFieldType
) ) );
176 m_eOrderDir
= static_cast< EOrderDir
>( aFieldDesc
.getOrDefault( "OrderDir", static_cast< sal_Int32
>( m_eOrderDir
) ) );
178 if ( i_bIncludingCriteria
)
180 const Sequence
< PropertyValue
> aCriteria( aFieldDesc
.getOrDefault( "Criteria", Sequence
< PropertyValue
>() ) );
181 m_aCriteria
.resize( aCriteria
.getLength() );
183 aCriteria
.getConstArray(),
184 aCriteria
.getConstArray() + aCriteria
.getLength(),
186 SelectPropertyValueAsString()
190 //------------------------------------------------------------------------------
191 void OTableFieldDesc::Save( ::comphelper::NamedValueCollection
& o_rSettings
, const bool i_bIncludingCriteria
)
193 DBG_CHKTHIS(OTableFieldDesc
,NULL
);
195 o_rSettings
.put( "AliasName", m_aAliasName
);
196 o_rSettings
.put( "TableName", m_aTableName
);
197 o_rSettings
.put( "FieldName", m_aFieldName
);
198 o_rSettings
.put( "FieldAlias", m_aFieldAlias
);
199 o_rSettings
.put( "FunctionName", m_aFunctionName
);
200 o_rSettings
.put( "DataType", m_eDataType
);
201 o_rSettings
.put( "FunctionType", (sal_Int32
)m_eFunctionType
);
202 o_rSettings
.put( "FieldType", (sal_Int32
)m_eFieldType
);
203 o_rSettings
.put( "OrderDir", (sal_Int32
)m_eOrderDir
);
204 o_rSettings
.put( "ColWidth", m_nColWidth
);
205 o_rSettings
.put( "GroupBy", m_bGroupBy
);
206 o_rSettings
.put( "Visible", m_bVisible
);
208 if ( i_bIncludingCriteria
)
210 if ( !m_aCriteria
.empty() )
213 Sequence
< PropertyValue
> aCriteria( m_aCriteria
.size() );
214 for ( ::std::vector
< OUString
>::const_iterator crit
= m_aCriteria
.begin();
215 crit
!= m_aCriteria
.end();
219 aCriteria
[c
].Name
= OUString( "Criterion_" ) + OUString::valueOf( c
);
220 aCriteria
[c
].Value
<<= *crit
;
223 o_rSettings
.put( "Criteria", aCriteria
);
227 // -----------------------------------------------------------------------------
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */