calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableFieldDescription.cxx
blob1e86041818861e767aa1a6813825a5bd39858830
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 <com/sun/star/sdbc/DataType.hpp>
24 #include <comphelper/namedvaluecollection.hxx>
26 using namespace ::com::sun::star::sdbc;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::beans;
29 using namespace comphelper;
30 using namespace dbaui;
32 OTableFieldDesc::OTableFieldDesc()
33 :m_pTabWindow(nullptr)
34 ,m_eDataType(1000)
35 ,m_eFunctionType( FKT_NONE )
36 ,m_eFieldType(TAB_NORMAL_FIELD)
37 ,m_eOrderDir( ORDER_NONE )
38 ,m_nIndex(0)
39 ,m_nColWidth(0)
40 ,m_nColumnId(sal_uInt16(-1))
41 ,m_bGroupBy(false)
42 ,m_bVisible(false)
46 OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc& rRS)
47 : ::salhelper::SimpleReferenceObject()
48 , m_pTabWindow(nullptr)
50 *this = rRS;
53 OTableFieldDesc::OTableFieldDesc(const OUString& rT, const OUString& rF )
54 :m_pTabWindow(nullptr)
55 ,m_eDataType(1000)
56 ,m_eFunctionType( FKT_NONE )
57 ,m_eFieldType(TAB_NORMAL_FIELD)
58 ,m_eOrderDir( ORDER_NONE )
59 ,m_nIndex(0)
60 ,m_nColWidth(0)
61 ,m_nColumnId(sal_uInt16(-1))
62 ,m_bGroupBy(false)
63 ,m_bVisible(false)
65 SetField( rF ); SetTable( rT );
68 OTableFieldDesc::~OTableFieldDesc()
72 OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS )
74 if (&rRS == this)
75 return *this;
77 m_aCriteria = rRS.GetCriteria();
78 m_aTableName = rRS.GetTable();
79 m_aAliasName = rRS.GetAlias(); // table range
80 m_aFieldName = rRS.GetField(); // column
81 m_aFieldAlias = rRS.GetFieldAlias(); // column alias
82 m_aFunctionName = rRS.GetFunction();
83 m_pTabWindow = rRS.GetTabWindow();
84 m_eDataType = rRS.GetDataType();
85 m_eFunctionType = rRS.GetFunctionType();
86 m_eFieldType = rRS.GetFieldType();
87 m_eOrderDir = rRS.GetOrderDir();
88 m_nIndex = rRS.GetFieldIndex();
89 m_nColWidth = rRS.GetColWidth();
90 m_nColumnId = rRS.m_nColumnId;
91 m_bGroupBy = rRS.IsGroupBy();
92 m_bVisible = rRS.IsVisible();
94 return *this;
97 void OTableFieldDesc::SetCriteria( sal_uInt16 nIdx, const OUString& rCrit)
99 if (nIdx < m_aCriteria.size())
100 m_aCriteria[nIdx] = rCrit;
101 else
103 m_aCriteria.insert(m_aCriteria.end(), nIdx - m_aCriteria.size(), OUString());
104 m_aCriteria.push_back(rCrit);
108 OUString OTableFieldDesc::GetCriteria( sal_uInt16 nIdx ) const
110 OUString aRetStr;
111 if( nIdx < m_aCriteria.size())
112 aRetStr = m_aCriteria[nIdx];
114 return aRetStr;
117 namespace
119 struct SelectPropertyValueAsString
121 OUString operator()( const PropertyValue& i_rPropValue ) const
123 OUString sValue;
124 OSL_VERIFY( i_rPropValue.Value >>= sValue );
125 return sValue;
130 void OTableFieldDesc::Load( const css::beans::PropertyValue& i_rSettings, const bool i_bIncludingCriteria )
133 ::comphelper::NamedValueCollection aFieldDesc( i_rSettings.Value );
134 m_aAliasName = aFieldDesc.getOrDefault( "AliasName", m_aAliasName );
135 m_aTableName = aFieldDesc.getOrDefault( "TableName", m_aTableName );
136 m_aFieldName = aFieldDesc.getOrDefault( "FieldName", m_aFieldName );
137 m_aFieldAlias = aFieldDesc.getOrDefault( "FieldAlias", m_aFieldAlias );
138 m_aFunctionName = aFieldDesc.getOrDefault( "FunctionName", m_aFunctionName );
139 m_eDataType = aFieldDesc.getOrDefault( "DataType", m_eDataType );
140 m_eFunctionType = aFieldDesc.getOrDefault( "FunctionType", m_eFunctionType );
141 m_nColWidth = aFieldDesc.getOrDefault( "ColWidth", m_nColWidth );
142 m_bGroupBy = aFieldDesc.getOrDefault( "GroupBy", m_bGroupBy );
143 m_bVisible = aFieldDesc.getOrDefault( "Visible", m_bVisible );
145 m_eFieldType = static_cast< ETableFieldType >( aFieldDesc.getOrDefault( "FieldType", static_cast< sal_Int32 >( m_eFieldType ) ) );
146 m_eOrderDir = static_cast< EOrderDir >( aFieldDesc.getOrDefault( "OrderDir", static_cast< sal_Int32 >( m_eOrderDir ) ) );
148 if ( i_bIncludingCriteria )
150 const Sequence< PropertyValue > aCriteria( aFieldDesc.getOrDefault( "Criteria", Sequence< PropertyValue >() ) );
151 m_aCriteria.resize( aCriteria.getLength() );
152 std::transform(
153 aCriteria.begin(),
154 aCriteria.end(),
155 m_aCriteria.begin(),
156 SelectPropertyValueAsString()
161 void OTableFieldDesc::Save( ::comphelper::NamedValueCollection& o_rSettings, const bool i_bIncludingCriteria )
164 o_rSettings.put( "AliasName", m_aAliasName );
165 o_rSettings.put( "TableName", m_aTableName );
166 o_rSettings.put( "FieldName", m_aFieldName );
167 o_rSettings.put( "FieldAlias", m_aFieldAlias );
168 o_rSettings.put( "FunctionName", m_aFunctionName );
169 o_rSettings.put( "DataType", m_eDataType );
170 o_rSettings.put( "FunctionType", m_eFunctionType );
171 o_rSettings.put( "FieldType", static_cast<sal_Int32>(m_eFieldType) );
172 o_rSettings.put( "OrderDir", static_cast<sal_Int32>(m_eOrderDir) );
173 o_rSettings.put( "ColWidth", m_nColWidth );
174 o_rSettings.put( "GroupBy", m_bGroupBy );
175 o_rSettings.put( "Visible", m_bVisible );
177 if ( !i_bIncludingCriteria )
178 return;
180 if ( m_aCriteria.empty() )
181 return;
183 sal_Int32 c = 0;
184 Sequence< PropertyValue > aCriteria( m_aCriteria.size() );
185 auto pCriteria = aCriteria.getArray();
186 for (auto const& criteria : m_aCriteria)
188 pCriteria[c].Name = "Criterion_" + OUString::number( c );
189 pCriteria[c].Value <<= criteria;
190 ++c;
193 o_rSettings.put( "Criteria", aCriteria );
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */