Line data Source code
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 :
21 : #include "TableFieldDescription.hxx"
22 : #include <tools/debug.hxx>
23 : #include <com/sun/star/sdbc/DataType.hpp>
24 : #include <comphelper/namedvaluecollection.hxx>
25 :
26 : #include <functional>
27 :
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;
33 :
34 : DBG_NAME(OTableFieldDesc)
35 : //==============================================================================
36 0 : OTableFieldDesc::OTableFieldDesc()
37 : :m_pTabWindow(0)
38 : ,m_eDataType(1000)
39 : ,m_eFunctionType( FKT_NONE )
40 : ,m_eFieldType(TAB_NORMAL_FIELD)
41 : ,m_eOrderDir( ORDER_NONE )
42 : ,m_nIndex(0)
43 : ,m_nColWidth(0)
44 : ,m_nColumnId((sal_uInt16)-1)
45 : ,m_bGroupBy(sal_False)
46 0 : ,m_bVisible(sal_False)
47 : {
48 : DBG_CTOR(OTableFieldDesc,NULL);
49 0 : }
50 : //------------------------------------------------------------------------------
51 0 : OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc& rRS)
52 0 : : ::salhelper::SimpleReferenceObject()
53 :
54 : {
55 : DBG_CTOR(OTableFieldDesc,NULL);
56 0 : *this = rRS;
57 0 : }
58 :
59 : //------------------------------------------------------------------------------
60 0 : OTableFieldDesc::OTableFieldDesc(const ::rtl::OUString& rT, const ::rtl::OUString& rF )
61 : :m_pTabWindow(0)
62 : ,m_eFunctionType( FKT_NONE )
63 : ,m_eOrderDir( ORDER_NONE )
64 : ,m_nColumnId((sal_uInt16)-1)
65 : ,m_bGroupBy(sal_False)
66 0 : ,m_bVisible(sal_False)
67 : {
68 : DBG_CTOR(OTableFieldDesc,NULL);
69 0 : SetField( rF ); SetTable( rT );
70 0 : }
71 :
72 : //------------------------------------------------------------------------------
73 0 : OTableFieldDesc::~OTableFieldDesc()
74 : {
75 : DBG_DTOR(OTableFieldDesc,NULL);
76 0 : }
77 : //------------------------------------------------------------------------------
78 0 : OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS )
79 : {
80 0 : if (&rRS == this)
81 0 : return *this;
82 :
83 0 : m_aCriteria = rRS.GetCriteria();
84 0 : m_aTableName = rRS.GetTable();
85 0 : m_aAliasName = rRS.GetAlias(); // table range
86 0 : m_aFieldName = rRS.GetField(); // column
87 0 : m_aFieldAlias = rRS.GetFieldAlias(); // column alias
88 0 : m_aFunctionName = rRS.GetFunction(); // Funktionsname
89 0 : m_pTabWindow = rRS.GetTabWindow();
90 0 : m_eDataType = rRS.GetDataType();
91 0 : m_eFunctionType = rRS.GetFunctionType();
92 0 : m_eFieldType = rRS.GetFieldType();
93 0 : m_eOrderDir = rRS.GetOrderDir();
94 0 : m_nIndex = rRS.GetFieldIndex();
95 0 : m_nColWidth = rRS.GetColWidth();
96 0 : m_nColumnId = rRS.m_nColumnId;
97 0 : m_bGroupBy = rRS.IsGroupBy();
98 0 : m_bVisible = rRS.IsVisible();
99 :
100 0 : return *this;
101 : }
102 : //------------------------------------------------------------------------------
103 0 : sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc )
104 : {
105 : DBG_CHKTHIS(OTableFieldDesc,NULL);
106 :
107 0 : return ( m_eOrderDir != rDesc.GetOrderDir() ||
108 0 : m_eDataType != rDesc.GetDataType() ||
109 0 : m_aAliasName != rDesc.GetAlias() ||
110 0 : m_aFunctionName != rDesc.GetFunction() ||
111 0 : m_aFieldName != rDesc.GetField() ||
112 0 : m_aTableName != rDesc.GetTable() ||
113 0 : m_bGroupBy != rDesc.IsGroupBy() ||
114 0 : m_aCriteria != rDesc.GetCriteria() ||
115 0 : m_bVisible != rDesc.IsVisible() );
116 :
117 : }
118 :
119 : //------------------------------------------------------------------------------
120 0 : void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const ::rtl::OUString& rCrit)
121 : {
122 : DBG_CHKTHIS(OTableFieldDesc,NULL);
123 0 : if (nIdx < m_aCriteria.size())
124 0 : m_aCriteria[nIdx] = rCrit;
125 : else
126 : {
127 0 : for(sal_Int32 i=m_aCriteria.size();i<nIdx;++i)
128 0 : m_aCriteria.push_back( ::rtl::OUString());
129 0 : m_aCriteria.push_back(rCrit);
130 : }
131 0 : }
132 :
133 : //------------------------------------------------------------------------------
134 0 : ::rtl::OUString OTableFieldDesc::GetCriteria( sal_uInt16 nIdx ) const
135 : {
136 : DBG_CHKTHIS(OTableFieldDesc,NULL);
137 0 : ::rtl::OUString aRetStr;
138 0 : if( nIdx < m_aCriteria.size())
139 0 : aRetStr = m_aCriteria[nIdx];
140 :
141 0 : return aRetStr;
142 : }
143 :
144 : // -----------------------------------------------------------------------------
145 : namespace
146 : {
147 : struct SelectPropertyValueAsString : public ::std::unary_function< PropertyValue, ::rtl::OUString >
148 : {
149 0 : ::rtl::OUString operator()( const PropertyValue& i_rPropValue ) const
150 : {
151 0 : ::rtl::OUString sValue;
152 0 : OSL_VERIFY( i_rPropValue.Value >>= sValue );
153 0 : return sValue;
154 : }
155 : };
156 : }
157 :
158 : // -----------------------------------------------------------------------------
159 0 : void OTableFieldDesc::Load( const ::com::sun::star::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria )
160 : {
161 : DBG_CHKTHIS(OTableFieldDesc,NULL);
162 :
163 0 : ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value );
164 0 : m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName );
165 0 : m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName );
166 0 : m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName );
167 0 : m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias );
168 0 : m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName );
169 0 : m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType );
170 0 : m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType );
171 0 : m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth );
172 0 : m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy );
173 0 : m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible );
174 :
175 0 : m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) );
176 0 : m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) );
177 :
178 0 : if ( i_bIncludingCriteria )
179 : {
180 0 : const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) );
181 0 : m_aCriteria.resize( aCriteria.getLength() );
182 : ::std::transform(
183 : aCriteria.getConstArray(),
184 0 : aCriteria.getConstArray() + aCriteria.getLength(),
185 : m_aCriteria.begin(),
186 : SelectPropertyValueAsString()
187 0 : );
188 0 : }
189 0 : }
190 : //------------------------------------------------------------------------------
191 0 : void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria )
192 : {
193 : DBG_CHKTHIS(OTableFieldDesc,NULL);
194 :
195 0 : o_rSettings.put( "AliasName", m_aAliasName );
196 0 : o_rSettings.put( "TableName", m_aTableName );
197 0 : o_rSettings.put( "FieldName", m_aFieldName );
198 0 : o_rSettings.put( "FieldAlias", m_aFieldAlias );
199 0 : o_rSettings.put( "FunctionName", m_aFunctionName );
200 0 : o_rSettings.put( "DataType", m_eDataType );
201 0 : o_rSettings.put( "FunctionType", (sal_Int32)m_eFunctionType );
202 0 : o_rSettings.put( "FieldType", (sal_Int32)m_eFieldType );
203 0 : o_rSettings.put( "OrderDir", (sal_Int32)m_eOrderDir );
204 0 : o_rSettings.put( "ColWidth", m_nColWidth );
205 0 : o_rSettings.put( "GroupBy", m_bGroupBy );
206 0 : o_rSettings.put( "Visible", m_bVisible );
207 :
208 0 : if ( i_bIncludingCriteria )
209 : {
210 0 : if ( !m_aCriteria.empty() )
211 : {
212 0 : sal_Int32 c = 0;
213 0 : Sequence< PropertyValue > aCriteria( m_aCriteria.size() );
214 0 : for ( ::std::vector< ::rtl::OUString >::const_iterator crit = m_aCriteria.begin();
215 0 : crit != m_aCriteria.end();
216 : ++crit, ++c
217 : )
218 : {
219 0 : aCriteria[c].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Criterion_" ) ) + ::rtl::OUString::valueOf( c );
220 0 : aCriteria[c].Value <<= *crit;
221 : }
222 :
223 0 : o_rSettings.put( "Criteria", aCriteria );
224 : }
225 : }
226 0 : }
227 : // -----------------------------------------------------------------------------
228 :
229 :
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|