Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableFieldDescription.cxx
blobc9d755d8b26f2e898652886c4d759c618aa0d398
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
28 #include <functional>
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()
37 :m_pTabWindow(nullptr)
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 ,m_bVisible(false)
50 OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc& rRS)
51 : ::salhelper::SimpleReferenceObject()
52 , m_pTabWindow(nullptr)
54 *this = rRS;
57 OTableFieldDesc::OTableFieldDesc(const OUString& rT, const OUString& rF )
58 :m_pTabWindow(nullptr)
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 ,m_bVisible(false)
69 SetField( rF ); SetTable( rT );
72 OTableFieldDesc::~OTableFieldDesc()
76 OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS )
78 if (&rRS == this)
79 return *this;
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();
98 return *this;
101 void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const OUString& rCrit)
103 if (nIdx < m_aCriteria.size())
104 m_aCriteria[nIdx] = rCrit;
105 else
107 for(sal_Int32 i=m_aCriteria.size();i<nIdx;++i)
108 m_aCriteria.push_back( OUString());
109 m_aCriteria.push_back(rCrit);
113 OUString OTableFieldDesc::GetCriteria( sal_uInt16 nIdx ) const
115 OUString aRetStr;
116 if( nIdx < m_aCriteria.size())
117 aRetStr = m_aCriteria[nIdx];
119 return aRetStr;
122 namespace
124 struct SelectPropertyValueAsString : public ::std::unary_function< PropertyValue, OUString >
126 OUString operator()( const PropertyValue& i_rPropValue ) const
128 OUString sValue;
129 OSL_VERIFY( i_rPropValue.Value >>= sValue );
130 return sValue;
135 void OTableFieldDesc::Load( const css::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria )
138 ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value );
139 m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName );
140 m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName );
141 m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName );
142 m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias );
143 m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName );
144 m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType );
145 m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType );
146 m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth );
147 m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy );
148 m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible );
150 m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) );
151 m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) );
153 if ( i_bIncludingCriteria )
155 const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) );
156 m_aCriteria.resize( aCriteria.getLength() );
157 ::std::transform(
158 aCriteria.getConstArray(),
159 aCriteria.getConstArray() + aCriteria.getLength(),
160 m_aCriteria.begin(),
161 SelectPropertyValueAsString()
166 void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria )
169 o_rSettings.put( "AliasName", m_aAliasName );
170 o_rSettings.put( "TableName", m_aTableName );
171 o_rSettings.put( "FieldName", m_aFieldName );
172 o_rSettings.put( "FieldAlias", m_aFieldAlias );
173 o_rSettings.put( "FunctionName", m_aFunctionName );
174 o_rSettings.put( "DataType", m_eDataType );
175 o_rSettings.put( "FunctionType", (sal_Int32)m_eFunctionType );
176 o_rSettings.put( "FieldType", (sal_Int32)m_eFieldType );
177 o_rSettings.put( "OrderDir", (sal_Int32)m_eOrderDir );
178 o_rSettings.put( "ColWidth", m_nColWidth );
179 o_rSettings.put( "GroupBy", m_bGroupBy );
180 o_rSettings.put( "Visible", m_bVisible );
182 if ( i_bIncludingCriteria )
184 if ( !m_aCriteria.empty() )
186 sal_Int32 c = 0;
187 Sequence< PropertyValue > aCriteria( m_aCriteria.size() );
188 for ( ::std::vector< OUString >::const_iterator crit = m_aCriteria.begin();
189 crit != m_aCriteria.end();
190 ++crit, ++c
193 aCriteria[c].Name = "Criterion_" + OUString::number( c );
194 aCriteria[c].Value <<= *crit;
197 o_rSettings.put( "Criteria", aCriteria );
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */