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 .
20 #include "TableFieldDescription.hxx"
22 #include <osl/diagnose.h>
23 #include <tools/debug.hxx>
24 #include <com/sun/star/sdbc/DataType.hpp>
25 #include <comphelper/namedvaluecollection.hxx>
26 #include <vcl/window.hxx>
30 using namespace ::com::sun::star::sdbc
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace comphelper
;
34 using namespace dbaui
;
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)
50 OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc
& rRS
)
51 : ::salhelper::SimpleReferenceObject()
57 OTableFieldDesc::OTableFieldDesc(const OUString
& rT
, const OUString
& rF
)
60 ,m_eFunctionType( FKT_NONE
)
61 ,m_eFieldType(TAB_NORMAL_FIELD
)
62 ,m_eOrderDir( ORDER_NONE
)
65 ,m_nColumnId((sal_uInt16
)-1)
69 SetField( rF
); SetTable( rT
);
72 OTableFieldDesc::~OTableFieldDesc()
76 OTableFieldDesc
& OTableFieldDesc::operator=( const OTableFieldDesc
& rRS
)
81 m_aCriteria
= rRS
.GetCriteria();
82 m_aTableName
= rRS
.GetTable();
83 m_aAliasName
= rRS
.GetAlias(); // table range
84 m_aFieldName
= rRS
.GetField(); // column
85 m_aFieldAlias
= rRS
.GetFieldAlias(); // column alias
86 m_aFunctionName
= rRS
.GetFunction(); // Funktionsname
87 m_pTabWindow
= rRS
.GetTabWindow();
88 m_eDataType
= rRS
.GetDataType();
89 m_eFunctionType
= rRS
.GetFunctionType();
90 m_eFieldType
= rRS
.GetFieldType();
91 m_eOrderDir
= rRS
.GetOrderDir();
92 m_nIndex
= rRS
.GetFieldIndex();
93 m_nColWidth
= rRS
.GetColWidth();
94 m_nColumnId
= rRS
.m_nColumnId
;
95 m_bGroupBy
= rRS
.IsGroupBy();
96 m_bVisible
= rRS
.IsVisible();
101 bool OTableFieldDesc::operator==( const OTableFieldDesc
& rDesc
)
104 return ( m_eOrderDir
!= rDesc
.GetOrderDir() ||
105 m_eDataType
!= rDesc
.GetDataType() ||
106 m_aAliasName
!= rDesc
.GetAlias() ||
107 m_aFunctionName
!= rDesc
.GetFunction() ||
108 m_aFieldName
!= rDesc
.GetField() ||
109 m_aTableName
!= rDesc
.GetTable() ||
110 m_bGroupBy
!= rDesc
.IsGroupBy() ||
111 m_aCriteria
!= rDesc
.GetCriteria() ||
112 m_bVisible
!= rDesc
.IsVisible() );
116 void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx
, const OUString
& rCrit
)
118 if (nIdx
< m_aCriteria
.size())
119 m_aCriteria
[nIdx
] = rCrit
;
122 for(sal_Int32 i
=m_aCriteria
.size();i
<nIdx
;++i
)
123 m_aCriteria
.push_back( OUString());
124 m_aCriteria
.push_back(rCrit
);
128 OUString
OTableFieldDesc::GetCriteria( sal_uInt16 nIdx
) const
131 if( nIdx
< m_aCriteria
.size())
132 aRetStr
= m_aCriteria
[nIdx
];
139 struct SelectPropertyValueAsString
: public ::std::unary_function
< PropertyValue
, OUString
>
141 OUString
operator()( const PropertyValue
& i_rPropValue
) const
144 OSL_VERIFY( i_rPropValue
.Value
>>= sValue
);
150 void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue
& i_rSettings
, const bool i_bIncludingCriteria
)
153 ::comphelper::NamedValueCollection
aFieldDesc( i_rSettings
.Value
);
154 m_aAliasName
= aFieldDesc
.getOrDefault( "AliasName", m_aAliasName
);
155 m_aTableName
= aFieldDesc
.getOrDefault( "TableName", m_aTableName
);
156 m_aFieldName
= aFieldDesc
.getOrDefault( "FieldName", m_aFieldName
);
157 m_aFieldAlias
= aFieldDesc
.getOrDefault( "FieldAlias", m_aFieldAlias
);
158 m_aFunctionName
= aFieldDesc
.getOrDefault( "FunctionName", m_aFunctionName
);
159 m_eDataType
= aFieldDesc
.getOrDefault( "DataType", m_eDataType
);
160 m_eFunctionType
= aFieldDesc
.getOrDefault( "FunctionType", m_eFunctionType
);
161 m_nColWidth
= aFieldDesc
.getOrDefault( "ColWidth", m_nColWidth
);
162 m_bGroupBy
= aFieldDesc
.getOrDefault( "GroupBy", m_bGroupBy
);
163 m_bVisible
= aFieldDesc
.getOrDefault( "Visible", m_bVisible
);
165 m_eFieldType
= static_cast< ETableFieldType
>( aFieldDesc
.getOrDefault( "FieldType", static_cast< sal_Int32
>( m_eFieldType
) ) );
166 m_eOrderDir
= static_cast< EOrderDir
>( aFieldDesc
.getOrDefault( "OrderDir", static_cast< sal_Int32
>( m_eOrderDir
) ) );
168 if ( i_bIncludingCriteria
)
170 const Sequence
< PropertyValue
> aCriteria( aFieldDesc
.getOrDefault( "Criteria", Sequence
< PropertyValue
>() ) );
171 m_aCriteria
.resize( aCriteria
.getLength() );
173 aCriteria
.getConstArray(),
174 aCriteria
.getConstArray() + aCriteria
.getLength(),
176 SelectPropertyValueAsString()
181 void OTableFieldDesc::Save( ::comphelper::NamedValueCollection
& o_rSettings
, const bool i_bIncludingCriteria
)
184 o_rSettings
.put( "AliasName", m_aAliasName
);
185 o_rSettings
.put( "TableName", m_aTableName
);
186 o_rSettings
.put( "FieldName", m_aFieldName
);
187 o_rSettings
.put( "FieldAlias", m_aFieldAlias
);
188 o_rSettings
.put( "FunctionName", m_aFunctionName
);
189 o_rSettings
.put( "DataType", m_eDataType
);
190 o_rSettings
.put( "FunctionType", (sal_Int32
)m_eFunctionType
);
191 o_rSettings
.put( "FieldType", (sal_Int32
)m_eFieldType
);
192 o_rSettings
.put( "OrderDir", (sal_Int32
)m_eOrderDir
);
193 o_rSettings
.put( "ColWidth", m_nColWidth
);
194 o_rSettings
.put( "GroupBy", m_bGroupBy
);
195 o_rSettings
.put( "Visible", m_bVisible
);
197 if ( i_bIncludingCriteria
)
199 if ( !m_aCriteria
.empty() )
202 Sequence
< PropertyValue
> aCriteria( m_aCriteria
.size() );
203 for ( ::std::vector
< OUString
>::const_iterator crit
= m_aCriteria
.begin();
204 crit
!= m_aCriteria
.end();
208 aCriteria
[c
].Name
= "Criterion_" + OUString::number( c
);
209 aCriteria
[c
].Value
<<= *crit
;
212 o_rSettings
.put( "Criteria", aCriteria
);
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */