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